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

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

Issue 1932083002: Mojo: Use new message APIs to reduce copying (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 4 years, 7 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
« no previous file with comments | « mojo/public/cpp/system/message.cc ('k') | 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 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
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
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_
OLDNEW
« no previous file with comments | « mojo/public/cpp/system/message.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698