2 * Copyright (c) 2000-2004,2006-2008 Apple 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@
26 // notifications - handling of securityd-gated notification messages
28 #ifndef _H_NOTIFICATIONS
29 #define _H_NOTIFICATIONS
31 #include <security_utilities/mach++.h>
32 #include <security_utilities/machserver.h>
33 #include <security_utilities/globalizer.h>
34 #include <securityd_client/ssclient.h>
38 #include "SharedMemoryServer.h"
40 using MachPlusPlus::Port
;
41 using MachPlusPlus::MachServer
;
42 using SecurityServer::NotificationDomain
;
43 using SecurityServer::NotificationEvent
;
44 using SecurityServer::NotificationMask
;
46 class SharedMemoryListener
;
49 // A registered receiver of notifications.
50 // This is an abstract class; you must subclass to define notifyMe().
52 // All Listeners in existence are collected in an internal map of ports to
53 // Listener*s, which makes them eligible to have events delivered to them via
54 // their notifyMe() method. There are (only) two viable lifetime management
55 // strategies for your Listener subclass:
56 // (1) Eternal: don't ever destroy your Listener. All is well. By convention,
57 // such Listeners use the null port.
58 // (2) Port-based: To get rid of your Listeners, call Listener::remove(port),
59 // which will delete(!) all Listeners constructed with that port.
60 // Except for the remove() functionality, Listener does not interpret the port.
62 // If you need another Listener lifetime management strategy, you will probably
63 // have to change things around here.
65 class Listener
: public RefCount
{
67 Listener(NotificationDomain domain
, NotificationMask events
,
68 mach_port_t port
= MACH_PORT_NULL
);
71 // inject an event into the notification system
72 static void notify(NotificationDomain domain
,
73 NotificationEvent event
, const CssmData
&data
);
74 static void notify(NotificationDomain domain
,
75 NotificationEvent event
, uint32 sequence
, const CssmData
&data
);
76 static bool remove(Port port
);
78 const NotificationDomain domain
;
79 const NotificationMask events
;
81 bool wants(NotificationEvent event
)
82 { return (1 << event
) & events
; }
85 class Notification
: public RefCount
{
87 Notification(NotificationDomain domain
, NotificationEvent event
,
88 uint32 seq
, const CssmData
&data
);
89 virtual ~Notification();
91 const NotificationDomain domain
;
92 const NotificationEvent event
;
93 const uint32 sequence
;
94 const CssmAutoData data
;
97 { return data
.length(); } //@@@ add "slop" here for heuristic?
100 virtual void notifyMe(Notification
*message
) = 0;
105 JitterBuffer() : mNotifyLast(0) { }
107 bool inSequence(Notification
*message
);
108 RefPointer
<Notification
> popNotification();
111 uint32 mNotifyLast
; // last notification seq processed
112 typedef std::map
<uint32
, RefPointer
<Notification
> > JBuffer
;
113 JBuffer mBuffer
; // early messages buffer
117 static void sendNotification(Notification
*message
);
120 typedef multimap
<mach_port_t
, RefPointer
<Listener
> > ListenerMap
;
121 static ListenerMap
& listeners
;
122 static Mutex setLock
;
127 class SharedMemoryListener
: public Listener
, public SharedMemoryServer
, public Security::MachPlusPlus::MachServer::Timer
130 virtual void action ();
131 virtual void notifyMe(Notification
*message
);
136 SharedMemoryListener (const char* serverName
, u_int32_t serverSize
);
137 virtual ~SharedMemoryListener ();