1 /* 2 * A pipe server. 3 * 4 * Copyright (C) 2020, 2021, 2022, 2023 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/pipe_opener_resource.h> 31 #include <fsserver/resource_server.h> 32 #include <systypes/env.h> 33 34 35 36 /* Server program. */ 37 38 int main(int argc, char *argv[]) 39 { 40 long err; 41 42 /* Introduce concurrency control. */ 43 44 err = ipc_thread_init(); 45 46 if (err) 47 { 48 printf("Initialisation error: %s\n", l4sys_errtostr(err)); 49 return 1; 50 } 51 52 unsigned int memory_pages = 0; 53 54 if (argc > 1) 55 memory_pages = atoi(argv[1]); 56 57 /* Some memory plus infrastructure. */ 58 59 Memory *mem = NULL; 60 61 if (memory_pages) 62 mem = new MemoryIncremental(memory_pages); 63 else 64 mem = new MemoryIncremental(); 65 66 PipeOpenerResource opener(mem); 67 68 /* Register a server associating it with the given object. */ 69 70 const char *server_name = (argc > 2) ? argv[2] : ENV_PIPE_SERVER_NAME; 71 72 ResourceServer server(&opener); 73 err = server.bind(server_name); 74 75 if (err) 76 { 77 printf("Could not bind server: %s\n", l4sys_errtostr(err)); 78 return 1; 79 } 80 81 printf("Starting server using %d pages...\n", memory_pages); 82 server.start(); 83 return 0; 84 } 85 86 // vim: tabstop=2 expandtab shiftwidth=2