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