1 // Copyright (c) 2012 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.
5 #ifndef REMOTING_JINGLE_GLUE_SIGNAL_STRATEGY_H_
6 #define REMOTING_JINGLE_GLUE_SIGNAL_STRATEGY_H_
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
19 class SignalStrategy
{
22 // Connection is being established.
25 // Signalling is connected.
28 // Connection is closed due to an error or because Disconnect()
35 AUTHENTICATION_FAILED
,
39 // Callback interface for signaling event. Event handlers are not
40 // allowed to destroy SignalStrategy, but may add or remove other
44 virtual ~Listener() {}
46 // Called after state of the connection has changed. If the state
47 // is DISCONNECTED, then GetError() can be used to get the reason
48 // for the disconnection.
49 virtual void OnSignalStrategyStateChange(State state
) = 0;
51 // Must return true if the stanza was handled, false
52 // otherwise. The signal strategy must not be deleted from a
53 // handler of this message.
54 virtual bool OnSignalStrategyIncomingStanza(
55 const buzz::XmlElement
* stanza
) = 0;
59 virtual ~SignalStrategy() {}
61 // Starts connection attempt. If connection is currently active
62 // disconnects it and opens a new connection (implicit disconnect
63 // triggers CLOSED notification). Connection is finished
65 virtual void Connect() = 0;
67 // Disconnects current connection if connected. Triggers CLOSED
69 virtual void Disconnect() = 0;
71 // Returns current state.
72 virtual State
GetState() const = 0;
74 // Returns the last error. Set when state changes to DISCONNECT.
75 virtual Error
GetError() const = 0;
77 // Returns local JID or an empty string when not connected.
78 virtual std::string
GetLocalJid() const = 0;
80 // Add a |listener| that can listen to all incoming
81 // messages. Doesn't take ownership of the |listener|. All listeners
82 // must be removed before this object is destroyed.
83 virtual void AddListener(Listener
* listener
) = 0;
85 // Remove a |listener| previously added with AddListener().
86 virtual void RemoveListener(Listener
* listener
) = 0;
88 // Sends a raw XMPP stanza.
89 virtual bool SendStanza(scoped_ptr
<buzz::XmlElement
> stanza
) = 0;
91 // Returns new ID that should be used for the next outgoing IQ
93 virtual std::string
GetNextId() = 0;
96 DISALLOW_COPY_AND_ASSIGN(SignalStrategy
);
99 } // namespace remoting
101 #endif // REMOTING_JINGLE_GLUE_SIGNAL_STRATEGY_H_