Added Plugin helpers
This commit is contained in:
parent
16fb99162f
commit
2560d7179f
2
Makefile
2
Makefile
|
@ -32,6 +32,7 @@ dist:
|
|||
$(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 \
|
||||
|
@ -50,6 +51,7 @@ dist:
|
|||
$(PACKAGE)-$(VERSION)/include/System/hash.h \
|
||||
$(PACKAGE)-$(VERSION)/include/System/object.h \
|
||||
$(PACKAGE)-$(VERSION)/include/System/parser.h \
|
||||
$(PACKAGE)-$(VERSION)/include/System/plugin.h \
|
||||
$(PACKAGE)-$(VERSION)/include/System/string.h \
|
||||
$(PACKAGE)-$(VERSION)/include/System/token.h \
|
||||
$(PACKAGE)-$(VERSION)/include/Makefile \
|
||||
|
|
|
@ -33,6 +33,7 @@ install: all
|
|||
$(INSTALL) -m 0644 System/hash.h $(DESTDIR)$(INCLUDEDIR)/System/hash.h
|
||||
$(INSTALL) -m 0644 System/object.h $(DESTDIR)$(INCLUDEDIR)/System/object.h
|
||||
$(INSTALL) -m 0644 System/parser.h $(DESTDIR)$(INCLUDEDIR)/System/parser.h
|
||||
$(INSTALL) -m 0644 System/plugin.h $(DESTDIR)$(INCLUDEDIR)/System/plugin.h
|
||||
$(INSTALL) -m 0644 System/string.h $(DESTDIR)$(INCLUDEDIR)/System/string.h
|
||||
$(INSTALL) -m 0644 System/token.h $(DESTDIR)$(INCLUDEDIR)/System/token.h
|
||||
|
||||
|
@ -50,6 +51,7 @@ uninstall:
|
|||
$(RM) $(DESTDIR)$(INCLUDEDIR)/System/hash.h
|
||||
$(RM) $(DESTDIR)$(INCLUDEDIR)/System/object.h
|
||||
$(RM) $(DESTDIR)$(INCLUDEDIR)/System/parser.h
|
||||
$(RM) $(DESTDIR)$(INCLUDEDIR)/System/plugin.h
|
||||
$(RM) $(DESTDIR)$(INCLUDEDIR)/System/string.h
|
||||
$(RM) $(DESTDIR)$(INCLUDEDIR)/System/token.h
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
# include "System/file.h"
|
||||
# include "System/object.h"
|
||||
# include "System/parser.h"
|
||||
# include "System/plugin.h"
|
||||
# include "System/string.h"
|
||||
|
||||
#endif /* !LIBSYSTEM_SYSTEM_H */
|
||||
|
|
32
include/System/plugin.h
Normal file
32
include/System/plugin.h
Normal file
|
@ -0,0 +1,32 @@
|
|||
/* $Id$ */
|
||||
/* Copyright (c) 2008 Pierre Pronchery <khorben@defora.org> */
|
||||
/* This file is part of DeforaOS System libSystem */
|
||||
/* libSystem is not free software; you can redistribute it and/or modify it
|
||||
* under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike
|
||||
* 3.0 Unported as published by the Creative Commons organization.
|
||||
*
|
||||
* libSystem 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 Creative Commons Attribution-NonCommercial-
|
||||
* ShareAlike 3.0 Unported license for more details.
|
||||
*
|
||||
* You should have received a copy of the Creative Commons Attribution-
|
||||
* NonCommercial-ShareAlike 3.0 along with libSystem; if not, browse to
|
||||
* http://creativecommons.org/licenses/by-nc-sa/3.0/ */
|
||||
|
||||
|
||||
|
||||
#ifndef LIBSYSTEM_PLUGIN_H
|
||||
# define LIBSYSTEM_PLUGIN_H
|
||||
|
||||
|
||||
/* Object */
|
||||
typedef void Plugin;
|
||||
|
||||
|
||||
/* functions */
|
||||
Plugin * plugin_new(char const * libdir, char const * package,
|
||||
char const * type, char const * name);
|
||||
void plugin_delete(Plugin * plugin);
|
||||
|
||||
#endif /* !LIBSYSTEM_PLUGIN_H */
|
|
@ -1,3 +1,3 @@
|
|||
subdirs=System
|
||||
includes=System.h,System/appclient.h,System/appserver.h,System/array.h,System/buffer.h,System/config.h,System/error.h,System/event.h,System/file.h,System/hash.h,System/object.h,System/parser.h,System/string.h,System/token.h
|
||||
includes=System.h,System/appclient.h,System/appserver.h,System/array.h,System/buffer.h,System/config.h,System/error.h,System/event.h,System/file.h,System/hash.h,System/object.h,System/parser.h,System/plugin.h,System/string.h,System/token.h
|
||||
dist=Makefile
|
||||
|
|
|
@ -16,7 +16,7 @@ INSTALL = install
|
|||
|
||||
all: $(TARGETS)
|
||||
|
||||
libSystem_OBJS = appclient.o appinterface.o appserver.o array.o buffer.o config.o error.o event.o hash.o object.o parser.o string.o token.o
|
||||
libSystem_OBJS = appclient.o appinterface.o appserver.o array.o buffer.o config.o error.o event.o hash.o object.o parser.o plugin.o string.o token.o
|
||||
libSystem_CFLAGS = $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
|
||||
|
||||
libSystem.a: $(libSystem_OBJS)
|
||||
|
@ -59,6 +59,9 @@ object.o: object.c
|
|||
parser.o: parser.c token.h
|
||||
$(CC) $(libSystem_CFLAGS) -c parser.c
|
||||
|
||||
plugin.o: plugin.c
|
||||
$(CC) $(libSystem_CFLAGS) -c plugin.c
|
||||
|
||||
string.o: string.c
|
||||
$(CC) $(libSystem_CFLAGS) -c string.c
|
||||
|
||||
|
|
63
src/plugin.c
Normal file
63
src/plugin.c
Normal file
|
@ -0,0 +1,63 @@
|
|||
/* $Id$ */
|
||||
/* Copyright (c) 2008 Pierre Pronchery <khorben@defora.org> */
|
||||
/* This file is part of DeforaOS System libSystem */
|
||||
/* libSystem is not free software; you can redistribute it and/or modify it
|
||||
* under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike
|
||||
* 3.0 Unported as published by the Creative Commons organization.
|
||||
*
|
||||
* libSystem 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 Creative Commons Attribution-NonCommercial-
|
||||
* ShareAlike 3.0 Unported license for more details.
|
||||
*
|
||||
* You should have received a copy of the Creative Commons Attribution-
|
||||
* NonCommercial-ShareAlike 3.0 along with libSystem; if not, browse to
|
||||
* http://creativecommons.org/licenses/by-nc-sa/3.0/ */
|
||||
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <dlfcn.h>
|
||||
#include "System.h"
|
||||
|
||||
|
||||
/* Plugin */
|
||||
/* private */
|
||||
/* constants */
|
||||
#define PLUGIN_EXTENSION ".so"
|
||||
|
||||
|
||||
/* public */
|
||||
/* functions */
|
||||
/* plugin_new */
|
||||
Plugin * plugin_new(char const * libdir, char const * package,
|
||||
char const * type, char const * name)
|
||||
{
|
||||
Plugin * plugin;
|
||||
size_t len;
|
||||
char * filename;
|
||||
|
||||
len = strlen(libdir) + 1 + strlen(package) + 1 + strlen(type) + 1
|
||||
+ strlen(name) + strlen(PLUGIN_EXTENSION) + 1;
|
||||
if((filename = malloc(len)) == NULL)
|
||||
{
|
||||
error_set_code(1, "%s", strerror(errno));
|
||||
return NULL;
|
||||
}
|
||||
snprintf(filename, len, "%s/%s/%s/%s%s", libdir, package, type, name,
|
||||
PLUGIN_EXTENSION);
|
||||
if((plugin = dlopen(filename, RTLD_LAZY)) == NULL)
|
||||
error_set_code(1, "%s: %s", filename, dlerror());
|
||||
free(filename);
|
||||
return plugin;
|
||||
}
|
||||
|
||||
|
||||
/* plugin_delete */
|
||||
void plugin_delete(Plugin * plugin)
|
||||
{
|
||||
dlclose(plugin);
|
||||
}
|
|
@ -7,7 +7,7 @@ dist=Makefile,appinterface.h,token.h
|
|||
|
||||
[libSystem]
|
||||
type=library
|
||||
sources=appclient.c,appinterface.c,appserver.c,array.c,buffer.c,config.c,error.c,event.c,hash.c,object.c,parser.c,string.c,token.c
|
||||
sources=appclient.c,appinterface.c,appserver.c,array.c,buffer.c,config.c,error.c,event.c,hash.c,object.c,parser.c,plugin.c,string.c,token.c
|
||||
ldflags=-l ssl
|
||||
|
||||
[appclient.c]
|
||||
|
|
Loading…
Reference in New Issue
Block a user