paul@93 | 1 | /* |
paul@93 | 2 | * Generic accessor functionality. |
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@6 | 22 | #pragma once |
paul@6 | 23 | |
paul@94 | 24 | #include <mem/flexpage.h> |
paul@6 | 25 | |
paul@93 | 26 | |
paul@93 | 27 | |
paul@6 | 28 | /* A file accessor, providing flexpages corresponding to file regions. */ |
paul@6 | 29 | |
paul@6 | 30 | class Accessor |
paul@6 | 31 | { |
paul@6 | 32 | protected: |
paul@200 | 33 | bool _closed = false; |
paul@6 | 34 | offset_t _size; |
paul@6 | 35 | |
paul@56 | 36 | /* Data transfer helper methods. */ |
paul@56 | 37 | |
paul@56 | 38 | virtual void fill_populated(Flexpage *flexpage); |
paul@56 | 39 | |
paul@56 | 40 | virtual void flush_populated(Flexpage *flexpage); |
paul@56 | 41 | |
paul@6 | 42 | public: |
paul@6 | 43 | fileid_t fileid; |
paul@6 | 44 | |
paul@101 | 45 | explicit Accessor(fileid_t fileid); |
paul@6 | 46 | |
paul@94 | 47 | virtual ~Accessor(); |
paul@79 | 48 | |
paul@101 | 49 | virtual offset_t get_size() = 0; |
paul@6 | 50 | |
paul@101 | 51 | virtual void set_size(offset_t size) = 0; |
paul@53 | 52 | |
paul@6 | 53 | virtual void close(); |
paul@6 | 54 | |
paul@6 | 55 | /* Data transfer methods. */ |
paul@6 | 56 | |
paul@56 | 57 | virtual void fill(Flexpage *flexpage); |
paul@6 | 58 | |
paul@56 | 59 | virtual void flush(Flexpage *flexpage); |
paul@232 | 60 | |
paul@232 | 61 | /* Lifecycle methods. */ |
paul@232 | 62 | |
paul@232 | 63 | virtual void remove(); |
paul@6 | 64 | }; |
paul@6 | 65 | |
paul@6 | 66 | // vim: tabstop=4 expandtab shiftwidth=4 |