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