1 /* 2 * Notification support. 3 * 4 * Copyright (C) 2021 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 <mutex> 25 #include <set> 26 #include <vector> 27 28 #include <systypes/base.h> 29 30 31 32 /* Collection data types. */ 33 34 typedef std::set<l4_cap_idx_t> NotifierSet; 35 36 /* Notification endpoint details. */ 37 38 class NotificationEndpoint 39 { 40 public: 41 NotifierSet notifiers; 42 notify_flags_t flags = 0, deferred = 0; 43 }; 44 45 typedef std::vector<NotificationEndpoint> NotificationEndpointList; 46 47 48 49 /* Notification support, allowing pipe or file users to receive events due to 50 activity on those objects. */ 51 52 class NotificationSupport 53 { 54 protected: 55 std::mutex _lock; 56 57 /* Endpoint count. */ 58 59 unsigned int _min_endpoints; 60 61 /* Notification endpoint details. */ 62 63 NotificationEndpointList _endpoints; 64 65 /* Deferred notifications for new endpoints. */ 66 67 notify_flags_t _deferred = 0; 68 69 virtual void release_notifiers(); 70 71 virtual void _notify(unsigned int endpoint, notify_flags_t flags); 72 73 virtual void _subscribe(unsigned int endpoint, l4_cap_idx_t notifier, notify_flags_t flags); 74 75 public: 76 explicit NotificationSupport(unsigned int endpoints=0); 77 78 virtual ~NotificationSupport(); 79 80 virtual void notify(unsigned int endpoint, notify_flags_t flags); 81 82 virtual void notify_others(unsigned int endpoint, notify_flags_t flags); 83 84 virtual unsigned int subscribe(l4_cap_idx_t notifier, notify_flags_t flags); 85 86 virtual void subscribe(unsigned int endpoint, l4_cap_idx_t notifier, notify_flags_t flags); 87 88 virtual void unsubscribe(unsigned int endpoint, l4_cap_idx_t notifier); 89 }; 90 91 // vim: tabstop=4 expandtab shiftwidth=4