OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_PROTOCOL_CHANNEL_DISPATCHER_BASE_H_ | 5 #ifndef REMOTING_PROTOCOL_CHANNEL_DISPATCHER_BASE_H_ |
6 #define REMOTING_PROTOCOL_CHANNEL_DISPATCHER_BASE_H_ | 6 #define REMOTING_PROTOCOL_CHANNEL_DISPATCHER_BASE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "remoting/protocol/buffered_socket_writer.h" | 13 #include "remoting/protocol/buffered_socket_writer.h" |
14 #include "remoting/protocol/errors.h" | 14 #include "remoting/protocol/errors.h" |
15 #include "remoting/protocol/message_reader.h" | 15 #include "remoting/protocol/message_reader.h" |
| 16 #include "remoting/protocol/session_config.h" |
16 | 17 |
17 namespace net { | 18 namespace net { |
18 class StreamSocket; | 19 class StreamSocket; |
19 } // namespace net | 20 } // namespace net |
20 | 21 |
21 namespace remoting { | 22 namespace remoting { |
22 namespace protocol { | 23 namespace protocol { |
23 | 24 |
24 struct ChannelConfig; | |
25 class StreamChannelFactory; | 25 class StreamChannelFactory; |
26 class Session; | 26 class Session; |
27 | 27 |
28 // Base class for channel message dispatchers. It's responsible for | 28 // Base class for channel message dispatchers. It's responsible for |
29 // creating the named channel. Derived dispatchers then dispatch | 29 // creating the named channel. Derived dispatchers then dispatch |
30 // incoming messages on this channel as well as send outgoing | 30 // incoming messages on this channel as well as send outgoing |
31 // messages. | 31 // messages. |
32 class ChannelDispatcherBase { | 32 class ChannelDispatcherBase { |
33 public: | 33 public: |
34 class EventHandler { | 34 class EventHandler { |
(...skipping 20 matching lines...) Expand all Loading... |
55 EventHandler* event_handler); | 55 EventHandler* event_handler); |
56 | 56 |
57 const std::string& channel_name() { return channel_name_; } | 57 const std::string& channel_name() { return channel_name_; } |
58 | 58 |
59 // Returns true if the channel is currently connected. | 59 // Returns true if the channel is currently connected. |
60 bool is_connected() { return channel_ != nullptr; } | 60 bool is_connected() { return channel_ != nullptr; } |
61 | 61 |
62 protected: | 62 protected: |
63 explicit ChannelDispatcherBase(const char* channel_name); | 63 explicit ChannelDispatcherBase(const char* channel_name); |
64 | 64 |
| 65 // Calls event_handler_->OnChannelError() with the supplied |error|. |
| 66 void NotifyError(ErrorCode error); |
| 67 |
65 BufferedSocketWriter* writer() { return &writer_; } | 68 BufferedSocketWriter* writer() { return &writer_; } |
66 MessageReader* reader() { return &reader_; } | 69 MessageReader* reader() { return &reader_; } |
| 70 const ChannelConfig& channel_config() { return channel_config_; } |
67 | 71 |
68 private: | 72 private: |
69 void OnChannelReady(scoped_ptr<net::StreamSocket> socket); | 73 void OnChannelReady(scoped_ptr<net::StreamSocket> socket); |
70 void OnWriteFailed(int error); | 74 void OnWriteFailed(int error); |
71 | 75 |
72 std::string channel_name_; | 76 std::string channel_name_; |
73 StreamChannelFactory* channel_factory_; | 77 StreamChannelFactory* channel_factory_; |
| 78 ChannelConfig channel_config_; |
74 EventHandler* event_handler_; | 79 EventHandler* event_handler_; |
75 scoped_ptr<net::StreamSocket> channel_; | 80 scoped_ptr<net::StreamSocket> channel_; |
76 | 81 |
77 BufferedSocketWriter writer_; | 82 BufferedSocketWriter writer_; |
78 MessageReader reader_; | 83 MessageReader reader_; |
79 | 84 |
80 DISALLOW_COPY_AND_ASSIGN(ChannelDispatcherBase); | 85 DISALLOW_COPY_AND_ASSIGN(ChannelDispatcherBase); |
81 }; | 86 }; |
82 | 87 |
83 } // namespace protocol | 88 } // namespace protocol |
84 } // namespace remoting | 89 } // namespace remoting |
85 | 90 |
86 #endif // REMOTING_PROTOCOL_CHANNEL_DISPATCHER_BASE_H_ | 91 #endif // REMOTING_PROTOCOL_CHANNEL_DISPATCHER_BASE_H_ |
OLD | NEW |