Added a tools folder with an early version of a AppInterface definition broker
This commit is contained in:
parent
427b42d1b3
commit
44c43d3254
42
Makefile
42
Makefile
|
@ -1,6 +1,6 @@
|
||||||
PACKAGE = libSystem
|
PACKAGE = libSystem
|
||||||
VERSION = 0.1.2
|
VERSION = 0.1.2
|
||||||
SUBDIRS = src include
|
SUBDIRS = include src tools
|
||||||
RM = rm -f
|
RM = rm -f
|
||||||
LN = ln -f
|
LN = ln -f
|
||||||
TAR = tar -czvf
|
TAR = tar -czvf
|
||||||
|
@ -21,24 +21,6 @@ dist:
|
||||||
$(RM) -r $(PACKAGE)-$(VERSION)
|
$(RM) -r $(PACKAGE)-$(VERSION)
|
||||||
$(LN) -s . $(PACKAGE)-$(VERSION)
|
$(LN) -s . $(PACKAGE)-$(VERSION)
|
||||||
@$(TAR) $(PACKAGE)-$(VERSION).tar.gz \
|
@$(TAR) $(PACKAGE)-$(VERSION).tar.gz \
|
||||||
$(PACKAGE)-$(VERSION)/src/appclient.c \
|
|
||||||
$(PACKAGE)-$(VERSION)/src/appinterface.c \
|
|
||||||
$(PACKAGE)-$(VERSION)/src/appserver.c \
|
|
||||||
$(PACKAGE)-$(VERSION)/src/array.c \
|
|
||||||
$(PACKAGE)-$(VERSION)/src/buffer.c \
|
|
||||||
$(PACKAGE)-$(VERSION)/src/config.c \
|
|
||||||
$(PACKAGE)-$(VERSION)/src/error.c \
|
|
||||||
$(PACKAGE)-$(VERSION)/src/event.c \
|
|
||||||
$(PACKAGE)-$(VERSION)/src/hash.c \
|
|
||||||
$(PACKAGE)-$(VERSION)/src/object.c \
|
|
||||||
$(PACKAGE)-$(VERSION)/src/parser.c \
|
|
||||||
$(PACKAGE)-$(VERSION)/src/plugin.c \
|
|
||||||
$(PACKAGE)-$(VERSION)/src/string.c \
|
|
||||||
$(PACKAGE)-$(VERSION)/src/token.c \
|
|
||||||
$(PACKAGE)-$(VERSION)/src/Makefile \
|
|
||||||
$(PACKAGE)-$(VERSION)/src/appinterface.h \
|
|
||||||
$(PACKAGE)-$(VERSION)/src/token.h \
|
|
||||||
$(PACKAGE)-$(VERSION)/src/project.conf \
|
|
||||||
$(PACKAGE)-$(VERSION)/include/System.h \
|
$(PACKAGE)-$(VERSION)/include/System.h \
|
||||||
$(PACKAGE)-$(VERSION)/include/Makefile \
|
$(PACKAGE)-$(VERSION)/include/Makefile \
|
||||||
$(PACKAGE)-$(VERSION)/include/project.conf \
|
$(PACKAGE)-$(VERSION)/include/project.conf \
|
||||||
|
@ -58,6 +40,28 @@ dist:
|
||||||
$(PACKAGE)-$(VERSION)/include/System/token.h \
|
$(PACKAGE)-$(VERSION)/include/System/token.h \
|
||||||
$(PACKAGE)-$(VERSION)/include/System/Makefile \
|
$(PACKAGE)-$(VERSION)/include/System/Makefile \
|
||||||
$(PACKAGE)-$(VERSION)/include/System/project.conf \
|
$(PACKAGE)-$(VERSION)/include/System/project.conf \
|
||||||
|
$(PACKAGE)-$(VERSION)/src/appclient.c \
|
||||||
|
$(PACKAGE)-$(VERSION)/src/appinterface.c \
|
||||||
|
$(PACKAGE)-$(VERSION)/src/appserver.c \
|
||||||
|
$(PACKAGE)-$(VERSION)/src/array.c \
|
||||||
|
$(PACKAGE)-$(VERSION)/src/buffer.c \
|
||||||
|
$(PACKAGE)-$(VERSION)/src/config.c \
|
||||||
|
$(PACKAGE)-$(VERSION)/src/error.c \
|
||||||
|
$(PACKAGE)-$(VERSION)/src/event.c \
|
||||||
|
$(PACKAGE)-$(VERSION)/src/hash.c \
|
||||||
|
$(PACKAGE)-$(VERSION)/src/object.c \
|
||||||
|
$(PACKAGE)-$(VERSION)/src/parser.c \
|
||||||
|
$(PACKAGE)-$(VERSION)/src/plugin.c \
|
||||||
|
$(PACKAGE)-$(VERSION)/src/string.c \
|
||||||
|
$(PACKAGE)-$(VERSION)/src/token.c \
|
||||||
|
$(PACKAGE)-$(VERSION)/src/Makefile \
|
||||||
|
$(PACKAGE)-$(VERSION)/src/appinterface.h \
|
||||||
|
$(PACKAGE)-$(VERSION)/src/token.h \
|
||||||
|
$(PACKAGE)-$(VERSION)/src/project.conf \
|
||||||
|
$(PACKAGE)-$(VERSION)/tools/broker.c \
|
||||||
|
$(PACKAGE)-$(VERSION)/tools/Makefile \
|
||||||
|
$(PACKAGE)-$(VERSION)/tools/README \
|
||||||
|
$(PACKAGE)-$(VERSION)/tools/project.conf \
|
||||||
$(PACKAGE)-$(VERSION)/Makefile \
|
$(PACKAGE)-$(VERSION)/Makefile \
|
||||||
$(PACKAGE)-$(VERSION)/COPYING \
|
$(PACKAGE)-$(VERSION)/COPYING \
|
||||||
$(PACKAGE)-$(VERSION)/config.h \
|
$(PACKAGE)-$(VERSION)/config.h \
|
||||||
|
|
|
@ -3,4 +3,4 @@ version=0.1.2
|
||||||
config=h
|
config=h
|
||||||
dist=Makefile,COPYING,config.h
|
dist=Makefile,COPYING,config.h
|
||||||
|
|
||||||
subdirs=src,include
|
subdirs=include,src,tools
|
||||||
|
|
39
tools/Makefile
Normal file
39
tools/Makefile
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
TARGETS = broker
|
||||||
|
PREFIX = /usr/local
|
||||||
|
DESTDIR =
|
||||||
|
BINDIR = $(PREFIX)/bin
|
||||||
|
CC = cc
|
||||||
|
CPPFLAGSF= -I ../include
|
||||||
|
CPPFLAGS=
|
||||||
|
CFLAGSF = -W
|
||||||
|
CFLAGS = -Wall -g -O2 -pedantic
|
||||||
|
LDFLAGSF= -lSystem -L$(PREFIX)/lib -Wl,-rpath,$(PREFIX)/lib
|
||||||
|
RM = rm -f
|
||||||
|
LN = ln -f
|
||||||
|
MKDIR = mkdir -p
|
||||||
|
INSTALL = install
|
||||||
|
|
||||||
|
|
||||||
|
all: $(TARGETS)
|
||||||
|
|
||||||
|
broker_OBJS = broker.o
|
||||||
|
broker_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
|
||||||
|
broker_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
|
||||||
|
|
||||||
|
broker: $(broker_OBJS)
|
||||||
|
$(CC) -o broker $(broker_OBJS) $(broker_LDFLAGS)
|
||||||
|
|
||||||
|
broker.o: broker.c
|
||||||
|
$(CC) $(broker_CFLAGS) -c broker.c
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RM) $(broker_OBJS)
|
||||||
|
|
||||||
|
distclean: clean
|
||||||
|
$(RM) $(TARGETS)
|
||||||
|
|
||||||
|
install: all
|
||||||
|
|
||||||
|
uninstall:
|
||||||
|
|
||||||
|
.PHONY: all clean distclean install uninstall
|
45
tools/README
Normal file
45
tools/README
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
broker reads a configuration file for a given AppInterface, eg:
|
||||||
|
|
||||||
|
=== BEGIN FILE ===
|
||||||
|
service=VFS
|
||||||
|
|
||||||
|
[chmod]
|
||||||
|
ret=INT32
|
||||||
|
arg1=STRING,pathname
|
||||||
|
arg2=UINT32,mode
|
||||||
|
=== END FILE ===
|
||||||
|
|
||||||
|
which is then translated into a C header file, eg:
|
||||||
|
=== BEGIN FILE ===
|
||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef VFS_H
|
||||||
|
# define VFS_H
|
||||||
|
|
||||||
|
# include <stdint.h>
|
||||||
|
# include <System.h>
|
||||||
|
|
||||||
|
|
||||||
|
/* types */
|
||||||
|
typedef Buffer * BUFFER;
|
||||||
|
typedef int32_t INT32;
|
||||||
|
typedef uint32_t UINT32;
|
||||||
|
typedef String * STRING;
|
||||||
|
|
||||||
|
|
||||||
|
/* functions */
|
||||||
|
INT32 VFS_chmod(STRING pathname, UINT32 mode);
|
||||||
|
|
||||||
|
#endif /* !VFS_H */
|
||||||
|
=== END FILE ===
|
||||||
|
|
||||||
|
This service definition file and corresponding header may then be committed
|
||||||
|
along the relevant source code.
|
||||||
|
|
||||||
|
It would also be helpful to:
|
||||||
|
- add scripting possibilities to configure (to regenerate the headers
|
||||||
|
accordingly)
|
||||||
|
- place this code directly inside AppInterface's class
|
||||||
|
- implement IN/OUT/IN_OUT
|
163
tools/broker.c
Normal file
163
tools/broker.c
Normal file
|
@ -0,0 +1,163 @@
|
||||||
|
/* $Id$ */
|
||||||
|
/* Copyright (c) 2009 Pierre Pronchery <khorben@defora.org> */
|
||||||
|
/* This file is part of DeforaOS System libSystem */
|
||||||
|
/* This program 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, version 3 of the License.
|
||||||
|
*
|
||||||
|
* This program 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <System.h>
|
||||||
|
|
||||||
|
#define PACKAGE "broker"
|
||||||
|
|
||||||
|
|
||||||
|
/* broker */
|
||||||
|
typedef struct _BrokerData
|
||||||
|
{
|
||||||
|
char const * prefix;
|
||||||
|
char const * outfile;
|
||||||
|
FILE * fp;
|
||||||
|
} BrokerData;
|
||||||
|
|
||||||
|
|
||||||
|
/* broker */
|
||||||
|
static void _broker_head(BrokerData * data);
|
||||||
|
static int _broker_foreach(char const * key, Hash * value, BrokerData * data);
|
||||||
|
static void _broker_foreach_arg(BrokerData * data, char const * sep,
|
||||||
|
char const * arg);
|
||||||
|
static void _broker_tail(BrokerData * data);
|
||||||
|
|
||||||
|
static int _broker(char const * outfile, char const * filename)
|
||||||
|
{
|
||||||
|
Config * config;
|
||||||
|
BrokerData data;
|
||||||
|
|
||||||
|
if((config = config_new()) == NULL)
|
||||||
|
return error_print(PACKAGE);
|
||||||
|
if(config_load(config, filename) != 0)
|
||||||
|
{
|
||||||
|
config_delete(config);
|
||||||
|
return error_print(PACKAGE);
|
||||||
|
}
|
||||||
|
data.prefix = config_get(config, NULL, "service");
|
||||||
|
if((data.outfile = outfile) == NULL)
|
||||||
|
data.fp = stdout;
|
||||||
|
else if((data.fp = fopen(outfile, "w")) == NULL)
|
||||||
|
{
|
||||||
|
config_delete(config);
|
||||||
|
return error_set_print(PACKAGE, 1, "%s: %s", outfile,
|
||||||
|
strerror(errno));
|
||||||
|
}
|
||||||
|
_broker_head(&data);
|
||||||
|
fputs("\n\n/* functions */\n", data.fp);
|
||||||
|
hash_foreach(config, _broker_foreach, &data);
|
||||||
|
_broker_tail(&data);
|
||||||
|
if(outfile != NULL)
|
||||||
|
fclose(data.fp);
|
||||||
|
config_delete(config);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void _broker_head(BrokerData * data)
|
||||||
|
{
|
||||||
|
fputs("/* $Id$ */\n\n\n\n", data->fp);
|
||||||
|
if(data->prefix != NULL)
|
||||||
|
fprintf(data->fp, "%s%s%s%s%s%s", "#ifndef ", data->prefix,
|
||||||
|
"_H\n", "# define ", data->prefix, "_H\n");
|
||||||
|
fputs("\n# include <stdint.h>\n", data->fp);
|
||||||
|
fputs("# include <System.h>\n\n", data->fp);
|
||||||
|
fputs("\n/* types */\n", data->fp);
|
||||||
|
fputs("typedef Buffer * BUFFER;\n", data->fp);
|
||||||
|
fputs("typedef int32_t INT32;\n", data->fp);
|
||||||
|
fputs("typedef uint32_t UINT32;\n", data->fp);
|
||||||
|
fputs("typedef String * STRING;\n", data->fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int _broker_foreach(char const * key, Hash * value, BrokerData * data)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
char buf[8];
|
||||||
|
char const * p;
|
||||||
|
char const * sep = "";
|
||||||
|
|
||||||
|
if(key == NULL || key[0] == '\0')
|
||||||
|
return 0;
|
||||||
|
if((p = hash_get(value, "ret")) == NULL)
|
||||||
|
p = "void";
|
||||||
|
fprintf(data->fp, "%s%s%s%s%s%s", p, " ", data->prefix, "_", key, "(");
|
||||||
|
for(i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
snprintf(buf, sizeof(buf), "arg%d", i + 1);
|
||||||
|
if((p = hash_get(value, buf)) == NULL)
|
||||||
|
break;
|
||||||
|
_broker_foreach_arg(data, sep, p);
|
||||||
|
sep = ", ";
|
||||||
|
}
|
||||||
|
fprintf(data->fp, "%s", ");\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void _broker_foreach_arg(BrokerData * data, char const * sep,
|
||||||
|
char const * arg)
|
||||||
|
{
|
||||||
|
char * p;
|
||||||
|
|
||||||
|
if((p = strchr(arg, ',')) == NULL)
|
||||||
|
{
|
||||||
|
fprintf(data->fp, "%s%s", sep, arg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fputs(sep, data->fp);
|
||||||
|
fwrite(arg, sizeof(*arg), p - arg, data->fp);
|
||||||
|
if(*(++p) != '\0')
|
||||||
|
fprintf(data->fp, " %s", p);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void _broker_tail(BrokerData * data)
|
||||||
|
{
|
||||||
|
if(data->prefix != NULL)
|
||||||
|
fprintf(data->fp, "%s%s%s", "\n#endif /* !", data->prefix,
|
||||||
|
"_H */\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* usage */
|
||||||
|
static int _usage(void)
|
||||||
|
{
|
||||||
|
fputs("Usage: broker [-o outfile] filename\n", stderr);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* main */
|
||||||
|
int main(int argc, char * argv[])
|
||||||
|
{
|
||||||
|
int o;
|
||||||
|
char const * outfile = NULL;
|
||||||
|
|
||||||
|
while((o = getopt(argc, argv, "o:")) != -1)
|
||||||
|
switch(o)
|
||||||
|
{
|
||||||
|
case 'o':
|
||||||
|
outfile = optarg;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return _usage();
|
||||||
|
}
|
||||||
|
if(optind + 1 != argc)
|
||||||
|
return _usage();
|
||||||
|
return (_broker(outfile, argv[optind]) == 0) ? 0 : 2;
|
||||||
|
}
|
10
tools/project.conf
Normal file
10
tools/project.conf
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
targets=broker
|
||||||
|
cppflags_force=-I ../include
|
||||||
|
cflags_force=-W
|
||||||
|
cflags=-Wall -g -O2 -pedantic
|
||||||
|
ldflags_force=-lSystem -L$(PREFIX)/lib -Wl,-rpath,$(PREFIX)/lib
|
||||||
|
dist=Makefile,README
|
||||||
|
|
||||||
|
[broker]
|
||||||
|
type=binary
|
||||||
|
sources=broker.c
|
Loading…
Reference in New Issue
Block a user