]>
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 debug("notify", "%p created domain %ld events 0x%lx port %d",
47 this, domain
, events
, mNotificationPort
.port());
52 // Destroy a listener. Cleans up.
56 mNotificationPort
.deallocate();
57 debug("notify", "%p destroyed", this);
62 // Send a single notification for this listener
64 void Listener::notifyMe(Domain domain
, Event event
, const CssmData
&data
)
66 if (domain
!= this->domain
|| !(event
& events
))
67 return; // not interested
69 debug("notify", "%p sending domain %ld event 0x%lx to port %d process %d",
70 this, domain
, event
, mNotificationPort
.port(), process
.pid());
72 // send mach message (via MIG simpleroutine)
73 if (kern_return_t rc
= ucsp_notify_sender_notify(mNotificationPort
,
75 domain
, event
, data
.data(), data
.length(),
76 0 /*@@@ placeholder for sender ID */))
77 debug("notify", "%p send failed (error=%d)", this, rc
);
82 // Send a notification to all registered listeners
84 void Listener::notify(Domain domain
, Event event
, const CssmData
&data
)
86 for (ListenerMap::const_iterator it
= listeners
.begin();
87 it
!= listeners
.end(); it
++)
88 it
->second
->notifyMe(domain
, event
, data
);
93 // Handle a port death or deallocation by removing all Listeners using that port.
94 // Returns true iff we had one.
96 bool Listener::remove(Port port
)
98 typedef ListenerMap::iterator Iterator
;
99 StLock
<Mutex
> _(setLock
);
100 pair
<Iterator
, Iterator
> range
= listeners
.equal_range(port
);
101 if (range
.first
== range
.second
)
102 return false; // not one of ours
104 Server::active().notifyIfDead(port
, false);
105 for (Iterator it
= range
.first
; it
!= range
.second
; it
++)
107 listeners
.erase(range
.first
, range
.second
);
108 return true; // got it