1 /* 2 * General functionality supporting file paging. 3 * 4 * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA 20 */ 21 22 #pragma once 23 24 #include <map> 25 #include <mutex> 26 27 #include "accessor.h" 28 #include "pager.h" 29 #include "page_mapper.h" 30 31 32 33 /* Mapping type from accessors to page mappers. */ 34 35 typedef std::map<fileid_t, PageMapper *> FileMapping; 36 typedef std::pair<fileid_t, PageMapper *> FileMappingEntry; 37 38 39 40 /* A registry of mappers for accessors. */ 41 42 class FilePaging 43 { 44 protected: 45 Pages *_pages; 46 47 FileMapping _mappers; 48 std::mutex _lock; 49 50 /* Pager initialisation methods. */ 51 52 PageMapper *get_mapper(fileid_t fileid); 53 54 Pager *get_pager(fileid_t fileid, flags_t flags); 55 56 /* Configurable methods. */ 57 58 virtual fileid_t get_fileid(const char *path) = 0; 59 60 virtual flags_t get_flags(flags_t flags); 61 62 virtual Accessor *make_accessor(fileid_t fileid) = 0; 63 64 /* Mapper registry access. */ 65 66 PageMapper *get(fileid_t fileid); 67 68 void set(fileid_t fileid, PageMapper *mapper); 69 70 public: 71 explicit FilePaging(Pages *pages); 72 73 virtual ~FilePaging() 74 { 75 } 76 77 /* Methods for the pager. */ 78 79 void detach_pager(fileid_t fileid, PageMapper *mapper); 80 }; 81 82 // vim: tabstop=4 expandtab shiftwidth=4