L4Re/departure

servers/client_file_server.cc

263:9edfe5795697
2022-02-19 Paul Boddie Moved input-related functions into a separate module.
     1 /*     2  * A dataspace server exposing file contents accessed via the filesystem client     3  * interface.     4  *     5  * Copyright (C) 2020, 2021 Paul Boddie <paul@boddie.org.uk>     6  *     7  * This program is free software; you can redistribute it and/or     8  * modify it under the terms of the GNU General Public License as     9  * published by the Free Software Foundation; either version 2 of    10  * the License, or (at your option) any later version.    11  *    12  * This program is distributed in the hope that it will be useful,    13  * but WITHOUT ANY WARRANTY; without even the implied warranty of    14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    15  * GNU General Public License for more details.    16  *    17  * You should have received a copy of the GNU General Public License    18  * along with this program; if not, write to the Free Software    19  * Foundation, Inc., 51 Franklin Street, Fifth Floor,    20  * Boston, MA  02110-1301, USA    21  */    22     23 #include <l4/sys/err.h>    24     25 #include <ipc/thread.h>    26     27 #include <stdio.h>    28 #include <stdlib.h>    29     30 #include <mem/memory_incremental.h>    31 #include <fsserver/page_queue_shared.h>    32 #include <fsserver/pages.h>    33 #include <fsserver/resource_server.h>    34 #include <fsserver/client_file_opener.h>    35     36     37     38 /* Default number of pages for files. */    39     40 const unsigned int MEMORY_PAGES = 20;    41     42     43     44 /* Server program. */    45     46 int main(int argc, char *argv[])    47 {    48   long err;    49     50   /* Introduce concurrency control. */    51     52   err = ipc_thread_init();    53     54   if (err)    55   {    56     printf("Initialisation error: %s\n", l4sys_errtostr(err));    57     return 1;    58   }    59     60   unsigned int memory_pages = MEMORY_PAGES;    61     62   if (argc > 1)    63     memory_pages = atoi(argv[1]);    64     65   /* Some memory plus infrastructure. */    66     67   MemoryIncremental mem(memory_pages);    68   PageQueueShared queue;    69   Pages pages(&mem, &queue);    70   ResourceRegistry registry(&pages);    71   ClientFileOpener opener(&registry);    72     73   /* Register a server associating it with the given object. */    74     75   const char *server_name = (argc > 2) ? argv[2] : "server";    76     77   ResourceServer server(&opener);    78   err = server.bind(server_name);    79     80   if (err)    81   {    82     printf("Could not bind server: %s\n", l4sys_errtostr(err));    83     return 1;    84   }    85     86   printf("Starting server using %d pages...\n", memory_pages);    87   server.start();    88   return 0;    89 }