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/callback.h" | 10 #include "base/callback.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "remoting/base/buffered_socket_writer.h" | 13 #include "remoting/base/buffered_socket_writer.h" |
14 #include "remoting/protocol/errors.h" | 14 #include "remoting/protocol/errors.h" |
15 #include "remoting/protocol/message_reader.h" | |
16 | 15 |
17 namespace remoting { | 16 namespace remoting { |
| 17 |
| 18 class CompoundBuffer; |
| 19 |
18 namespace protocol { | 20 namespace protocol { |
19 | 21 |
| 22 class MessagePipe; |
| 23 class P2PStreamSocket; |
20 class StreamChannelFactory; | 24 class StreamChannelFactory; |
21 | 25 |
22 // Base class for channel message dispatchers. It's responsible for | 26 // Base class for channel message dispatchers. It's responsible for |
23 // creating the named channel. Derived dispatchers then dispatch | 27 // creating the named channel. Derived dispatchers then dispatch |
24 // incoming messages on this channel as well as send outgoing | 28 // incoming messages on this channel as well as send outgoing |
25 // messages. | 29 // messages. |
26 class ChannelDispatcherBase { | 30 class ChannelDispatcherBase { |
27 public: | 31 public: |
28 class EventHandler { | 32 class EventHandler { |
29 public: | 33 public: |
(...skipping 12 matching lines...) Expand all Loading... |
42 | 46 |
43 virtual ~ChannelDispatcherBase(); | 47 virtual ~ChannelDispatcherBase(); |
44 | 48 |
45 // Creates and connects the channel in the specified | 49 // Creates and connects the channel in the specified |
46 // |session|. Caller retains ownership of the Session. | 50 // |session|. Caller retains ownership of the Session. |
47 void Init(StreamChannelFactory* channel_factory, EventHandler* event_handler); | 51 void Init(StreamChannelFactory* channel_factory, EventHandler* event_handler); |
48 | 52 |
49 const std::string& channel_name() { return channel_name_; } | 53 const std::string& channel_name() { return channel_name_; } |
50 | 54 |
51 // Returns true if the channel is currently connected. | 55 // Returns true if the channel is currently connected. |
52 bool is_connected() { return channel_ != nullptr; } | 56 bool is_connected() { return message_pipe() != nullptr; } |
53 | 57 |
54 protected: | 58 protected: |
55 explicit ChannelDispatcherBase(const char* channel_name); | 59 explicit ChannelDispatcherBase(const char* channel_name); |
56 | 60 |
57 BufferedSocketWriter* writer() { return &writer_; } | 61 MessagePipe* message_pipe() { return message_pipe_.get(); } |
58 | 62 |
59 // Child classes must override this method to handle incoming messages. | 63 // Child classes must override this method to handle incoming messages. |
60 virtual void OnIncomingMessage(scoped_ptr<CompoundBuffer> message) = 0; | 64 virtual void OnIncomingMessage(scoped_ptr<CompoundBuffer> message) = 0; |
61 | 65 |
62 private: | 66 private: |
63 void OnChannelReady(scoped_ptr<P2PStreamSocket> socket); | 67 void OnChannelReady(scoped_ptr<P2PStreamSocket> socket); |
64 void OnReadWriteFailed(int error); | 68 void OnPipeError(int error); |
65 | 69 |
66 std::string channel_name_; | 70 std::string channel_name_; |
67 StreamChannelFactory* channel_factory_; | 71 StreamChannelFactory* channel_factory_; |
68 EventHandler* event_handler_; | 72 EventHandler* event_handler_; |
69 scoped_ptr<P2PStreamSocket> channel_; | |
70 | 73 |
71 BufferedSocketWriter writer_; | 74 scoped_ptr<MessagePipe> message_pipe_; |
72 MessageReader reader_; | |
73 | 75 |
74 DISALLOW_COPY_AND_ASSIGN(ChannelDispatcherBase); | 76 DISALLOW_COPY_AND_ASSIGN(ChannelDispatcherBase); |
75 }; | 77 }; |
76 | 78 |
77 } // namespace protocol | 79 } // namespace protocol |
78 } // namespace remoting | 80 } // namespace remoting |
79 | 81 |
80 #endif // REMOTING_PROTOCOL_CHANNEL_DISPATCHER_BASE_H_ | 82 #endif // REMOTING_PROTOCOL_CHANNEL_DISPATCHER_BASE_H_ |
OLD | NEW |