L4Re/departure

servers/block_file_server.cc

263:9edfe5795697
2022-02-19 Paul Boddie Moved input-related functions into a separate module.
     1 /*     2  * A dataspace server exposing files each as a block of writable memory.     3  *     4  * Copyright (C) 2020, 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 <l4/sys/err.h>    23     24 #include <ipc/thread.h>    25     26 #include <stdio.h>    27 #include <stdlib.h>    28     29 #include <mem/memory_incremental.h>    30 #include <fsserver/page_queue_shared.h>    31 #include <fsserver/pages.h>    32 #include <fsserver/resource_server.h>    33 #include <fsserver/block_file_opener.h>    34     35     36     37 /* Default number of pages for files. */    38     39 const unsigned int MEMORY_PAGES = 20;    40     41     42     43 /* Server program. */    44     45 int main(int argc, char *argv[])    46 {    47   long err;    48     49   /* Introduce concurrency control. */    50     51   err = ipc_thread_init();    52     53   if (err)    54   {    55     printf("Initialisation error: %s\n", l4sys_errtostr(err));    56     return 1;    57   }    58     59   unsigned int memory_pages = MEMORY_PAGES;    60     61   if (argc > 1)    62     memory_pages = atoi(argv[1]);    63     64   /* Some memory plus infrastructure. */    65     66   MemoryIncremental mem(memory_pages);    67   PageQueueShared queue;    68   Pages pages(&mem, &queue);    69   ResourceRegistry registry(&pages);    70   BlockFileOpener opener(&registry);    71     72   /* Register a server associating it with the given object. */    73     74   const char *server_name = (argc > 2) ? argv[2] : "server";    75     76   ResourceServer server(&opener);    77   err = server.bind(server_name);    78     79   if (err)    80   {    81     printf("Could not bind server: %s\n", l4sys_errtostr(err));    82     return 1;    83   }    84     85   printf("Starting server using %d pages...\n", memory_pages);    86   server.start();    87   return 0;    88 }    89     90 // vim: tabstop=2 expandtab shiftwidth=2