summaryrefslogtreecommitdiffstats
path: root/remoting/client/jingle_host_connection.h
blob: 96178aaec7ea41de3bbbbf612a77e821062b706f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// JingleHostConnection implements the HostConnection interface using
// libjingle as the transport protocol.
//
// Much of this class focuses on translating JingleClient and JingleChannel
// callbacks into HostConnection::HostEventCallback messages.
//
// The public API of this class is designed to be asynchronous, and thread
// safe for invocation from other threads.
//
// Internally though, all work delegeated to the |network_thread| given
// during construction.  Any event handlers running on the |network_thread|
// should not block.

#ifndef REMOTING_CLIENT_JINGLE_HOST_CONNECTION_H_
#define REMOTING_CLIENT_JINGLE_HOST_CONNECTION_H_

#include "base/ref_counted.h"
#include "base/scoped_ptr.h"
#include "base/task.h"
#include "remoting/base/protocol_decoder.h"
#include "remoting/client/host_connection.h"
#include "remoting/jingle_glue/jingle_channel.h"
#include "remoting/jingle_glue/jingle_client.h"

class MessageLoop;

namespace remoting {

class JingleThread;

class JingleHostConnection : public HostConnection,
                             public JingleChannel::Callback,
                             public JingleClient::Callback {
 public:
  explicit JingleHostConnection(JingleThread* network_thread);
  virtual ~JingleHostConnection();

  virtual void Connect(const std::string& username,
                       const std::string& auth_token,
                       const std::string& host_jid,
                       HostEventCallback* event_callback);
  virtual void Disconnect();

  // JingleChannel::Callback interface.
  virtual void OnStateChange(JingleChannel* channel,
                             JingleChannel::State state);
  virtual void OnPacketReceived(JingleChannel* channel,
                                scoped_refptr<media::DataBuffer> buffer);

  // JingleClient::Callback interface.
  virtual void OnStateChange(JingleClient* client, JingleClient::State state);
  virtual bool OnAcceptConnection(JingleClient* client, const std::string& jid,
                                  JingleChannel::Callback** callback);
  virtual void OnNewConnection(JingleClient* client,
                               scoped_refptr<JingleChannel> channel);

 private:
  MessageLoop* message_loop();

  void DoConnect(const std::string& username,
                 const std::string& auth_token,
                 const std::string& host_jid,
                 HostEventCallback* event_callback);
  void DoDisconnect();

  JingleThread* network_thread_;

  scoped_refptr<JingleClient> jingle_client_;
  scoped_refptr<JingleChannel> jingle_channel_;

  ProtocolDecoder decoder_;
  HostEventCallback* event_callback_;

  DISALLOW_COPY_AND_ASSIGN(JingleHostConnection);
};

}  // namespace remoting

DISABLE_RUNNABLE_METHOD_REFCOUNT(remoting::JingleHostConnection);

#endif  // REMOTING_CLIENT_JINGLE_HOST_CONNECTION_H_