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 BLIMP_HELIUM_STREAM_H_ | 5 #ifndef BLIMP_HELIUM_STREAM_H_ |
6 #define BLIMP_HELIUM_STREAM_H_ | 6 #define BLIMP_HELIUM_STREAM_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "blimp/helium/result.h" | 11 #include "blimp/helium/result.h" |
12 | 12 |
13 namespace blimp { | 13 namespace blimp { |
| 14 |
| 15 class HeliumWrapper; |
| 16 |
14 namespace helium { | 17 namespace helium { |
15 | 18 |
16 class HeliumMessage; | |
17 | |
18 // Pure virtual interface for HeliumMessage-oriented transport streams. | 19 // Pure virtual interface for HeliumMessage-oriented transport streams. |
19 // Details about how the helium::Stream is bound to the network layer are | 20 // Details about how the helium::Stream is bound to the network layer are |
20 // handled by subclasses of helium::Stream. | 21 // handled by subclasses of helium::Stream. |
21 class Stream { | 22 class Stream { |
22 public: | 23 public: |
| 24 using SendMessageCallback = base::Callback<void(Result)>; |
23 using ReceiveMessageCallback = | 25 using ReceiveMessageCallback = |
24 base::Callback<void(std::unique_ptr<HeliumMessage>, Result)>; | 26 base::Callback<void(std::unique_ptr<HeliumWrapper>, Result)>; |
25 | 27 |
26 virtual ~Stream() = default; | 28 virtual ~Stream() = default; |
27 | 29 |
28 // Sends |helium_message| over the Stream. |callback| is invoked when the | 30 // Sends |helium_message| over the Stream. |callback| is invoked when the |
29 // message is sent (or otherwise moved to the low-level write buffers), | 31 // message is sent (or otherwise moved to the low-level write buffers), |
30 // which signals the caller that it is clear to send another message. | 32 // which signals the caller that it is clear to send another message. |
31 // | 33 // |
32 // The caller is responsible for ensuring that only one outstanding | 34 // The caller is responsible for ensuring that only one outstanding |
33 // SendMessage() call is made at a time. | 35 // SendMessage() call is made at a time. |
34 virtual void SendMessage(std::unique_ptr<HeliumMessage> helium_message, | 36 virtual void SendMessage(std::unique_ptr<HeliumWrapper> helium_message, |
35 const base::Callback<void(Result)>& callback) = 0; | 37 const SendMessageCallback& callback) = 0; |
36 | 38 |
37 // Asynchronously reads a HeliumMessage from the stream. | 39 // Asynchronously reads a HeliumMessage from the stream. |
38 // The caller is responsible for ensuring that only one outstanding | 40 // The caller is responsible for ensuring that only one outstanding |
39 // ReceiveMessage() call is made at a time. | 41 // ReceiveMessage() call is made at a time. |
40 // | 42 // |
41 // In the event that an error occurred, a null pointer will be passed instead | 43 // In the event that an error occurred, a null pointer will be passed instead |
42 // of a HeliumMessage, with a HeliumResult describing the failure reason. | 44 // of a HeliumMessage, with a HeliumResult describing the failure reason. |
43 // The HeliumStream object is considered inactive/unusable at this point and | 45 // The HeliumStream object is considered inactive/unusable at this point and |
44 // should be discarded by its owner. | 46 // should be discarded by its owner. |
45 virtual void ReceiveMessage(const ReceiveMessageCallback& on_receive_cb) = 0; | 47 virtual void ReceiveMessage(const ReceiveMessageCallback& on_receive_cb) = 0; |
46 }; | 48 }; |
47 | 49 |
48 } // namespace helium | 50 } // namespace helium |
49 } // namespace blimp | 51 } // namespace blimp |
50 | 52 |
51 #endif // BLIMP_HELIUM_STREAM_H_ | 53 #endif // BLIMP_HELIUM_STREAM_H_ |
OLD | NEW |