]>
git.saurik.com Git - apple/security.git/blob - SecurityServer/notifications.cpp
2 * Copyright (c) 2000-2002 Apple Computer, Inc. All Rights Reserved.
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
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.
20 // EntropyManager - manage entropy on the system.
22 #include "notifications.h"
24 #include "ucspNotify.h"
27 Listener::ListenerMap
Listener::listeners
;
28 Mutex
Listener::setLock
;
32 // Construct a new Listener and hook it up
34 Listener::Listener(Process
&proc
, Port receiver
, Domain dom
, EventMask evs
)
35 : process(proc
), domain(dom
), events(evs
), mNotificationPort(receiver
)
37 assert(events
); // what's the point?
39 // register in listener set
40 StLock
<Mutex
> _(setLock
);
41 listeners
.insert(ListenerMap::value_type(receiver
, this));
43 // let's get told when the receiver port dies
44 Server::active().notifyIfDead(receiver
);
46 secdebug("notify", "%p created domain %ld events 0x%lx port %d",
47 this, domain
, events
, mNotificationPort
.port());
52 // Destroy a listener. Cleans up.
56 secdebug("notify", "%p destroyed", this);
61 // Send a single notification for this listener
63 void Listener::notifyMe(Domain domain
, Event event
, const CssmData
&data
)
65 if (domain
!= this->domain
|| !(event
& events
))
66 return; // not interested
68 secdebug("notify", "%p sending domain %ld event 0x%lx to port %d process %d",
69 this, domain
, event
, mNotificationPort
.port(), process
.pid());
71 // send mach message (via MIG simpleroutine)
72 if (IFDEBUG(kern_return_t rc
=) ucsp_notify_sender_notify(mNotificationPort
,
74 domain
, event
, data
.data(), data
.length(),
75 0 /*@@@ placeholder for sender ID */))
76 secdebug("notify", "%p send failed (error=%d)", this, rc
);
81 // Send a notification to all registered listeners
83 void Listener::notify(Domain domain
, Event event
, const CssmData
&data
)
85 for (ListenerMap::const_iterator it
= listeners
.begin();
86 it
!= listeners
.end(); it
++)
87 it
->second
->notifyMe(domain
, event
, data
);
92 // Handle a port death or deallocation by removing all Listeners using that port.
93 // Returns true iff we had one.
95 bool Listener::remove(Port port
)
97 typedef ListenerMap::iterator Iterator
;
98 StLock
<Mutex
> _(setLock
);
99 pair
<Iterator
, Iterator
> range
= listeners
.equal_range(port
);
100 if (range
.first
== range
.second
)
101 return false; // not one of ours
103 for (Iterator it
= range
.first
; it
!= range
.second
; it
++)
105 listeners
.erase(range
.first
, range
.second
);
107 return true; // got it