1.1 --- a/libfsserver/lib/generic/notification.cc Mon Mar 14 01:33:25 2022 +0100
1.2 +++ b/libfsserver/lib/generic/notification.cc Mon Mar 14 17:44:41 2022 +0100
1.3 @@ -23,7 +23,6 @@
1.4
1.5 #include "notification.h"
1.6 #include "notifier_client.h"
1.7 -#include "notifier_peer_endpoint.h"
1.8
1.9 #include "resource_server.h"
1.10
1.11 @@ -45,7 +44,7 @@
1.12 endpoint number. */
1.13
1.14 long NotificationSupport::subscribe(l4_cap_idx_t notifier, notify_flags_t flags,
1.15 - l4_cap_idx_t *peer, unsigned int *endpoint_number)
1.16 + void *subscriber, unsigned int *endpoint_number)
1.17 {
1.18 std::lock_guard<std::mutex> guard(_lock);
1.19
1.20 @@ -58,14 +57,14 @@
1.21 _endpoints[endpoint].deferred = _deferred;
1.22
1.23 *endpoint_number = endpoint;
1.24 - return _subscribe(endpoint, notifier, flags, peer);
1.25 + return _subscribe(endpoint, notifier, flags, subscriber);
1.26 }
1.27
1.28 /* Subscribe to a specific endpoint's notifications using a notification
1.29 object. */
1.30
1.31 long NotificationSupport::subscribe(unsigned int endpoint, l4_cap_idx_t notifier,
1.32 - notify_flags_t flags, l4_cap_idx_t *peer)
1.33 + notify_flags_t flags, void *subscriber)
1.34 {
1.35 std::lock_guard<std::mutex> guard(_lock);
1.36
1.37 @@ -79,22 +78,22 @@
1.38 _endpoints[endpoint].deferred = _deferred;
1.39 }
1.40
1.41 - return _subscribe(endpoint, notifier, flags, peer);
1.42 + return _subscribe(endpoint, notifier, flags, subscriber);
1.43 }
1.44
1.45 /* Unsubscribe from an endpoint's notifications. */
1.46
1.47 -void NotificationSupport::unsubscribe(unsigned int endpoint, l4_cap_idx_t notifier)
1.48 +void NotificationSupport::unsubscribe(unsigned int endpoint, void *subscriber)
1.49 {
1.50 std::lock_guard<std::mutex> guard(_lock);
1.51
1.52 - _unsubscribe(endpoint, notifier);
1.53 + _unsubscribe(endpoint, subscriber);
1.54 }
1.55
1.56 /* Common subscription functionality. */
1.57
1.58 long NotificationSupport::_subscribe(unsigned int endpoint, l4_cap_idx_t notifier,
1.59 - notify_flags_t flags, l4_cap_idx_t *peer)
1.60 + notify_flags_t flags, void *subscriber)
1.61 {
1.62 /* Record details of the notifier itself. */
1.63
1.64 @@ -111,25 +110,30 @@
1.65 ep.deferred = 0;
1.66 }
1.67
1.68 - /* Create a notifier peer for unsubscribing. */
1.69 -
1.70 - NotifierPeerEndpoint *peer_ep = new NotifierPeerEndpoint(this, endpoint, notifier);
1.71 -
1.72 - _peers[notifier] = peer_ep;
1.73 + /* Record the subscriber's notifier. */
1.74
1.75 - long err = ResourceServer(peer_ep).start_thread(peer);
1.76 -
1.77 - if (err)
1.78 - _unsubscribe(endpoint, notifier);
1.79 -
1.80 - return err;
1.81 + _subscribers[subscriber] = notifier;
1.82 + return L4_EOK;
1.83 }
1.84
1.85 -void NotificationSupport::_unsubscribe(unsigned int endpoint, l4_cap_idx_t notifier)
1.86 +void NotificationSupport::_unsubscribe(unsigned int endpoint, void *subscriber)
1.87 {
1.88 if (endpoint >= _endpoints.size())
1.89 return;
1.90
1.91 + /* Find and remove the subscriber's notifier. */
1.92 +
1.93 + SubscriberNotifierMap::iterator itp = _subscribers.find(subscriber);
1.94 + l4_cap_idx_t notifier;
1.95 +
1.96 + if (itp == _subscribers.end())
1.97 + return;
1.98 +
1.99 + notifier = itp->second;
1.100 + _subscribers.erase(itp);
1.101 +
1.102 + /* Release the notifier. */
1.103 +
1.104 NotificationEndpoint &ep = _endpoints[endpoint];
1.105 NotifierSet::iterator it = ep.notifiers.find(notifier);
1.106
1.107 @@ -144,13 +148,6 @@
1.108 ep.deferred = 0;
1.109 }
1.110 }
1.111 -
1.112 - /* Remove the notifier peer. */
1.113 -
1.114 - NotifierPeerMap::iterator itp = _peers.find(notifier);
1.115 -
1.116 - if (itp != _peers.end())
1.117 - _peers.erase(itp);
1.118 }
1.119
1.120 /* Notify a particular endpoint. */