Chromium Code Reviews| Index: mojo/edk/system/message_for_transit.h |
| diff --git a/mojo/edk/system/message_for_transit.h b/mojo/edk/system/message_for_transit.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..290989a8374779b869e40ff361e71ae21cb87ae6 |
| --- /dev/null |
| +++ b/mojo/edk/system/message_for_transit.h |
| @@ -0,0 +1,84 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef MOJO_EDK_SYSTEM_MESSAGE_FOR_TRANSIT_H_ |
| +#define MOJO_EDK_SYSTEM_MESSAGE_FOR_TRANSIT_H_ |
| + |
| +#include <stdint.h> |
|
Anand Mistry (off Chromium)
2016/04/19 12:57:35
#include <memory> for unique_ptr
Ken Rockot(use gerrit already)
2016/04/19 18:11:25
Done
|
| + |
| +#include "base/macros.h" |
| +#include "mojo/edk/system/dispatcher.h" |
| +#include "mojo/edk/system/ports_message.h" |
| +#include "mojo/edk/system/system_impl_export.h" |
| + |
| +namespace mojo { |
| +namespace edk { |
| + |
| +// MessageForTransit holds onto a PortsMessage which may be sent via |
| +// |MojoWriteMessage()| or which may have been received on a pipe endpoint. |
| +// Instances of this class are exposed to Mojo system API consumers via the |
| +// opaque pointers used with |MojoCreateMessage()|, |MojoDestroyMessage()|, |
| +// |MojoWriteMessageNew()|, and |MojoReadMessageNew()|. |
| +class MOJO_SYSTEM_IMPL_EXPORT MessageForTransit { |
| + public: |
| +#pragma pack(push, 1) |
| + // Header attached to every message. |
| + struct MessageHeader { |
| + // The number of serialized dispatchers included in this header. |
| + uint32_t num_dispatchers; |
| + |
| + // Total size of the header, including serialized dispatcher data. |
| + uint32_t header_size; |
| + }; |
| + |
| + // Header for each dispatcher in a message, immediately following the message |
| + // header. |
| + struct DispatcherHeader { |
| + // The type of the dispatcher, correpsonding to the Dispatcher::Type enum. |
| + int32_t type; |
| + |
| + // The size of the serialized dispatcher, not including this header. |
| + uint32_t num_bytes; |
| + |
| + // The number of ports needed to deserialize this dispatcher. |
| + uint32_t num_ports; |
| + |
| + // The number of platform handles needed to deserialize this dispatcher. |
| + uint32_t num_platform_handles; |
| + }; |
| +#pragma pack(pop) |
| + |
| + ~MessageForTransit(); |
| + |
| + // A static constructor for building outbound messages. |
| + static MojoResult Create( |
| + MessageForTransit** message, |
| + uint32_t num_bytes, |
| + const Dispatcher::DispatcherInTransit* dispatchers, |
| + uint32_t num_dispatchers); |
| + |
| + // A static constructor for wrapping inbound messages. |
| + static MessageForTransit* WrapPortsMessage( |
| + std::unique_ptr<PortsMessage> message); |
| + |
| + const void* bytes() const; |
| + void* mutable_bytes(); |
| + size_t num_bytes() const; |
| + |
| + size_t num_handles() const; |
| + |
| + std::unique_ptr<PortsMessage>* message(); |
|
Anand Mistry (off Chromium)
2016/04/19 12:57:35
Returning a pointer to a unique_ptr seems weird. W
Ken Rockot(use gerrit already)
2016/04/19 18:11:25
The rationale was that a caller may or may not wan
|
| + |
| + private: |
| + explicit MessageForTransit(std::unique_ptr<PortsMessage> message); |
| + |
| + std::unique_ptr<PortsMessage> message_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(MessageForTransit); |
| +}; |
| + |
| +} // namespace edk |
| +} // namespace mojo |
| + |
| +#endif // MOJO_EDK_SYSTEM_MESSAGE_FOR_TRANSIT_H_ |