OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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_EDK_SYSTEM_CHANNEL_H_ | 5 #ifndef MOJO_EDK_SYSTEM_CHANNEL_H_ |
6 #define MOJO_EDK_SYSTEM_CHANNEL_H_ | 6 #define MOJO_EDK_SYSTEM_CHANNEL_H_ |
7 | 7 |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 // A control message containing handles to echo back. | 38 // A control message containing handles to echo back. |
39 HANDLES_SENT, | 39 HANDLES_SENT, |
40 // A control message containing handles that can now be closed. | 40 // A control message containing handles that can now be closed. |
41 HANDLES_SENT_ACK, | 41 HANDLES_SENT_ACK, |
42 #endif | 42 #endif |
43 }; | 43 }; |
44 | 44 |
45 // Message size in bytes, including the header. | 45 // Message size in bytes, including the header. |
46 uint32_t num_bytes; | 46 uint32_t num_bytes; |
47 | 47 |
48 #if defined(OS_CHROMEOS) || defined(OS_ANDROID) | 48 #if defined(MOJO_EDK_LEGACY_PROTOCOL) |
49 // Old message wire format for ChromeOS and Android. | 49 // Old message wire format for ChromeOS and Android. |
50 // Number of attached handles. | 50 // Number of attached handles. |
51 uint16_t num_handles; | 51 uint16_t num_handles; |
52 | 52 |
53 MessageType message_type; | 53 MessageType message_type; |
54 #else | 54 #else |
55 // Total size of header, including extra header data (i.e. HANDLEs on | 55 // Total size of header, including extra header data (i.e. HANDLEs on |
56 // windows). | 56 // windows). |
57 uint16_t num_header_bytes; | 57 uint16_t num_header_bytes; |
58 | 58 |
59 // Number of attached handles. May be less than the reserved handle | 59 // Number of attached handles. May be less than the reserved handle |
60 // storage size in this message on platforms that serialise handles as | 60 // storage size in this message on platforms that serialise handles as |
61 // data (i.e. HANDLEs on Windows, Mach ports on OSX). | 61 // data (i.e. HANDLEs on Windows, Mach ports on OSX). |
62 uint16_t num_handles; | 62 uint16_t num_handles; |
63 | 63 |
64 MessageType message_type; | 64 MessageType message_type; |
65 | 65 |
66 char padding[6]; | 66 char padding[6]; |
67 #endif // defined(OS_CHROMEOS) || defined(OS_ANDROID) | 67 #endif // defined(MOJO_EDK_LEGACY_PROTOCOL) |
68 }; | 68 }; |
69 | 69 |
70 #if defined(OS_MACOSX) && !defined(OS_IOS) | 70 #if defined(OS_MACOSX) && !defined(OS_IOS) |
71 struct MachPortsEntry { | 71 struct MachPortsEntry { |
72 // Index of Mach port in the original vector of PlatformHandles. | 72 // Index of Mach port in the original vector of PlatformHandles. |
73 uint16_t index; | 73 uint16_t index; |
74 | 74 |
75 // Mach port name. | 75 // Mach port name. |
76 uint32_t mach_port; | 76 uint32_t mach_port; |
77 static_assert(sizeof(mach_port_t) <= sizeof(uint32_t), | 77 static_assert(sizeof(mach_port_t) <= sizeof(uint32_t), |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 Header::MessageType message_type = Header::MessageType::NORMAL); | 109 Header::MessageType message_type = Header::MessageType::NORMAL); |
110 | 110 |
111 ~Message(); | 111 ~Message(); |
112 | 112 |
113 // Constructs a Message from serialized message data. | 113 // Constructs a Message from serialized message data. |
114 static MessagePtr Deserialize(const void* data, size_t data_num_bytes); | 114 static MessagePtr Deserialize(const void* data, size_t data_num_bytes); |
115 | 115 |
116 const void* data() const { return data_; } | 116 const void* data() const { return data_; } |
117 size_t data_num_bytes() const { return size_; } | 117 size_t data_num_bytes() const { return size_; } |
118 | 118 |
119 #if defined(OS_CHROMEOS) || defined(OS_ANDROID) | 119 #if defined(MOJO_EDK_LEGACY_PROTOCOL) |
120 void* mutable_payload() { return static_cast<void*>(header_ + 1); } | 120 void* mutable_payload() { return static_cast<void*>(header_ + 1); } |
121 const void* payload() const { | 121 const void* payload() const { |
122 return static_cast<const void*>(header_ + 1); | 122 return static_cast<const void*>(header_ + 1); |
123 } | 123 } |
124 size_t payload_size() const; | 124 size_t payload_size() const; |
125 #else | 125 #else |
126 const void* extra_header() const { return data_ + sizeof(Header); } | 126 const void* extra_header() const { return data_ + sizeof(Header); } |
127 void* mutable_extra_header() { return data_ + sizeof(Header); } | 127 void* mutable_extra_header() { return data_ + sizeof(Header); } |
128 size_t extra_header_size() const { | 128 size_t extra_header_size() const { |
129 return header_->num_header_bytes - sizeof(Header); | 129 return header_->num_header_bytes - sizeof(Header); |
130 } | 130 } |
131 | 131 |
132 void* mutable_payload() { return data_ + header_->num_header_bytes; } | 132 void* mutable_payload() { return data_ + header_->num_header_bytes; } |
133 const void* payload() const { return data_ + header_->num_header_bytes; } | 133 const void* payload() const { return data_ + header_->num_header_bytes; } |
134 size_t payload_size() const; | 134 size_t payload_size() const; |
135 #endif // defined(OS_CHROMEOS) || defined(OS_ANDROID) | 135 #endif // defined(MOJO_EDK_LEGACY_PROTOCOL) |
136 | 136 |
137 size_t num_handles() const { return header_->num_handles; } | 137 size_t num_handles() const { return header_->num_handles; } |
138 bool has_handles() const { return header_->num_handles > 0; } | 138 bool has_handles() const { return header_->num_handles > 0; } |
139 #if defined(OS_MACOSX) && !defined(OS_IOS) | 139 #if defined(OS_MACOSX) && !defined(OS_IOS) |
140 bool has_mach_ports() const; | 140 bool has_mach_ports() const; |
141 #endif | 141 #endif |
142 | 142 |
143 // Note: SetHandles() and TakeHandles() invalidate any previous value of | 143 // Note: SetHandles() and TakeHandles() invalidate any previous value of |
144 // handles(). | 144 // handles(). |
145 void SetHandles(ScopedPlatformHandleVectorPtr new_handles); | 145 void SetHandles(ScopedPlatformHandleVectorPtr new_handles); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 Delegate* delegate_; | 283 Delegate* delegate_; |
284 const std::unique_ptr<ReadBuffer> read_buffer_; | 284 const std::unique_ptr<ReadBuffer> read_buffer_; |
285 | 285 |
286 DISALLOW_COPY_AND_ASSIGN(Channel); | 286 DISALLOW_COPY_AND_ASSIGN(Channel); |
287 }; | 287 }; |
288 | 288 |
289 } // namespace edk | 289 } // namespace edk |
290 } // namespace mojo | 290 } // namespace mojo |
291 | 291 |
292 #endif // MOJO_EDK_SYSTEM_CHANNEL_H_ | 292 #endif // MOJO_EDK_SYSTEM_CHANNEL_H_ |
OLD | NEW |