1 /* 2 * A resource offering support for creating contexts and opening files. 3 * 4 * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA 20 */ 21 22 #include "opener_server.h" 23 #include "opener_resource.h" 24 #include "resource_server.h" 25 26 /* Support for providing access to files. */ 27 28 OpenerResource::OpenerResource(Pages *pages) 29 : FilePaging(pages) 30 { 31 } 32 33 int OpenerResource::expected_items() 34 { 35 return Opener_expected_items; 36 } 37 38 ipc_server_handler_type OpenerResource::handler() 39 { 40 return (ipc_server_handler_type) handle_Opener; 41 } 42 43 44 45 /* Return a pager object for the given path and flags. */ 46 47 Pager *OpenerResource::open(const char *path, flags_t flags) 48 { 49 fileid_t fileid = get_fileid(path); 50 51 if (fileid == FILEID_INVALID) 52 return NULL; 53 54 return get_pager(path, fileid, get_flags(flags)); 55 } 56 57 58 59 /* Opener interface methods. */ 60 61 long OpenerResource::context(l4_cap_idx_t *context) 62 { 63 OpenerContextResource *resource = new OpenerContextResource(this); 64 65 /* Complete the initialisation and start a server in a new thread. 66 If the thread does not start, the resource will be finalised. */ 67 68 return ResourceServer(resource).start_thread(context); 69 } 70 71 // vim: tabstop=4 expandtab shiftwidth=4