OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_SYSTEM_MESSAGE_IN_TRANSIT_H_ | 5 #ifndef MOJO_SYSTEM_MESSAGE_IN_TRANSIT_H_ |
6 #define MOJO_SYSTEM_MESSAGE_IN_TRANSIT_H_ | 6 #define MOJO_SYSTEM_MESSAGE_IN_TRANSIT_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/aligned_memory.h" | 14 #include "base/memory/aligned_memory.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "mojo/system/dispatcher.h" | 16 #include "mojo/system/dispatcher.h" |
| 17 #include "mojo/system/memory.h" |
17 #include "mojo/system/system_impl_export.h" | 18 #include "mojo/system/system_impl_export.h" |
18 | 19 |
19 namespace mojo { | 20 namespace mojo { |
20 namespace system { | 21 namespace system { |
21 | 22 |
22 class Channel; | 23 class Channel; |
23 class TransportData; | 24 class TransportData; |
24 | 25 |
25 // This class is used to represent data in transit. It is thread-unsafe. | 26 // This class is used to represent data in transit. It is thread-unsafe. |
26 // | 27 // |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 // own its data. (If you're copying/assigning this, you're probably doing | 128 // own its data. (If you're copying/assigning this, you're probably doing |
128 // something wrong.) | 129 // something wrong.) |
129 DISALLOW_COPY_AND_ASSIGN(View); | 130 DISALLOW_COPY_AND_ASSIGN(View); |
130 }; | 131 }; |
131 | 132 |
132 // |bytes| is optional; if null, the message data will be zero-initialized. | 133 // |bytes| is optional; if null, the message data will be zero-initialized. |
133 MessageInTransit(Type type, | 134 MessageInTransit(Type type, |
134 Subtype subtype, | 135 Subtype subtype, |
135 uint32_t num_bytes, | 136 uint32_t num_bytes, |
136 const void* bytes); | 137 const void* bytes); |
| 138 // |bytes| should be valid (and non-null), unless |num_bytes| is zero. |
| 139 MessageInTransit(Type type, |
| 140 Subtype subtype, |
| 141 uint32_t num_bytes, |
| 142 UserPointer<const void> bytes); |
137 // Constructs a |MessageInTransit| from a |View|. | 143 // Constructs a |MessageInTransit| from a |View|. |
138 explicit MessageInTransit(const View& message_view); | 144 explicit MessageInTransit(const View& message_view); |
139 | 145 |
140 ~MessageInTransit(); | 146 ~MessageInTransit(); |
141 | 147 |
142 // Gets the size of the next message from |buffer|, which has |buffer_size| | 148 // Gets the size of the next message from |buffer|, which has |buffer_size| |
143 // bytes currently available, returning true and setting |*next_message_size| | 149 // bytes currently available, returning true and setting |*next_message_size| |
144 // on success. |buffer| should be aligned on a |kMessageAlignment| boundary | 150 // on success. |buffer| should be aligned on a |kMessageAlignment| boundary |
145 // (and on success, |*next_message_size| will be a multiple of | 151 // (and on success, |*next_message_size| will be a multiple of |
146 // |kMessageAlignment|). | 152 // |kMessageAlignment|). |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 // Size of actual message data. | 235 // Size of actual message data. |
230 uint32_t num_bytes; | 236 uint32_t num_bytes; |
231 uint32_t unused; | 237 uint32_t unused; |
232 }; | 238 }; |
233 | 239 |
234 const Header* header() const { | 240 const Header* header() const { |
235 return reinterpret_cast<const Header*>(main_buffer_.get()); | 241 return reinterpret_cast<const Header*>(main_buffer_.get()); |
236 } | 242 } |
237 Header* header() { return reinterpret_cast<Header*>(main_buffer_.get()); } | 243 Header* header() { return reinterpret_cast<Header*>(main_buffer_.get()); } |
238 | 244 |
| 245 void ConstructorHelper(Type type, |
| 246 Subtype subtype, |
| 247 uint32_t num_bytes); |
239 void UpdateTotalSize(); | 248 void UpdateTotalSize(); |
240 | 249 |
241 const size_t main_buffer_size_; | 250 const size_t main_buffer_size_; |
242 const scoped_ptr<char, base::AlignedFreeDeleter> main_buffer_; // Never null. | 251 const scoped_ptr<char, base::AlignedFreeDeleter> main_buffer_; // Never null. |
243 | 252 |
244 scoped_ptr<TransportData> transport_data_; // May be null. | 253 scoped_ptr<TransportData> transport_data_; // May be null. |
245 | 254 |
246 // Any dispatchers that may be attached to this message. These dispatchers | 255 // Any dispatchers that may be attached to this message. These dispatchers |
247 // should be "owned" by this message, i.e., have a ref count of exactly 1. (We | 256 // should be "owned" by this message, i.e., have a ref count of exactly 1. (We |
248 // allow a dispatcher entry to be null, in case it couldn't be duplicated for | 257 // allow a dispatcher entry to be null, in case it couldn't be duplicated for |
249 // some reason.) | 258 // some reason.) |
250 scoped_ptr<DispatcherVector> dispatchers_; | 259 scoped_ptr<DispatcherVector> dispatchers_; |
251 | 260 |
252 DISALLOW_COPY_AND_ASSIGN(MessageInTransit); | 261 DISALLOW_COPY_AND_ASSIGN(MessageInTransit); |
253 }; | 262 }; |
254 | 263 |
255 } // namespace system | 264 } // namespace system |
256 } // namespace mojo | 265 } // namespace mojo |
257 | 266 |
258 #endif // MOJO_SYSTEM_MESSAGE_IN_TRANSIT_H_ | 267 #endif // MOJO_SYSTEM_MESSAGE_IN_TRANSIT_H_ |
OLD | NEW |