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 | 7 |
8 #include <mach/mach.h> | 8 #include <mach/mach.h> |
9 #include <mach/message.h> | 9 #include <mach/message.h> |
10 #include <servers/bootstrap.h> | 10 #include <servers/bootstrap.h> |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 MachReceiveMessage(void *storage, size_t storage_length) | 251 MachReceiveMessage(void *storage, size_t storage_length) |
252 : MachMessage(storage, storage_length) {} | 252 : MachMessage(storage, storage_length) {} |
253 | 253 |
254 private: | 254 private: |
255 DISALLOW_COPY_AND_ASSIGN(MachReceiveMessage); | 255 DISALLOW_COPY_AND_ASSIGN(MachReceiveMessage); |
256 }; | 256 }; |
257 | 257 |
258 //============================================================================== | 258 //============================================================================== |
259 class MachSendMessage : public MachMessage { | 259 class MachSendMessage : public MachMessage { |
260 public: | 260 public: |
261 MachSendMessage(int32_t message_id); | 261 explicit MachSendMessage(int32_t message_id); |
262 MachSendMessage(void *storage, size_t storage_length, int32_t message_id); | 262 MachSendMessage(void *storage, size_t storage_length, int32_t message_id); |
263 | 263 |
264 private: | 264 private: |
265 void Initialize(int32_t message_id); | 265 void Initialize(int32_t message_id); |
266 | 266 |
267 DISALLOW_COPY_AND_ASSIGN(MachSendMessage); | 267 DISALLOW_COPY_AND_ASSIGN(MachSendMessage); |
268 }; | 268 }; |
269 | 269 |
270 //============================================================================== | 270 //============================================================================== |
271 // Represents a mach port for which we have receive rights | 271 // Represents a mach port for which we have receive rights |
272 class ReceivePort { | 272 class ReceivePort { |
273 public: | 273 public: |
274 // Creates a new mach port for receiving messages and registers a name for it | 274 // Creates a new mach port for receiving messages and registers a name for it |
275 ReceivePort(const char *receive_port_name); | 275 explicit ReceivePort(const char *receive_port_name); |
276 | 276 |
277 // Given an already existing mach port, use it. We take ownership of the | 277 // Given an already existing mach port, use it. We take ownership of the |
278 // port and deallocate it in our destructor. | 278 // port and deallocate it in our destructor. |
279 ReceivePort(mach_port_t receive_port); | 279 explicit ReceivePort(mach_port_t receive_port); |
280 | 280 |
281 // Create a new mach port for receiving messages | 281 // Create a new mach port for receiving messages |
282 ReceivePort(); | 282 ReceivePort(); |
283 | 283 |
284 ~ReceivePort(); | 284 ~ReceivePort(); |
285 | 285 |
286 // Waits on the mach port until message received or timeout | 286 // Waits on the mach port until message received or timeout |
287 kern_return_t WaitForMessage(MachReceiveMessage *out_message, | 287 kern_return_t WaitForMessage(MachReceiveMessage *out_message, |
288 mach_msg_timeout_t timeout); | 288 mach_msg_timeout_t timeout); |
289 | 289 |
290 // The underlying mach port that we wrap | 290 // The underlying mach port that we wrap |
291 mach_port_t GetPort() const { return port_; } | 291 mach_port_t GetPort() const { return port_; } |
292 | 292 |
293 private: | 293 private: |
294 mach_port_t port_; | 294 mach_port_t port_; |
295 kern_return_t init_result_; | 295 kern_return_t init_result_; |
296 | 296 |
297 DISALLOW_COPY_AND_ASSIGN(ReceivePort); | 297 DISALLOW_COPY_AND_ASSIGN(ReceivePort); |
298 }; | 298 }; |
299 | 299 |
300 //============================================================================== | 300 //============================================================================== |
301 // Represents a mach port for which we have send rights | 301 // Represents a mach port for which we have send rights |
302 class MachPortSender { | 302 class MachPortSender { |
303 public: | 303 public: |
304 // get a port with send rights corresponding to a named registered service | 304 // get a port with send rights corresponding to a named registered service |
305 MachPortSender(const char *receive_port_name); | 305 explicit MachPortSender(const char *receive_port_name); |
306 | 306 |
307 | 307 |
308 // Given an already existing mach port, use it. | 308 // Given an already existing mach port, use it. Does not take ownership of |
309 MachPortSender(mach_port_t send_port); | 309 // |send_port|. |
| 310 explicit MachPortSender(mach_port_t send_port); |
310 | 311 |
311 kern_return_t SendMessage(MachSendMessage &message, | 312 kern_return_t SendMessage(MachSendMessage &message, |
312 mach_msg_timeout_t timeout); | 313 mach_msg_timeout_t timeout); |
313 | 314 |
314 private: | 315 private: |
315 mach_port_t send_port_; | 316 mach_port_t send_port_; |
316 kern_return_t init_result_; | 317 kern_return_t init_result_; |
317 | 318 |
318 DISALLOW_COPY_AND_ASSIGN(MachPortSender); | 319 DISALLOW_COPY_AND_ASSIGN(MachPortSender); |
319 }; | 320 }; |
320 | 321 |
321 #endif // BASE_MACH_IPC_MAC_H_ | 322 #endif // BASE_MACH_IPC_MAC_H_ |
OLD | NEW |