Revision
17533
Author
moy
Date
2010-05-12 10:54:50 -0500 (Wed, 12 May 2010)

Log Message

freetdm: added dso sample app

Modified Paths

Added Paths

Removed Paths

Diff

Modified: freeswitch/trunk/libs/freetdm/Makefile.am (17532 => 17533)


--- freeswitch/trunk/libs/freetdm/Makefile.am	2010-05-12 15:49:16 UTC (rev 17532)
+++ freeswitch/trunk/libs/freetdm/Makefile.am	2010-05-12 15:54:50 UTC (rev 17533)
@@ -77,7 +77,8 @@
 $(SRC)/include/freetdm.h \
 $(SRC)/include/ftdm_declare.h \
 $(SRC)/include/ftdm_threadmutex.h \
-$(SRC)/include/ftdm_os.h 
+$(SRC)/include/ftdm_os.h \
+$(SRC)/include/ftdm_dso.h 
 
 lib_LTLIBRARIES	       = libfreetdm.la
 libfreetdm_la_CFLAGS   = $(AM_CFLAGS) $(MY_CFLAGS)

Added: freeswitch/trunk/libs/freetdm/sample/dso/Makefile (0 => 17533)


--- freeswitch/trunk/libs/freetdm/sample/dso/Makefile	                        (rev 0)
+++ freeswitch/trunk/libs/freetdm/sample/dso/Makefile	2010-05-12 15:54:50 UTC (rev 17533)
@@ -0,0 +1,13 @@
+CC=gcc
+CFLAGS=-Wall -I/usr/local/freeswitch/include 
+LDFLAGS=-L/usr/local/freeswitch/lib -lfreetdm
+
+ftdmload: ftdmload.o
+
+clean:
+	rm -rf ftdmload.o
+
+export:
+	export LD_LIBRARY_PATH=/usr/local/freeswitch/lib
+	
+

Added: freeswitch/trunk/libs/freetdm/sample/dso/ftdmload.c (0 => 17533)


--- freeswitch/trunk/libs/freetdm/sample/dso/ftdmload.c	                        (rev 0)
+++ freeswitch/trunk/libs/freetdm/sample/dso/ftdmload.c	2010-05-12 15:54:50 UTC (rev 17533)
@@ -0,0 +1,108 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <freetdm.h>
+#include <ftdm_dso.h>
+
+#define ARRLEN(obj) (sizeof(obj)/sizeof(obj[0]))
+
+struct dso_entry {
+	char name[25];
+	ftdm_dso_lib_t lib;
+};
+
+struct dso_entry loaded[10];
+
+int load(char *name)
+{
+	char path[255];
+	char *err;
+	struct dso_entry *entry = NULL;
+	int i;
+	
+	for (i = 0; i < ARRLEN(loaded); i++) {
+		if (!loaded[i].lib) {
+			entry = &loaded[i];
+			break;
+		}
+	}
+
+	if (!entry) {
+		ftdm_log(FTDM_LOG_CRIT, "Cannot load more libraries\n");
+		return -1;
+	}
+
+	ftdm_build_dso_path(name, path, sizeof(path));
+	ftdm_log(FTDM_LOG_DEBUG, "Loading %s!\n", path);
+	entry->lib = ftdm_dso_open(path, &err);
+	if (!entry->lib) {
+		ftdm_log(FTDM_LOG_CRIT, "Cannot load library '%s': %s\n", path, err);
+		return -1;
+	}
+	strncpy(entry->name, name, sizeof(entry->name)-1);
+	entry->name[sizeof(entry->name)-1] = 0;
+	return 0;
+}
+
+int unload(char *name)
+{
+	int i;
+	struct dso_entry *entry = NULL;
+	ftdm_log(FTDM_LOG_DEBUG, "Unloading %s!\n", name);
+	for (i = 0; i < ARRLEN(loaded); i++) {
+		if (loaded[i].lib && !strcasecmp(loaded[i].name, name)) {
+			entry = &loaded[i];
+			break;
+		}
+	}
+
+	if (!entry) {
+		ftdm_log(FTDM_LOG_CRIT, "Library %s not found\n", name);
+		return -1;
+	}
+
+	ftdm_dso_destroy(&entry->lib);
+	entry->lib = NULL;
+	return 0;
+}
+
+int main(int argc, char *argv[])
+{
+	char cmdline[255];
+	char name[255];
+	
+	ftdm_global_set_default_logger(FTDM_LOG_LEVEL_DEBUG);
+
+	ftdm_cpu_monitor_disable();
+
+	if (ftdm_global_init() != FTDM_SUCCESS) {
+		fprintf(stderr, "Error loading FreeTDM\n");
+		exit(-1);
+	}
+
+	memset(loaded, 0, sizeof(loaded));
+
+	printf("CLI> ");
+	while (fgets(cmdline, sizeof(cmdline), stdin)) {
+		if (sscanf(cmdline, "load=%s\n", name) == 1) {
+			load(name);
+		} else if (sscanf(cmdline, "unload=%s\n", name) == 1) {
+			unload(name);
+		} else if (!strncasecmp(cmdline, "exit", sizeof("exit")-1)) {
+			printf("Quitting ...\n");
+			sleep(1);
+			break;
+		} else {
+			fprintf(stderr, "load=<name> | unload=<name> | exit\n");
+		}
+		printf("\nCLI> ");
+	}
+
+
+	ftdm_global_destroy();
+
+	printf("Done, press any key to die!\n");
+
+	getchar();
+	return 0;
+}
+

Modified: freeswitch/trunk/libs/freetdm/src/include/ftdm_dso.h (17532 => 17533)


--- freeswitch/trunk/libs/freetdm/src/include/ftdm_dso.h	2010-05-12 15:49:16 UTC (rev 17532)
+++ freeswitch/trunk/libs/freetdm/src/include/ftdm_dso.h	2010-05-12 15:54:50 UTC (rev 17533)
@@ -17,6 +17,7 @@
  *
  */
 
+#include "freetdm.h"
 
 #ifndef _FTDM_DSO_H
 #define _FTDM_DSO_H
@@ -28,10 +29,12 @@
 typedef void (*ftdm_func_ptr_t) (void);
 typedef void * ftdm_dso_lib_t;
 
-FT_DECLARE(void) ftdm_dso_destroy(ftdm_dso_lib_t *lib);
+FT_DECLARE(ftdm_status_t) ftdm_dso_destroy(ftdm_dso_lib_t *lib);
 FT_DECLARE(ftdm_dso_lib_t) ftdm_dso_open(const char *path, char **err);
 FT_DECLARE(void *) ftdm_dso_func_sym(ftdm_dso_lib_t lib, const char *sym, char **err);
+FT_DECLARE(char *) ftdm_build_dso_path(const char *name, char *path, ftdm_size_t len);
 
+
 #ifdef __cplusplus
 }
 #endif

Deleted: freeswitch/trunk/libs/freetdm/src/include/private/ftdm_dso.h