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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/system/core_cpp.h
diff --git a/mojo/public/system/core_cpp.h b/mojo/public/system/core_cpp.h
index 2b1fb8a4e85eefc895e089ef6182ab15b542c03e..c0f3d4329e0d1a0e0e9856d9b5b8dbe9a0b105a9 100644
--- a/mojo/public/system/core_cpp.h
+++ b/mojo/public/system/core_cpp.h
@@ -6,6 +6,7 @@
#define MOJO_PUBLIC_SYSTEM_CORE_CPP_H_
#include <assert.h>
+#include <stddef.h>
#include <limits>
@@ -199,6 +200,8 @@ inline void CreateMessagePipe(ScopedMessagePipeHandle* message_pipe0,
message_pipe1->reset(h1);
}
+// A wrapper class that automatically creates a message pipe and owns both
+// handles.
class MessagePipe {
public:
MessagePipe();
@@ -208,8 +211,12 @@ class MessagePipe {
ScopedMessagePipeHandle handle1;
};
-inline MessagePipe::MessagePipe() { CreateMessagePipe(&handle0, &handle1); }
-inline MessagePipe::~MessagePipe() {}
+inline MessagePipe::MessagePipe() {
+ CreateMessagePipe(&handle0, &handle1);
+}
+
+inline MessagePipe::~MessagePipe() {
+}
// These "raw" versions fully expose the underlying API, but don't help with
// ownership of handles (especially when writing messages).
@@ -268,9 +275,6 @@ MOJO_COMPILE_ASSERT(sizeof(ScopedDataPipeConsumerHandle) ==
sizeof(DataPipeConsumerHandle),
bad_size_for_cpp_ScopedDataPipeConsumerHandle);
-// TODO(vtl): Make more friendly wrappers (e.g., a create that doesn't "require"
-// |options|; maybe templatized functions that are optimized for a particular
-// "type" instead of some vague "element", or functions that take a "vector").
inline MojoResult CreateDataPipe(
const MojoCreateDataPipeOptions* options,
ScopedDataPipeProducerHandle* data_pipe_producer,
@@ -329,6 +333,31 @@ inline MojoResult EndReadDataRaw(DataPipeConsumerHandle data_pipe_consumer,
return MojoEndReadData(data_pipe_consumer.value(), num_bytes_read);
}
+// A wrapper class that automatically creates a data pipe and owns both handles.
+// TODO(vtl): Make an even more friendly version? (Maybe templatized for a
+// particular type instead of some "element"? Maybe functions that take
+// vectors?)
+class DataPipe {
+ public:
+ DataPipe();
+ explicit DataPipe(const MojoCreateDataPipeOptions& options);
+ ~DataPipe();
+
+ ScopedDataPipeProducerHandle producer_handle;
+ ScopedDataPipeConsumerHandle consumer_handle;
+};
+
+inline DataPipe::DataPipe() {
+ CreateDataPipe(NULL, &producer_handle, &consumer_handle);
+}
+
+inline DataPipe::DataPipe(const MojoCreateDataPipeOptions& options) {
+ CreateDataPipe(&options, &producer_handle, &consumer_handle);
+}
+
+inline DataPipe::~DataPipe() {
+}
+
} // namespace mojo
#endif // MOJO_PUBLIC_SYSTEM_CORE_CPP_H_
« 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