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