Added a template transport

This commit is contained in:
Pierre Pronchery 2012-10-18 02:08:42 +00:00
parent 15ebf43c9e
commit 20f1156396
4 changed files with 124 additions and 3 deletions

View File

@ -53,6 +53,7 @@ dist:
$(PACKAGE)-$(VERSION)/src/common.h \
$(PACKAGE)-$(VERSION)/src/project.conf \
$(PACKAGE)-$(VERSION)/src/transport/tcp.c \
$(PACKAGE)-$(VERSION)/src/transport/template.c \
$(PACKAGE)-$(VERSION)/src/transport/udp.c \
$(PACKAGE)-$(VERSION)/src/transport/Makefile \
$(PACKAGE)-$(VERSION)/src/transport/project.conf \

View File

@ -1,4 +1,4 @@
TARGETS = tcp.so udp.so
TARGETS = tcp.so template.so udp.so
PREFIX = /usr/local
DESTDIR =
LIBDIR = $(PREFIX)/lib
@ -25,6 +25,13 @@ tcp_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
tcp.so: $(tcp_OBJS)
$(CCSHARED) -o tcp.so $(tcp_OBJS) $(tcp_LDFLAGS)
template_OBJS = template.o
template_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
template_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
template.so: $(template_OBJS)
$(CCSHARED) -o template.so $(template_OBJS) $(template_LDFLAGS)
udp_OBJS = udp.o
udp_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
udp_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
@ -35,11 +42,14 @@ udp.so: $(udp_OBJS)
tcp.o: tcp.c
$(CC) $(tcp_CFLAGS) -c tcp.c
template.o: template.c
$(CC) $(template_CFLAGS) -c template.c
udp.o: udp.c
$(CC) $(udp_CFLAGS) -c udp.c
clean:
$(RM) -- $(tcp_OBJS) $(udp_OBJS)
$(RM) -- $(tcp_OBJS) $(template_OBJS) $(udp_OBJS)
distclean: clean
$(RM) -- $(TARGETS)

View File

@ -1,4 +1,4 @@
targets=tcp,udp
targets=tcp,template,udp
cppflags_force=-I ../../include
cppflags=
cflags_force=-W -fPIC
@ -10,6 +10,10 @@ type=plugin
sources=tcp.c
install=$(LIBDIR)/App/transport
[template]
type=plugin
sources=template.c
[udp]
type=plugin
sources=udp.c

106
src/transport/template.c Normal file
View File

@ -0,0 +1,106 @@
/* $Id$ */
/* Copyright (c) 2012 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 <System.h>
#include "App/apptransport.h"
/* Template */
/* private */
/* types */
typedef struct _AppTransportPlugin Template;
struct _AppTransportPlugin
{
AppTransportPluginHelper * helper;
};
/* protected */
/* prototypes */
/* plug-in */
static Template * _template_init(AppTransportPluginHelper * helper,
AppTransportMode mode, char const * name);
static void _template_destroy(Template * template);
/* public */
/* constants */
/* plug-in */
AppTransportPluginDefinition transport =
{
"Template",
NULL,
_template_init,
_template_destroy,
NULL
};
/* protected */
/* functions */
/* plug-in */
/* template_init */
static int _init_client(Template * template, char const * name);
static int _init_server(Template * template, char const * name);
static Template * _template_init(AppTransportPluginHelper * helper,
AppTransportMode mode, char const * name)
{
Template * template;
int res = -1;
if((template = object_new(sizeof(*template))) == NULL)
return NULL;
template->helper = helper;
switch(mode)
{
case ATM_CLIENT:
res = _init_client(template, name);
break;
case ATM_SERVER:
res = _init_server(template, name);
break;
}
/* check for errors */
if(res != 0)
{
_template_destroy(template);
return NULL;
}
return template;
}
static int _init_client(Template * template, char const * name)
{
/* FIXME really implement */
return -1;
}
static int _init_server(Template * template, char const * name)
{
/* FIXME really implement */
return -1;
}
/* template_destroy */
static void _template_destroy(Template * template)
{
/* FIXME really implement */
object_delete(template);
}