OLD | NEW |
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 CHROME_COMMON_MACH_MESSAGE_SOURCE_MAC_H_ | 5 #ifndef CHROME_COMMON_MACH_MESSAGE_SOURCE_MAC_H_ |
6 #define CHROME_COMMON_MACH_MESSAGE_SOURCE_MAC_H_ | 6 #define CHROME_COMMON_MACH_MESSAGE_SOURCE_MAC_H_ |
7 | 7 |
8 #include <CoreServices/CoreServices.h> | 8 #include <CoreServices/CoreServices.h> |
9 | 9 |
10 #include "base/scoped_cftyperef.h" | 10 #include "base/scoped_cftyperef.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 // | 31 // |
32 // CFRunLoopRun(); // Process messages on runloop... | 32 // CFRunLoopRun(); // Process messages on runloop... |
33 class MachMessageSource { | 33 class MachMessageSource { |
34 public: | 34 public: |
35 // Classes that want to listen on a Mach port can implement | 35 // Classes that want to listen on a Mach port can implement |
36 // OnMachMessageReceived, |mach_msg| is a pointer to the raw message data and | 36 // OnMachMessageReceived, |mach_msg| is a pointer to the raw message data and |
37 // |size| is the buffer size; | 37 // |size| is the buffer size; |
38 class MachPortListener { | 38 class MachPortListener { |
39 public: | 39 public: |
40 virtual void OnMachMessageReceived(void* mach_msg, size_t size) = 0; | 40 virtual void OnMachMessageReceived(void* mach_msg, size_t size) = 0; |
| 41 |
| 42 protected: |
| 43 virtual ~OnMachMessageReceived() {} |
41 }; | 44 }; |
42 | 45 |
43 // |listener| is a week reference passed to CF, it needs to remain in | 46 // |listener| is a week reference passed to CF, it needs to remain in |
44 // existence till this object is destroeyd. | 47 // existence till this object is destroeyd. |
45 MachMessageSource(mach_port_t port, | 48 MachMessageSource(mach_port_t port, |
46 MachPortListener* listener, | 49 MachPortListener* listener, |
47 bool* success); | 50 bool* success); |
48 ~MachMessageSource(); | 51 ~MachMessageSource(); |
49 | 52 |
50 private: | 53 private: |
51 // Called by CF when a new message arrives on the Mach port. | 54 // Called by CF when a new message arrives on the Mach port. |
52 static void OnReceiveMachMessage(CFMachPortRef port, void* msg, CFIndex size, | 55 static void OnReceiveMachMessage(CFMachPortRef port, void* msg, CFIndex size, |
53 void* closure); | 56 void* closure); |
54 | 57 |
55 scoped_cftyperef<CFRunLoopSourceRef> machport_runloop_ref_; | 58 scoped_cftyperef<CFRunLoopSourceRef> machport_runloop_ref_; |
56 DISALLOW_COPY_AND_ASSIGN(MachMessageSource); | 59 DISALLOW_COPY_AND_ASSIGN(MachMessageSource); |
57 }; | 60 }; |
58 | 61 |
59 #endif // CHROME_COMMON_MACH_MESSAGE_SOURCE_MAC_H_ | 62 #endif // CHROME_COMMON_MACH_MESSAGE_SOURCE_MAC_H_ |
OLD | NEW |