| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef REMOTING_JINGLE_GLUE_SIGNAL_STRATEGY_H_ | 5 #ifndef REMOTING_JINGLE_GLUE_SIGNAL_STRATEGY_H_ |
| 6 #define REMOTING_JINGLE_GLUE_SIGNAL_STRATEGY_H_ | 6 #define REMOTING_JINGLE_GLUE_SIGNAL_STRATEGY_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 | 11 |
| 12 namespace buzz { | 12 namespace buzz { |
| 13 class XmlElement; | 13 class XmlElement; |
| 14 } // namespace buzz | 14 } // namespace buzz |
| 15 | 15 |
| 16 namespace remoting { | 16 namespace remoting { |
| 17 | 17 |
| 18 class SignalStrategy { | 18 class SignalStrategy { |
| 19 public: | 19 public: |
| 20 class StatusObserver { | 20 enum State { |
| 21 public: | 21 // Connection is being established. |
| 22 enum State { | 22 CONNECTING, |
| 23 START, | |
| 24 CONNECTING, | |
| 25 CONNECTED, | |
| 26 CLOSED, | |
| 27 }; | |
| 28 | 23 |
| 29 // Called when state of the connection is changed. | 24 // Signalling is connected. |
| 30 virtual void OnStateChange(State state) = 0; | 25 CONNECTED, |
| 31 virtual void OnJidChange(const std::string& full_jid) = 0; | 26 |
| 27 // Connection is closed due to an error or because Disconnect() |
| 28 // was called. |
| 29 DISCONNECTED, |
| 32 }; | 30 }; |
| 33 | 31 |
| 32 // Callback interface for signaling event. Event handlers are not |
| 33 // allowed to destroy SignalStrategy, but may add or remove other |
| 34 // listeners. |
| 34 class Listener { | 35 class Listener { |
| 35 public: | 36 public: |
| 37 virtual ~Listener() {} |
| 38 |
| 39 // Called after state of the connection has changed. |
| 40 virtual void OnSignalStrategyStateChange(State state) {} |
| 41 |
| 36 // Must return true if the stanza was handled, false otherwise. | 42 // Must return true if the stanza was handled, false otherwise. |
| 37 virtual bool OnIncomingStanza(const buzz::XmlElement* stanza) = 0; | 43 virtual bool OnSignalStrategyIncomingStanza( |
| 44 const buzz::XmlElement* stanza) { return false; } |
| 38 }; | 45 }; |
| 39 | 46 |
| 40 SignalStrategy() {} | 47 SignalStrategy() {} |
| 41 virtual ~SignalStrategy() {} | 48 virtual ~SignalStrategy() {} |
| 42 virtual void Init(StatusObserver* observer) = 0; | 49 |
| 43 virtual void Close() = 0; | 50 // Starts connection attempt. If connection is currently active |
| 51 // disconnects it and opens a new connection (implicit disconnect |
| 52 // triggers CLOSED notification). Connection is finished |
| 53 // asynchronously. |
| 54 virtual void Connect() = 0; |
| 55 |
| 56 // Disconnects current connection if connected. Triggers CLOSED |
| 57 // notification. |
| 58 virtual void Disconnect() = 0; |
| 59 |
| 60 // Returns current state. |
| 61 virtual State GetState() const = 0; |
| 62 |
| 63 // Returns local JID or an empty string when not connected. |
| 64 virtual std::string GetLocalJid() const = 0; |
| 44 | 65 |
| 45 // Add a |listener| that can listen to all incoming | 66 // Add a |listener| that can listen to all incoming |
| 46 // messages. Doesn't take ownership of the |listener|. | 67 // messages. Doesn't take ownership of the |listener|. All listeners |
| 68 // must be removed before this object is destroyed. |
| 47 virtual void AddListener(Listener* listener) = 0; | 69 virtual void AddListener(Listener* listener) = 0; |
| 48 | 70 |
| 49 // Remove a |listener| previously added with AddListener(). | 71 // Remove a |listener| previously added with AddListener(). |
| 50 virtual void RemoveListener(Listener* listener) = 0; | 72 virtual void RemoveListener(Listener* listener) = 0; |
| 51 | 73 |
| 52 // Sends a raw XMPP stanza. Takes ownership of the |stanza|. | 74 // Sends a raw XMPP stanza. Takes ownership of the |stanza|. |
| 53 virtual bool SendStanza(buzz::XmlElement* stanza) = 0; | 75 virtual bool SendStanza(buzz::XmlElement* stanza) = 0; |
| 54 | 76 |
| 55 // Returns new ID that should be used for the next outgoing IQ | 77 // Returns new ID that should be used for the next outgoing IQ |
| 56 // request. | 78 // request. |
| 57 virtual std::string GetNextId() = 0; | 79 virtual std::string GetNextId() = 0; |
| 58 | 80 |
| 59 private: | 81 private: |
| 60 DISALLOW_COPY_AND_ASSIGN(SignalStrategy); | 82 DISALLOW_COPY_AND_ASSIGN(SignalStrategy); |
| 61 }; | 83 }; |
| 62 | 84 |
| 63 } // namespace remoting | 85 } // namespace remoting |
| 64 | 86 |
| 65 #endif // REMOTING_JINGLE_GLUE_SIGNAL_STRATEGY_H_ | 87 #endif // REMOTING_JINGLE_GLUE_SIGNAL_STRATEGY_H_ |
| OLD | NEW |