OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_MESSAGE_PIPE_H_ | 5 #ifndef REMOTING_PROTOCOL_MESSAGE_PIPE_H_ |
6 #define REMOTING_PROTOCOL_MESSAGE_PIPE_H_ | 6 #define REMOTING_PROTOCOL_MESSAGE_PIPE_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
11 | 11 |
12 namespace google { | 12 namespace google { |
13 namespace protobuf { | 13 namespace protobuf { |
14 class MessageLite; | 14 class MessageLite; |
15 } // namespace protobuf | 15 } // namespace protobuf |
16 } // namespace google | 16 } // namespace google |
17 | 17 |
18 namespace remoting { | 18 namespace remoting { |
19 | 19 |
20 class CompoundBuffer; | 20 class CompoundBuffer; |
21 | 21 |
22 namespace protocol { | 22 namespace protocol { |
23 | 23 |
24 // Represents a bi-directional pipe that allows to send and receive messages. | 24 // Represents a bi-directional pipe that allows to send and receive messages. |
25 class MessagePipe { | 25 class MessagePipe { |
26 public: | 26 public: |
27 typedef base::Callback<void(std::unique_ptr<CompoundBuffer> message)> | 27 class EventHandler { |
28 MessageReceivedCallback; | 28 public: |
29 // Called when a message is received. | |
30 virtual void OnMessageReceived(std::unique_ptr<CompoundBuffer> message) = 0; | |
31 | |
32 // Called when the channel is closed. | |
33 virtual void OnMessagePipeClosed() = 0; | |
34 | |
35 protected: | |
36 virtual ~EventHandler() {} | |
37 }; | |
29 | 38 |
30 virtual ~MessagePipe() {} | 39 virtual ~MessagePipe() {} |
31 | 40 |
32 // Starts receiving incoming messages and calls |callback| for each message. | 41 // Starts the channel. |event_handle| will be called to notify when a message |
Jamie
2016/07/19 18:24:47
s/handle/handler/
Sergey Ulanov
2016/07/19 23:38:43
Done.
| |
33 virtual void StartReceiving(const MessageReceivedCallback& callback) = 0; | 42 // is received of the pipe is closed. |
Jamie
2016/07/19 18:24:47
s/of/or/
Sergey Ulanov
2016/07/19 23:38:43
Done.
| |
43 virtual void Start(EventHandler* event_handler) = 0; | |
34 | 44 |
35 // Sends a message. |done| is called when the message has been sent to the | 45 // Sends a message. |done| is called when the message has been sent to the |
36 // client, but it doesn't mean that the client has received it. |done| is | 46 // client, but it doesn't mean that the client has received it. |done| is |
37 // never called if the message is never sent (e.g. if the pipe is destroyed | 47 // never called if the message is never sent (e.g. if the pipe is destroyed |
38 // before the message is sent). | 48 // before the message is sent). |
39 virtual void Send(google::protobuf::MessageLite* message, | 49 virtual void Send(google::protobuf::MessageLite* message, |
40 const base::Closure& done) = 0; | 50 const base::Closure& done) = 0; |
41 }; | 51 }; |
42 | 52 |
43 } // namespace protocol | 53 } // namespace protocol |
44 } // namespace remoting | 54 } // namespace remoting |
45 | 55 |
46 #endif // REMOTING_PROTOCOL_MESSAGE_PIPE_H_ | 56 #endif // REMOTING_PROTOCOL_MESSAGE_PIPE_H_ |
OLD | NEW |