Separated the marshaller from the AppInterface class
This commit is contained in:
parent
e87b1cd21d
commit
e6cc2c5d75
2
Makefile
2
Makefile
|
@ -46,10 +46,12 @@ dist:
|
|||
$(PACKAGE)-$(VERSION)/src/appmessage.c \
|
||||
$(PACKAGE)-$(VERSION)/src/appserver.c \
|
||||
$(PACKAGE)-$(VERSION)/src/apptransport.c \
|
||||
$(PACKAGE)-$(VERSION)/src/marshall.c \
|
||||
$(PACKAGE)-$(VERSION)/src/Makefile \
|
||||
$(PACKAGE)-$(VERSION)/src/appinterface.h \
|
||||
$(PACKAGE)-$(VERSION)/src/appmessage.h \
|
||||
$(PACKAGE)-$(VERSION)/src/apptransport.h \
|
||||
$(PACKAGE)-$(VERSION)/src/marshall.h \
|
||||
$(PACKAGE)-$(VERSION)/src/project.conf \
|
||||
$(PACKAGE)-$(VERSION)/src/transport/tcp.c \
|
||||
$(PACKAGE)-$(VERSION)/src/transport/tcp4.c \
|
||||
|
|
|
@ -20,7 +20,7 @@ INSTALL = install
|
|||
|
||||
all: $(TARGETS)
|
||||
|
||||
libApp_OBJS = appclient.o appinterface.o appmessage.o appserver.o apptransport.o
|
||||
libApp_OBJS = appclient.o appinterface.o appmessage.o appserver.o apptransport.o marshall.o
|
||||
libApp_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
|
||||
libApp_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
|
||||
|
||||
|
@ -36,7 +36,7 @@ libApp.so.0.0 libApp.so.0 libApp.so: $(libApp_OBJS)
|
|||
appclient.o: appclient.c appinterface.h ../include/App/appclient.h
|
||||
$(CC) $(libApp_CFLAGS) -c appclient.c
|
||||
|
||||
appinterface.o: appinterface.c ../include/App/appserver.h ../config.h
|
||||
appinterface.o: appinterface.c ../include/App/appserver.h marshall.h ../config.h
|
||||
$(CC) $(libApp_CFLAGS) -c appinterface.c
|
||||
|
||||
appmessage.o: appmessage.c ../include/App/appmessage.h appmessage.h
|
||||
|
@ -48,6 +48,9 @@ appserver.o: appserver.c appinterface.h ../include/App/appserver.h ../config.h
|
|||
apptransport.o: apptransport.c apptransport.h ../include/App/apptransport.h ../config.h
|
||||
$(CC) $(libApp_CFLAGS) -c apptransport.c
|
||||
|
||||
marshall.o: marshall.c marshall.h
|
||||
$(CC) $(libApp_CFLAGS) -c marshall.c
|
||||
|
||||
clean:
|
||||
$(RM) -- $(libApp_OBJS)
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include <errno.h>
|
||||
#include <System.h>
|
||||
#include "App/appserver.h"
|
||||
#include "marshall.h"
|
||||
#include "appinterface.h"
|
||||
#include "../config.h"
|
||||
|
||||
|
@ -45,29 +46,21 @@
|
|||
/* AppInterface */
|
||||
/* private */
|
||||
/* types */
|
||||
typedef enum _AppInterfaceCallType
|
||||
{
|
||||
AICT_VOID = 000, AICT_BOOL = 001,
|
||||
AICT_INT8 = 002, AICT_UINT8 = 003,
|
||||
AICT_INT16 = 004, AICT_UINT16 = 005,
|
||||
AICT_INT32 = 006, AICT_UINT32 = 007,
|
||||
AICT_INT64 = 010, AICT_UINT64 = 011,
|
||||
AICT_STRING = 012, AICT_BUFFER = 013,
|
||||
AICT_FLOAT = 014, AICT_DOUBLE = 015
|
||||
} AppInterfaceCallType;
|
||||
#define AICT_LAST AICT_DOUBLE
|
||||
#define AICT_COUNT (AICT_LAST + 1)
|
||||
/* XXX get rid of this */
|
||||
#define VT_LAST VT_STRING
|
||||
#define VT_COUNT (VT_LAST + 1)
|
||||
#define AICT_MASK 077
|
||||
|
||||
#ifdef DEBUG
|
||||
static const String * AICTString[AICT_COUNT] =
|
||||
static const String * AICTString[VT_COUNT] =
|
||||
{
|
||||
"void", "bool", "int8", "uint8", "int16", "uint16", "int32", "uint32",
|
||||
"int64", "uint64", "String", "Buffer", "float", "double"
|
||||
};
|
||||
#endif
|
||||
|
||||
static int _aict_size[AICT_COUNT] =
|
||||
/* XXX get rid of this */
|
||||
static int _aict_size[VT_COUNT] =
|
||||
{
|
||||
0, sizeof(char),
|
||||
sizeof(int8_t), sizeof(uint8_t),
|
||||
|
@ -88,7 +81,7 @@ typedef enum _AppInterfaceCallDirection
|
|||
|
||||
typedef struct _AppInterfaceCallArg
|
||||
{
|
||||
AppInterfaceCallType type;
|
||||
VariableType type;
|
||||
AppInterfaceCallDirection direction;
|
||||
size_t size;
|
||||
} AppInterfaceCallArg;
|
||||
|
@ -122,22 +115,22 @@ typedef struct _StringEnum
|
|||
/* variables */
|
||||
StringEnum _string_type[] =
|
||||
{
|
||||
{ "VOID", AICT_VOID },
|
||||
{ "BOOL", AICT_BOOL },
|
||||
{ "INT8", AICT_INT8 },
|
||||
{ "UINT8", AICT_UINT8 },
|
||||
{ "INT16", AICT_INT16 },
|
||||
{ "UINT16", AICT_UINT16 },
|
||||
{ "INT32", AICT_INT32 },
|
||||
{ "UINT32", AICT_UINT32 },
|
||||
{ "INT64", AICT_INT64 },
|
||||
{ "UINT64", AICT_UINT64 },
|
||||
{ "STRING", AICT_STRING },
|
||||
{ "STRING_OUT", AICT_STRING | AICD_OUT },
|
||||
{ "BUFFER", AICT_BUFFER },
|
||||
{ "BUFFER_OUT", AICT_BUFFER | AICD_OUT },
|
||||
{ "FLOAT", AICT_FLOAT },
|
||||
{ "DOUBLE", AICT_DOUBLE },
|
||||
{ "VOID", VT_NULL },
|
||||
{ "BOOL", VT_BOOL },
|
||||
{ "INT8", VT_INT8 },
|
||||
{ "UINT8", VT_UINT8 },
|
||||
{ "INT16", VT_INT16 },
|
||||
{ "UINT16", VT_UINT16 },
|
||||
{ "INT32", VT_INT32 },
|
||||
{ "UINT32", VT_UINT32 },
|
||||
{ "INT64", VT_INT64 },
|
||||
{ "UINT64", VT_UINT64 },
|
||||
{ "STRING", VT_STRING },
|
||||
{ "STRING_OUT", VT_STRING | AICD_OUT },
|
||||
{ "BUFFER", VT_BUFFER },
|
||||
{ "BUFFER_OUT", VT_BUFFER | AICD_OUT },
|
||||
{ "FLOAT", VT_FLOAT },
|
||||
{ "DOUBLE", VT_DOUBLE },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
|
@ -172,7 +165,7 @@ static int _string_enum(String const * string, StringEnum * se)
|
|||
/* appinterface_new */
|
||||
static int _new_foreach(char const * key, Hash * value,
|
||||
AppInterface * appinterface);
|
||||
static int _new_append(AppInterface * ai, AppInterfaceCallType type,
|
||||
static int _new_append(AppInterface * ai, VariableType type,
|
||||
char const * function);
|
||||
static int _new_append_arg(AppInterface * ai, char const * arg);
|
||||
|
||||
|
@ -218,7 +211,7 @@ static int _new_foreach(char const * key, Hash * value,
|
|||
char const prefix[] = "call::";
|
||||
int i;
|
||||
char buf[8];
|
||||
int type = AICT_VOID;
|
||||
int type = VT_NULL;
|
||||
char const * p;
|
||||
|
||||
if(key == NULL || strncmp(prefix, key, sizeof(prefix) - 1) != 0)
|
||||
|
@ -251,7 +244,7 @@ static int _new_foreach(char const * key, Hash * value,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int _new_append(AppInterface * ai, AppInterfaceCallType type,
|
||||
static int _new_append(AppInterface * ai, VariableType type,
|
||||
char const * function)
|
||||
{
|
||||
AppInterfaceCall * p;
|
||||
|
@ -411,8 +404,9 @@ int appinterface_callv(AppInterface * appinterface, Variable ** result,
|
|||
|
||||
if((call = _appinterface_get_call(appinterface, method)) == NULL)
|
||||
return -1;
|
||||
/* FIXME implement */
|
||||
return -1;
|
||||
if(argc != call->args_cnt)
|
||||
return -1;
|
||||
return marshall_call(call->type.type, result, call->func, argc, argv);
|
||||
}
|
||||
|
||||
|
||||
|
|
83
src/marshall.c
Normal file
83
src/marshall.c
Normal file
|
@ -0,0 +1,83 @@
|
|||
/* $Id$ */
|
||||
/* Copyright (c) 2014 Pierre Pronchery <khorben@defora.org> */
|
||||
/* This file is part of DeforaOS System libApp */
|
||||
/* 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 <stddef.h>
|
||||
#include "marshall.h"
|
||||
|
||||
|
||||
/* Marshall */
|
||||
/* public */
|
||||
/* functions */
|
||||
static int _call0(VariableType type, Variable ** result, void * func);
|
||||
|
||||
int marshall_call(VariableType type, Variable ** result, void * func,
|
||||
size_t argc, Variable ** argv)
|
||||
{
|
||||
if(argc == 0)
|
||||
return _call0(type, result, func);
|
||||
/* FIXME implement */
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int _call0(VariableType type, Variable ** result, void * func)
|
||||
{
|
||||
Variable * v;
|
||||
union
|
||||
{
|
||||
void * call;
|
||||
int16_t (*call_i16)(void);
|
||||
uint16_t (*call_u16)(void);
|
||||
int32_t (*call_i32)(void);
|
||||
uint32_t (*call_u32)(void);
|
||||
} f;
|
||||
union
|
||||
{
|
||||
int16_t i16;
|
||||
uint16_t u16;
|
||||
int32_t i32;
|
||||
uint32_t u32;
|
||||
} res;
|
||||
|
||||
/* FIXME implement through the generic marshaller instead */
|
||||
f.call = func;
|
||||
if((v = variable_new(type, NULL)) == NULL)
|
||||
return -1;
|
||||
switch(type)
|
||||
{
|
||||
case VT_INT16:
|
||||
res.i16 = f.call_i16();
|
||||
variable_set_from(v, type, &res.i16);
|
||||
break;
|
||||
case VT_UINT16:
|
||||
res.u16 = f.call_u16();
|
||||
variable_set_from(v, type, &res.u16);
|
||||
break;
|
||||
case VT_INT32:
|
||||
res.i32 = f.call_i32();
|
||||
variable_set_from(v, type, &res.i32);
|
||||
break;
|
||||
case VT_UINT32:
|
||||
res.u32 = f.call_u32();
|
||||
variable_set_from(v, type, &res.u32);
|
||||
break;
|
||||
default:
|
||||
variable_delete(v);
|
||||
return -1;
|
||||
}
|
||||
*result = v;
|
||||
return 0;
|
||||
}
|
29
src/marshall.h
Normal file
29
src/marshall.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
/* $Id$ */
|
||||
/* Copyright (c) 2014 Pierre Pronchery <khorben@defora.org> */
|
||||
/* This file is part of DeforaOS System libApp */
|
||||
/* 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/>. */
|
||||
|
||||
|
||||
|
||||
#ifndef LIBAPP_MARSHALL_H
|
||||
# define LIBAPP_MARSHALL_H
|
||||
|
||||
# include <System/variable.h>
|
||||
|
||||
|
||||
/* Marshall */
|
||||
/* functions */
|
||||
int marshall_call(VariableType type, Variable ** result, void * func,
|
||||
size_t argc, Variable ** argv);
|
||||
|
||||
#endif /* !LIBAPP_MARSHALL_H */
|
|
@ -5,11 +5,11 @@ cflags_force=-W -fPIC `pkg-config --cflags libSystem`
|
|||
cflags=-Wall -g -O2 -pedantic
|
||||
ldflags_force=`pkg-config --libs libSystem`
|
||||
ldflags=
|
||||
dist=Makefile,appinterface.h,appmessage.h,apptransport.h
|
||||
dist=Makefile,appinterface.h,appmessage.h,apptransport.h,marshall.h
|
||||
|
||||
[libApp]
|
||||
type=library
|
||||
sources=appclient.c,appinterface.c,appmessage.c,appserver.c,apptransport.c
|
||||
sources=appclient.c,appinterface.c,appmessage.c,appserver.c,apptransport.c,marshall.c
|
||||
ldflags=-lsocket -lws2_32
|
||||
install=$(LIBDIR)
|
||||
|
||||
|
@ -17,7 +17,7 @@ install=$(LIBDIR)
|
|||
depends=appinterface.h,../include/App/appclient.h
|
||||
|
||||
[appinterface.c]
|
||||
depends=../include/App/appserver.h,../config.h
|
||||
depends=../include/App/appserver.h,marshall.h,../config.h
|
||||
|
||||
[appmessage.c]
|
||||
depends=../include/App/appmessage.h,appmessage.h
|
||||
|
@ -30,3 +30,6 @@ depends=appinterface.h,../include/App/appserver.h,../config.h
|
|||
|
||||
[apptransport.c]
|
||||
depends=apptransport.h,../include/App/apptransport.h,../config.h
|
||||
|
||||
[marshall.c]
|
||||
depends=marshall.h
|
||||
|
|
Loading…
Reference in New Issue
Block a user