Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: mojo/edk/system/message_for_transit.h

Issue 1880823005: [mojo-edk] Add explicit message object APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: make VS happy Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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>
9
10 #include <memory>
11
12 #include "base/macros.h"
13 #include "mojo/edk/system/dispatcher.h"
14 #include "mojo/edk/system/ports_message.h"
15 #include "mojo/edk/system/system_impl_export.h"
16
17 namespace mojo {
18 namespace edk {
19
20 // MessageForTransit holds onto a PortsMessage which may be sent via
21 // |MojoWriteMessage()| or which may have been received on a pipe endpoint.
22 // Instances of this class are exposed to Mojo system API consumers via the
23 // opaque pointers used with |MojoCreateMessage()|, |MojoDestroyMessage()|,
24 // |MojoWriteMessageNew()|, and |MojoReadMessageNew()|.
25 class MOJO_SYSTEM_IMPL_EXPORT MessageForTransit {
26 public:
27 #pragma pack(push, 1)
28 // Header attached to every message.
29 struct MessageHeader {
30 // The number of serialized dispatchers included in this header.
31 uint32_t num_dispatchers;
32
33 // Total size of the header, including serialized dispatcher data.
34 uint32_t header_size;
35 };
36
37 // Header for each dispatcher in a message, immediately following the message
38 // header.
39 struct DispatcherHeader {
40 // The type of the dispatcher, correpsonding to the Dispatcher::Type enum.
41 int32_t type;
42
43 // The size of the serialized dispatcher, not including this header.
44 uint32_t num_bytes;
45
46 // The number of ports needed to deserialize this dispatcher.
47 uint32_t num_ports;
48
49 // The number of platform handles needed to deserialize this dispatcher.
50 uint32_t num_platform_handles;
51 };
52 #pragma pack(pop)
53
54 ~MessageForTransit();
55
56 // A static constructor for building outbound messages.
57 static MojoResult Create(
58 MessageForTransit** message,
Anand Mistry (off Chromium) 2016/04/21 12:19:42 WDYT about: unique_ptr<MessageForTransit>* message
Ken Rockot(use gerrit already) 2016/04/21 16:47:40 Done
59 uint32_t num_bytes,
60 const Dispatcher::DispatcherInTransit* dispatchers,
61 uint32_t num_dispatchers);
62
63 // A static constructor for wrapping inbound messages.
64 static MessageForTransit* WrapPortsMessage(
65 std::unique_ptr<PortsMessage> message);
66
67 const void* bytes() const;
68 void* mutable_bytes();
69 size_t num_bytes() const;
70
71 size_t num_handles() const;
72
73 std::unique_ptr<PortsMessage> TakePortsMessage();
74
75 private:
76 explicit MessageForTransit(std::unique_ptr<PortsMessage> message);
77
78 std::unique_ptr<PortsMessage> message_;
79
80 DISALLOW_COPY_AND_ASSIGN(MessageForTransit);
81 };
82
83 } // namespace edk
84 } // namespace mojo
85
86 #endif // MOJO_EDK_SYSTEM_MESSAGE_FOR_TRANSIT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698