Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MOJO_PUBLIC_SYSTEM_CORE_H_ | 5 #ifndef MOJO_PUBLIC_SYSTEM_CORE_H_ |
| 6 #define MOJO_PUBLIC_SYSTEM_CORE_H_ | 6 #define MOJO_PUBLIC_SYSTEM_CORE_H_ |
| 7 | 7 |
| 8 // Note: This header should be compilable as C. | |
| 9 | |
| 8 #include <stdint.h> | 10 #include <stdint.h> |
|
darin (slow to review)
2013/09/24 22:48:19
This probably goes without saying:
I think on Wind
| |
| 9 | 11 |
| 12 // Types ----------------------------------------------------------------------- | |
| 13 | |
| 14 // TODO(vtl): Notes: Use of undefined flags will lead to undefined behavior | |
| 15 // (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
| |
| 16 | |
| 10 typedef uint32_t MojoHandle; | 17 typedef uint32_t MojoHandle; |
| 11 | 18 |
| 19 typedef int32_t MojoResult; | |
| 20 | |
| 21 typedef uint32_t MojoWaitFlags; | |
| 22 | |
| 23 // Used to specify deadlines in microseconds. Note that -1 means "forever". | |
| 24 typedef uint64_t MojoDeadline; | |
| 25 | |
| 26 typedef uint32_t MojoWriteMessageFlags; | |
| 27 | |
| 28 typedef uint32_t MojoReadMessageFlags; | |
| 29 | |
| 30 // Constants ------------------------------------------------------------------- | |
| 31 | |
| 32 // |MojoHandle|: | |
| 33 #ifdef __cplusplus | |
| 34 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
| |
| 35 #else | |
| 36 #define MOJO_HANDLE_INVALID ((MojoHandle) 0) | |
| 37 #endif | |
| 38 | |
| 39 // |MojoResult|: | |
| 40 // TODO(vtl): Add documentation. The first N are equivalent to Google3 canonical | |
| 41 // error codes (google3/util/task/codes.proto). | |
| 42 #ifdef __cplusplus | |
| 43 const MojoResult MOJO_RESULT_OK = 0; | |
| 44 const MojoResult MOJO_RESULT_CANCELLED = -1; | |
| 45 const MojoResult MOJO_RESULT_UNKNOWN = -2; | |
| 46 const MojoResult MOJO_RESULT_INVALID_ARGUMENT = -3; | |
| 47 const MojoResult MOJO_RESULT_DEADLINE_EXCEEDED = -4; | |
| 48 const MojoResult MOJO_RESULT_NOT_FOUND = -5; | |
| 49 const MojoResult MOJO_RESULT_ALREADY_EXISTS = -6; | |
| 50 const MojoResult MOJO_RESULT_PERMISSION_DENIED = -7; | |
| 51 const MojoResult MOJO_RESULT_RESOURCE_EXHAUSTED = -8; | |
| 52 const MojoResult MOJO_RESULT_FAILED_PRECONDITION = -9; | |
| 53 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
| |
| 54 const MojoResult MOJO_RESULT_OUT_OF_RANGE = -11; | |
| 55 const MojoResult MOJO_RESULT_UNIMPLEMENTED = -12; | |
| 56 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
| |
| 57 const MojoResult MOJO_RESULT_UNAVAILABLE = -14; | |
| 58 const MojoResult MOJO_RESULT_DATA_LOSS = -15; | |
| 59 #else | |
| 60 #define MOJO_RESULT_OK ((MojoResult) 0) | |
| 61 #define MOJO_RESULT_CANCELLED ((MojoResult) -1) | |
| 62 #define MOJO_RESULT_UNKNOWN ((MojoResult) -2) | |
| 63 #define MOJO_RESULT_INVALID_ARGUMENT ((MojoResult) -3) | |
| 64 #define MOJO_RESULT_DEADLINE_EXCEEDED ((MojoResult) -4) | |
| 65 #define MOJO_RESULT_NOT_FOUND ((MojoResult) -5) | |
| 66 #define MOJO_RESULT_ALREADY_EXISTS ((MojoResult) -6) | |
| 67 #define MOJO_RESULT_PERMISSION_DENIED ((MojoResult) -7) | |
| 68 #define MOJO_RESULT_RESOURCE_EXHAUSTED ((MojoResult) -8) | |
| 69 #define MOJO_RESULT_FAILED_PRECONDITION ((MojoResult) -9) | |
| 70 #define MOJO_RESULT_ABORTED ((MojoResult) -10) | |
| 71 #define MOJO_RESULT_OUT_OF_RANGE ((MojoResult) -11) | |
| 72 #define MOJO_RESULT_UNIMPLEMENTED ((MojoResult) -12) | |
| 73 #define MOJO_RESULT_INTERNAL ((MojoResult) -13) | |
| 74 #define MOJO_RESULT_UNAVAILABLE ((MojoResult) -14) | |
| 75 #define MOJO_RESULT_DATA_LOSS ((MojoResult) -15) | |
| 76 #endif | |
| 77 | |
| 78 // |MojoWaitFlags|: | |
| 79 // MOJO_WAIT_FLAG_NONE - default flags: will wait on everything | |
| 80 // MOJO_WAIT_FLAG_READABLE - can read from the handle | |
| 81 // MOJO_WAIT_FLAG_WRITABLE - can write to the handle | |
| 82 #ifdef __cplusplus | |
| 83 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
| |
| 84 const MojoWaitFlags MOJO_WAIT_FLAG_READABLE = 1 << 0; | |
| 85 const MojoWaitFlags MOJO_WAIT_FLAG_WRITABLE = 1 << 1; | |
| 86 const MojoWaitFlags MOJO_WAIT_FLAG_EVERYTHING = ~0; | |
| 87 // TODO(vtl): Moar. | |
| 88 #else | |
| 89 #define MOJO_WAIT_FLAG_NONE ((MojoWaitFlags) 0) | |
| 90 #define MOJO_WAIT_FLAG_READABLE ((MojoWaitFlags) 1 << 0) | |
| 91 #define MOJO_WAIT_FLAG_WRITABLE ((MojoWaitFlags) 1 << 1) | |
| 92 #define MOJO_WAIT_FLAG_EVERYTHING (~((MojoWaitFlags) 0)) | |
| 93 // TODO(vtl): Moar. | |
| 94 #endif | |
| 95 | |
| 96 // |MojoDeadline|: | |
| 97 #ifdef __cplusplus | |
| 98 const MojoDeadline MOJO_DEADLINE_INDEFINITE = static_cast<MojoDeadline>(-1); | |
| 99 #else | |
| 100 #define MOJO_DEADLINE_INDEFINITE = ((MojoDeadline) -1); | |
| 101 #endif | |
| 102 | |
| 103 // |MojoWriteMessageFlags|: | |
| 104 #ifdef __cplusplus | |
| 105 const MojoWriteMessageFlags MOJO_WRITE_MESSAGE_FLAG_NONE = 0; | |
| 106 // TODO(vtl): Moar. | |
| 107 #else | |
| 108 #define MOJO_WRITE_MESSAGE_FLAG_NONE ((MojoWriteMessageFlags) 0) | |
| 109 // TODO(vtl): Moar. | |
| 110 #endif | |
| 111 | |
| 112 // |MojoReadMessageFlags|: | |
| 113 #ifdef __cplusplus | |
| 114 const MojoReadMessageFlags MOJO_READ_MESSAGE_FLAG_NONE = 0; | |
| 115 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.
| |
| 116 // TODO(vtl): Moar. | |
| 117 #else | |
| 118 #define MOJO_READ_MESSAGE_FLAG_NONE ((MojoReadMessageFlags) 0) | |
| 119 #define MOJO_READ_MESSAGE_FLAG_MAY_DISCARD ((MojoReadMessageFlags) 1 << 0) | |
| 120 // TODO(vtl): Moar. | |
| 121 #endif | |
| 122 | |
| 123 // Functions ------------------------------------------------------------------- | |
| 124 | |
| 125 #ifdef __cplusplus | |
| 126 extern "C" { | |
| 127 #endif | |
| 128 | |
| 129 MojoResult MojoClose(MojoHandle handle); | |
| 130 | |
| 131 MojoResult MojoWait(MojoHandle handle, | |
| 132 MojoWaitFlags flags, | |
| 133 MojoDeadline deadline); | |
| 134 | |
| 135 MojoResult MojoWaitMany(const MojoHandle* handles, | |
| 136 const MojoWaitFlags* flags, | |
| 137 uint32_t num_handles, | |
| 138 MojoDeadline deadline); | |
| 139 | |
| 140 // 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
| |
| 141 MojoResult MojoCreateMessagePipe(MojoHandle* handle_0, MojoHandle* handle_1); | |
| 142 | |
| 143 MojoResult MojoWriteMessage(MojoHandle handle, | |
| 144 const void* bytes, uint32_t num_bytes, | |
| 145 const MojoHandle* handles, uint32_t num_handles, | |
| 146 MojoWriteMessageFlags flags); | |
| 147 | |
| 148 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. :)
| |
| 149 void* bytes, uint32_t* num_bytes, | |
| 150 MojoHandle* handles, uint32_t* num_handles, | |
| 151 MojoReadMessageFlags flags); | |
| 152 | |
| 153 #ifdef __cplusplus | |
| 154 } // extern "C" | |
| 155 #endif | |
| 156 | |
| 157 // C++ wrapper functions ------------------------------------------------------- | |
| 158 | |
| 12 #ifdef __cplusplus | 159 #ifdef __cplusplus |
| 13 namespace mojo { | 160 namespace mojo { |
| 14 | 161 |
| 15 struct Handle { MojoHandle value; }; | 162 struct Handle { MojoHandle value; }; |
| 16 | 163 |
| 164 inline MojoResult Close(Handle handle) { | |
| 165 return MojoClose(handle.value); | |
| 166 } | |
| 167 | |
| 168 inline MojoResult Wait(Handle handle, | |
| 169 MojoWaitFlags flags, | |
| 170 MojoDeadline deadline) { | |
| 171 return MojoWait(handle.value, flags, deadline); | |
| 172 } | |
| 173 | |
| 174 // 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.
| |
| 175 | |
| 17 } // namespace mojo | 176 } // namespace mojo |
| 18 #endif | 177 #endif |
| 19 | 178 |
| 20 #endif // MOJO_PUBLIC_SYSTEM_CORE_H_ | 179 #endif // MOJO_PUBLIC_SYSTEM_CORE_H_ |
| OLD | NEW |