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<l4_cap_idx_t, unsigned int> NotifierEndpointMap; 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 endpoint details. */ 79 80 NotifierEndpointMap _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 long _get_endpoint(l4_cap_idx_t notifier, bool remove, 90 unsigned int *endpoint); 91 92 virtual void _notify(unsigned int endpoint, notify_flags_t flags, 93 notify_values_t values); 94 95 virtual void _notify_others(unsigned int endpoint, notify_flags_t flags, 96 notify_values_t values); 97 98 virtual long _subscribe(unsigned int endpoint, l4_cap_idx_t notifier, 99 notify_flags_t flags); 100 101 virtual void _unsubscribe(l4_cap_idx_t notifier); 102 103 public: 104 explicit NotificationSupport(unsigned int endpoints=0); 105 106 virtual ~NotificationSupport(); 107 108 virtual void notify(unsigned int endpoint, notify_flags_t flags, 109 notify_values_t values); 110 111 virtual void notify_all(notify_flags_t flags, notify_values_t values); 112 113 virtual void notify_others(unsigned int endpoint, notify_flags_t flags, 114 notify_values_t values); 115 116 virtual void notify_others(l4_cap_idx_t notifier, notify_flags_t flags, 117 notify_values_t values); 118 119 virtual long subscribe(l4_cap_idx_t notifier, notify_flags_t flags); 120 121 virtual long subscribe(unsigned int endpoint, l4_cap_idx_t notifier, 122 notify_flags_t flags); 123 124 virtual long unsubscribe(l4_cap_idx_t notifier); 125 }; 126 127 // vim: tabstop=4 expandtab shiftwidth=4