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