]> git.saurik.com Git - apple/security.git/blob - SecurityServer/notifications.h
Security-176.tar.gz
[apple/security.git] / SecurityServer / notifications.h
1 /*
2 * Copyright (c) 2000-2002 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 //
21 //
22 #ifndef _H_NOTIFICATIONS
23 #define _H_NOTIFICATIONS
24
25 #include <Security/mach++.h>
26 #include <Security/globalizer.h>
27 #include <map>
28
29
30 using namespace MachPlusPlus;
31
32
33 class Process;
34
35
36 //
37 // A registered receiver of notifications.
38 // Each one is for a particular database (or all), set of events,
39 // and to a particular Mach port. A process may have any number
40 // of listeners, each independent; so that multiple notifications can
41 // be sent to the same process if it registers repeatedly.
42 //
43 class Listener {
44 public:
45 enum {
46 lockedEvent = 1, // a keychain was locked
47 unlockedEvent = 2, // a keychain was unlocked
48 passphraseChangedEvent = 6, // a keychain password was (possibly) changed
49
50 allEvents = lockedEvent | unlockedEvent | passphraseChangedEvent
51 };
52 typedef uint32 Event, EventMask;
53
54 enum {
55 allNotifications = 0, // all domains (useful for testing only)
56 databaseNotifications = 1 // something happened to a database (aka keychain)
57 };
58 typedef uint32 Domain;
59
60 public:
61 Listener(Process &proc, Port receiver, Domain domain, EventMask evs = allEvents);
62 virtual ~Listener();
63
64 Process &process;
65 const Domain domain;
66 const EventMask events;
67
68 virtual void notifyMe(Domain domain, Event event, const CssmData &data);
69 static void notify(Domain domain, Event event, const CssmData &data);
70 static bool remove(Port port);
71
72 protected:
73 Port mNotificationPort;
74
75 private:
76 typedef multimap<mach_port_t, Listener *> ListenerMap;
77 static ListenerMap listeners;
78 static Mutex setLock;
79 };
80
81
82 #endif //_H_NOTIFICATIONS