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