paul@93 | 1 | /* |
paul@93 | 2 | * A resource offering support for creating contexts and opening files. |
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@10 | 22 | #include "opener_server.h" |
paul@10 | 23 | #include "opener_resource.h" |
paul@10 | 24 | #include "resource_server.h" |
paul@9 | 25 | |
paul@9 | 26 | /* Support for providing access to files. */ |
paul@9 | 27 | |
paul@79 | 28 | OpenerResource::OpenerResource(Pages *pages) |
paul@81 | 29 | : FilePaging(pages) |
paul@9 | 30 | { |
paul@9 | 31 | } |
paul@9 | 32 | |
paul@10 | 33 | int OpenerResource::expected_items() |
paul@9 | 34 | { |
paul@10 | 35 | return Opener_expected_items; |
paul@9 | 36 | } |
paul@9 | 37 | |
paul@10 | 38 | ipc_server_handler_type OpenerResource::handler() |
paul@10 | 39 | { |
paul@10 | 40 | return (ipc_server_handler_type) handle_Opener; |
paul@10 | 41 | } |
paul@10 | 42 | |
paul@10 | 43 | |
paul@10 | 44 | |
paul@48 | 45 | /* Return a pager object for the given path and flags. */ |
paul@10 | 46 | |
paul@79 | 47 | Pager *OpenerResource::open(const char *path, flags_t flags) |
paul@9 | 48 | { |
paul@9 | 49 | fileid_t fileid = get_fileid(path); |
paul@9 | 50 | |
paul@9 | 51 | if (fileid == FILEID_INVALID) |
paul@9 | 52 | return NULL; |
paul@9 | 53 | |
paul@85 | 54 | return get_pager(fileid, get_flags(flags)); |
paul@9 | 55 | } |
paul@9 | 56 | |
paul@10 | 57 | |
paul@10 | 58 | |
paul@10 | 59 | /* Opener interface methods. */ |
paul@10 | 60 | |
paul@10 | 61 | long OpenerResource::context(l4_cap_idx_t *context) |
paul@10 | 62 | { |
paul@10 | 63 | OpenerContextResource *resource = new OpenerContextResource(this); |
paul@10 | 64 | |
paul@62 | 65 | /* Complete the initialisation and start a server in a new thread. |
paul@62 | 66 | If the thread does not start, the resource should be finalised. */ |
paul@10 | 67 | |
paul@10 | 68 | ResourceServer server(resource); |
paul@10 | 69 | long err = server.start_thread(); |
paul@10 | 70 | |
paul@10 | 71 | /* Return the server capability to the caller. */ |
paul@10 | 72 | |
paul@62 | 73 | if (!err) |
paul@62 | 74 | *context = server.config()->server; |
paul@62 | 75 | |
paul@10 | 76 | return err; |
paul@10 | 77 | } |
paul@10 | 78 | |
paul@9 | 79 | // vim: tabstop=4 expandtab shiftwidth=4 |