1 /* 2 * Notification support. 3 * 4 * Copyright (C) 2021, 2022, 2023 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA 20 */ 21 22 #pragma once 23 24 #include <map> 25 #include <mutex> 26 #include <set> 27 #include <vector> 28 29 #include <systypes/base.h> 30 31 32 33 /* Forward declaration. */ 34 35 class NotifierPeerEndpoint; 36 37 /* Collection data types. */ 38 39 typedef std::set<l4_cap_idx_t> NotifierSet; 40 typedef std::map<void *, l4_cap_idx_t> SubscriberNotifierMap; 41 42 /* Notification endpoint details. */ 43 44 class NotificationEndpoint 45 { 46 public: 47 NotifierSet notifiers; 48 49 /* Notification flag mask, deferred flags. */ 50 51 notify_flags_t flags = 0, deferred_flags = 0; 52 53 /* Deferred values. */ 54 55 notify_values_t deferred_values = NOTIFY_VALUES_NULL; 56 }; 57 58 typedef std::vector<NotificationEndpoint> NotificationEndpointList; 59 60 61 62 /* Notification support, allowing pipe or file users to receive events due to 63 activity on those objects. */ 64 65 class NotificationSupport 66 { 67 protected: 68 std::mutex _lock; 69 70 /* Endpoint count. */ 71 72 unsigned int _min_endpoints; 73 74 /* Notification endpoint details. */ 75 76 NotificationEndpointList _endpoints; 77 78 /* Notifier subscriber details. */ 79 80 SubscriberNotifierMap _subscribers; 81 82 /* Deferred notifications for new endpoints. */ 83 84 notify_flags_t _deferred_flags = 0; 85 notify_values_t _deferred_values = NOTIFY_VALUES_NULL; 86 87 virtual void release_notifiers(); 88 89 virtual void _notify(unsigned int endpoint, notify_flags_t flags, 90 notify_values_t values); 91 92 virtual long _subscribe(unsigned int endpoint, l4_cap_idx_t notifier, 93 notify_flags_t flags, void *subscriber); 94 95 virtual void _unsubscribe(unsigned int endpoint, void *subscriber); 96 97 public: 98 explicit NotificationSupport(unsigned int endpoints=0); 99 100 virtual ~NotificationSupport(); 101 102 virtual void notify(unsigned int endpoint, notify_flags_t flags, 103 notify_values_t values); 104 105 virtual void notify_all(notify_flags_t flags, notify_values_t values); 106 107 virtual void notify_others(unsigned int endpoint, notify_flags_t flags, 108 notify_values_t values); 109 110 virtual long subscribe(l4_cap_idx_t notifier, notify_flags_t flags, 111 void *subscriber, unsigned int *endpoint_number); 112 113 virtual long subscribe(unsigned int endpoint, l4_cap_idx_t notifier, 114 notify_flags_t flags, void *subscriber); 115 116 virtual void unsubscribe(unsigned int endpoint, void *subscriber); 117 }; 118 119 // vim: tabstop=4 expandtab shiftwidth=4