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_ |