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 |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 // TODO(vtl): In |RawChannelPosix|, the alignment requirements are currently | 142 // TODO(vtl): In |RawChannelPosix|, the alignment requirements are currently |
143 // satisified on a faith-based basis. | 143 // satisified on a faith-based basis. |
144 static bool GetNextMessageSize(const void* buffer, | 144 static bool GetNextMessageSize(const void* buffer, |
145 size_t buffer_size, | 145 size_t buffer_size, |
146 size_t* next_message_size); | 146 size_t* next_message_size); |
147 | 147 |
148 // Makes this message "own" the given set of dispatchers. The dispatchers must | 148 // Makes this message "own" the given set of dispatchers. The dispatchers must |
149 // not be referenced from anywhere else (in particular, not from the handle | 149 // not be referenced from anywhere else (in particular, not from the handle |
150 // table), i.e., each dispatcher must have a reference count of 1. This | 150 // table), i.e., each dispatcher must have a reference count of 1. This |
151 // message must not already have dispatchers. | 151 // message must not already have dispatchers. |
152 void SetDispatchers( | 152 void SetDispatchers(scoped_ptr<DispatcherVector> dispatchers); |
153 scoped_ptr<std::vector<scoped_refptr<Dispatcher> > > dispatchers); | |
154 | 153 |
155 // Serializes any dispatchers to the secondary buffer. This message must not | 154 // Serializes any dispatchers to the secondary buffer. This message must not |
156 // already have a secondary buffer (so this must only be called once). The | 155 // already have a secondary buffer (so this must only be called once). The |
157 // caller must ensure (e.g., by holding on to a reference) that |channel| | 156 // caller must ensure (e.g., by holding on to a reference) that |channel| |
158 // stays alive through the call. | 157 // stays alive through the call. |
159 void SerializeAndCloseDispatchers(Channel* channel); | 158 void SerializeAndCloseDispatchers(Channel* channel); |
160 | 159 |
161 // Gets the main buffer and its size (in number of bytes), respectively. | 160 // Gets the main buffer and its size (in number of bytes), respectively. |
162 const void* main_buffer() const { return main_buffer_.get(); } | 161 const void* main_buffer() const { return main_buffer_.get(); } |
163 size_t main_buffer_size() const { return main_buffer_size_; } | 162 size_t main_buffer_size() const { return main_buffer_size_; } |
(...skipping 17 matching lines...) Expand all Loading... |
181 EndpointId destination_id() const { return header()->destination_id; } | 180 EndpointId destination_id() const { return header()->destination_id; } |
182 | 181 |
183 void set_source_id(EndpointId source_id) { header()->source_id = source_id; } | 182 void set_source_id(EndpointId source_id) { header()->source_id = source_id; } |
184 void set_destination_id(EndpointId destination_id) { | 183 void set_destination_id(EndpointId destination_id) { |
185 header()->destination_id = destination_id; | 184 header()->destination_id = destination_id; |
186 } | 185 } |
187 | 186 |
188 // Gets the dispatchers attached to this message; this may return null if | 187 // Gets the dispatchers attached to this message; this may return null if |
189 // there are none. Note that the caller may mutate the set of dispatchers | 188 // there are none. Note that the caller may mutate the set of dispatchers |
190 // (e.g., take ownership of all the dispatchers, leaving the vector empty). | 189 // (e.g., take ownership of all the dispatchers, leaving the vector empty). |
191 std::vector<scoped_refptr<Dispatcher> >* dispatchers() { | 190 DispatcherVector* dispatchers() { return dispatchers_.get(); } |
192 return dispatchers_.get(); | |
193 } | |
194 | 191 |
195 // Returns true if this message has dispatchers attached. | 192 // Returns true if this message has dispatchers attached. |
196 bool has_dispatchers() const { | 193 bool has_dispatchers() const { |
197 return dispatchers_ && !dispatchers_->empty(); | 194 return dispatchers_ && !dispatchers_->empty(); |
198 } | 195 } |
199 | 196 |
200 // Rounds |n| up to a multiple of |kMessageAlignment|. | 197 // Rounds |n| up to a multiple of |kMessageAlignment|. |
201 static inline size_t RoundUpMessageAlignment(size_t n) { | 198 static inline size_t RoundUpMessageAlignment(size_t n) { |
202 return (n + kMessageAlignment - 1) & ~(kMessageAlignment - 1); | 199 return (n + kMessageAlignment - 1) & ~(kMessageAlignment - 1); |
203 } | 200 } |
(...skipping 29 matching lines...) Expand all Loading... |
233 | 230 |
234 const size_t main_buffer_size_; | 231 const size_t main_buffer_size_; |
235 const scoped_ptr<char, base::AlignedFreeDeleter> main_buffer_; // Never null. | 232 const scoped_ptr<char, base::AlignedFreeDeleter> main_buffer_; // Never null. |
236 | 233 |
237 scoped_ptr<TransportData> transport_data_; // May be null. | 234 scoped_ptr<TransportData> transport_data_; // May be null. |
238 | 235 |
239 // Any dispatchers that may be attached to this message. These dispatchers | 236 // Any dispatchers that may be attached to this message. These dispatchers |
240 // should be "owned" by this message, i.e., have a ref count of exactly 1. (We | 237 // should be "owned" by this message, i.e., have a ref count of exactly 1. (We |
241 // allow a dispatcher entry to be null, in case it couldn't be duplicated for | 238 // allow a dispatcher entry to be null, in case it couldn't be duplicated for |
242 // some reason.) | 239 // some reason.) |
243 scoped_ptr<std::vector<scoped_refptr<Dispatcher> > > dispatchers_; | 240 scoped_ptr<DispatcherVector> dispatchers_; |
244 | 241 |
245 DISALLOW_COPY_AND_ASSIGN(MessageInTransit); | 242 DISALLOW_COPY_AND_ASSIGN(MessageInTransit); |
246 }; | 243 }; |
247 | 244 |
248 } // namespace system | 245 } // namespace system |
249 } // namespace mojo | 246 } // namespace mojo |
250 | 247 |
251 #endif // MOJO_SYSTEM_MESSAGE_IN_TRANSIT_H_ | 248 #endif // MOJO_SYSTEM_MESSAGE_IN_TRANSIT_H_ |
OLD | NEW |