1 /* 2 * Notification support. 3 * 4 * Copyright (C) 2021, 2022 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, NotifierPeerEndpoint *> NotifierPeerMap; 41 42 /* Notification endpoint details. */ 43 44 class NotificationEndpoint 45 { 46 public: 47 NotifierSet notifiers; 48 notify_flags_t flags = 0, deferred = 0; 49 }; 50 51 typedef std::vector<NotificationEndpoint> NotificationEndpointList; 52 53 54 55 /* Notification support, allowing pipe or file users to receive events due to 56 activity on those objects. */ 57 58 class NotificationSupport 59 { 60 protected: 61 std::mutex _lock; 62 63 /* Endpoint count. */ 64 65 unsigned int _min_endpoints; 66 67 /* Notification endpoint details. */ 68 69 NotificationEndpointList _endpoints; 70 71 /* Notifier peer details. */ 72 73 NotifierPeerMap _peers; 74 75 /* Deferred notifications for new endpoints. */ 76 77 notify_flags_t _deferred = 0; 78 79 virtual void release_notifiers(); 80 81 virtual void _notify(unsigned int endpoint, notify_flags_t flags); 82 83 virtual long _subscribe(unsigned int endpoint, l4_cap_idx_t notifier, 84 notify_flags_t flags, l4_cap_idx_t *peer); 85 86 virtual void _unsubscribe(unsigned int endpoint, l4_cap_idx_t notifier); 87 88 public: 89 explicit NotificationSupport(unsigned int endpoints=0); 90 91 virtual ~NotificationSupport(); 92 93 virtual void notify(unsigned int endpoint, notify_flags_t flags); 94 95 virtual void notify_all(notify_flags_t flags); 96 97 virtual void notify_others(unsigned int endpoint, notify_flags_t flags); 98 99 virtual long subscribe(l4_cap_idx_t notifier, notify_flags_t flags, 100 l4_cap_idx_t *peer, unsigned int *endpoint_number); 101 102 virtual long subscribe(unsigned int endpoint, l4_cap_idx_t notifier, 103 notify_flags_t flags, l4_cap_idx_t *peer); 104 105 virtual void unsubscribe(unsigned int endpoint, l4_cap_idx_t notifier); 106 }; 107 108 // vim: tabstop=4 expandtab shiftwidth=4