OLD | NEW |
---|---|
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 BASE_MACH_IPC_MAC_H_ | 5 #ifndef BASE_MACH_IPC_MAC_H_ |
6 #define BASE_MACH_IPC_MAC_H_ | 6 #define BASE_MACH_IPC_MAC_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <mach/mach.h> | 9 #include <mach/mach.h> |
10 #include <mach/message.h> | 10 #include <mach/message.h> |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
171 | 171 |
172 // Convenience method which gets the Mach port described by the descriptor | 172 // Convenience method which gets the Mach port described by the descriptor |
173 mach_port_t GetTranslatedPort(int n); | 173 mach_port_t GetTranslatedPort(int n); |
174 | 174 |
175 // A simple message is one with no descriptors | 175 // A simple message is one with no descriptors |
176 bool IsSimpleMessage() const { return GetDescriptorCount() == 0; } | 176 bool IsSimpleMessage() const { return GetDescriptorCount() == 0; } |
177 | 177 |
178 // Sets raw data for the message (returns false if not enough space) | 178 // Sets raw data for the message (returns false if not enough space) |
179 bool SetData(const void* data, int32_t data_length); | 179 bool SetData(const void* data, int32_t data_length); |
180 | 180 |
181 static const size_t kEmptyMessageSize; | |
Peter Kasting
2011/03/27 19:22:59
Nit: This actually goes at the very top, above the
KushalP
2011/03/27 20:18:28
Done.
| |
182 | |
181 protected: | 183 protected: |
182 // Consider this an abstract base class - must create an actual instance | 184 // Consider this an abstract base class - must create an actual instance |
183 // of MachReceiveMessage or MachSendMessage | 185 // of MachReceiveMessage or MachSendMessage |
184 MachMessage(); | 186 MachMessage(); |
185 | 187 |
186 // Constructor for use with preallocate storage. | 188 // Constructor for use with preallocate storage. |
187 // storage_length must be >= EmptyMessageSize() | 189 // storage_length must be >= EmptyMessageSize() |
188 MachMessage(void *storage, size_t storage_length); | 190 MachMessage(void *storage, size_t storage_length); |
189 | 191 |
190 friend class ReceivePort; | 192 friend class ReceivePort; |
(...skipping 11 matching lines...) Expand all Loading... | |
202 void SetDescriptorCount(int n); | 204 void SetDescriptorCount(int n); |
203 void SetDescriptor(int n, const MachMsgPortDescriptor &desc); | 205 void SetDescriptor(int n, const MachMsgPortDescriptor &desc); |
204 | 206 |
205 // Returns total message size setting msgh_size in the header to this value | 207 // Returns total message size setting msgh_size in the header to this value |
206 int CalculateSize(); | 208 int CalculateSize(); |
207 | 209 |
208 // Returns total storage size that this object can grow to, this is inclusive | 210 // Returns total storage size that this object can grow to, this is inclusive |
209 // of the Mach header. | 211 // of the Mach header. |
210 size_t MaxSize() const { return storage_length_bytes_; } | 212 size_t MaxSize() const { return storage_length_bytes_; } |
211 | 213 |
212 protected: | |
213 mach_msg_header_t *Head() { return &(storage_->head); } | 214 mach_msg_header_t *Head() { return &(storage_->head); } |
214 | 215 |
215 private: | 216 private: |
216 struct MachMessageData { | 217 struct MachMessageData { |
217 mach_msg_header_t head; | 218 mach_msg_header_t head; |
218 mach_msg_body_t body; | 219 mach_msg_body_t body; |
219 // descriptors and data may be embedded here. | 220 // descriptors and data may be embedded here. |
220 u_int8_t padding[1024]; | 221 u_int8_t padding[1024]; |
221 }; | 222 }; |
222 | 223 |
223 // kEmptyMessageSize needs to have the definition of MachMessageData before | |
224 // it. | |
225 public: | |
226 // The size of an empty message with no data. | |
227 static const size_t kEmptyMessageSize = sizeof(mach_msg_header_t) + | |
228 sizeof(mach_msg_body_t) + | |
229 sizeof(MessageDataPacket); | |
230 | |
231 private: | |
232 MachMessageData *storage_; | 224 MachMessageData *storage_; |
233 size_t storage_length_bytes_; | 225 size_t storage_length_bytes_; |
234 bool own_storage_; // Is storage owned by this object? | 226 bool own_storage_; // Is storage owned by this object? |
235 }; | 227 }; |
236 | 228 |
237 //============================================================================== | 229 //============================================================================== |
238 // MachReceiveMessage and MachSendMessage are useful to separate the idea | 230 // MachReceiveMessage and MachSendMessage are useful to separate the idea |
239 // of a Mach message being sent and being received, and adds increased type | 231 // of a Mach message being sent and being received, and adds increased type |
240 // safety: | 232 // safety: |
241 // ReceivePort::WaitForMessage() only accepts a MachReceiveMessage | 233 // ReceivePort::WaitForMessage() only accepts a MachReceiveMessage |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
313 private: | 305 private: |
314 mach_port_t send_port_; | 306 mach_port_t send_port_; |
315 kern_return_t init_result_; | 307 kern_return_t init_result_; |
316 | 308 |
317 DISALLOW_COPY_AND_ASSIGN(MachPortSender); | 309 DISALLOW_COPY_AND_ASSIGN(MachPortSender); |
318 }; | 310 }; |
319 | 311 |
320 } // namespace base | 312 } // namespace base |
321 | 313 |
322 #endif // BASE_MACH_IPC_MAC_H_ | 314 #endif // BASE_MACH_IPC_MAC_H_ |
OLD | NEW |