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