paul@9 | 1 | #pragma once |
paul@9 | 2 | |
paul@9 | 3 | #include <map> |
paul@9 | 4 | #include <mutex> |
paul@9 | 5 | |
paul@79 | 6 | #include "accessor.h" |
paul@79 | 7 | #include "pager.h" |
paul@9 | 8 | #include "page_mapper.h" |
paul@9 | 9 | |
paul@9 | 10 | |
paul@9 | 11 | |
paul@9 | 12 | /* Mapping type from accessors to page mappers. */ |
paul@9 | 13 | |
paul@78 | 14 | typedef std::map<fileid_t, PageMapper *> FileMapping; |
paul@78 | 15 | typedef std::pair<fileid_t, PageMapper *> FileMappingEntry; |
paul@9 | 16 | |
paul@9 | 17 | |
paul@9 | 18 | |
paul@9 | 19 | /* A registry of mappers for accessors. */ |
paul@9 | 20 | |
paul@9 | 21 | class Paging |
paul@9 | 22 | { |
paul@9 | 23 | protected: |
paul@79 | 24 | Pages *_pages; |
paul@79 | 25 | |
paul@78 | 26 | FileMapping _mappers; |
paul@9 | 27 | std::mutex _lock; |
paul@9 | 28 | |
paul@79 | 29 | /* Pager initialisation methods. */ |
paul@79 | 30 | |
paul@79 | 31 | PageMapper *get_mapper(fileid_t fileid); |
paul@79 | 32 | |
paul@79 | 33 | Pager *get_pager(fileid_t fileid, flags_t flags); |
paul@79 | 34 | |
paul@79 | 35 | /* Configurable methods. */ |
paul@79 | 36 | |
paul@79 | 37 | virtual fileid_t get_fileid(const char *path) = 0; |
paul@79 | 38 | |
paul@79 | 39 | virtual Accessor *make_accessor(fileid_t fileid) = 0; |
paul@79 | 40 | |
paul@79 | 41 | /* Mapper registry access. */ |
paul@9 | 42 | |
paul@78 | 43 | PageMapper *get(fileid_t fileid); |
paul@9 | 44 | |
paul@78 | 45 | void set(fileid_t fileid, PageMapper *mapper); |
paul@79 | 46 | |
paul@79 | 47 | public: |
paul@79 | 48 | explicit Paging(Pages *pages); |
paul@79 | 49 | |
paul@79 | 50 | virtual ~Paging() |
paul@79 | 51 | { |
paul@79 | 52 | } |
paul@79 | 53 | |
paul@79 | 54 | /* Methods for the pager. */ |
paul@79 | 55 | |
paul@79 | 56 | void detach_pager(fileid_t fileid, PageMapper *mapper); |
paul@9 | 57 | }; |
paul@9 | 58 | |
paul@9 | 59 | // vim: tabstop=4 expandtab shiftwidth=4 |