From 20f11563961232da51a30794e0b3bc166ec21d70 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Thu, 18 Oct 2012 02:08:42 +0000 Subject: [PATCH] Added a template transport --- Makefile | 1 + src/transport/Makefile | 14 ++++- src/transport/project.conf | 6 ++- src/transport/template.c | 106 +++++++++++++++++++++++++++++++++++++ 4 files changed, 124 insertions(+), 3 deletions(-) create mode 100644 src/transport/template.c diff --git a/Makefile b/Makefile index de0e4f8..6f9fa7c 100644 --- a/Makefile +++ b/Makefile @@ -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 \ diff --git a/src/transport/Makefile b/src/transport/Makefile index 4ac8774..7859783 100644 --- a/src/transport/Makefile +++ b/src/transport/Makefile @@ -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) diff --git a/src/transport/project.conf b/src/transport/project.conf index d5d4f7f..bf43f5f 100644 --- a/src/transport/project.conf +++ b/src/transport/project.conf @@ -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 diff --git a/src/transport/template.c b/src/transport/template.c new file mode 100644 index 0000000..ff26a5e --- /dev/null +++ b/src/transport/template.c @@ -0,0 +1,106 @@ +/* $Id$ */ +/* Copyright (c) 2012 Pierre Pronchery */ +/* 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 . */ + + + +#include +#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); +}