paul@10 | 1 | #include "opener_server.h" |
paul@10 | 2 | #include "opener_resource.h" |
paul@10 | 3 | #include "resource_server.h" |
paul@9 | 4 | |
paul@9 | 5 | /* Support for providing access to files. */ |
paul@9 | 6 | |
paul@78 | 7 | OpenerResource::OpenerResource(Paging *paging, Pages *pages) |
paul@78 | 8 | : _paging(paging), _pages(pages) |
paul@9 | 9 | { |
paul@9 | 10 | } |
paul@9 | 11 | |
paul@10 | 12 | int OpenerResource::expected_items() |
paul@9 | 13 | { |
paul@10 | 14 | return Opener_expected_items; |
paul@9 | 15 | } |
paul@9 | 16 | |
paul@10 | 17 | ipc_server_handler_type OpenerResource::handler() |
paul@10 | 18 | { |
paul@10 | 19 | return (ipc_server_handler_type) handle_Opener; |
paul@10 | 20 | } |
paul@10 | 21 | |
paul@10 | 22 | |
paul@10 | 23 | |
paul@48 | 24 | /* Return a pager object for the given path and flags. */ |
paul@10 | 25 | |
paul@51 | 26 | FilePager *OpenerResource::open(const char *path, flags_t flags) |
paul@9 | 27 | { |
paul@9 | 28 | fileid_t fileid = get_fileid(path); |
paul@9 | 29 | |
paul@9 | 30 | if (fileid == FILEID_INVALID) |
paul@9 | 31 | return NULL; |
paul@9 | 32 | |
paul@78 | 33 | PageMapper *mapper = get_mapper(fileid); |
paul@48 | 34 | return new FilePager(fileid, mapper, flags); |
paul@9 | 35 | } |
paul@9 | 36 | |
paul@78 | 37 | /* Obtain a page mapper for the 'fileid' or register a new one in the |
paul@9 | 38 | paging object. */ |
paul@9 | 39 | |
paul@78 | 40 | PageMapper *OpenerResource::get_mapper(fileid_t fileid) |
paul@9 | 41 | { |
paul@9 | 42 | PageMapper *mapper; |
paul@9 | 43 | |
paul@78 | 44 | if (_paging->reserve(fileid)) |
paul@78 | 45 | mapper = _paging->get(fileid); |
paul@9 | 46 | else |
paul@9 | 47 | { |
paul@78 | 48 | Accessor *accessor = make_accessor(fileid); |
paul@9 | 49 | mapper = new PageMapper(accessor, _pages); |
paul@78 | 50 | _paging->set(fileid, mapper); |
paul@9 | 51 | } |
paul@9 | 52 | |
paul@9 | 53 | return mapper; |
paul@9 | 54 | } |
paul@9 | 55 | |
paul@10 | 56 | |
paul@10 | 57 | |
paul@10 | 58 | /* Opener interface methods. */ |
paul@10 | 59 | |
paul@10 | 60 | long OpenerResource::context(l4_cap_idx_t *context) |
paul@10 | 61 | { |
paul@10 | 62 | OpenerContextResource *resource = new OpenerContextResource(this); |
paul@10 | 63 | |
paul@62 | 64 | /* Complete the initialisation and start a server in a new thread. |
paul@62 | 65 | If the thread does not start, the resource should be finalised. */ |
paul@10 | 66 | |
paul@10 | 67 | ResourceServer server(resource); |
paul@10 | 68 | long err = server.start_thread(); |
paul@10 | 69 | |
paul@10 | 70 | /* Return the server capability to the caller. */ |
paul@10 | 71 | |
paul@62 | 72 | if (!err) |
paul@62 | 73 | *context = server.config()->server; |
paul@62 | 74 | |
paul@10 | 75 | return err; |
paul@10 | 76 | } |
paul@10 | 77 | |
paul@9 | 78 | // vim: tabstop=4 expandtab shiftwidth=4 |