1 // Copyright 2014 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_SIGNALING_SIGNAL_STRATEGY_H_
6 #define REMOTING_SIGNALING_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
,
40 // Callback interface for signaling event. Event handlers are not
41 // allowed to destroy SignalStrategy, but may add or remove other
45 virtual ~Listener() {}
47 // Called after state of the connection has changed. If the state
48 // is DISCONNECTED, then GetError() can be used to get the reason
49 // for the disconnection.
50 virtual void OnSignalStrategyStateChange(State state
) = 0;
52 // Must return true if the stanza was handled, false
53 // otherwise. The signal strategy must not be deleted from a
54 // handler of this message.
55 virtual bool OnSignalStrategyIncomingStanza(
56 const buzz::XmlElement
* stanza
) = 0;
60 virtual ~SignalStrategy() {}
62 // Starts connection attempt. If connection is currently active
63 // disconnects it and opens a new connection (implicit disconnect
64 // triggers CLOSED notification). Connection is finished
66 virtual void Connect() = 0;
68 // Disconnects current connection if connected. Triggers CLOSED
70 virtual void Disconnect() = 0;
72 // Returns current state.
73 virtual State
GetState() const = 0;
75 // Returns the last error. Set when state changes to DISCONNECT.
76 virtual Error
GetError() const = 0;
78 // Returns local JID or an empty string when not connected.
79 virtual std::string
GetLocalJid() const = 0;
81 // Add a |listener| that can listen to all incoming
82 // messages. Doesn't take ownership of the |listener|. All listeners
83 // must be removed before this object is destroyed.
84 virtual void AddListener(Listener
* listener
) = 0;
86 // Remove a |listener| previously added with AddListener().
87 virtual void RemoveListener(Listener
* listener
) = 0;
89 // Sends a raw XMPP stanza.
90 virtual bool SendStanza(scoped_ptr
<buzz::XmlElement
> stanza
) = 0;
92 // Returns new ID that should be used for the next outgoing IQ
94 virtual std::string
GetNextId() = 0;
97 DISALLOW_COPY_AND_ASSIGN(SignalStrategy
);
100 } // namespace remoting
102 #endif // REMOTING_SIGNALING_SIGNAL_STRATEGY_H_