L4Re/departure

resource_server.h

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 /*     2  * Common resource server functions.     3  *     4  * Copyright (C) 2018, 2019, 2020 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 #pragma once    23     24 #include "resource.h"    25 #include <ipc/server.h>    26     27     28     29 /* Convenience abstraction for blocking servers. */    30     31 class ResourceServer    32 {    33 protected:    34   Resource *_resource;    35   ipc_server_config_type *_config;    36     37 public:    38   explicit ResourceServer(Resource *resource)    39   : _resource(resource)    40   {    41     _config = new ipc_server_config_type;    42     ipc_server_init_config(_config);    43   }    44     45   /* Access to configuration. */    46     47   ipc_server_config_type *config()    48   { return _config; }    49     50   /* Server IPC gate allocation. */    51     52   long bind(const char *name);    53     54   /* Server initiation. */    55     56   long start();    57     58   long start_thread();    59 };    60     61     62     63 /* Server initialisation. */    64     65 void resource_init_config(ipc_server_config_type *config, Resource *resource);    66     67 void resource_set_config_threaded(ipc_server_config_type *config,    68                                   l4_cap_idx_t thread, int new_thread);    69     70 /* Server initiation. */    71     72 long resource_start_config(ipc_server_config_type *config, Resource *resource);    73     74 /* Server finalisation. */    75     76 void resource_thread_finaliser(ipc_server_config_type *config);