connection_to_host.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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.
  4. #ifndef REMOTING_PROTOCOL_CONNECTION_TO_HOST_H_
  5. #define REMOTING_PROTOCOL_CONNECTION_TO_HOST_H_
  6. #include <memory>
  7. #include <string>
  8. #include "base/memory/ref_counted.h"
  9. #include "base/memory/weak_ptr.h"
  10. #include "remoting/protocol/errors.h"
  11. namespace base {
  12. class SingleThreadTaskRunner;
  13. } // namespace base
  14. namespace remoting {
  15. namespace protocol {
  16. class AudioStub;
  17. class ClientStub;
  18. class ClipboardStub;
  19. class HostStub;
  20. class InputStub;
  21. class Session;
  22. class SessionConfig;
  23. class TransportContext;
  24. struct TransportRoute;
  25. class VideoRenderer;
  26. class ConnectionToHost {
  27. public:
  28. // The UI implementations maintain corresponding definitions of this
  29. // enumeration in client_session.js and
  30. // android/java/src/org/chromium/chromoting/jni/JniInterface.java. Be sure to
  31. // update these locations if you make any changes to the ordering.
  32. enum State {
  33. INITIALIZING,
  34. CONNECTING,
  35. AUTHENTICATED,
  36. CONNECTED,
  37. FAILED,
  38. CLOSED,
  39. };
  40. // Returns the literal string of |state|.
  41. static const char* StateToString(State state);
  42. class HostEventCallback {
  43. public:
  44. virtual ~HostEventCallback() {}
  45. // Called when state of the connection changes.
  46. virtual void OnConnectionState(State state, ErrorCode error) = 0;
  47. // Called when ready state of the connection changes. When |ready|
  48. // is set to false some data sent by the peers may be
  49. // delayed. This is used to indicate in the UI when connection is
  50. // temporarily broken.
  51. virtual void OnConnectionReady(bool ready) = 0;
  52. // Called when the route type (direct vs. STUN vs. proxied) changes.
  53. virtual void OnRouteChanged(const std::string& channel_name,
  54. const protocol::TransportRoute& route) = 0;
  55. };
  56. virtual ~ConnectionToHost() {}
  57. // Set the stubs which will handle messages from the host.
  58. // The caller must ensure that stubs out-live the connection.
  59. // Unless otherwise specified, all stubs must be set before Connect()
  60. // is called.
  61. virtual void set_client_stub(ClientStub* client_stub) = 0;
  62. virtual void set_clipboard_stub(ClipboardStub* clipboard_stub) = 0;
  63. virtual void set_video_renderer(VideoRenderer* video_renderer) = 0;
  64. // Initializes audio stream. Must be called before Connect().
  65. // |audio_decode_task_runner| will be used for audio decoding. |audio_stub|
  66. // will be called on the main thread.
  67. virtual void InitializeAudio(
  68. scoped_refptr<base::SingleThreadTaskRunner> audio_decode_task_runner,
  69. base::WeakPtr<AudioStub> audio_stub) = 0;
  70. // Initiates a connection using |session|. |event_callback| will be notified
  71. // of changes in the state of the connection and must outlive the
  72. // ConnectionToHost. Caller must set stubs (see below) before calling Connect.
  73. virtual void Connect(std::unique_ptr<Session> session,
  74. scoped_refptr<TransportContext> transport_context,
  75. HostEventCallback* event_callback) = 0;
  76. // Disconnects the host connection.
  77. virtual void Disconnect(ErrorCode error) = 0;
  78. // Returns the session configuration that was negotiated with the host.
  79. virtual const SessionConfig& config() = 0;
  80. // Stubs for sending data to the host.
  81. virtual ClipboardStub* clipboard_forwarder() = 0;
  82. virtual HostStub* host_stub() = 0;
  83. virtual InputStub* input_stub() = 0;
  84. // Return the current state of ConnectionToHost.
  85. virtual State state() const = 0;
  86. };
  87. } // namespace protocol
  88. } // namespace remoting
  89. #endif // REMOTING_PROTOCOL_CONNECTION_TO_HOST_H_