L4Re/departure

Annotated servers/pipe_server.cc

94:b6dab1e89e3c
2021-04-15 Paul Boddie Reorganised into a collection of packages for each area of functionality.
paul@65 1
/*
paul@84 2
 * A pipe server.
paul@65 3
 *
paul@65 4
 * Copyright (C) 2020, 2021 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@65 22
#include <l4/sys/err.h>
paul@65 23
paul@84 24
#include <ipc/thread.h>
paul@84 25
paul@65 26
#include <stdio.h>
paul@84 27
#include <stdlib.h>
paul@65 28
paul@94 29
#include <mem/memory_incremental.h>
paul@94 30
#include <fsserver/pipe_opener_resource.h>
paul@94 31
#include <fsserver/resource_server.h>
paul@65 32
paul@65 33
paul@65 34
paul@84 35
/* Default number of pages for pipes. */
paul@84 36
paul@65 37
const unsigned int MEMORY_PAGES = 20;
paul@65 38
paul@84 39
paul@84 40
paul@84 41
/* Server program. */
paul@84 42
paul@84 43
int main(int argc, char *argv[])
paul@65 44
{
paul@84 45
  long err;
paul@84 46
paul@84 47
  /* Introduce concurrency control. */
paul@84 48
paul@84 49
  err = ipc_thread_init();
paul@84 50
paul@84 51
  if (err)
paul@84 52
  {
paul@84 53
    printf("Initialisation error: %s\n", l4sys_errtostr(err));
paul@84 54
    return 1;
paul@84 55
  }
paul@84 56
paul@84 57
  unsigned int memory_pages = MEMORY_PAGES;
paul@84 58
paul@84 59
  if (argc > 1)
paul@84 60
    memory_pages = atoi(argv[1]);
paul@84 61
paul@65 62
  /* Some memory plus infrastructure. */
paul@65 63
paul@84 64
  MemoryIncremental mem(memory_pages);
paul@70 65
  PipeOpenerResource opener(&mem);
paul@65 66
paul@65 67
  /* Register a server associating it with the given object. */
paul@65 68
paul@65 69
  ResourceServer server(&opener);
paul@84 70
  err = server.bind("server");
paul@65 71
paul@65 72
  if (err)
paul@65 73
  {
paul@65 74
    printf("Could not bind server: %s\n", l4sys_errtostr(err));
paul@65 75
    return 1;
paul@65 76
  }
paul@65 77
paul@84 78
  printf("Starting server using %d pages...\n", memory_pages);
paul@65 79
  server.start();
paul@65 80
  return 0;
paul@65 81
}
paul@70 82
paul@70 83
// vim: tabstop=2 expandtab shiftwidth=2