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. | 8 // Note: This header should be compilable as C. |
9 | 9 |
10 #include <stdint.h> | 10 #include <stdint.h> |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 MOJO_SYSTEM_EXPORT MojoResult MojoReadMessage(MojoHandle message_pipe_handle, | 431 MOJO_SYSTEM_EXPORT MojoResult MojoReadMessage(MojoHandle message_pipe_handle, |
432 void* bytes, | 432 void* bytes, |
433 uint32_t* num_bytes, | 433 uint32_t* num_bytes, |
434 MojoHandle* handles, | 434 MojoHandle* handles, |
435 uint32_t* num_handles, | 435 uint32_t* num_handles, |
436 MojoReadMessageFlags flags); | 436 MojoReadMessageFlags flags); |
437 | 437 |
438 // Data pipe: | 438 // Data pipe: |
439 // TODO(vtl): Moar docs. | 439 // TODO(vtl): Moar docs. |
440 | 440 |
| 441 // Creates a data pipe, which is a unidirectional communication channel for |
| 442 // unframed data, with the given options. Data is unframed, but must come as |
| 443 // (multiples of) discrete elements, of the size given in |options|. See |
| 444 // |MojoCreateDataPipeOptions| for a description of the different options |
| 445 // available for data pipes. |
| 446 // |
| 447 // |options| may be set to null for a data pipe with the default options (which |
| 448 // will have an element size of one byte and have some system-dependent |
| 449 // capacity). |
| 450 // |
| 451 // On success, |*data_pipe_producer_handle| will be set to the handle for the |
| 452 // producer and |*data_pipe_consumer_handle| will be set to the handle for the |
| 453 // consumer. (On failure, they are not modified.) |
| 454 // |
| 455 // Returns: |
| 456 // |MOJO_RESULT_OK| on success. |
| 457 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., if |
| 458 // |*options| is invalid or one of the pointer handles looks invalid). |
| 459 // |MOJO_RESULT_RESOURCE_EXHAUSTED| if a process/system/quota/etc. limit has |
| 460 // been reached (e.g., if the requested capacity was too large, or if the |
| 461 // maximum number of handles was exceeded). |
441 MOJO_SYSTEM_EXPORT MojoResult MojoCreateDataPipe( | 462 MOJO_SYSTEM_EXPORT MojoResult MojoCreateDataPipe( |
442 const struct MojoCreateDataPipeOptions* options, | 463 const struct MojoCreateDataPipeOptions* options, |
443 MojoHandle* data_pipe_producer_handle, | 464 MojoHandle* data_pipe_producer_handle, |
444 MojoHandle* data_pipe_consumer_handle); | 465 MojoHandle* data_pipe_consumer_handle); |
445 | 466 |
| 467 // Writes the given data to the data pipe producer given by |
| 468 // |data_pipe_producer_handle|. |elements| points to data of size |*num_bytes|; |
| 469 // |*num_bytes| should be a multiple of the data pipe's element size. If |
| 470 // |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| is set in |flags|, either all the data |
| 471 // will be written or none is. |
| 472 // |
| 473 // On success, |*num_bytes| is set to the amount of data that was actually |
| 474 // written. |
| 475 // |
| 476 // Note: If the data pipe has the "may discard" option flag (specified on |
| 477 // creation), this will discard as much data as required to write the given |
| 478 // data, starting with the earliest written data that has not been consumed. |
| 479 // However, even with "may discard", if |*num_bytes| is greater than the data |
| 480 // pipe's capacity (and |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| is not set), this |
| 481 // will write the maximum amount possible (namely, the data pipe's capacity) and |
| 482 // set |*num_bytes| to that amount. It will *not* discard data from |elements|. |
| 483 // |
| 484 // Returns: |
| 485 // |MOJO_RESULT_OK| on success. |
| 486 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., if |
| 487 // |data_pipe_producer_dispatcher| is not a handle to a data pipe |
| 488 // producer, |elements| does not look like a valid pointer, or |
| 489 // |*num_bytes| is not a multiple of the data pipe's element size). |
| 490 // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe consumer handle has been |
| 491 // closed. |
| 492 // |MOJO_RESULT_OUT_OF_RANGE| if |flags| has |
| 493 // |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| set and the required amount of data |
| 494 // (specified by |*num_bytes|) could not be written. |
| 495 // |MOJO_RESULT_BUSY| if there is a two-phase write ongoing with |
| 496 // |data_pipe_producer_handle| (i.e., |MojoBeginWriteData()| has been |
| 497 // called, but not yet the matching |MojoEndWriteData()|). |
| 498 // |MOJO_RESULT_SHOULD_WAIT| if no data can currently be written (and the |
| 499 // consumer is still open) and |flags| does *not* have |
| 500 // |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| set. |
| 501 // |
| 502 // TODO(vtl): Should there be a way of querying how much data can be written? |
446 MOJO_SYSTEM_EXPORT MojoResult MojoWriteData( | 503 MOJO_SYSTEM_EXPORT MojoResult MojoWriteData( |
447 MojoHandle data_pipe_producer_handle, | 504 MojoHandle data_pipe_producer_handle, |
448 const void* elements, | 505 const void* elements, |
449 uint32_t* num_bytes, | 506 uint32_t* num_bytes, |
450 MojoWriteDataFlags flags); | 507 MojoWriteDataFlags flags); |
451 | 508 |
| 509 // TODO(vtl): Document me. |
452 // TODO(vtl): Note to self: |buffer_num_bytes| is an "in-out" parameter: on the | 510 // TODO(vtl): Note to self: |buffer_num_bytes| is an "in-out" parameter: on the |
453 // "in" side, |*buffer_num_bytes| is the number requested; on success, on the | 511 // "in" side, |*buffer_num_bytes| is the number requested; on success, on the |
454 // "out" side, it's the number available (which may be GREATER or LESS than the | 512 // "out" side, it's the number available (which may be GREATER or LESS than the |
455 // number requested; if the "all-or-nothing" flag is set, it's AT LEAST the | 513 // number requested; if the "all-or-nothing" flag is set, it's AT LEAST the |
456 // number requested). | 514 // number requested). |
457 MOJO_SYSTEM_EXPORT MojoResult MojoBeginWriteData( | 515 MOJO_SYSTEM_EXPORT MojoResult MojoBeginWriteData( |
458 MojoHandle data_pipe_producer_handle, | 516 MojoHandle data_pipe_producer_handle, |
459 void** buffer, | 517 void** buffer, |
460 uint32_t* buffer_num_bytes, | 518 uint32_t* buffer_num_bytes, |
461 MojoWriteDataFlags flags); | 519 MojoWriteDataFlags flags); |
462 | 520 |
| 521 // TODO(vtl): Document me. |
463 MOJO_SYSTEM_EXPORT MojoResult MojoEndWriteData( | 522 MOJO_SYSTEM_EXPORT MojoResult MojoEndWriteData( |
464 MojoHandle data_pipe_producer_handle, | 523 MojoHandle data_pipe_producer_handle, |
465 uint32_t num_bytes_written); | 524 uint32_t num_bytes_written); |
466 | 525 |
| 526 // Reads data from the data pipe consumer given by |data_pipe_consumer_handle|. |
| 527 // May also be used to discard data or query the amount of data available. |
| 528 // |
| 529 // If |flags| has neither |MOJO_READ_DATA_FLAG_DISCARD| nor |
| 530 // |MOJO_READ_DATA_FLAG_QUERY| set, this tries to read up to |*num_bytes| (which |
| 531 // must be a multiple of the data pipe's element size) bytes of data to |
| 532 // |elements| and set |*num_bytes| to the amount actually read. If flags has |
| 533 // |MOJO_READ_DATA_FLAG_ALL_OR_NONE| set, it will either read exactly |
| 534 // |*num_bytes| bytes of data or none. |
| 535 // |
| 536 // If flags has |MOJO_READ_DATA_FLAG_DISCARD| set, it discards up to |
| 537 // |*num_bytes| (which again be a multiple of the element size) bytes of data, |
| 538 // setting |*num_bytes| to the amount actually discarded. If flags has |
| 539 // |MOJO_READ_DATA_FLAG_ALL_OR_NONE|, it will either discard exactly |
| 540 // |*num_bytes| bytes of data or none. In this case, |MOJO_READ_DATA_FLAG_QUERY| |
| 541 // must not be set, and |elements| is ignored (and should typically be set to |
| 542 // null). |
| 543 // |
| 544 // If flags has |MOJO_READ_DATA_FLAG_QUERY| set, it queries the amount of data |
| 545 // available, setting |*num_bytes| to the number of bytes available. In this |
| 546 // case, |MOJO_READ_DATA_FLAG_DISCARD| must not be set, and |
| 547 // |MOJO_READ_DATA_FLAG_ALL_OR_NONE| is ignored, as are |elements| and the input |
| 548 // value of |*num_bytes|. |
| 549 // |
| 550 // Returns: |
| 551 // |MOJO_RESULT_OK| on success (see above for a description of the different |
| 552 // operations). |
| 553 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., |
| 554 // |data_pipe_consumer_handle| is invalid, the combination of flags in |
| 555 // |flags| is invalid, etc.). |
| 556 // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe producer handle has been |
| 557 // closed and data (or the required amount of data) was not available to |
| 558 // be read or discarded. |
| 559 // |MOJO_RESULT_OUT_OF_RANGE| if |flags| has |MOJO_READ_DATA_FLAG_ALL_OR_NONE| |
| 560 // set and the required amount of data is not available to be read or |
| 561 // discarded (and the producer is still open). |
| 562 // |MOJO_RESULT_BUSY| if there is a two-phase read ongoing with |
| 563 // |data_pipe_consumer_handle| (i.e., |MojoBeginReadData()| has been |
| 564 // called, but not yet the matching |MojoEndReadData()|). |
| 565 // |MOJO_RESULT_SHOULD_WAIT| if there is no data to be read or discarded (and |
| 566 // the producer is still open) and |flags| does *not* have |
| 567 // |MOJO_READ_DATA_FLAG_ALL_OR_NONE| set. |
| 568 // |
467 // TODO(vtl): Note to self: If |MOJO_READ_DATA_FLAG_QUERY| is set, then | 569 // TODO(vtl): Note to self: If |MOJO_READ_DATA_FLAG_QUERY| is set, then |
468 // |elements| must be null (and nothing will be read). | 570 // |elements| must be null (and nothing will be read). |
469 MOJO_SYSTEM_EXPORT MojoResult MojoReadData( | 571 MOJO_SYSTEM_EXPORT MojoResult MojoReadData( |
470 MojoHandle data_pipe_consumer_handle, | 572 MojoHandle data_pipe_consumer_handle, |
471 void* elements, | 573 void* elements, |
472 uint32_t* num_bytes, | 574 uint32_t* num_bytes, |
473 MojoReadDataFlags flags); | 575 MojoReadDataFlags flags); |
474 | 576 |
| 577 // TODO(vtl): Document me. |
475 MOJO_SYSTEM_EXPORT MojoResult MojoBeginReadData( | 578 MOJO_SYSTEM_EXPORT MojoResult MojoBeginReadData( |
476 MojoHandle data_pipe_consumer_handle, | 579 MojoHandle data_pipe_consumer_handle, |
477 const void** buffer, | 580 const void** buffer, |
478 uint32_t* buffer_num_bytes, | 581 uint32_t* buffer_num_bytes, |
479 MojoReadDataFlags flags); | 582 MojoReadDataFlags flags); |
480 | 583 |
| 584 // TODO(vtl): Document me. |
481 MOJO_SYSTEM_EXPORT MojoResult MojoEndReadData( | 585 MOJO_SYSTEM_EXPORT MojoResult MojoEndReadData( |
482 MojoHandle data_pipe_consumer_handle, | 586 MojoHandle data_pipe_consumer_handle, |
483 uint32_t num_bytes_read); | 587 uint32_t num_bytes_read); |
484 | 588 |
485 #ifdef __cplusplus | 589 #ifdef __cplusplus |
486 } // extern "C" | 590 } // extern "C" |
487 #endif | 591 #endif |
488 | 592 |
489 #endif // MOJO_PUBLIC_SYSTEM_CORE_H_ | 593 #endif // MOJO_PUBLIC_SYSTEM_CORE_H_ |
OLD | NEW |