paul@93 | 1 | /* |
paul@93 | 2 | * An opener for a "host" file provided via the C library. |
paul@93 | 3 | * |
paul@93 | 4 | * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk> |
paul@93 | 5 | * |
paul@93 | 6 | * This program is free software; you can redistribute it and/or |
paul@93 | 7 | * modify it under the terms of the GNU General Public License as |
paul@93 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@93 | 9 | * the License, or (at your option) any later version. |
paul@93 | 10 | * |
paul@93 | 11 | * This program is distributed in the hope that it will be useful, |
paul@93 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@93 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@93 | 14 | * GNU General Public License for more details. |
paul@93 | 15 | * |
paul@93 | 16 | * You should have received a copy of the GNU General Public License |
paul@93 | 17 | * along with this program; if not, write to the Free Software |
paul@93 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@93 | 19 | * Boston, MA 02110-1301, USA |
paul@93 | 20 | */ |
paul@93 | 21 | |
paul@12 | 22 | #pragma once |
paul@12 | 23 | |
paul@12 | 24 | #include <map> |
paul@139 | 25 | #include <mutex> |
paul@139 | 26 | #include <string> |
paul@12 | 27 | |
paul@94 | 28 | #include <fsserver/opener_resource.h> |
paul@12 | 29 | |
paul@12 | 30 | |
paul@12 | 31 | |
paul@139 | 32 | /* Collection data types. */ |
paul@139 | 33 | |
paul@139 | 34 | typedef std::map<std::string, fileid_t> HostFileIdentifiers; |
paul@139 | 35 | |
paul@139 | 36 | |
paul@139 | 37 | |
paul@12 | 38 | /* Support for providing access to files. */ |
paul@12 | 39 | |
paul@12 | 40 | class HostFileOpener : public OpenerResource |
paul@12 | 41 | { |
paul@12 | 42 | protected: |
paul@139 | 43 | std::mutex _lock; |
paul@139 | 44 | |
paul@139 | 45 | /* File identifier register. */ |
paul@139 | 46 | |
paul@139 | 47 | HostFileIdentifiers _fileids; |
paul@12 | 48 | |
paul@12 | 49 | /* Configurable methods. */ |
paul@12 | 50 | |
paul@12 | 51 | virtual fileid_t get_fileid(const char *path); |
paul@12 | 52 | |
paul@106 | 53 | virtual Accessor *make_accessor(const char *path, fileid_t fileid); |
paul@12 | 54 | |
paul@12 | 55 | public: |
paul@79 | 56 | explicit HostFileOpener(Pages *pages) |
paul@79 | 57 | : OpenerResource(pages) |
paul@12 | 58 | { |
paul@12 | 59 | } |
paul@12 | 60 | }; |
paul@12 | 61 | |
paul@12 | 62 | // vim: tabstop=4 expandtab shiftwidth=4 |