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_EDK_SYSTEM_MESSAGE_IN_TRANSIT_H_ | 5 #ifndef MOJO_EDK_SYSTEM_MESSAGE_IN_TRANSIT_H_ |
6 #define MOJO_EDK_SYSTEM_MESSAGE_IN_TRANSIT_H_ | 6 #define MOJO_EDK_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 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 } | 96 } |
97 size_t transport_data_buffer_size() const { | 97 size_t transport_data_buffer_size() const { |
98 return total_size() - main_buffer_size(); | 98 return total_size() - main_buffer_size(); |
99 } | 99 } |
100 size_t total_size() const { return header()->total_size; } | 100 size_t total_size() const { return header()->total_size; } |
101 uint32_t num_bytes() const { return header()->num_bytes; } | 101 uint32_t num_bytes() const { return header()->num_bytes; } |
102 const void* bytes() const { | 102 const void* bytes() const { |
103 return static_cast<const char*>(buffer_) + sizeof(Header); | 103 return static_cast<const char*>(buffer_) + sizeof(Header); |
104 } | 104 } |
105 Type type() const { return header()->type; } | 105 Type type() const { return header()->type; } |
| 106 uint64_t route_id() const { return header()->route_id; } |
106 | 107 |
107 private: | 108 private: |
108 const Header* header() const { return static_cast<const Header*>(buffer_); } | 109 const Header* header() const { return static_cast<const Header*>(buffer_); } |
109 | 110 |
110 const void* const buffer_; | 111 const void* const buffer_; |
111 | 112 |
112 // Though this struct is trivial, disallow copy and assign, since it doesn't | 113 // Though this struct is trivial, disallow copy and assign, since it doesn't |
113 // own its data. (If you're copying/assigning this, you're probably doing | 114 // own its data. (If you're copying/assigning this, you're probably doing |
114 // something wrong.) | 115 // something wrong.) |
115 MOJO_DISALLOW_COPY_AND_ASSIGN(View); | 116 MOJO_DISALLOW_COPY_AND_ASSIGN(View); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 | 165 |
165 // Gets the size of the message data. | 166 // Gets the size of the message data. |
166 uint32_t num_bytes() const { return header()->num_bytes; } | 167 uint32_t num_bytes() const { return header()->num_bytes; } |
167 | 168 |
168 // Gets the message data (of size |num_bytes()| bytes). | 169 // Gets the message data (of size |num_bytes()| bytes). |
169 const void* bytes() const { return main_buffer_.get() + sizeof(Header); } | 170 const void* bytes() const { return main_buffer_.get() + sizeof(Header); } |
170 void* bytes() { return main_buffer_.get() + sizeof(Header); } | 171 void* bytes() { return main_buffer_.get() + sizeof(Header); } |
171 | 172 |
172 Type type() const { return header()->type; } | 173 Type type() const { return header()->type; } |
173 | 174 |
| 175 void set_route_id(uint64_t route_id) { header()->route_id = route_id; } |
| 176 uint64_t route_id() const { return header()->route_id; } |
| 177 |
174 // Gets the dispatchers attached to this message; this may return null if | 178 // Gets the dispatchers attached to this message; this may return null if |
175 // there are none. Note that the caller may mutate the set of dispatchers | 179 // there are none. Note that the caller may mutate the set of dispatchers |
176 // (e.g., take ownership of all the dispatchers, leaving the vector empty). | 180 // (e.g., take ownership of all the dispatchers, leaving the vector empty). |
177 DispatcherVector* dispatchers() { return dispatchers_.get(); } | 181 DispatcherVector* dispatchers() { return dispatchers_.get(); } |
178 | 182 |
179 // Returns true if this message has dispatchers attached. | 183 // Returns true if this message has dispatchers attached. |
180 bool has_dispatchers() const { | 184 bool has_dispatchers() const { |
181 return dispatchers_ && !dispatchers_->empty(); | 185 return dispatchers_ && !dispatchers_->empty(); |
182 } | 186 } |
183 | 187 |
184 // Rounds |n| up to a multiple of |kMessageAlignment|. | 188 // Rounds |n| up to a multiple of |kMessageAlignment|. |
185 static inline size_t RoundUpMessageAlignment(size_t n) { | 189 static inline size_t RoundUpMessageAlignment(size_t n) { |
186 return (n + kMessageAlignment - 1) & ~(kMessageAlignment - 1); | 190 return (n + kMessageAlignment - 1) & ~(kMessageAlignment - 1); |
187 } | 191 } |
188 | 192 |
189 private: | 193 private: |
190 // To allow us to make compile-assertions about |Header| in the .cc file. | 194 // To allow us to make compile-assertions about |Header| in the .cc file. |
191 struct PrivateStructForCompileAsserts; | 195 struct PrivateStructForCompileAsserts; |
192 | 196 |
193 // Header for the data (main buffer). Must be a multiple of | 197 // Header for the data (main buffer). Must be a multiple of |
194 // |kMessageAlignment| bytes in size. Must be POD. | 198 // |kMessageAlignment| bytes in size. Must be POD. |
195 struct Header { | 199 struct Header { |
196 // Total size of the message, including the header, the message data | 200 // Total size of the message, including the header, the message data |
197 // ("bytes") including padding (to make it a multiple of |kMessageAlignment| | 201 // ("bytes") including padding (to make it a multiple of |kMessageAlignment| |
198 // bytes), and serialized handle information. Note that this may not be the | 202 // bytes), and serialized handle information. Note that this may not be the |
199 // correct value if dispatchers are attached but | 203 // correct value if dispatchers are attached but |
200 // |SerializeAndCloseDispatchers()| has not been called. | 204 // |SerializeAndCloseDispatchers()| has not been called. |
201 uint32_t total_size; | 205 uint32_t total_size; |
202 Type type; // 2 bytes. | 206 Type type; // 2 bytes. |
203 Type unusedforalignment; // 2 bytes. | 207 uint16_t unusedforalignment; // 2 bytes. |
204 uint32_t num_bytes; | 208 uint32_t num_bytes; |
205 uint32_t unused; | 209 uint32_t unused; |
| 210 uint64_t route_id; |
206 }; | 211 }; |
207 | 212 |
208 const Header* header() const { | 213 const Header* header() const { |
209 return reinterpret_cast<const Header*>(main_buffer_.get()); | 214 return reinterpret_cast<const Header*>(main_buffer_.get()); |
210 } | 215 } |
211 Header* header() { return reinterpret_cast<Header*>(main_buffer_.get()); } | 216 Header* header() { return reinterpret_cast<Header*>(main_buffer_.get()); } |
212 | 217 |
213 void ConstructorHelper(Type type, uint32_t num_bytes); | 218 void ConstructorHelper(Type type, uint32_t num_bytes); |
214 void UpdateTotalSize(); | 219 void UpdateTotalSize(); |
215 | 220 |
(...skipping 15 matching lines...) Expand all Loading... |
231 MOJO_SYSTEM_IMPL_EXPORT inline std::ostream& operator<<( | 236 MOJO_SYSTEM_IMPL_EXPORT inline std::ostream& operator<<( |
232 std::ostream& out, | 237 std::ostream& out, |
233 MessageInTransit::Type type) { | 238 MessageInTransit::Type type) { |
234 return out << static_cast<uint16_t>(type); | 239 return out << static_cast<uint16_t>(type); |
235 } | 240 } |
236 | 241 |
237 } // namespace edk | 242 } // namespace edk |
238 } // namespace mojo | 243 } // namespace mojo |
239 | 244 |
240 #endif // MOJO_EDK_SYSTEM_MESSAGE_IN_TRANSIT_H_ | 245 #endif // MOJO_EDK_SYSTEM_MESSAGE_IN_TRANSIT_H_ |
OLD | NEW |