1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/files/file_paging.h Thu Apr 01 00:57:43 2021 +0200
1.3 @@ -0,0 +1,59 @@
1.4 +#pragma once
1.5 +
1.6 +#include <map>
1.7 +#include <mutex>
1.8 +
1.9 +#include "accessor.h"
1.10 +#include "pager.h"
1.11 +#include "page_mapper.h"
1.12 +
1.13 +
1.14 +
1.15 +/* Mapping type from accessors to page mappers. */
1.16 +
1.17 +typedef std::map<fileid_t, PageMapper *> FileMapping;
1.18 +typedef std::pair<fileid_t, PageMapper *> FileMappingEntry;
1.19 +
1.20 +
1.21 +
1.22 +/* A registry of mappers for accessors. */
1.23 +
1.24 +class FilePaging
1.25 +{
1.26 +protected:
1.27 + Pages *_pages;
1.28 +
1.29 + FileMapping _mappers;
1.30 + std::mutex _lock;
1.31 +
1.32 + /* Pager initialisation methods. */
1.33 +
1.34 + PageMapper *get_mapper(fileid_t fileid);
1.35 +
1.36 + Pager *get_pager(fileid_t fileid, flags_t flags);
1.37 +
1.38 + /* Configurable methods. */
1.39 +
1.40 + virtual fileid_t get_fileid(const char *path) = 0;
1.41 +
1.42 + virtual Accessor *make_accessor(fileid_t fileid) = 0;
1.43 +
1.44 + /* Mapper registry access. */
1.45 +
1.46 + PageMapper *get(fileid_t fileid);
1.47 +
1.48 + void set(fileid_t fileid, PageMapper *mapper);
1.49 +
1.50 +public:
1.51 + explicit FilePaging(Pages *pages);
1.52 +
1.53 + virtual ~FilePaging()
1.54 + {
1.55 + }
1.56 +
1.57 + /* Methods for the pager. */
1.58 +
1.59 + void detach_pager(fileid_t fileid, PageMapper *mapper);
1.60 +};
1.61 +
1.62 +// vim: tabstop=4 expandtab shiftwidth=4