Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(337)

Side by Side Diff: mojo/public/system/core_cpp.h

Issue 130633005: Mojo: Add a C++ DataPipe wrapper paralleling the MessagePipe wrapper. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 MOJO_PUBLIC_SYSTEM_CORE_CPP_H_ 5 #ifndef MOJO_PUBLIC_SYSTEM_CORE_CPP_H_
6 #define MOJO_PUBLIC_SYSTEM_CORE_CPP_H_ 6 #define MOJO_PUBLIC_SYSTEM_CORE_CPP_H_
7 7
8 #include <assert.h> 8 #include <assert.h>
9 #include <stddef.h>
9 10
10 #include <limits> 11 #include <limits>
11 12
12 #include "mojo/public/system/core.h" 13 #include "mojo/public/system/core.h"
13 #include "mojo/public/system/macros.h" 14 #include "mojo/public/system/macros.h"
14 #include "mojo/public/system/system_export.h" 15 #include "mojo/public/system/system_export.h"
15 16
16 namespace mojo { 17 namespace mojo {
17 18
18 // Standalone functions -------------------------------------------------------- 19 // Standalone functions --------------------------------------------------------
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 assert(message_pipe1); 193 assert(message_pipe1);
193 MessagePipeHandle h0; 194 MessagePipeHandle h0;
194 MessagePipeHandle h1; 195 MessagePipeHandle h1;
195 MojoResult result MOJO_ALLOW_UNUSED = 196 MojoResult result MOJO_ALLOW_UNUSED =
196 MojoCreateMessagePipe(h0.mutable_value(), h1.mutable_value()); 197 MojoCreateMessagePipe(h0.mutable_value(), h1.mutable_value());
197 assert(result == MOJO_RESULT_OK); 198 assert(result == MOJO_RESULT_OK);
198 message_pipe0->reset(h0); 199 message_pipe0->reset(h0);
199 message_pipe1->reset(h1); 200 message_pipe1->reset(h1);
200 } 201 }
201 202
203 // A wrapper class that automatically creates a message pipe and owns both
204 // handles.
202 class MessagePipe { 205 class MessagePipe {
203 public: 206 public:
204 MessagePipe(); 207 MessagePipe();
205 ~MessagePipe(); 208 ~MessagePipe();
206 209
207 ScopedMessagePipeHandle handle0; 210 ScopedMessagePipeHandle handle0;
208 ScopedMessagePipeHandle handle1; 211 ScopedMessagePipeHandle handle1;
209 }; 212 };
210 213
211 inline MessagePipe::MessagePipe() { CreateMessagePipe(&handle0, &handle1); } 214 inline MessagePipe::MessagePipe() {
212 inline MessagePipe::~MessagePipe() {} 215 CreateMessagePipe(&handle0, &handle1);
216 }
217
218 inline MessagePipe::~MessagePipe() {
219 }
213 220
214 // These "raw" versions fully expose the underlying API, but don't help with 221 // These "raw" versions fully expose the underlying API, but don't help with
215 // ownership of handles (especially when writing messages). 222 // ownership of handles (especially when writing messages).
216 // TODO(vtl): Write "baked" versions. 223 // TODO(vtl): Write "baked" versions.
217 inline MojoResult WriteMessageRaw(MessagePipeHandle message_pipe, 224 inline MojoResult WriteMessageRaw(MessagePipeHandle message_pipe,
218 const void* bytes, 225 const void* bytes,
219 uint32_t num_bytes, 226 uint32_t num_bytes,
220 const MojoHandle* handles, 227 const MojoHandle* handles,
221 uint32_t num_handles, 228 uint32_t num_handles,
222 MojoWriteMessageFlags flags) { 229 MojoWriteMessageFlags flags) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 }; 268 };
262 269
263 MOJO_COMPILE_ASSERT(sizeof(DataPipeConsumerHandle) == sizeof(Handle), 270 MOJO_COMPILE_ASSERT(sizeof(DataPipeConsumerHandle) == sizeof(Handle),
264 bad_size_for_cpp_DataPipeConsumerHandle); 271 bad_size_for_cpp_DataPipeConsumerHandle);
265 272
266 typedef ScopedHandleBase<DataPipeConsumerHandle> ScopedDataPipeConsumerHandle; 273 typedef ScopedHandleBase<DataPipeConsumerHandle> ScopedDataPipeConsumerHandle;
267 MOJO_COMPILE_ASSERT(sizeof(ScopedDataPipeConsumerHandle) == 274 MOJO_COMPILE_ASSERT(sizeof(ScopedDataPipeConsumerHandle) ==
268 sizeof(DataPipeConsumerHandle), 275 sizeof(DataPipeConsumerHandle),
269 bad_size_for_cpp_ScopedDataPipeConsumerHandle); 276 bad_size_for_cpp_ScopedDataPipeConsumerHandle);
270 277
271 // TODO(vtl): Make more friendly wrappers (e.g., a create that doesn't "require"
272 // |options|; maybe templatized functions that are optimized for a particular
273 // "type" instead of some vague "element", or functions that take a "vector").
274 inline MojoResult CreateDataPipe( 278 inline MojoResult CreateDataPipe(
275 const MojoCreateDataPipeOptions* options, 279 const MojoCreateDataPipeOptions* options,
276 ScopedDataPipeProducerHandle* data_pipe_producer, 280 ScopedDataPipeProducerHandle* data_pipe_producer,
277 ScopedDataPipeConsumerHandle* data_pipe_consumer) { 281 ScopedDataPipeConsumerHandle* data_pipe_consumer) {
278 assert(data_pipe_producer); 282 assert(data_pipe_producer);
279 assert(data_pipe_consumer); 283 assert(data_pipe_consumer);
280 DataPipeProducerHandle producer_handle; 284 DataPipeProducerHandle producer_handle;
281 DataPipeConsumerHandle consumer_handle; 285 DataPipeConsumerHandle consumer_handle;
282 MojoResult rv = MojoCreateDataPipe(options, 286 MojoResult rv = MojoCreateDataPipe(options,
283 producer_handle.mutable_value(), 287 producer_handle.mutable_value(),
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 MojoReadDataFlags flags) { 326 MojoReadDataFlags flags) {
323 return MojoBeginReadData(data_pipe_consumer.value(), buffer, buffer_num_bytes, 327 return MojoBeginReadData(data_pipe_consumer.value(), buffer, buffer_num_bytes,
324 flags); 328 flags);
325 } 329 }
326 330
327 inline MojoResult EndReadDataRaw(DataPipeConsumerHandle data_pipe_consumer, 331 inline MojoResult EndReadDataRaw(DataPipeConsumerHandle data_pipe_consumer,
328 uint32_t num_bytes_read) { 332 uint32_t num_bytes_read) {
329 return MojoEndReadData(data_pipe_consumer.value(), num_bytes_read); 333 return MojoEndReadData(data_pipe_consumer.value(), num_bytes_read);
330 } 334 }
331 335
336 // A wrapper class that automatically creates a data pipe and owns both handles.
337 // TODO(vtl): Make an even more friendly version? (Maybe templatized for a
338 // particular type instead of some "element"? Maybe functions that take
339 // vectors?)
340 class DataPipe {
341 public:
342 DataPipe();
343 explicit DataPipe(const MojoCreateDataPipeOptions& options);
344 ~DataPipe();
345
346 ScopedDataPipeProducerHandle producer_handle;
347 ScopedDataPipeConsumerHandle consumer_handle;
348 };
349
350 inline DataPipe::DataPipe() {
351 CreateDataPipe(NULL, &producer_handle, &consumer_handle);
352 }
353
354 inline DataPipe::DataPipe(const MojoCreateDataPipeOptions& options) {
355 CreateDataPipe(&options, &producer_handle, &consumer_handle);
356 }
357
358 inline DataPipe::~DataPipe() {
359 }
360
332 } // namespace mojo 361 } // namespace mojo
333 362
334 #endif // MOJO_PUBLIC_SYSTEM_CORE_CPP_H_ 363 #endif // MOJO_PUBLIC_SYSTEM_CORE_CPP_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698