Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 142943 Details for
Bug 225082
[tcf][releng] Improve TCF Agent build directory structure
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposal patch for TCF plugins system.
tcf_plugins.patch (text/plain), 7.34 KB, created by
Philippe Proulx
on 2009-07-29 16:14:07 EDT
(
hide
)
Description:
Proposal patch for TCF plugins system.
Filename:
MIME Type:
Creator:
Philippe Proulx
Created:
2009-07-29 16:14:07 EDT
Size:
7.34 KB
patch
obsolete
>diff --git a/Makefile b/Makefile >index 6c7ffa4..8195a11 100644 >--- a/Makefile >+++ b/Makefile >@@ -25,6 +25,12 @@ LIBS=-lpthread > RANLIB=ranlib $@ > else > LIBS=-lpthread -lssl -lrt >+ >+ifdef PATH_Plugins >+CFLAGS += -rdynamic -DPATH_Plugins="$(PATH_Plugins)" >+LIBS += -ldl >+endif >+ > endif > endif > endif >diff --git a/config.h b/config.h >index 0d8728e..3f2188c 100644 >--- a/config.h >+++ b/config.h >@@ -79,6 +79,13 @@ > #define SERVICE_Streams (TARGET_UNIX || TARGET_VXWORKS || TARGET_WINDOWS) > #endif > >+/* >+ * If a plugins' path is defined, then enable plugins for UNIX/Linux. >+ */ >+#ifdef PATH_Plugins >+#define EN_Plugins (TARGET_UNIX) >+#endif >+ > #if !defined(ENABLE_ZeroCopy) > #define ENABLE_ZeroCopy 1 > #endif >@@ -128,6 +135,8 @@ > #include "proxy.h" > #include "tcf_elf.h" > >+#include "plugins.h" >+ > static void ini_services(Protocol * proto, TCFBroadcastGroup * bcg, TCFSuspendGroup * spg) { > #if SERVICE_Locator > ini_locator_service(proto, bcg); >@@ -177,9 +186,15 @@ static void ini_services(Protocol * proto, TCFBroadcastGroup * bcg, TCFSuspendGr > #if ENABLE_ELF > ini_elf(); > #endif >+ >+#if EN_Plugins >+ plugins_load(proto, bcg, spg); >+#endif >+ > ini_diagnostics_service(proto); > } > > #endif /* CONFIG_MAIN */ > > #endif /* D_config */ >+ >diff --git a/main.c b/main.c >index 45e6d0c..9c9a7bc 100644 >--- a/main.c >+++ b/main.c >@@ -30,6 +30,7 @@ > #include "myalloc.h" > #include "test.h" > #include "cmdline.h" >+#include "plugins.h" > #include "channel_tcp.h" > > static char * progname; >@@ -206,5 +207,10 @@ int main(int argc, char ** argv) { > /* Process events - must run on the initial thread since ptrace() > * returns ECHILD otherwise, thinking we are not the owner. */ > run_event_loop(); >+ >+#ifdef EN_Plugins >+ plugins_destroy(); >+#endif // EN_Plugins >+ > return 0; > } >diff --git a/plugins.c b/plugins.c >new file mode 100644 >index 0000000..378df73 >--- /dev/null >+++ b/plugins.c >@@ -0,0 +1,133 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 Philippe Proulx, Ãcole Polytechnique de Montréal >+ * Michael Sills-Lavoie, Ãcole Polytechnique de Montréal >+ * and others. All rights reserved. >+ * This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * and Eclipse Distribution License v1.0 which accompany this distribution. >+ * The Eclipse Public License is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * and the Eclipse Distribution License is available at >+ * http://www.eclipse.org/org/documents/edl-v10.php. >+ * >+ * Contributors: >+ * Philippe Proulx - initial plugins system >+ *******************************************************************************/ >+ >+/* >+ * Expression evaluation service. >+ */ >+ >+#include "config.h" >+ >+#if EN_Plugins >+ >+#ifndef _GNU_SOURCE >+#define _GNU_SOURCE >+#endif /* _GNU_SOURCE */ >+ >+#include <stdio.h> >+#include <stdlib.h> >+#include <string.h> >+#include <sys/types.h> >+#include <dirent.h> >+#include <dlfcn.h> >+ >+#include "trace.h" >+#include "plugins.h" >+ >+static void ** plugins_handles = NULL; >+static size_t plugins_count = 0; >+ >+static inline int plugins_ext_is(const char * ext, const char * filename) { >+ int ret = 0; >+ const char* real_ext = strrchr(filename, '.'); >+ >+ if (real_ext != NULL) { >+ ret = !strcmp(real_ext + 1, ext); >+ } >+ >+ return ret; >+} >+ >+int plugins_load(Protocol * proto, TCFBroadcastGroup * bcg, TCFSuspendGroup * spg) { >+ int ret = 0; >+ char* cur_plugin_path; >+ struct dirent* dirent; >+ DIR* dir; >+ >+ dir = opendir(QUOTE(PATH_Plugins)); >+ if (!dir) { >+ trace(LOG_ALWAYS, "plugins error: failed opening plugins directory \"" QUOTE(PATH_Plugins) "\""); >+ return -1; >+ } >+ while (dirent = readdir(dir)) { >+ if (!strcmp(dirent->d_name, ".") || !strcmp(dirent->d_name, "..")) { >+ continue; >+ } >+ if (!plugins_ext_is(PLUGINS_DEF_EXT, dirent->d_name) || dirent->d_type == DT_DIR) { >+ continue; >+ } >+ if (asprintf(&cur_plugin_path, QUOTE(PATH_Plugins) "/%s", dirent->d_name) == -1) { >+ trace(LOG_ALWAYS, "plugins error: `asprintf' failed for plugin \"%s\"", dirent->d_name); >+ return -1; >+ } >+ if (plugin_init(cur_plugin_path, proto, bcg, spg)) { >+ trace(LOG_ALWAYS, "plugins error: unable to start plugin \"%s\"", cur_plugin_path); >+ ret = -1; >+ goto error_free; >+ } >+ } >+ error_free: >+ free(cur_plugin_path); >+ >+ return ret; >+} >+ >+int plugin_init(const char * name, Protocol * proto, TCFBroadcastGroup * bcg, TCFSuspendGroup * spg) { >+ void* handle; >+ void (* init)(Protocol *, TCFBroadcastGroup *, TCFSuspendGroup *); >+ char* error; >+ >+ /* Plugin loading: */ >+ trace(LOG_ALWAYS, "loading plugin \"%s\"", name); >+ handle = dlopen(name, RTLD_LAZY); >+ if (!handle) { >+ trace(LOG_ALWAYS, "plugins error: \"%s\"", dlerror()); >+ return -1; >+ } >+ >+ /* Plugin initialization: */ >+ init = dlsym(handle, "tcf_init_plugin"); >+ if ((error = dlerror()) != NULL) { >+ trace(LOG_ALWAYS, "plugins error: \"%s\"", error); >+ return -1; >+ } >+ trace(LOG_ALWAYS, "initializing plugin \"%s\"", name); >+ init(proto, bcg, spg); >+ >+ /* Handles table update: */ >+ plugins_handles = (void **) realloc(plugins_handles, ++plugins_count * sizeof(void *)); >+ plugins_handles[plugins_count - 1] = handle; >+ >+ return 0; >+} >+ >+int plugins_destroy(void) { >+ if (plugins_handles == NULL) { >+ return 0; >+ } >+ size_t i; >+ >+ for (i = 0; i < plugins_count; ++i) { >+ if (dlclose(plugins_handles[i])) { >+ trace(LOG_ALWAYS, "plugins error: \"%s\"", dlerror()); >+ } >+ } >+ free(plugins_handles); >+ >+ return 0; >+} >+ >+#endif /* if EN_Plugins */ >+ >diff --git a/plugins.h b/plugins.h >new file mode 100644 >index 0000000..54394e9 >--- /dev/null >+++ b/plugins.h >@@ -0,0 +1,47 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 Philippe Proulx, Ãcole Polytechnique de Montréal >+ * Michael Sills-Lavoie, Ãcole Polytechnique de Montréal >+ * and others. All rights reserved. >+ * This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * and Eclipse Distribution License v1.0 which accompany this distribution. >+ * The Eclipse Public License is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * and the Eclipse Distribution License is available at >+ * http://www.eclipse.org/org/documents/edl-v10.php. >+ * >+ * Contributors: >+ * Philippe Proulx - initial plugins system >+ *******************************************************************************/ >+ >+/* >+ * Plugins system. >+ */ >+ >+#ifndef D_plugins >+#define D_plugins >+ >+#include "protocol.h" >+ >+#define _QUOTEME(x) #x >+#define QUOTE(x) _QUOTEME(x) >+ >+#define PLUGINS_DEF_EXT "so" /* Default plugins' extension */ >+ >+/* >+ * Loads ALL plugins from the directory PATH_Plugins (from `config.h'). >+ */ >+int plugins_load(Protocol *, TCFBroadcastGroup *, TCFSuspendGroup *); >+ >+/* >+ * Initializes a particular plugin according to its path. >+ */ >+int plugin_init(const char *, Protocol *, TCFBroadcastGroup *, TCFSuspendGroup *); >+ >+/* >+ * Destroys loaded plugins. >+ */ >+int plugins_destroy(void); >+ >+#endif /* D_plugins */ >+
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 225082
:
142943