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 <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "mojo/embedder/platform_handle.h" |
14 #include "mojo/system/dispatcher.h" | 15 #include "mojo/system/dispatcher.h" |
15 #include "mojo/system/system_impl_export.h" | 16 #include "mojo/system/system_impl_export.h" |
16 | 17 |
17 namespace mojo { | 18 namespace mojo { |
18 namespace system { | 19 namespace system { |
19 | 20 |
20 class Channel; | 21 class Channel; |
21 | 22 |
22 // This class is used to represent data in transit. It is thread-unsafe. | 23 // This class is used to represent data in transit. It is thread-unsafe. |
23 // | 24 // |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 | 205 |
205 // Gets the dispatchers attached to this message; this may return null if | 206 // Gets the dispatchers attached to this message; this may return null if |
206 // there are none. Note that the caller may mutate the set of dispatchers | 207 // there are none. Note that the caller may mutate the set of dispatchers |
207 // (e.g., take ownership of all the dispatchers, leaving the vector empty). | 208 // (e.g., take ownership of all the dispatchers, leaving the vector empty). |
208 std::vector<scoped_refptr<Dispatcher> >* dispatchers() { | 209 std::vector<scoped_refptr<Dispatcher> >* dispatchers() { |
209 return dispatchers_.get(); | 210 return dispatchers_.get(); |
210 } | 211 } |
211 | 212 |
212 // Returns true if this message has dispatchers attached. | 213 // Returns true if this message has dispatchers attached. |
213 bool has_dispatchers() const { | 214 bool has_dispatchers() const { |
214 return dispatchers_.get() && !dispatchers_->empty(); | 215 return dispatchers_ && !dispatchers_->empty(); |
| 216 } |
| 217 |
| 218 // Gets the platform-specific handles attached to this message; this may |
| 219 // return null if there are none. Note that the caller may mutate the set of |
| 220 // platform-specific handles. |
| 221 std::vector<embedder::PlatformHandle>* platform_handles() { |
| 222 return platform_handles_.get(); |
| 223 } |
| 224 |
| 225 // Returns true if this message has platform-specific handles attached. |
| 226 bool has_platform_handles() const { |
| 227 return platform_handles_ && !platform_handles_->empty(); |
215 } | 228 } |
216 | 229 |
217 // Rounds |n| up to a multiple of |kMessageAlignment|. | 230 // Rounds |n| up to a multiple of |kMessageAlignment|. |
218 static inline size_t RoundUpMessageAlignment(size_t n) { | 231 static inline size_t RoundUpMessageAlignment(size_t n) { |
219 return (n + kMessageAlignment - 1) & ~(kMessageAlignment - 1); | 232 return (n + kMessageAlignment - 1) & ~(kMessageAlignment - 1); |
220 } | 233 } |
221 | 234 |
222 private: | 235 private: |
223 // To allow us to make assertions about |Header| in the .cc file. | 236 // To allow us to make assertions about |Header| in the .cc file. |
224 struct PrivateStructForCompileAsserts; | 237 struct PrivateStructForCompileAsserts; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 | 284 |
272 size_t secondary_buffer_size_; | 285 size_t secondary_buffer_size_; |
273 void* secondary_buffer_; // May be null. | 286 void* secondary_buffer_; // May be null. |
274 | 287 |
275 // Any dispatchers that may be attached to this message. These dispatchers | 288 // Any dispatchers that may be attached to this message. These dispatchers |
276 // should be "owned" by this message, i.e., have a ref count of exactly 1. (We | 289 // should be "owned" by this message, i.e., have a ref count of exactly 1. (We |
277 // allow a dispatcher entry to be null, in case it couldn't be duplicated for | 290 // allow a dispatcher entry to be null, in case it couldn't be duplicated for |
278 // some reason.) | 291 // some reason.) |
279 scoped_ptr<std::vector<scoped_refptr<Dispatcher> > > dispatchers_; | 292 scoped_ptr<std::vector<scoped_refptr<Dispatcher> > > dispatchers_; |
280 | 293 |
| 294 // Any platform-specific handles attached to this message (for inter-process |
| 295 // transport). The vector (if any) owns the handles that it contains (and is |
| 296 // responsible for closing them). |
| 297 // TODO(vtl): With C++11, change it to a vector of |ScopedPlatformHandles|. |
| 298 scoped_ptr<std::vector<embedder::PlatformHandle> > platform_handles_; |
| 299 |
281 DISALLOW_COPY_AND_ASSIGN(MessageInTransit); | 300 DISALLOW_COPY_AND_ASSIGN(MessageInTransit); |
282 }; | 301 }; |
283 | 302 |
284 } // namespace system | 303 } // namespace system |
285 } // namespace mojo | 304 } // namespace mojo |
286 | 305 |
287 #endif // MOJO_SYSTEM_MESSAGE_IN_TRANSIT_H_ | 306 #endif // MOJO_SYSTEM_MESSAGE_IN_TRANSIT_H_ |
OLD | NEW |