2 * Copyright (c) 2000-2004 Apple Computer, Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
28 #ifndef _H_NOTIFICATIONS
29 #define _H_NOTIFICATIONS
31 #include <security_utilities/mach++.h>
32 #include <security_utilities/globalizer.h>
33 #include <securityd_client/ssclient.h>
36 using MachPlusPlus::Port
;
37 using SecurityServer::NotificationDomain
;
38 using SecurityServer::NotificationEvent
;
39 using SecurityServer::NotificationMask
;
43 // A registered receiver of notifications.
44 // This is an abstract class; you must subclass to define notifyMe().
46 // All Listeners in existence are collected in an internal map of ports to
47 // Listener*s, which makes them eligible to have events delivered to them via
48 // their notifyMe() method. There are (only) two viable lifetime management
49 // strategies for your Listener subclass:
50 // (1) Eternal: don't ever destroy your Listener. All is well. By convention,
51 // such Listeners use the null port.
52 // (2) Port-based: To get rid of your Listeners, call Listener::remove(port),
53 // which will delete(!) all Listeners constructed with that port.
54 // Except for the remove() functionality, Listener does not interpret the port.
56 // If you need another Listener lifetime management strategy, you will probably
57 // have to change things around here.
61 Listener(Port port
, NotificationDomain domain
, NotificationMask events
);
62 Listener(NotificationDomain domain
, NotificationMask events
);
65 // inject an event into the notification system
66 static void notify(NotificationDomain domain
,
67 NotificationEvent event
, const CssmData
&data
);
68 static bool remove(Port port
);
70 // consume an event for this Listener
71 virtual void notifyMe(NotificationDomain domain
,
72 NotificationEvent event
, const CssmData
&data
) = 0;
74 const NotificationDomain domain
;
75 const NotificationMask events
;
77 bool wants(NotificationEvent event
)
78 { return (1 << event
) & events
; }
87 typedef multimap
<mach_port_t
, Listener
*> ListenerMap
;
88 static ListenerMap listeners
;
94 // A registered receiver of notifications.
95 // Each one is for a particular database (or all), set of events,
96 // and to a particular Mach port. A process may have any number
97 // of listeners, each independent; so that multiple notifications can
98 // be sent to the same process if it registers repeatedly.
102 class ProcessListener
: public Listener
{
104 ProcessListener(Process
&proc
, Port receiver
, NotificationDomain domain
,
105 NotificationMask evs
= SecurityServer::kNotificationAllEvents
);
109 void notifyMe(NotificationDomain domain
,
110 NotificationEvent event
, const CssmData
&data
);
114 #endif //_H_NOTIFICATIONS