L4Re/departure

Annotated servers/host_file_server.cc

224:4fb242f7d360
2021-10-18 Paul Boddie Renamed the registry classes to be more descriptive.
paul@0 1
/*
paul@84 2
 * A dataspace server exposing "host" file contents.
paul@0 3
 *
paul@1 4
 * Copyright (C) 2020, 2021 Paul Boddie <paul@boddie.org.uk>
paul@0 5
 *
paul@0 6
 * This program is free software; you can redistribute it and/or
paul@0 7
 * modify it under the terms of the GNU General Public License as
paul@0 8
 * published by the Free Software Foundation; either version 2 of
paul@0 9
 * the License, or (at your option) any later version.
paul@0 10
 *
paul@0 11
 * This program is distributed in the hope that it will be useful,
paul@0 12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
paul@0 13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
paul@0 14
 * GNU General Public License for more details.
paul@0 15
 *
paul@0 16
 * You should have received a copy of the GNU General Public License
paul@0 17
 * along with this program; if not, write to the Free Software
paul@0 18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
paul@0 19
 * Boston, MA  02110-1301, USA
paul@0 20
 */
paul@0 21
paul@0 22
#include <l4/sys/err.h>
paul@0 23
paul@84 24
#include <ipc/thread.h>
paul@84 25
paul@0 26
#include <stdio.h>
paul@0 27
#include <stdlib.h>
paul@0 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/host_file_opener.h>
paul@0 34
paul@0 35
paul@0 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@7 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@9 64
  /* Some memory plus infrastructure. */
paul@0 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
  HostFileOpener opener(&registry);
paul@0 71
paul@0 72
  /* Register a server associating it with the given object. */
paul@0 73
paul@97 74
  const char *server_name = (argc > 2) ? argv[2] : "server";
paul@97 75
paul@10 76
  ResourceServer server(&opener);
paul@97 77
  err = server.bind(server_name);
paul@0 78
paul@0 79
  if (err)
paul@0 80
  {
paul@0 81
    printf("Could not bind server: %s\n", l4sys_errtostr(err));
paul@0 82
    return 1;
paul@0 83
  }
paul@0 84
paul@84 85
  printf("Starting server using %d pages...\n", memory_pages);
paul@10 86
  server.start();
paul@0 87
  return 0;
paul@0 88
}