Lines Matching full:mojo
1 # Mojo C++ System API
2 This document is a subset of the [Mojo documentation](/mojo/README.md).
7 The Mojo C++ System API provides a convenient set of helper classes and
8 functions for working with Mojo primitives. Unlike the low-level
9 [C API](/mojo/public/c/system/README.md) (upon which this is built) this library
11 provide a slightly more idiomatic interface to the Mojo system layer, making it
16 [//mojo/public/cpp/system](https://cs.chromium.org/chromium/src/mojo/public/cpp/system/README.md).
19 top-level `mojo` namespace.
23 All types of Mojo handles in the C API are simply opaque, integral `MojoHandle`
45 mojo::MessagePipe pipe;
51 mojo::ScopedMessagePipeHandle client = std::move(pipe.handle0);
52 mojo::ScopedMessagePipeHandle server = std::move(pipe.handle1);
58 mojo::ScopedMessagePipeHandle client;
59 mojo::ScopedMessagePipeHandle server;
60 mojo::CreateMessagePipe(nullptr, &client, &server);
68 mojo::ScopedMessageHandle message;
69 mojo::AllocMessage(6, nullptr, 0, MOJO_ALLOC_MESSAGE_FLAG_NONE, &message);
72 mojo::GetMessageBuffer(message.get(), &buffer);
77 mojo::WriteMessageNew(client.get(), std::move(message),
82 mojo::ScopedMessageHandle received_message;
84 mojo::ReadMessageNew(server.get(), &received_message, &num_bytes, nullptr,
88 See [message_pipe.h](https://cs.chromium.org/chromium/src/mojo/public/cpp/system/message_pipe.h)
97 mojo::DataPipe pipe;
98 mojo::ScopedDataPipeProducerHandle producer = std::move(pipe.producer);
99 mojo::ScopedDataPipeConsumerHandle consumer = std::move(pipe.consumer);
102 mojo::ScopedDataPipeProducerHandle producer;
103 mojo::ScopedDataPipeConsumerHandle consumer;
104 mojo::CreateDataPipe(null, &producer, &consumer);
108 [Data Pipe C API](/mojo/public/c/system/README.md#Data-Pipes) for immediate and
122 See [data_pipe.h](https://cs.chromium.org/chromium/src/mojo/public/cpp/system/data_pipe.h)
130 mojo::ScopedSharedBufferHandle buffer =
131 mojo::SharedBufferHandle::Create(4096);
138 mojo::ScopedSharedBufferHandle another_handle = buffer->Clone();
139 mojo::ScopedSharedBufferHandle read_only_handle =
140 buffer->Clone(mojo::SharedBufferHandle::AccessMode::READ_ONLY);
147 mojo::ScopedSharedBufferMapping mapping = buffer->Map(64);
150 mojo::ScopedSharedBufferMapping another_mapping = buffer->MapAtOffset(64, 4);
157 See [buffer.h](https://cs.chromium.org/chromium/src/mojo/public/cpp/system/buffer.h)
167 [platform_handle.h](https://cs.chromium.org/chromium/src/mojo/public/cpp/system/platform_handle.h)
174 [Signals & Traps](/mojo/public/c/system/README.md#Signals-Traps).
182 mojo::MessagePipe message_pipe;
183 mojo::DataPipe data_pipe;
184 mojo::HandleSignalsState a = message_pipe.handle0->QuerySignalsState();
185 mojo::HandleSignalsState b = data_pipe.consumer->QuerySignalsState();
210 The [`mojo::SimpleWatcher`](https://cs.chromium.org/chromium/src/mojo/public/cpp/system/simple_watc…
212 [low-level traps API](/mojo/public/c/system/README.md#Signals-Traps)
218 time by the `mojo::SimpleWatcher::ArmingPolicy` enum:
224 [Arming a Trap](/mojo/public/c/system/README.md#Arming-a-Trap) and the
240 PipeReader(mojo::ScopedMessagePipeHandle pipe)
242 watcher_(mojo::SimpleWatcher::ArmingPolicy::AUTOMATIC) {
254 mojo::ScopedMessageHandle message;
256 result = mojo::ReadMessageNew(pipe_.get(), &message, &num_bytes, nullptr,
263 mojo::ScopedMessagePipeHandle pipe_;
264 mojo::SimpleWatcher watcher_;
265 std::vector<mojo::ScopedMessageHandle> messages_;
268 mojo::MessagePipe pipe;
280 [low-level traps API](/mojo/public/c/system/README.md#Signals-Traps)
286 [wait.h](https://cs.chromium.org/chromium/src/mojo/public/cpp/system/wait.h)
287 and [wait_set.h](https://cs.chromium.org/chromium/src/mojo/public/cpp/system/wait_set.h)
292 The `mojo::Wait` function simply blocks the calling sequence until a given
297 mojo::MessagePipe pipe;
298 mojo::WriteMessageRaw(pipe.handle0.get(), "hey", 3, nullptr, nullptr,
300 MojoResult result = mojo::Wait(pipe.handle1.get(), MOJO_HANDLE_SIGNAL_READABLE);
304 mojo::ScopedMessageHandle message;
306 mojo::ReadMessageNew(pipe.handle1.get(), &num_bytes, nullptr, nullptr,
310 `mojo::Wait` is most typically useful in limited testing scenarios.
314 `mojo::WaitMany` provides a simple API to wait on multiple handles
319 mojo::MessagePipe a, b;
322 mojo::MessagePipeHandle handles[2] = {a.handle0.get(), b.handle0.get()};
326 MojoResult result = mojo::WaitMany(handles, signals, 2, &ready_index);
334 Similar to `mojo::Wait`, `mojo::WaitMany` is primarily useful in testing. When
336 use a more efficient and more flexible `mojo::WaitSet` as described in the next
346 [`mojo::WaitSet`](https://cs.chromium.org/chromium/src/mojo/public/cpp/system/wait_set.h)
348 set of (not-owned) Mojo handles and `base::WaitableEvent`s, which may be
360 mojo::MessagePipe a, b;
364 mojo::WaitSet wait_set;
377 mojo::Handle ready_handle;
396 Invitations are the means by which two processes can have Mojo IPC bootstrapped
399 [platform support library](/mojo/public/cpp/platform/README.md) provides some
413 #include "mojo/public/cpp/platform/platform_channel.h"
414 #include "mojo/public/cpp/system/invitation.h"
415 #include "mojo/public/cpp/system/message_pipe.h"
417 mojo::ScopedMessagePipeHandle LaunchAndConnectSomething() {
420 mojo::PlatformChannel channel;
422 mojo::OutgoingInvitation invitation;
426 mojo::ScopedMessagePipeHandle pipe =
446 #include "mojo/core/embedder/embedder.h"
447 #include "mojo/core/embedder/scoped_ipc_support.h"
448 #include "mojo/public/cpp/platform/platform_channel.h"
449 #include "mojo/public/cpp/system/invitation.h"
450 #include "mojo/public/cpp/system/message_pipe.h"
453 // Basic Mojo initialization for a new process.
454 mojo::core::Init();
458 mojo::core::ScopedIPCSupport ipc_support(
460 mojo::core::ScopedIPCSupport::ShutdownPolicy::CLEAN);
463 mojo::IncomingInvitation invitation = mojo::IncomingInvitation::Accept(
464 mojo::PlatformChannel::RecoverPassedEndpointFromCommandLine(
466 mojo::ScopedMessagePipeHandle pipe =
482 mojo::OutgoingInvitation invitation;
484 mojo::Binding<foo::mojom::Bar> binding(
489 auto invitation = mojo::IncomingInvitation::Accept(...);
508 to other processes without assistance; rather it means that Mojo handles created
510 over established message pipes, and similarly that Mojo handles created by any
523 It is possible to have two independent networks of Mojo-connected processes; for
524 example, a long-running system daemon which uses Mojo to talk to child processes
535 Once a connection is established via isolated invitation, Mojo IPC can be used