diff options
author | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-17 22:47:25 +0000 |
---|---|---|
committer | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-17 22:47:25 +0000 |
commit | e842c17b0d0aaf1b389f56c7e12c0fff4b3b10bb (patch) | |
tree | 7e659c18d7e705ec7581c016d314f485db8f8076 /mojo | |
parent | 9fdc6d91c7a7f33ed1b7baeb2114440b0b4d2d7b (diff) | |
download | chromium_src-e842c17b0d0aaf1b389f56c7e12c0fff4b3b10bb.zip chromium_src-e842c17b0d0aaf1b389f56c7e12c0fff4b3b10bb.tar.gz chromium_src-e842c17b0d0aaf1b389f56c7e12c0fff4b3b10bb.tar.bz2 |
Mojo: Add a C++ DataPipe wrapper paralleling the MessagePipe wrapper.
I should also write "end-to-end" data pipe tests ... but that will be a
nontrivial project.
R=sky@chromium.org
Review URL: https://codereview.chromium.org/130633005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@245647 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo')
-rw-r--r-- | mojo/public/system/core_cpp.h | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/mojo/public/system/core_cpp.h b/mojo/public/system/core_cpp.h index 2b1fb8a..c0f3d43 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_ |