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

Side by Side Diff: mojo/public/cpp/system/core.h

Issue 328753003: Mojo: Plumb MojoCreateMessagePipeOptions through to the C++ wrappers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 6 years, 6 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
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_CPP_SYSTEM_CORE_H_ 5 #ifndef MOJO_PUBLIC_CPP_SYSTEM_CORE_H_
6 #define MOJO_PUBLIC_CPP_SYSTEM_CORE_H_ 6 #define MOJO_PUBLIC_CPP_SYSTEM_CORE_H_
7 7
8 #include <assert.h> 8 #include <assert.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 10
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 }; 257 };
258 258
259 MOJO_COMPILE_ASSERT(sizeof(MessagePipeHandle) == sizeof(Handle), 259 MOJO_COMPILE_ASSERT(sizeof(MessagePipeHandle) == sizeof(Handle),
260 bad_size_for_cpp_MessagePipeHandle); 260 bad_size_for_cpp_MessagePipeHandle);
261 261
262 typedef ScopedHandleBase<MessagePipeHandle> ScopedMessagePipeHandle; 262 typedef ScopedHandleBase<MessagePipeHandle> ScopedMessagePipeHandle;
263 MOJO_COMPILE_ASSERT(sizeof(ScopedMessagePipeHandle) == 263 MOJO_COMPILE_ASSERT(sizeof(ScopedMessagePipeHandle) ==
264 sizeof(MessagePipeHandle), 264 sizeof(MessagePipeHandle),
265 bad_size_for_cpp_ScopedMessagePipeHandle); 265 bad_size_for_cpp_ScopedMessagePipeHandle);
266 266
267 inline MojoResult CreateMessagePipe(ScopedMessagePipeHandle* message_pipe0, 267 inline MojoResult CreateMessagePipe(const MojoCreateMessagePipeOptions* options,
268 ScopedMessagePipeHandle* message_pipe0,
268 ScopedMessagePipeHandle* message_pipe1) { 269 ScopedMessagePipeHandle* message_pipe1) {
269 assert(message_pipe0); 270 assert(message_pipe0);
270 assert(message_pipe1); 271 assert(message_pipe1);
271 MessagePipeHandle handle0; 272 MessagePipeHandle handle0;
272 MessagePipeHandle handle1; 273 MessagePipeHandle handle1;
273 // TODO(vtl): Add support for the options struct. 274 MojoResult rv = MojoCreateMessagePipe(options,
274 MojoResult rv = MojoCreateMessagePipe(NULL,
275 handle0.mutable_value(), 275 handle0.mutable_value(),
276 handle1.mutable_value()); 276 handle1.mutable_value());
277 // Reset even on failure (reduces the chances that a "stale"/incorrect handle 277 // Reset even on failure (reduces the chances that a "stale"/incorrect handle
278 // will be used). 278 // will be used).
279 message_pipe0->reset(handle0); 279 message_pipe0->reset(handle0);
280 message_pipe1->reset(handle1); 280 message_pipe1->reset(handle1);
281 return rv; 281 return rv;
282 } 282 }
283 283
284 // These "raw" versions fully expose the underlying API, but don't help with 284 // These "raw" versions fully expose the underlying API, but don't help with
(...skipping 17 matching lines...) Expand all
302 MojoReadMessageFlags flags) { 302 MojoReadMessageFlags flags) {
303 return MojoReadMessage(message_pipe.value(), bytes, num_bytes, handles, 303 return MojoReadMessage(message_pipe.value(), bytes, num_bytes, handles,
304 num_handles, flags); 304 num_handles, flags);
305 } 305 }
306 306
307 // A wrapper class that automatically creates a message pipe and owns both 307 // A wrapper class that automatically creates a message pipe and owns both
308 // handles. 308 // handles.
309 class MessagePipe { 309 class MessagePipe {
310 public: 310 public:
311 MessagePipe(); 311 MessagePipe();
312 explicit MessagePipe(const MojoCreateMessagePipeOptions& options);
312 ~MessagePipe(); 313 ~MessagePipe();
313 314
314 ScopedMessagePipeHandle handle0; 315 ScopedMessagePipeHandle handle0;
315 ScopedMessagePipeHandle handle1; 316 ScopedMessagePipeHandle handle1;
316 }; 317 };
317 318
318 inline MessagePipe::MessagePipe() { 319 inline MessagePipe::MessagePipe() {
319 MojoResult result MOJO_ALLOW_UNUSED = CreateMessagePipe(&handle0, &handle1); 320 MojoResult result MOJO_ALLOW_UNUSED =
321 CreateMessagePipe(NULL, &handle0, &handle1);
320 assert(result == MOJO_RESULT_OK); 322 assert(result == MOJO_RESULT_OK);
321 } 323 }
322 324
325 inline MessagePipe::MessagePipe(const MojoCreateMessagePipeOptions& options) {
326 MojoResult result MOJO_ALLOW_UNUSED =
327 CreateMessagePipe(&options, &handle0, &handle1);
328 assert(result == MOJO_RESULT_OK);
329 }
330
323 inline MessagePipe::~MessagePipe() { 331 inline MessagePipe::~MessagePipe() {
324 } 332 }
325 333
326 // DataPipeProducerHandle and DataPipeConsumerHandle --------------------------- 334 // DataPipeProducerHandle and DataPipeConsumerHandle ---------------------------
327 335
328 class DataPipeProducerHandle : public Handle { 336 class DataPipeProducerHandle : public Handle {
329 public: 337 public:
330 DataPipeProducerHandle() {} 338 DataPipeProducerHandle() {}
331 explicit DataPipeProducerHandle(MojoHandle value) : Handle(value) {} 339 explicit DataPipeProducerHandle(MojoHandle value) : Handle(value) {}
332 340
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 CreateSharedBuffer(&options, num_bytes, &handle); 542 CreateSharedBuffer(&options, num_bytes, &handle);
535 assert(result == MOJO_RESULT_OK); 543 assert(result == MOJO_RESULT_OK);
536 } 544 }
537 545
538 inline SharedBuffer::~SharedBuffer() { 546 inline SharedBuffer::~SharedBuffer() {
539 } 547 }
540 548
541 } // namespace mojo 549 } // namespace mojo
542 550
543 #endif // MOJO_PUBLIC_CPP_SYSTEM_CORE_H_ 551 #endif // MOJO_PUBLIC_CPP_SYSTEM_CORE_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/tests/router_unittest.cc ('k') | mojo/public/cpp/system/tests/core_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698