]>
Commit | Line | Data |
---|---|---|
bac41a7b A |
1 | /* |
2 | * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved. | |
3 | * | |
4 | * The contents of this file constitute Original Code as defined in and are | |
5 | * subject to the Apple Public Source License Version 1.2 (the 'License'). | |
6 | * You may not use this file except in compliance with the License. Please obtain | |
7 | * a copy of the License at http://www.apple.com/publicsource and read it before | |
8 | * using this file. | |
9 | * | |
10 | * This Original Code and all software distributed under the License are | |
11 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS | |
12 | * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT | |
13 | * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | |
14 | * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the | |
15 | * specific language governing rights and limitations under the License. | |
16 | */ | |
17 | ||
18 | ||
19 | // | |
20 | // machrunloopserver - C++ shell for writing Mach 3 servers called by CFRunLoop. | |
21 | // | |
22 | // Note that this is a subclass of MachServer and tries to preserve its interface, | |
23 | // so you can switch back-and-forth between them with a minimum of fuss. | |
24 | // Timers are not currently implemented; they're not that hard to add if you need them. | |
25 | // | |
26 | #ifndef _H_MACHRUNLOOPSERVER | |
27 | #define _H_MACHRUNLOOPSERVER | |
28 | ||
29 | #include <Security/machserver.h> | |
30 | #include <CoreFoundation/CFRunLoop.h> | |
31 | #include <CoreFoundation/CFMachPort.h> | |
32 | ||
33 | ||
34 | namespace Security | |
35 | { | |
36 | ||
37 | namespace MachPlusPlus | |
38 | { | |
39 | ||
40 | // | |
41 | // Mach server object | |
42 | // | |
43 | class MachRunLoopServer : public MachServer { | |
44 | public: | |
45 | MachRunLoopServer(const char *name); | |
46 | MachRunLoopServer(const char *name, const Bootstrap &boot); | |
47 | virtual ~MachRunLoopServer(); | |
48 | ||
49 | void run(size_t maxSize = 4096, mach_msg_options_t options = 0); | |
50 | ||
51 | static MachRunLoopServer &active() | |
52 | { return safer_cast<MachRunLoopServer &>(MachServer::active()); } | |
53 | ||
54 | void notifyIfDead(Port port) const; | |
55 | ||
56 | void blockNewRequests(bool block = true); | |
57 | ||
58 | void alsoListenOn(Port port); | |
59 | void stopListenOn(Port port); | |
60 | ||
61 | protected: | |
62 | void setup(const char *name, size_t bufferSize); | |
63 | static void cfCallback(CFMachPortRef port, void *msg, CFIndex size, void *info); | |
64 | static void cfInvalidateCallback(CFMachPortRef port, void *info); | |
65 | void oneRequest(mach_msg_header_t *request); | |
66 | ||
67 | private: | |
68 | CFRunLoopRef runLoop; | |
69 | CFRunLoopSourceRef runLoopSource; | |
70 | ||
71 | mach_msg_header_t *replyBuffer; | |
72 | }; | |
73 | ||
74 | ||
75 | } // end namespace MachPlusPlus | |
76 | ||
77 | } // end namespace Security | |
78 | ||
79 | #endif //_H_MACHRUNLOOPSERVER |