[xiph-commits] r18695 - icecast/branches/ph3/icecast/src
ph3-der-loewe at svn.xiph.org
ph3-der-loewe at svn.xiph.org
Tue Nov 13 03:56:35 PST 2012
Author: ph3-der-loewe
Date: 2012-11-13 03:56:34 -0800 (Tue, 13 Nov 2012)
New Revision: 18695
Modified:
icecast/branches/ph3/icecast/src/icecastplugin.h
icecast/branches/ph3/icecast/src/plugins.c
Log:
improved plugin interface by exporting very basic functions
Modified: icecast/branches/ph3/icecast/src/icecastplugin.h
===================================================================
--- icecast/branches/ph3/icecast/src/icecastplugin.h 2012-11-13 11:31:50 UTC (rev 18694)
+++ icecast/branches/ph3/icecast/src/icecastplugin.h 2012-11-13 11:56:34 UTC (rev 18695)
@@ -15,11 +15,14 @@
#define ICECASTPH_CHECK_VERSIONS() ROAR_DL_PLUGIN_CHECK_VERSIONS(ICECASTPH_APPNAME, ICECASTPH_ABIVERSION)
typedef int (*icecastph_func_t)();
-typedef icecastph_func_t(*icecastph_getter_t)(const char * abiversion, const char * func);
+typedef icecastph_func_t(*icecastph_getter_t)(const char * func);
-#define __icecastph_export_func(func) (((icecastph_getter_t)para->binargv)->(ICECASTPH_ABIVERSION, #func))
-#define __icecastph_export0(prefix,func) __icecastph_export_func(prefix,func)()
-#define __icecastph_export1(prefix,func,arg) __icecastph_export_func(prefix,func)(arg)
-#define __icecastph_exportn(prefix,func,arg,...) __icecastph_export_func(prefix,func)(arg, __VA_ARGS__)
+#define __icecastph_export_func(func) (((icecastph_getter_t)para->binargv)(#func))
+#define __icecastph_export0(func) __icecastph_export_func(func)()
+#define __icecastph_export1(func,arg) __icecastph_export_func(func)(arg)
+#define __icecastph_exportn(func,arg,...) __icecastph_export_func(func)(arg, __VA_ARGS__)
+#define icecastph_exit(arg) __icecastph_export1(exit,arg)
+#define icecastph_config_queue_reload() __icecastph_export0(config_queue_reload)
+
#endif /* __ICECASTPLUGIN_H__ */
Modified: icecast/branches/ph3/icecast/src/plugins.c
===================================================================
--- icecast/branches/ph3/icecast/src/plugins.c 2012-11-13 11:31:50 UTC (rev 18694)
+++ icecast/branches/ph3/icecast/src/plugins.c 2012-11-13 11:56:34 UTC (rev 18695)
@@ -16,6 +16,8 @@
#include <config.h>
#endif
+#include <signal.h>
+
#include "thread/thread.h"
#include "roarapi.h"
#include "plugins.h"
@@ -36,6 +38,7 @@
// not protected by roarapi_*lock()
static thread_type * plugin_thread;
static void *plugin_runner(void *arg);
+static icecastph_func_t plugin_getter(const char * func);
#endif
void plugins_initialize(void)
@@ -88,7 +91,7 @@
#ifdef HAVE_ROARAUDIO
struct roar_dl_librarypara * para = NULL;
- para = roar_dl_para_new(plugin->args, NULL, ICECASTPH_APPNAME, ICECASTPH_ABIVERSION);
+ para = roar_dl_para_new(plugin->args, plugin_getter, ICECASTPH_APPNAME, ICECASTPH_ABIVERSION);
if (!para)
return;
@@ -214,4 +217,55 @@
return NULL;
}
+
+// plugin API:
+// pcall = plugin call (think of syscalls ;)
+static int __pcall_send_sig(int sig) {
+ int ret;
+
+ roar_err_clear_all();
+ ret = kill(getpid(), sig);
+ roar_err_update();
+
+ if ( ret != 0 )
+ return -1;
+ return 0;
+}
+
+static int _pcall_exit(int err) {
+ (void)err;
+ return __pcall_send_sig(SIGTERM);
+}
+
+static int _pcall_config_queue_reload(void) {
+ return __pcall_send_sig(SIGHUP);
+}
+
+static const struct {
+ const char * name;
+ icecastph_func_t func;
+} __pcalls[] = {
+ {"exit", _pcall_exit},
+ {"config_queue_reload", _pcall_config_queue_reload}
+};
+
+static icecastph_func_t plugin_getter(const char * func)
+{
+ size_t i;
+
+ if (!func)
+ {
+ roar_err_set(ROAR_ERROR_FAULT);
+ return NULL;
+ }
+
+ for (i = 0; i < (sizeof(__pcalls)/sizeof(*__pcalls)); i++)
+ {
+ if (!strcmp(func, __pcalls[i].name))
+ return __pcalls[i].func;
+ }
+
+ roar_err_set(ROAR_ERROR_NOSYS);
+ return NULL;
+}
#endif
More information about the commits
mailing list