OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef REMOTING_JINGLE_GLUE_JINGLE_CLIENT_H_ |
| 6 #define REMOTING_JINGLE_GLUE_JINGLE_CLIENT_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "remoting/jingle_glue/jingle_channel.h" |
| 11 #include "talk/xmpp/xmppclient.h" |
| 12 |
| 13 class MessageLoop; |
| 14 |
| 15 namespace talk_base { |
| 16 class NetworkManager; |
| 17 } // namespace talk_base |
| 18 |
| 19 namespace cricket { |
| 20 class BasicPortAllocator; |
| 21 class SessionManager; |
| 22 class TunnelSessionClient; |
| 23 class SessionManagerTask; |
| 24 class Session; |
| 25 } // namespace cricket |
| 26 |
| 27 namespace remoting { |
| 28 |
| 29 class JingleClient : public base::RefCountedThreadSafe<JingleClient>, |
| 30 public sigslot::has_slots<> { |
| 31 public: |
| 32 enum State { |
| 33 START, // Initial state. |
| 34 CONNECTING, |
| 35 CONNECTED, |
| 36 CLOSED, |
| 37 }; |
| 38 |
| 39 class Callback { |
| 40 public: |
| 41 virtual ~Callback() {} |
| 42 |
| 43 // Called when state of the connection is changed. |
| 44 virtual void OnStateChange(JingleClient* client, State state) = 0; |
| 45 |
| 46 // Called when a client attempts to connect to the machine. If the |
| 47 // connection should be accepted, must return true and must set |
| 48 // channel_callback to the callback for the new channel. |
| 49 virtual bool OnAcceptConnection( |
| 50 JingleClient* client, const std::string& jid, |
| 51 JingleChannel::Callback** channel_callback) = 0; |
| 52 |
| 53 // Called when a new client connects to the host. Ownership of the |channel| |
| 54 // is transfered to the callee. |
| 55 virtual void OnNewConnection(JingleClient* client, |
| 56 scoped_refptr<JingleChannel> channel) = 0; |
| 57 }; |
| 58 |
| 59 JingleClient(); |
| 60 virtual ~JingleClient(); |
| 61 |
| 62 // Starts jingle thread and XMPP connection inialization. Must be called |
| 63 // only once. message_loop() is guaranteed to exist after this method returns, |
| 64 // but the connection may not be open yet. |callback| specifies callback |
| 65 // object for the client and must not be NULL. |
| 66 // TODO(sergeyu): Replace password with a token. |
| 67 void Init(const std::string& username, const std::string& password, |
| 68 Callback* callback); |
| 69 |
| 70 // Creates new JingleChannel connected to the host with the specified jid. |
| 71 // The result is returned immediately but the channel fails if the host |
| 72 // rejects connection. |host_jid| must be a full jid (includes resource ID). |
| 73 // Ownership of the result is transfered to the caller. The channel must |
| 74 // be closed/destroyed before JingleClient is destroyed. |
| 75 JingleChannel* Connect(const std::string& host_jid, |
| 76 JingleChannel::Callback* callback); |
| 77 |
| 78 // Closes XMPP connection and stops the thread. Must be called before the |
| 79 // object is destroyed. |
| 80 void Close(); |
| 81 |
| 82 // Returns JID with resource ID. Empty string is returned if full JID is not |
| 83 // known yet, i.e. authentication hasn't finished. |
| 84 std::string GetFullJid(); |
| 85 |
| 86 // Current state of the client. |
| 87 State state() { return state_; } |
| 88 |
| 89 // Returns XmppClient object for the xmpp connection or NULL if not connected. |
| 90 buzz::XmppClient* xmpp_client() { return client_; } |
| 91 |
| 92 // Message loop for the jingle thread or NULL if the thread is not started. |
| 93 MessageLoop* message_loop(); |
| 94 |
| 95 private: |
| 96 // Used by Connect(). |
| 97 class ConnectRequest; |
| 98 |
| 99 void OnConnectionStateChanged(buzz::XmppEngine::State state); |
| 100 |
| 101 void OnIncomingTunnel(cricket::TunnelSessionClient* client, buzz::Jid jid, |
| 102 std::string description, cricket::Session* session); |
| 103 |
| 104 void DoInitialize(); |
| 105 |
| 106 // Used by Connect(). |
| 107 void DoConnect(ConnectRequest* request, |
| 108 const std::string& host_jid, |
| 109 JingleChannel::Callback* callback); |
| 110 |
| 111 // Used by Close(). |
| 112 void DoClose(); |
| 113 |
| 114 // Updates current state of the connection. Must be called only in |
| 115 // the jingle thread. |
| 116 void UpdateState(State new_state); |
| 117 |
| 118 buzz::XmppClient* client_; |
| 119 scoped_ptr<JingleThread> thread_; |
| 120 State state_; |
| 121 Callback* callback_; |
| 122 |
| 123 std::string username_; |
| 124 std::string password_; |
| 125 Lock full_jid_lock_; |
| 126 std::string full_jid_; |
| 127 |
| 128 scoped_ptr<talk_base::NetworkManager> network_manager_; |
| 129 scoped_ptr<cricket::BasicPortAllocator> port_allocator_; |
| 130 scoped_ptr<cricket::SessionManager> session_manager_; |
| 131 scoped_ptr<cricket::TunnelSessionClient> tunnel_session_client_; |
| 132 cricket::SessionManagerTask* receiver_; |
| 133 |
| 134 DISALLOW_COPY_AND_ASSIGN(JingleClient); |
| 135 }; |
| 136 |
| 137 } // namespace remoting |
| 138 |
| 139 #endif // REMOTING_JINGLE_GLUE_JINGLE_CLIENT_H_ |
OLD | NEW |