cake
/
p7utils
Archived
1
0
Fork 0
This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
p7utils/src/p7servtest/server.c

106 lines
3.2 KiB
C

/* *****************************************************************************
* p7servtest/server.c -- p7servtest virtual server.
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of p7utils.
* p7utils is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2.0 of the License,
* or (at your option) any later version.
*
* p7utils is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with p7utils; if not, see <http://www.gnu.org/licenses/>.
* ************************************************************************** */
#include "main.h"
#include <string.h>
#include <libp7.h>
#include <libp7/stream.h>
/* ************************************************************************** */
/* Server callbacks */
/* ************************************************************************** */
/**
* directory_exists:
* Check if a directory exists.
*
* @arg dirname the directory.
* @arg devname the devname.
*/
static int directory_exists(const char *dirname)
{
/* check directory name */
if (!strcmp(dirname, "oui"))
return (0);
else return (p7_error_notfound);
}
/* ************************************************************************** */
/* Server configuration */
/* ************************************************************************** */
/* the server information */
static p7_server_t server_information = {
/* main calculator information */
.cpuid = "The CPU ID, wow!",
.hwid = "TESTSERV",
.product_id = "OMGOMGOMGOMGOMGO",
/* system configuration */
.username = "Cow",
/* preprogrammed ROM information */
.preprog_rom_wiped = 1,
/* flash ROM and RAM information */
.flash_rom_capacity = 8 * 1024 * 1024,
.ram_capacity = 256 * 1024,
/* bootcode information */
.bootcode_wiped = 1,
/* OS information */
.os_offset = 0x80000000, .os_size = 0x100000,
.os_version = {
.major = 2, .minor = 9, .rev = 2201
},
};
/* the server filesystems */
static p7_filesystem_t server_filesystems[] = {
{
.name = "fls0",
.directory_exists = directory_exists
},
{NULL}
};
/* ************************************************************************** */
/* Server functions */
/* ************************************************************************** */
/**
* run_server:
* Run the server!
*
* @arg in the input.
* @arg out the output.
*/
void run_server(int in, int out)
{
p7_handle_t *handle = NULL; int err;
if ((err = p7_fdinit(&handle, 0, "server", in, out,
&p7_default_settings))) {
fprintf(stderr, "Server encountered an error while initializing: %s\n",
p7_strerror(err));
return ;
}
p7_serve(handle, &server_information, server_filesystems);
p7_exit(handle);
}