L4Re/departure

servers/test_file_server.cc

263:9edfe5795697
2022-02-19 Paul Boddie Moved input-related functions into a separate module.
     1 /*     2  * Test dataspace operations.     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 <mem/memory_utils.h>    31 #include <fsserver/page_queue_shared.h>    32 #include <fsserver/pages.h>    33 #include <fsserver/resource_server.h>    34 #include <fsserver/test_file_opener.h>    35     36     37     38 const unsigned int REGION_PAGES = 8;    39 const unsigned int MEMORY_PAGES = REGION_PAGES * 10;    40 const unsigned int FILE_PAGES = 20;    41     42 int main(int argc, char *argv[])    43 {    44   long err;    45     46   /* Introduce concurrency control. */    47     48   err = ipc_thread_init();    49     50   if (err)    51   {    52     printf("Initialisation error: %s\n", l4sys_errtostr(err));    53     return 1;    54   }    55     56   /* Configure the number of available pages using any argument. */    57     58   unsigned int memory_pages = MEMORY_PAGES;    59     60   if (argc > 1)    61     memory_pages = atoi(argv[1]) * REGION_PAGES;    62     63   /* Some memory plus infrastructure. */    64     65   MemoryIncremental mem(memory_pages, page(REGION_PAGES));    66   PageQueueShared queue;    67   Pages pages(&mem, &queue);    68   ResourceRegistry registry(&pages);    69   TestFileOpener opener(&registry, page(FILE_PAGES));    70     71   /* Register a server associating it with the given object. */    72     73   const char *server_name = (argc > 2) ? argv[2] : "server";    74     75   ResourceServer server(&opener);    76   err = server.bind(server_name);    77     78   if (err)    79   {    80     printf("Could not bind server: %s\n", l4sys_errtostr(err));    81     return 1;    82   }    83     84   printf("Starting server...\n");    85   server.start();    86   return 0;    87 }    88     89 // vim: tabstop=2 expandtab shiftwidth=2