OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // This file provides a C++ wrapping around the Mojo C API for data pipes, | 5 // This file provides a C++ wrapping around the Mojo C API for data pipes, |
6 // replacing the prefix of "Mojo" with a "mojo" namespace, and using more | 6 // replacing the prefix of "Mojo" with a "mojo" namespace, and using more |
7 // strongly-typed representations of |MojoHandle|s. | 7 // strongly-typed representations of |MojoHandle|s. |
8 // | 8 // |
9 // Please see "mojo/public/c/system/data_pipe.h" for complete documentation of | 9 // Please see "mojo/public/c/system/data_pipe.h" for complete documentation of |
10 // the API. | 10 // the API. |
11 | 11 |
12 #ifndef MOJO_PUBLIC_CPP_SYSTEM_DATA_PIPE_H_ | 12 #ifndef MOJO_PUBLIC_CPP_SYSTEM_DATA_PIPE_H_ |
13 #define MOJO_PUBLIC_CPP_SYSTEM_DATA_PIPE_H_ | 13 #define MOJO_PUBLIC_CPP_SYSTEM_DATA_PIPE_H_ |
14 | 14 |
15 #include <assert.h> | |
16 #include <stdint.h> | 15 #include <stdint.h> |
17 | 16 |
18 #include "base/compiler_specific.h" | 17 #include "base/compiler_specific.h" |
| 18 #include "base/logging.h" |
19 #include "mojo/public/c/system/data_pipe.h" | 19 #include "mojo/public/c/system/data_pipe.h" |
20 #include "mojo/public/cpp/system/handle.h" | 20 #include "mojo/public/cpp/system/handle.h" |
21 #include "mojo/public/cpp/system/macros.h" | 21 #include "mojo/public/cpp/system/macros.h" |
22 | 22 |
23 namespace mojo { | 23 namespace mojo { |
24 | 24 |
25 // A strongly-typed representation of a |MojoHandle| to the producer end of a | 25 // A strongly-typed representation of a |MojoHandle| to the producer end of a |
26 // data pipe. | 26 // data pipe. |
27 class DataPipeProducerHandle : public Handle { | 27 class DataPipeProducerHandle : public Handle { |
28 public: | 28 public: |
(...skipping 28 matching lines...) Expand all Loading... |
57 static_assert(sizeof(ScopedDataPipeConsumerHandle) == | 57 static_assert(sizeof(ScopedDataPipeConsumerHandle) == |
58 sizeof(DataPipeConsumerHandle), | 58 sizeof(DataPipeConsumerHandle), |
59 "Bad size for C++ ScopedDataPipeConsumerHandle"); | 59 "Bad size for C++ ScopedDataPipeConsumerHandle"); |
60 | 60 |
61 // Creates a new data pipe. See |MojoCreateDataPipe()| for complete | 61 // Creates a new data pipe. See |MojoCreateDataPipe()| for complete |
62 // documentation. | 62 // documentation. |
63 inline MojoResult CreateDataPipe( | 63 inline MojoResult CreateDataPipe( |
64 const MojoCreateDataPipeOptions* options, | 64 const MojoCreateDataPipeOptions* options, |
65 ScopedDataPipeProducerHandle* data_pipe_producer, | 65 ScopedDataPipeProducerHandle* data_pipe_producer, |
66 ScopedDataPipeConsumerHandle* data_pipe_consumer) { | 66 ScopedDataPipeConsumerHandle* data_pipe_consumer) { |
67 assert(data_pipe_producer); | 67 DCHECK(data_pipe_producer); |
68 assert(data_pipe_consumer); | 68 DCHECK(data_pipe_consumer); |
69 DataPipeProducerHandle producer_handle; | 69 DataPipeProducerHandle producer_handle; |
70 DataPipeConsumerHandle consumer_handle; | 70 DataPipeConsumerHandle consumer_handle; |
71 MojoResult rv = MojoCreateDataPipe(options, | 71 MojoResult rv = MojoCreateDataPipe(options, |
72 producer_handle.mutable_value(), | 72 producer_handle.mutable_value(), |
73 consumer_handle.mutable_value()); | 73 consumer_handle.mutable_value()); |
74 // Reset even on failure (reduces the chances that a "stale"/incorrect handle | 74 // Reset even on failure (reduces the chances that a "stale"/incorrect handle |
75 // will be used). | 75 // will be used). |
76 data_pipe_producer->reset(producer_handle); | 76 data_pipe_producer->reset(producer_handle); |
77 data_pipe_consumer->reset(consumer_handle); | 77 data_pipe_consumer->reset(consumer_handle); |
78 return rv; | 78 return rv; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 ~DataPipe(); | 139 ~DataPipe(); |
140 | 140 |
141 ScopedDataPipeProducerHandle producer_handle; | 141 ScopedDataPipeProducerHandle producer_handle; |
142 ScopedDataPipeConsumerHandle consumer_handle; | 142 ScopedDataPipeConsumerHandle consumer_handle; |
143 }; | 143 }; |
144 | 144 |
145 inline DataPipe::DataPipe() { | 145 inline DataPipe::DataPipe() { |
146 MojoResult result = | 146 MojoResult result = |
147 CreateDataPipe(nullptr, &producer_handle, &consumer_handle); | 147 CreateDataPipe(nullptr, &producer_handle, &consumer_handle); |
148 ALLOW_UNUSED_LOCAL(result); | 148 ALLOW_UNUSED_LOCAL(result); |
149 assert(result == MOJO_RESULT_OK); | 149 DCHECK_EQ(MOJO_RESULT_OK, result); |
150 } | 150 } |
151 | 151 |
152 inline DataPipe::DataPipe(const MojoCreateDataPipeOptions& options) { | 152 inline DataPipe::DataPipe(const MojoCreateDataPipeOptions& options) { |
153 MojoResult result = | 153 MojoResult result = |
154 CreateDataPipe(&options, &producer_handle, &consumer_handle); | 154 CreateDataPipe(&options, &producer_handle, &consumer_handle); |
155 ALLOW_UNUSED_LOCAL(result); | 155 ALLOW_UNUSED_LOCAL(result); |
156 assert(result == MOJO_RESULT_OK); | 156 DCHECK_EQ(MOJO_RESULT_OK, result); |
157 } | 157 } |
158 | 158 |
159 inline DataPipe::~DataPipe() { | 159 inline DataPipe::~DataPipe() { |
160 } | 160 } |
161 | 161 |
162 } // namespace mojo | 162 } // namespace mojo |
163 | 163 |
164 #endif // MOJO_PUBLIC_CPP_SYSTEM_DATA_PIPE_H_ | 164 #endif // MOJO_PUBLIC_CPP_SYSTEM_DATA_PIPE_H_ |
OLD | NEW |