Chromium Code Reviews| Index: mojo/public/system/core.h |
| diff --git a/mojo/public/system/core.h b/mojo/public/system/core.h |
| index 9a75c41d3f190bbb9cee228c85b7bd63f64d1d13..a13b14f830a54758af42f1098376cc4debf52f71 100644 |
| --- a/mojo/public/system/core.h |
| +++ b/mojo/public/system/core.h |
| @@ -5,15 +5,174 @@ |
| #ifndef MOJO_PUBLIC_SYSTEM_CORE_H_ |
| #define MOJO_PUBLIC_SYSTEM_CORE_H_ |
| +// Note: This header should be compilable as C. |
| + |
| #include <stdint.h> |
|
darin (slow to review)
2013/09/24 22:48:19
This probably goes without saying:
I think on Wind
|
| +// Types ----------------------------------------------------------------------- |
| + |
| +// TODO(vtl): Notes: Use of undefined flags will lead to undefined behavior |
| +// (typically they'll be ignored), not necessarily an error. |
|
darin (slow to review)
2013/09/24 22:48:19
I guess this is primarily an issue for newer clien
viettrungluu
2013/09/26 17:59:15
Indeed. The reason I want to record this somewhere
|
| + |
| typedef uint32_t MojoHandle; |
| +typedef int32_t MojoResult; |
| + |
| +typedef uint32_t MojoWaitFlags; |
| + |
| +// Used to specify deadlines in microseconds. Note that -1 means "forever". |
| +typedef uint64_t MojoDeadline; |
| + |
| +typedef uint32_t MojoWriteMessageFlags; |
| + |
| +typedef uint32_t MojoReadMessageFlags; |
| + |
| +// Constants ------------------------------------------------------------------- |
| + |
| +// |MojoHandle|: |
| +#ifdef __cplusplus |
| +const MojoHandle MOJO_HANDLE_INVALID = 0; |
|
darin (slow to review)
2013/09/25 06:06:07
yay, sanity! i'm so glad you chose a value other
|
| +#else |
| +#define MOJO_HANDLE_INVALID ((MojoHandle) 0) |
| +#endif |
| + |
| +// |MojoResult|: |
| +// TODO(vtl): Add documentation. The first N are equivalent to Google3 canonical |
| +// error codes (google3/util/task/codes.proto). |
| +#ifdef __cplusplus |
| +const MojoResult MOJO_RESULT_OK = 0; |
| +const MojoResult MOJO_RESULT_CANCELLED = -1; |
| +const MojoResult MOJO_RESULT_UNKNOWN = -2; |
| +const MojoResult MOJO_RESULT_INVALID_ARGUMENT = -3; |
| +const MojoResult MOJO_RESULT_DEADLINE_EXCEEDED = -4; |
| +const MojoResult MOJO_RESULT_NOT_FOUND = -5; |
| +const MojoResult MOJO_RESULT_ALREADY_EXISTS = -6; |
| +const MojoResult MOJO_RESULT_PERMISSION_DENIED = -7; |
| +const MojoResult MOJO_RESULT_RESOURCE_EXHAUSTED = -8; |
| +const MojoResult MOJO_RESULT_FAILED_PRECONDITION = -9; |
| +const MojoResult MOJO_RESULT_ABORTED = -10; |
|
darin (slow to review)
2013/09/25 06:06:07
what is the difference between ABORTED and CANCELL
viettrungluu
2013/09/25 18:22:16
(I plan on adding/copying documentation, but for n
|
| +const MojoResult MOJO_RESULT_OUT_OF_RANGE = -11; |
| +const MojoResult MOJO_RESULT_UNIMPLEMENTED = -12; |
| +const MojoResult MOJO_RESULT_INTERNAL = -13; |
|
darin (slow to review)
2013/09/25 06:06:07
what does the INTERNAL error code refer too? my ex
viettrungluu
2013/09/25 18:22:16
"Internal" should basically never happen -- it ind
|
| +const MojoResult MOJO_RESULT_UNAVAILABLE = -14; |
| +const MojoResult MOJO_RESULT_DATA_LOSS = -15; |
| +#else |
| +#define MOJO_RESULT_OK ((MojoResult) 0) |
| +#define MOJO_RESULT_CANCELLED ((MojoResult) -1) |
| +#define MOJO_RESULT_UNKNOWN ((MojoResult) -2) |
| +#define MOJO_RESULT_INVALID_ARGUMENT ((MojoResult) -3) |
| +#define MOJO_RESULT_DEADLINE_EXCEEDED ((MojoResult) -4) |
| +#define MOJO_RESULT_NOT_FOUND ((MojoResult) -5) |
| +#define MOJO_RESULT_ALREADY_EXISTS ((MojoResult) -6) |
| +#define MOJO_RESULT_PERMISSION_DENIED ((MojoResult) -7) |
| +#define MOJO_RESULT_RESOURCE_EXHAUSTED ((MojoResult) -8) |
| +#define MOJO_RESULT_FAILED_PRECONDITION ((MojoResult) -9) |
| +#define MOJO_RESULT_ABORTED ((MojoResult) -10) |
| +#define MOJO_RESULT_OUT_OF_RANGE ((MojoResult) -11) |
| +#define MOJO_RESULT_UNIMPLEMENTED ((MojoResult) -12) |
| +#define MOJO_RESULT_INTERNAL ((MojoResult) -13) |
| +#define MOJO_RESULT_UNAVAILABLE ((MojoResult) -14) |
| +#define MOJO_RESULT_DATA_LOSS ((MojoResult) -15) |
| +#endif |
| + |
| +// |MojoWaitFlags|: |
| +// MOJO_WAIT_FLAG_NONE - default flags: will wait on everything |
| +// MOJO_WAIT_FLAG_READABLE - can read from the handle |
| +// MOJO_WAIT_FLAG_WRITABLE - can write to the handle |
| +#ifdef __cplusplus |
| +const MojoWaitFlags MOJO_WAIT_FLAG_NONE = 0; |
|
darin (slow to review)
2013/09/24 22:48:19
since MojoWaitFlags is just a typedef for an uint3
darin (slow to review)
2013/09/25 06:06:07
Not having to duplicate these values would be nice
viettrungluu
2013/09/25 18:22:16
Sigh. Maybe. enums are of unspecified width and si
viettrungluu
2013/09/25 19:48:00
Blech, of course you can't have a macro to define
|
| +const MojoWaitFlags MOJO_WAIT_FLAG_READABLE = 1 << 0; |
| +const MojoWaitFlags MOJO_WAIT_FLAG_WRITABLE = 1 << 1; |
| +const MojoWaitFlags MOJO_WAIT_FLAG_EVERYTHING = ~0; |
| +// TODO(vtl): Moar. |
| +#else |
| +#define MOJO_WAIT_FLAG_NONE ((MojoWaitFlags) 0) |
| +#define MOJO_WAIT_FLAG_READABLE ((MojoWaitFlags) 1 << 0) |
| +#define MOJO_WAIT_FLAG_WRITABLE ((MojoWaitFlags) 1 << 1) |
| +#define MOJO_WAIT_FLAG_EVERYTHING (~((MojoWaitFlags) 0)) |
| +// TODO(vtl): Moar. |
| +#endif |
| + |
| +// |MojoDeadline|: |
| +#ifdef __cplusplus |
| +const MojoDeadline MOJO_DEADLINE_INDEFINITE = static_cast<MojoDeadline>(-1); |
| +#else |
| +#define MOJO_DEADLINE_INDEFINITE = ((MojoDeadline) -1); |
| +#endif |
| + |
| +// |MojoWriteMessageFlags|: |
| +#ifdef __cplusplus |
| +const MojoWriteMessageFlags MOJO_WRITE_MESSAGE_FLAG_NONE = 0; |
| +// TODO(vtl): Moar. |
| +#else |
| +#define MOJO_WRITE_MESSAGE_FLAG_NONE ((MojoWriteMessageFlags) 0) |
| +// TODO(vtl): Moar. |
| +#endif |
| + |
| +// |MojoReadMessageFlags|: |
| +#ifdef __cplusplus |
| +const MojoReadMessageFlags MOJO_READ_MESSAGE_FLAG_NONE = 0; |
| +const MojoReadMessageFlags MOJO_READ_MESSAGE_FLAG_MAY_DISCARD = 1 << 0; |
|
darin (slow to review)
2013/09/25 06:06:07
nit: add a comment explaining what MAY_DISCARD mea
viettrungluu
2013/09/26 17:59:15
Done.
|
| +// TODO(vtl): Moar. |
| +#else |
| +#define MOJO_READ_MESSAGE_FLAG_NONE ((MojoReadMessageFlags) 0) |
| +#define MOJO_READ_MESSAGE_FLAG_MAY_DISCARD ((MojoReadMessageFlags) 1 << 0) |
| +// TODO(vtl): Moar. |
| +#endif |
| + |
| +// Functions ------------------------------------------------------------------- |
| + |
| +#ifdef __cplusplus |
| +extern "C" { |
| +#endif |
| + |
| +MojoResult MojoClose(MojoHandle handle); |
| + |
| +MojoResult MojoWait(MojoHandle handle, |
| + MojoWaitFlags flags, |
| + MojoDeadline deadline); |
| + |
| +MojoResult MojoWaitMany(const MojoHandle* handles, |
| + const MojoWaitFlags* flags, |
| + uint32_t num_handles, |
| + MojoDeadline deadline); |
| + |
| +// TODO(vtl): flags? other params (e.g., queue sizes, max message sizes?) |
|
darin (slow to review)
2013/09/24 22:48:19
Maybe we should have an attributes struct like pth
|
| +MojoResult MojoCreateMessagePipe(MojoHandle* handle_0, MojoHandle* handle_1); |
| + |
| +MojoResult MojoWriteMessage(MojoHandle handle, |
| + const void* bytes, uint32_t num_bytes, |
| + const MojoHandle* handles, uint32_t num_handles, |
| + MojoWriteMessageFlags flags); |
| + |
| +MojoResult MojoReadMessage(MojoHandle handle, |
|
darin (slow to review)
2013/09/25 06:06:07
nit: it'd be good to include some documentation fo
viettrungluu
2013/09/25 18:22:16
Yes, I still have to write documentation. :)
|
| + void* bytes, uint32_t* num_bytes, |
| + MojoHandle* handles, uint32_t* num_handles, |
| + MojoReadMessageFlags flags); |
| + |
| +#ifdef __cplusplus |
| +} // extern "C" |
| +#endif |
| + |
| +// C++ wrapper functions ------------------------------------------------------- |
| + |
| #ifdef __cplusplus |
| namespace mojo { |
| struct Handle { MojoHandle value; }; |
| +inline MojoResult Close(Handle handle) { |
| + return MojoClose(handle.value); |
| +} |
| + |
| +inline MojoResult Wait(Handle handle, |
| + MojoWaitFlags flags, |
| + MojoDeadline deadline) { |
| + return MojoWait(handle.value, flags, deadline); |
| +} |
| + |
| +// TODO(vtl): C++ wrapper for |WaitMany()|. |
|
darin (slow to review)
2013/09/24 22:48:19
We probably want to ensure that Handle is packed s
viettrungluu
2013/09/26 17:59:15
Done.
|
| + |
| } // namespace mojo |
| #endif |