paul@195 | 1 | /* |
paul@195 | 2 | * A registry of objects supporting notifications. |
paul@195 | 3 | * |
paul@195 | 4 | * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk> |
paul@195 | 5 | * |
paul@195 | 6 | * This program is free software; you can redistribute it and/or |
paul@195 | 7 | * modify it under the terms of the GNU General Public License as |
paul@195 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@195 | 9 | * the License, or (at your option) any later version. |
paul@195 | 10 | * |
paul@195 | 11 | * This program is distributed in the hope that it will be useful, |
paul@195 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@195 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@195 | 14 | * GNU General Public License for more details. |
paul@195 | 15 | * |
paul@195 | 16 | * You should have received a copy of the GNU General Public License |
paul@195 | 17 | * along with this program; if not, write to the Free Software |
paul@195 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@195 | 19 | * Boston, MA 02110-1301, USA |
paul@195 | 20 | */ |
paul@195 | 21 | |
paul@195 | 22 | #pragma once |
paul@195 | 23 | |
paul@195 | 24 | #include <map> |
paul@195 | 25 | #include <mutex> |
paul@195 | 26 | |
paul@195 | 27 | #include <fsserver/file_notification.h> |
paul@195 | 28 | #include <mem/types.h> |
paul@195 | 29 | |
paul@195 | 30 | |
paul@195 | 31 | |
paul@195 | 32 | /* Mapping type from file identifiers to notification managers. */ |
paul@195 | 33 | |
paul@195 | 34 | typedef std::map<fileid_t, FileNotification *> FileNotifiers; |
paul@195 | 35 | typedef std::map<fileid_t, FileNotification *> FileNotifierEntry; |
paul@195 | 36 | |
paul@195 | 37 | |
paul@195 | 38 | |
paul@195 | 39 | /* A registry of directory access objects. */ |
paul@195 | 40 | |
paul@195 | 41 | class FileNotifierRegistry |
paul@195 | 42 | { |
paul@195 | 43 | protected: |
paul@195 | 44 | FileNotifiers _notifiers; |
paul@195 | 45 | std::mutex _lock; |
paul@195 | 46 | |
paul@195 | 47 | FileNotification *_get(fileid_t fileid); |
paul@195 | 48 | |
paul@195 | 49 | public: |
paul@195 | 50 | explicit FileNotifierRegistry(); |
paul@195 | 51 | |
paul@195 | 52 | void attach(fileid_t fileid); |
paul@195 | 53 | |
paul@195 | 54 | void detach(fileid_t fileid); |
paul@195 | 55 | |
paul@195 | 56 | FileNotification *get(fileid_t fileid); |
paul@195 | 57 | }; |
paul@195 | 58 | |
paul@195 | 59 | // vim: tabstop=4 expandtab shiftwidth=4 |