OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // Note: This header should be compilable as C. | 5 // Note: This header should be compilable as C. |
6 | 6 |
7 #ifndef MOJO_PUBLIC_C_SYSTEM_CORE_H_ | 7 #ifndef MOJO_PUBLIC_C_SYSTEM_CORE_H_ |
8 #define MOJO_PUBLIC_C_SYSTEM_CORE_H_ | 8 #define MOJO_PUBLIC_C_SYSTEM_CORE_H_ |
9 | 9 |
10 #include <stdint.h> | |
11 | |
12 #include "mojo/public/c/system/functions.h" | 10 #include "mojo/public/c/system/functions.h" |
13 #include "mojo/public/c/system/macros.h" | 11 #include "mojo/public/c/system/macros.h" |
| 12 #include "mojo/public/c/system/message_pipe.h" |
14 #include "mojo/public/c/system/system_export.h" | 13 #include "mojo/public/c/system/system_export.h" |
15 #include "mojo/public/c/system/types.h" | 14 #include "mojo/public/c/system/types.h" |
16 | 15 |
17 // Types/constants ------------------------------------------------------------- | 16 // Types/constants ------------------------------------------------------------- |
18 | 17 |
19 // TODO(vtl): Split these into their own header files. | 18 // TODO(vtl): Split these into their own header files. |
20 | 19 |
21 // Message pipe: | |
22 | |
23 // |MojoWriteMessageFlags|: Used to specify different modes to | |
24 // |MojoWriteMessage()|. | |
25 // |MOJO_WRITE_MESSAGE_FLAG_NONE| - No flags; default mode. | |
26 | |
27 typedef uint32_t MojoWriteMessageFlags; | |
28 | |
29 #ifdef __cplusplus | |
30 const MojoWriteMessageFlags MOJO_WRITE_MESSAGE_FLAG_NONE = 0; | |
31 #else | |
32 #define MOJO_WRITE_MESSAGE_FLAG_NONE ((MojoWriteMessageFlags) 0) | |
33 #endif | |
34 | |
35 // |MojoReadMessageFlags|: Used to specify different modes to | |
36 // |MojoReadMessage()|. | |
37 // |MOJO_READ_MESSAGE_FLAG_NONE| - No flags; default mode. | |
38 // |MOJO_READ_MESSAGE_FLAG_MAY_DISCARD| - If the message is unable to be read | |
39 // for whatever reason (e.g., the caller-supplied buffer is too small), | |
40 // discard the message (i.e., simply dequeue it). | |
41 | |
42 typedef uint32_t MojoReadMessageFlags; | |
43 | |
44 #ifdef __cplusplus | |
45 const MojoReadMessageFlags MOJO_READ_MESSAGE_FLAG_NONE = 0; | |
46 const MojoReadMessageFlags MOJO_READ_MESSAGE_FLAG_MAY_DISCARD = 1 << 0; | |
47 #else | |
48 #define MOJO_READ_MESSAGE_FLAG_NONE ((MojoReadMessageFlags) 0) | |
49 #define MOJO_READ_MESSAGE_FLAG_MAY_DISCARD ((MojoReadMessageFlags) 1 << 0) | |
50 #endif | |
51 | |
52 // Data pipe: | 20 // Data pipe: |
53 | 21 |
54 // |MojoCreateDataPipeOptions|: Used to specify creation parameters for a data | 22 // |MojoCreateDataPipeOptions|: Used to specify creation parameters for a data |
55 // pipe to |MojoCreateDataPipe()|. | 23 // pipe to |MojoCreateDataPipe()|. |
56 // |uint32_t struct_size|: Set to the size of the |MojoCreateDataPipeOptions| | 24 // |uint32_t struct_size|: Set to the size of the |MojoCreateDataPipeOptions| |
57 // struct. (Used to allow for future extensions.) | 25 // struct. (Used to allow for future extensions.) |
58 // |MojoCreateDataPipeOptionsFlags flags|: Used to specify different modes of | 26 // |MojoCreateDataPipeOptionsFlags flags|: Used to specify different modes of |
59 // operation. | 27 // operation. |
60 // |MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE|: No flags; default mode. | 28 // |MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE|: No flags; default mode. |
61 // |MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_MAY_DISCARD|: May discard data for | 29 // |MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_MAY_DISCARD|: May discard data for |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 typedef uint32_t MojoMapBufferFlags; | 168 typedef uint32_t MojoMapBufferFlags; |
201 | 169 |
202 #ifdef __cplusplus | 170 #ifdef __cplusplus |
203 const MojoMapBufferFlags MOJO_MAP_BUFFER_FLAG_NONE = 0; | 171 const MojoMapBufferFlags MOJO_MAP_BUFFER_FLAG_NONE = 0; |
204 #else | 172 #else |
205 #define MOJO_MAP_BUFFER_FLAG_NONE ((MojoMapBufferFlags) 0) | 173 #define MOJO_MAP_BUFFER_FLAG_NONE ((MojoMapBufferFlags) 0) |
206 #endif | 174 #endif |
207 | 175 |
208 // Functions ------------------------------------------------------------------- | 176 // Functions ------------------------------------------------------------------- |
209 | 177 |
210 // Note: See the comment in functions.h about the meaning of the "optional" | |
211 // label for pointer parameters. | |
212 | |
213 #ifdef __cplusplus | 178 #ifdef __cplusplus |
214 extern "C" { | 179 extern "C" { |
215 #endif | 180 #endif |
216 | 181 |
217 // Message pipe: | 182 // Note: See the comment in functions.h about the meaning of the "optional" |
218 | 183 // label for pointer parameters. |
219 // Creates a message pipe, which is a bidirectional communication channel for | |
220 // framed data (i.e., messages). Messages can contain plain data and/or Mojo | |
221 // handles. On success, |*message_pipe_handle0| and |*message_pipe_handle1| are | |
222 // set to handles for the two endpoints (ports) for the message pipe. | |
223 // | |
224 // Returns: | |
225 // |MOJO_RESULT_OK| on success. | |
226 // |MOJO_RESULT_INVALID_ARGUMENT| if |message_pipe_handle0| and/or | |
227 // |message_pipe_handle1| do not appear to be valid pointers. | |
228 // |MOJO_RESULT_RESOURCE_EXHAUSTED| if a process/system/quota/etc. limit has | |
229 // been reached. | |
230 // | |
231 // TODO(vtl): Add an options struct pointer argument. | |
232 MOJO_SYSTEM_EXPORT MojoResult MojoCreateMessagePipe( | |
233 MojoHandle* message_pipe_handle0, // Out. | |
234 MojoHandle* message_pipe_handle1); // Out. | |
235 | |
236 // Writes a message to the message pipe endpoint given by |message_pipe_handle|, | |
237 // with message data specified by |bytes| of size |num_bytes| and attached | |
238 // handles specified by |handles| of count |num_handles|, and options specified | |
239 // by |flags|. If there is no message data, |bytes| may be null, in which case | |
240 // |num_bytes| must be zero. If there are no attached handles, |handles| may be | |
241 // null, in which case |num_handles| must be zero. | |
242 // | |
243 // If handles are attached, on success the handles will no longer be valid (the | |
244 // receiver will receive equivalent, but logically different, handles). Handles | |
245 // to be sent should not be in simultaneous use (e.g., on another thread). | |
246 // | |
247 // Returns: | |
248 // |MOJO_RESULT_OK| on success (i.e., the message was enqueued). | |
249 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., if | |
250 // |message_pipe_handle| is not a valid handle, or some of the | |
251 // requirements above are not satisfied). | |
252 // |MOJO_RESULT_RESOURCE_EXHAUSTED| if some system limit has been reached, or | |
253 // the number of handles to send is too large (TODO(vtl): reconsider the | |
254 // latter case). | |
255 // |MOJO_RESULT_FAILED_PRECONDITION| if the other endpoint has been closed. | |
256 // Note that closing an endpoint is not necessarily synchronous (e.g., | |
257 // across processes), so this function may be succeed even if the other | |
258 // endpoint has been closed (in which case the message would be dropped). | |
259 // |MOJO_RESULT_BUSY| if some handle to be sent is currently in use. | |
260 // | |
261 // TODO(vtl): Add a notion of capacity for message pipes, and return | |
262 // |MOJO_RESULT_SHOULD_WAIT| if the message pipe is full. | |
263 MOJO_SYSTEM_EXPORT MojoResult MojoWriteMessage( | |
264 MojoHandle message_pipe_handle, | |
265 const void* bytes, // Optional. | |
266 uint32_t num_bytes, | |
267 const MojoHandle* handles, // Optional. | |
268 uint32_t num_handles, | |
269 MojoWriteMessageFlags flags); | |
270 | |
271 // Reads a message from the message pipe endpoint given by | |
272 // |message_pipe_handle|; also usable to query the size of the next message or | |
273 // discard the next message. |bytes|/|*num_bytes| indicate the buffer/buffer | |
274 // size to receive the message data (if any) and |handles|/|*num_handles| | |
275 // indicate the buffer/maximum handle count to receive the attached handles (if | |
276 // any). | |
277 // | |
278 // |num_bytes| and |num_handles| are optional "in-out" parameters. If non-null, | |
279 // on return |*num_bytes| and |*num_handles| will usually indicate the number | |
280 // of bytes and number of attached handles in the "next" message, respectively, | |
281 // whether that message was read or not. (If null, the number of bytes/handles | |
282 // is treated as zero.) | |
283 // | |
284 // If |bytes| is null, then |*num_bytes| must be zero, and similarly for | |
285 // |handles| and |*num_handles|. | |
286 // | |
287 // Partial reads are NEVER done. Either a full read is done and |MOJO_RESULT_OK| | |
288 // returned, or the read is NOT done and |MOJO_RESULT_RESOURCE_EXHAUSTED| is | |
289 // returned (if |MOJO_READ_MESSAGE_FLAG_MAY_DISCARD| was set, the message is | |
290 // also discarded in this case). | |
291 // | |
292 // Returns: | |
293 // |MOJO_RESULT_OK| on success (i.e., a message was actually read). | |
294 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid. | |
295 // |MOJO_RESULT_FAILED_PRECONDITION| if the other endpoint has been closed. | |
296 // |MOJO_RESULT_RESOURCE_EXHAUSTED| if one of the buffers to receive the | |
297 // message/attached handles (|bytes|/|*num_bytes| or | |
298 // |handles|/|*num_handles|) was too small. (TODO(vtl): Reconsider this | |
299 // error code; should distinguish this from the hitting-system-limits | |
300 // case.) | |
301 // |MOJO_RESULT_SHOULD_WAIT| if no message was available to be read. | |
302 MOJO_SYSTEM_EXPORT MojoResult MojoReadMessage( | |
303 MojoHandle message_pipe_handle, | |
304 void* bytes, // Optional out. | |
305 uint32_t* num_bytes, // Optional in/out. | |
306 MojoHandle* handles, // Optional out. | |
307 uint32_t* num_handles, // Optional in/out. | |
308 MojoReadMessageFlags flags); | |
309 | 184 |
310 // Data pipe: | 185 // Data pipe: |
311 | 186 |
312 // Creates a data pipe, which is a unidirectional communication channel for | 187 // Creates a data pipe, which is a unidirectional communication channel for |
313 // unframed data, with the given options. Data is unframed, but must come as | 188 // unframed data, with the given options. Data is unframed, but must come as |
314 // (multiples of) discrete elements, of the size given in |options|. See | 189 // (multiples of) discrete elements, of the size given in |options|. See |
315 // |MojoCreateDataPipeOptions| for a description of the different options | 190 // |MojoCreateDataPipeOptions| for a description of the different options |
316 // available for data pipes. | 191 // available for data pipes. |
317 // | 192 // |
318 // |options| may be set to null for a data pipe with the default options (which | 193 // |options| may be set to null for a data pipe with the default options (which |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 | 481 |
607 // Unmap a buffer pointer that was mapped by |MojoMapBuffer()|. | 482 // Unmap a buffer pointer that was mapped by |MojoMapBuffer()|. |
608 // TODO(vtl): More. | 483 // TODO(vtl): More. |
609 MOJO_SYSTEM_EXPORT MojoResult MojoUnmapBuffer(void* buffer); // In. | 484 MOJO_SYSTEM_EXPORT MojoResult MojoUnmapBuffer(void* buffer); // In. |
610 | 485 |
611 #ifdef __cplusplus | 486 #ifdef __cplusplus |
612 } // extern "C" | 487 } // extern "C" |
613 #endif | 488 #endif |
614 | 489 |
615 #endif // MOJO_PUBLIC_C_SYSTEM_CORE_H_ | 490 #endif // MOJO_PUBLIC_C_SYSTEM_CORE_H_ |
OLD | NEW |