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 13 matching lines...) Expand all Loading... | |
48 | 48 |
49 virtual ~ChannelDispatcherBase(); | 49 virtual ~ChannelDispatcherBase(); |
50 | 50 |
51 // Creates and connects the channel in the specified | 51 // Creates and connects the channel in the specified |
52 // |session|. Caller retains ownership of the Session. | 52 // |session|. Caller retains ownership of the Session. |
53 void Init(Session* session, | 53 void Init(Session* session, |
54 const ChannelConfig& config, | 54 const ChannelConfig& config, |
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 const ChannelConfig& channel_config() { return channel_config_; } | |
Wez
2015/01/21 01:35:38
Does this need to be public, or could it be protec
Sergey Ulanov
2015/01/29 01:33:28
Yes, it's better to make it protected. Done.
| |
58 | 59 |
59 // Returns true if the channel is currently connected. | 60 // Returns true if the channel is currently connected. |
60 bool is_connected() { return channel_ != nullptr; } | 61 bool is_connected() { return channel_ != nullptr; } |
61 | 62 |
62 protected: | 63 protected: |
63 explicit ChannelDispatcherBase(const char* channel_name); | 64 explicit ChannelDispatcherBase(const char* channel_name); |
64 | 65 |
66 void NotifyError(ErrorCode error); | |
Wez
2015/01/21 01:35:38
Do you need this, or could you just expose an even
Sergey Ulanov
2015/01/29 01:33:28
Yes, I think it's better to have this method inste
| |
67 | |
65 BufferedSocketWriter* writer() { return &writer_; } | 68 BufferedSocketWriter* writer() { return &writer_; } |
66 MessageReader* reader() { return &reader_; } | 69 MessageReader* reader() { return &reader_; } |
67 | 70 |
68 private: | 71 private: |
69 void OnChannelReady(scoped_ptr<net::StreamSocket> socket); | 72 void OnChannelReady(scoped_ptr<net::StreamSocket> socket); |
70 void OnWriteFailed(int error); | 73 void OnWriteFailed(int error); |
71 | 74 |
72 std::string channel_name_; | 75 std::string channel_name_; |
73 StreamChannelFactory* channel_factory_; | 76 StreamChannelFactory* channel_factory_; |
77 ChannelConfig channel_config_; | |
74 EventHandler* event_handler_; | 78 EventHandler* event_handler_; |
75 scoped_ptr<net::StreamSocket> channel_; | 79 scoped_ptr<net::StreamSocket> channel_; |
76 | 80 |
77 BufferedSocketWriter writer_; | 81 BufferedSocketWriter writer_; |
78 MessageReader reader_; | 82 MessageReader reader_; |
79 | 83 |
80 DISALLOW_COPY_AND_ASSIGN(ChannelDispatcherBase); | 84 DISALLOW_COPY_AND_ASSIGN(ChannelDispatcherBase); |
81 }; | 85 }; |
82 | 86 |
83 } // namespace protocol | 87 } // namespace protocol |
84 } // namespace remoting | 88 } // namespace remoting |
85 | 89 |
86 #endif // REMOTING_PROTOCOL_CHANNEL_DISPATCHER_BASE_H_ | 90 #endif // REMOTING_PROTOCOL_CHANNEL_DISPATCHER_BASE_H_ |
OLD | NEW |