L4Re/departure

opener_resource.cc

10:54182479d4bd
2021-02-01 Paul Boddie Made the opener, opener context and file pager resources, introducing the resource server functionality as a wrapper around server configurations. Introduced testing of the opener-related abstractions.
     1 #include "opener_server.h"     2 #include "opener_resource.h"     3 #include "resource_server.h"     4      5 /* Support for providing access to files. */     6      7 OpenerResource::OpenerResource(Accessing *accessing, Paging *paging, Pages *pages)     8 : _accessing(accessing), _paging(paging), _pages(pages)     9 {    10 }    11     12 int OpenerResource::expected_items()    13 {    14     return Opener_expected_items;    15 }    16     17 ipc_server_handler_type OpenerResource::handler()    18 {    19     return (ipc_server_handler_type) handle_Opener;    20 }    21     22     23     24 /* Return a pager object for the given path. */    25     26 FilePager *OpenerResource::open(const char *path)    27 {    28     fileid_t fileid = get_fileid(path);    29     30     if (fileid == FILEID_INVALID)    31         return NULL;    32     33     Accessor *accessor = get_accessor(fileid);    34     PageMapper *mapper = get_mapper(accessor);    35     return new FilePager(fileid, mapper);    36 }    37     38 /* Obtain an accessor for the 'fileid' or register a new one in the accessing    39    object. */    40     41 Accessor *OpenerResource::get_accessor(fileid_t fileid)    42 {    43     Accessor *accessor;    44     45     if (_accessing->reserve(fileid))    46         accessor = _accessing->get(fileid);    47     else    48     {    49         accessor = make_accessor(fileid);    50         _accessing->set(fileid, accessor);    51     }    52     53     return accessor;    54 }    55     56 /* Obtain a page mapper for the 'accessor' or register a new one in the    57    paging object. */    58     59 PageMapper *OpenerResource::get_mapper(Accessor *accessor)    60 {    61     PageMapper *mapper;    62     63     if (_paging->reserve(accessor))    64         mapper = _paging->get(accessor);    65     else    66     {    67         mapper = new PageMapper(accessor, _pages);    68         _paging->set(accessor, mapper);    69     }    70     71     return mapper;    72 }    73     74     75     76 /* Opener interface methods. */    77     78 long OpenerResource::context(l4_cap_idx_t *context)    79 {    80     OpenerContextResource *resource = new OpenerContextResource(this);    81     82     /* Complete the initialisation and start a server in a new thread. */    83     84     ResourceServer server(resource);    85     long err = server.start_thread();    86     87     /* Return the server capability to the caller. */    88     89     *context = server.config()->server;    90     return err;    91 }    92     93 // vim: tabstop=4 expandtab shiftwidth=4