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

Unified Diff: mojo/public/c/system/message_pipe.h

Issue 1880823005: [mojo-edk] Add explicit message object APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
Index: mojo/public/c/system/message_pipe.h
diff --git a/mojo/public/c/system/message_pipe.h b/mojo/public/c/system/message_pipe.h
index 8c5c215eafa4c8a19a02045021d8e5fa446ecda0..00c27fbf07f0bdf9c4484dd97a2a8517759bdcbc 100644
--- a/mojo/public/c/system/message_pipe.h
+++ b/mojo/public/c/system/message_pipe.h
@@ -79,6 +79,18 @@ const MojoReadMessageFlags MOJO_READ_MESSAGE_FLAG_MAY_DISCARD = 1 << 0;
#define MOJO_READ_MESSAGE_FLAG_MAY_DISCARD ((MojoReadMessageFlags)1 << 0)
#endif
+// |MojoCreateMessageFlags|: Used to specify different options for
+// |MojoCreateMessage()|.
+// |MOJO_CREATE_MESSAGE_FLAG_NONE| - No flags; default mode.
+
+typedef uint32_t MojoCreateMessageFlags;
+
+#ifdef __cplusplus
+const MojoCreateMessageFlags MOJO_CREATE_MESSAGE_FLAG_NONE = 0;
+#else
+#define MOJO_CREATE_MESSAGE_FLAG_NONE ((MojoCreateMessageFlags)0)
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -117,6 +129,8 @@ MOJO_SYSTEM_EXPORT MojoResult MojoCreateMessagePipe(
// receiver will receive equivalent, but logically different, handles). Handles
// to be sent should not be in simultaneous use (e.g., on another thread).
//
+// DEPRECATED: This function will be removed. Use |MojoWriteMessageNew()|.
Anand Mistry (off Chromium) 2016/04/19 12:57:36 I'd prefer if these weren't marked as deprecated j
Ken Rockot(use gerrit already) 2016/04/19 18:11:25 OK - Removed DEPRECATED notices and TODOs for now.
+//
// Returns:
// |MOJO_RESULT_OK| on success (i.e., the message was enqueued).
// |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., if
@@ -142,6 +156,21 @@ MOJO_SYSTEM_EXPORT MojoResult
uint32_t num_handles,
MojoWriteMessageFlags flags);
+// Writes a message to the message pipe endpoint given by |message_pipe_handle|.
+//
+// |message|: A message object created by |MojoCreateMessage()|. Ownership of
+// the message is passed into Mojo.
+//
+//
+// TODO(rockot/amistry): Rename this to |MojoWriteMessage()| once that API is
+// no longer used in its current form.
+//
+// Returns results corresponding to |MojoWriteMessage()| above.
+MOJO_SYSTEM_EXPORT MojoResult
+ MojoWriteMessageNew(MojoHandle message_pipe_handle,
+ void* message,
+ MojoWriteMessageFlags);
+
// Reads the next message from a message pipe, or indicates the size of the
// message if it cannot fit in the provided buffers. The message will be read
// in its entirety or not at all; if it is not, it will remain enqueued unless
@@ -162,6 +191,8 @@ MOJO_SYSTEM_EXPORT MojoResult
// retrieved. Either or both may be null, in which case the corresponding size
// parameter(s) must also be set to zero or passed as null.
//
+// DEPRECATED: This function will be removed. Use |MojoReadMessageNew()|.
+//
// Returns:
// |MOJO_RESULT_OK| on success (i.e., a message was actually read).
// |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid.
@@ -181,6 +212,33 @@ MOJO_SYSTEM_EXPORT MojoResult
uint32_t* num_handles, // Optional in/out.
MojoReadMessageFlags flags);
+// Reads the next message from a message pipe and returns an address to a
+// message containing the message bytes. The returned message must eventually be
+// freed using |MojoDestroyMessage()|.
+//
+// Message payload can be accessed using |MojoGetMessageBuffer()|.
+//
+// |message_pipe_handle|, |num_bytes|, |handles|, |num_handles|, and |flags|
+// correspond to their use in |MojoReadMessage()| above, with the
+// exception that |num_bytes| is only an output argument.
+// |message| must be non-null unless |MOJO_READ_MESSAGE_FLAG_MAY_DISCARD| is
+// set in flags.
+//
+// Return values correspond to the return values for |MojoReadMessage()| above.
+// On success (MOJO_RESULT_OK), |*message| will contain the address of a
+// message object which may be passed to |MojoGetMessageBuffer()| and/or
+// |MojoDestroyMessage()|.
+//
+// TODO(rockot/amistry): Rename this to |MojoReadMessage()| once that API is no
+// longer used in its current form.
+MOJO_SYSTEM_EXPORT MojoResult
+ MojoReadMessageNew(MojoHandle message_pipe_handle,
+ void** message, // Optional out.
+ uint32_t* num_bytes, // Optional out.
+ MojoHandle* handles, // Optional out.
+ uint32_t* num_handles, // Optional in/out.
+ MojoReadMessageFlags flags);
+
// Fuses two message pipe endpoints together. Given two pipes:
//
// A <-> B and C <-> D
@@ -205,6 +263,63 @@ MOJO_SYSTEM_EXPORT MojoResult
MOJO_SYSTEM_EXPORT MojoResult
MojoFuseMessagePipes(MojoHandle handle0, MojoHandle handle1);
+// Allocates a new message whose ownership may be passed to
+// |MojoWriteMessageNew()|. Use |MojoGetMessageBuffer()| to retrieve the address
+// of the mutable message payload.
+//
+// |num_bytes|: The size of the message payload in bytes.
+// |handles|: An array of handles to transfer in the message. This takes
+// ownership of and invalidates all contained handles. Must be null if and
+// only if |num_handles| is 0.
+// |num_handles|: The number of handles contained in |handles|.
+// |flags|: Must be |MOJO_CREATE_MESSAGE_FLAG_NONE|.
+// |message|: The address of a pointer to be filled with the new message's
+// address. Must be non-null.
+//
+// Returns:
+// |MOJO_RESULT_OK| if the message was successfully allocated. In this case
+// |*message| will be populated with the address of an allocated message
+// large enough to hold at least |num_bytes| contiguous bytes.
+// |MOJO_RESULT_INVALID_ARGUMENT| if one or more handles in |handles| was
+// invalid, or |handles| was null with a non-zero |num_handles|.
+// |MOJO_RESULT_RESOURCE_EXHAUSTED| if allocation failed because either
+// |num_bytes| or |num_handles| exceeds an implementation-defined maximum.
+// |MOJO_RESULT_BUSY| if one or more handles in |handles| cannot be sent at
+// the time of this call.
+//
+// Only upon successful message allocation will all handles in |handles| be
+// transferred into the message and invalidated.
+MOJO_SYSTEM_EXPORT MojoResult
+MojoCreateMessage(uint32_t num_bytes,
+ const MojoHandle* handles,
+ uint32_t num_handles,
+ MojoCreateMessageFlags flags,
+ void** message); // Out
Anand Mistry (off Chromium) 2016/04/19 12:57:36 Since you're not meant to directly read/write the
Ken Rockot(use gerrit already) 2016/04/19 18:11:25 Done.
+
+// Destroys a message allocated by |MojoCreateMessage()| or
+// |MojoReadMessageNew()|.
+//
+// |message|: The address of the message to destroy. This must correspond to a
+// message previously created by |MojoCreateMessage()| or
+// |MojoReadMessageNew()|. Note that if the message has already been passed
+// to |MojoWriteMessageNew()| it should NOT also be destroyed with this API.
+//
+// Returns:
+// |MOJO_RESULT_OK| if |message| was valid and has been destroyed.
+// |MOJO_RESULT_INVALID_ARGUMENT| if |message| was not a valid message object.
+MOJO_SYSTEM_EXPORT MojoResult MojoDestroyMessage(void* message);
Anand Mistry (off Chromium) 2016/04/19 12:57:36 nit: In my experience (mainly media APIs), buffer
Ken Rockot(use gerrit already) 2016/04/19 18:11:25 I left the names unchanged for now. In general I t
Anand Mistry (off Chromium) 2016/04/21 12:19:42 I like Alloc/Free better than Create/Destroy. I do
Ken Rockot(use gerrit already) 2016/04/21 16:47:40 Done. MojoAllocMessage and MojoFreeMessage.
+
+// Retrieves the address of mutable message bytes for a message created by
+// either |MojoCreateMessage()| or |MojoReadMessageNew()|.
+//
+// |message|: The message object.
+//
+// Returns:
+// |MOJO_RESULT_OK| if |message| is a valid message object. |*buffer| will
+// be updated to point to mutable message bytes.
+// |MOJO_RESULT_INVALID_ARGUMENT| if |message| is not a valid message object.
+MOJO_SYSTEM_EXPORT MojoResult MojoGetMessageBuffer(void* message,
+ void** buffer); // Out
#ifdef __cplusplus
} // extern "C"

Powered by Google App Engine
This is Rietveld 408576698