Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef MOJO_EDK_SYSTEM_MESSAGE_FOR_TRANSIT_H_ | |
| 6 #define MOJO_EDK_SYSTEM_MESSAGE_FOR_TRANSIT_H_ | |
| 7 | |
| 8 #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
| |
| 9 | |
| 10 #include "base/macros.h" | |
| 11 #include "mojo/edk/system/dispatcher.h" | |
| 12 #include "mojo/edk/system/ports_message.h" | |
| 13 #include "mojo/edk/system/system_impl_export.h" | |
| 14 | |
| 15 namespace mojo { | |
| 16 namespace edk { | |
| 17 | |
| 18 // MessageForTransit holds onto a PortsMessage which may be sent via | |
| 19 // |MojoWriteMessage()| or which may have been received on a pipe endpoint. | |
| 20 // Instances of this class are exposed to Mojo system API consumers via the | |
| 21 // opaque pointers used with |MojoCreateMessage()|, |MojoDestroyMessage()|, | |
| 22 // |MojoWriteMessageNew()|, and |MojoReadMessageNew()|. | |
| 23 class MOJO_SYSTEM_IMPL_EXPORT MessageForTransit { | |
| 24 public: | |
| 25 #pragma pack(push, 1) | |
| 26 // Header attached to every message. | |
| 27 struct MessageHeader { | |
| 28 // The number of serialized dispatchers included in this header. | |
| 29 uint32_t num_dispatchers; | |
| 30 | |
| 31 // Total size of the header, including serialized dispatcher data. | |
| 32 uint32_t header_size; | |
| 33 }; | |
| 34 | |
| 35 // Header for each dispatcher in a message, immediately following the message | |
| 36 // header. | |
| 37 struct DispatcherHeader { | |
| 38 // The type of the dispatcher, correpsonding to the Dispatcher::Type enum. | |
| 39 int32_t type; | |
| 40 | |
| 41 // The size of the serialized dispatcher, not including this header. | |
| 42 uint32_t num_bytes; | |
| 43 | |
| 44 // The number of ports needed to deserialize this dispatcher. | |
| 45 uint32_t num_ports; | |
| 46 | |
| 47 // The number of platform handles needed to deserialize this dispatcher. | |
| 48 uint32_t num_platform_handles; | |
| 49 }; | |
| 50 #pragma pack(pop) | |
| 51 | |
| 52 ~MessageForTransit(); | |
| 53 | |
| 54 // A static constructor for building outbound messages. | |
| 55 static MojoResult Create( | |
| 56 MessageForTransit** message, | |
| 57 uint32_t num_bytes, | |
| 58 const Dispatcher::DispatcherInTransit* dispatchers, | |
| 59 uint32_t num_dispatchers); | |
| 60 | |
| 61 // A static constructor for wrapping inbound messages. | |
| 62 static MessageForTransit* WrapPortsMessage( | |
| 63 std::unique_ptr<PortsMessage> message); | |
| 64 | |
| 65 const void* bytes() const; | |
| 66 void* mutable_bytes(); | |
| 67 size_t num_bytes() const; | |
| 68 | |
| 69 size_t num_handles() const; | |
| 70 | |
| 71 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
| |
| 72 | |
| 73 private: | |
| 74 explicit MessageForTransit(std::unique_ptr<PortsMessage> message); | |
| 75 | |
| 76 std::unique_ptr<PortsMessage> message_; | |
| 77 | |
| 78 DISALLOW_COPY_AND_ASSIGN(MessageForTransit); | |
| 79 }; | |
| 80 | |
| 81 } // namespace edk | |
| 82 } // namespace mojo | |
| 83 | |
| 84 #endif // MOJO_EDK_SYSTEM_MESSAGE_FOR_TRANSIT_H_ | |
| OLD | NEW |