| 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 message pipes, | 5 // This file provides a C++ wrapping around the Mojo C API for message 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/message_pipe.h" for complete documentation | 9 // Please see "mojo/public/c/system/message_pipe.h" for complete documentation |
| 10 // of the API. | 10 // of the API. |
| 11 | 11 |
| 12 #ifndef MOJO_PUBLIC_CPP_SYSTEM_MESSAGE_PIPE_H_ | 12 #ifndef MOJO_PUBLIC_CPP_SYSTEM_MESSAGE_PIPE_H_ |
| 13 #define MOJO_PUBLIC_CPP_SYSTEM_MESSAGE_PIPE_H_ | 13 #define MOJO_PUBLIC_CPP_SYSTEM_MESSAGE_PIPE_H_ |
| 14 | 14 |
| 15 #include <stdint.h> | 15 #include <stdint.h> |
| 16 | 16 |
| 17 #include "base/compiler_specific.h" | 17 #include "base/compiler_specific.h" |
| 18 #include "base/logging.h" | 18 #include "base/logging.h" |
| 19 #include "mojo/public/c/system/message_pipe.h" | 19 #include "mojo/public/c/system/message_pipe.h" |
| 20 #include "mojo/public/cpp/system/handle.h" | 20 #include "mojo/public/cpp/system/handle.h" |
| 21 #include "mojo/public/cpp/system/message.h" |
| 21 | 22 |
| 22 namespace mojo { | 23 namespace mojo { |
| 23 | 24 |
| 24 // A strongly-typed representation of a |MojoHandle| to one end of a message | 25 // A strongly-typed representation of a |MojoHandle| to one end of a message |
| 25 // pipe. | 26 // pipe. |
| 26 class MessagePipeHandle : public Handle { | 27 class MessagePipeHandle : public Handle { |
| 27 public: | 28 public: |
| 28 MessagePipeHandle() {} | 29 MessagePipeHandle() {} |
| 29 explicit MessagePipeHandle(MojoHandle value) : Handle(value) {} | 30 explicit MessagePipeHandle(MojoHandle value) : Handle(value) {} |
| 30 | 31 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 inline MojoResult ReadMessageRaw(MessagePipeHandle message_pipe, | 82 inline MojoResult ReadMessageRaw(MessagePipeHandle message_pipe, |
| 82 void* bytes, | 83 void* bytes, |
| 83 uint32_t* num_bytes, | 84 uint32_t* num_bytes, |
| 84 MojoHandle* handles, | 85 MojoHandle* handles, |
| 85 uint32_t* num_handles, | 86 uint32_t* num_handles, |
| 86 MojoReadMessageFlags flags) { | 87 MojoReadMessageFlags flags) { |
| 87 return MojoReadMessage( | 88 return MojoReadMessage( |
| 88 message_pipe.value(), bytes, num_bytes, handles, num_handles, flags); | 89 message_pipe.value(), bytes, num_bytes, handles, num_handles, flags); |
| 89 } | 90 } |
| 90 | 91 |
| 92 // Writes to a message pipe. Takes ownership of |message| and any attached |
| 93 // handles. |
| 94 inline MojoResult WriteMessageNew(MessagePipeHandle message_pipe, |
| 95 ScopedMessageHandle message, |
| 96 MojoWriteMessageFlags flags) { |
| 97 return MojoWriteMessageNew( |
| 98 message_pipe.value(), message.release().value(), flags); |
| 99 } |
| 100 |
| 101 // Reads from a message pipe. See |MojoReadMessageNew()| for complete |
| 102 // documentation. |
| 103 inline MojoResult ReadMessageNew(MessagePipeHandle message_pipe, |
| 104 ScopedMessageHandle* message, |
| 105 uint32_t* num_bytes, |
| 106 MojoHandle* handles, |
| 107 uint32_t* num_handles, |
| 108 MojoReadMessageFlags flags) { |
| 109 MojoMessageHandle raw_message; |
| 110 MojoResult rv = MojoReadMessageNew(message_pipe.value(), &raw_message, |
| 111 num_bytes, handles, num_handles, flags); |
| 112 if (rv != MOJO_RESULT_OK) |
| 113 return rv; |
| 114 |
| 115 message->reset(MessageHandle(raw_message)); |
| 116 return MOJO_RESULT_OK; |
| 117 } |
| 118 |
| 91 // Fuses two message pipes together at the given handles. See | 119 // Fuses two message pipes together at the given handles. See |
| 92 // |MojoFuseMessagePipes()| for complete documentation. | 120 // |MojoFuseMessagePipes()| for complete documentation. |
| 93 inline MojoResult FuseMessagePipes(ScopedMessagePipeHandle message_pipe0, | 121 inline MojoResult FuseMessagePipes(ScopedMessagePipeHandle message_pipe0, |
| 94 ScopedMessagePipeHandle message_pipe1) { | 122 ScopedMessagePipeHandle message_pipe1) { |
| 95 return MojoFuseMessagePipes(message_pipe0.release().value(), | 123 return MojoFuseMessagePipes(message_pipe0.release().value(), |
| 96 message_pipe1.release().value()); | 124 message_pipe1.release().value()); |
| 97 } | 125 } |
| 98 | 126 |
| 99 // A wrapper class that automatically creates a message pipe and owns both | 127 // A wrapper class that automatically creates a message pipe and owns both |
| 100 // handles. | 128 // handles. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 117 MojoResult result = CreateMessagePipe(&options, &handle0, &handle1); | 145 MojoResult result = CreateMessagePipe(&options, &handle0, &handle1); |
| 118 DCHECK_EQ(MOJO_RESULT_OK, result); | 146 DCHECK_EQ(MOJO_RESULT_OK, result); |
| 119 } | 147 } |
| 120 | 148 |
| 121 inline MessagePipe::~MessagePipe() { | 149 inline MessagePipe::~MessagePipe() { |
| 122 } | 150 } |
| 123 | 151 |
| 124 } // namespace mojo | 152 } // namespace mojo |
| 125 | 153 |
| 126 #endif // MOJO_PUBLIC_CPP_SYSTEM_MESSAGE_PIPE_H_ | 154 #endif // MOJO_PUBLIC_CPP_SYSTEM_MESSAGE_PIPE_H_ |
| OLD | NEW |