]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
initial checkin of switch_dso.
authorMichael Jerris <mike@jerris.com>
Fri, 31 Oct 2008 21:53:07 +0000 (21:53 +0000)
committerMichael Jerris <mike@jerris.com>
Fri, 31 Oct 2008 21:53:07 +0000 (21:53 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@10215 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_dso.h [new file with mode: 0644]
src/switch_dso.c [new file with mode: 0644]
w32/Library/FreeSwitchCore.2008.vcproj

diff --git a/src/include/switch_dso.h b/src/include/switch_dso.h
new file mode 100644 (file)
index 0000000..12e3a22
--- /dev/null
@@ -0,0 +1,53 @@
+/* 
+ * Cross Platform dso/dll load abstraction
+ * Copyright(C) 2008 Michael Jerris
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so.
+ *
+ * This work is provided under this license on an "as is" basis, without warranty of any kind,
+ * either expressed or implied, including, without limitation, warranties that the covered code
+ * is free of defects, merchantable, fit for a particular purpose or non-infringing. The entire
+ * risk as to the quality and performance of the covered code is with you. Should any covered
+ * code prove defective in any respect, you (not the initial developer or any other contributor)
+ * assume the cost of any necessary servicing, repair or correction. This disclaimer of warranty
+ * constitutes an essential part of this license. No use of any covered code is authorized hereunder
+ * except under this disclaimer. 
+ *
+ */
+
+
+#ifndef _SWITCH_DSO_H
+#define _SWITCH_DSO_H
+
+typedef void (*switch_func_ptr_t) (void);
+#ifdef WIN32
+typedef HINSTANCE switch_dso_lib_t;
+#else
+typedef void * switch_dso_lib_t;
+#endif
+#ifdef WIN32
+typedef FARPROC switch_dso_func_t;
+#else
+typedef void * switch_dso_func_t;
+#endif
+
+void switch_dso_destroy(switch_dso_lib_t *lib);
+switch_dso_lib_t switch_dso_open(const char *path, int global, char **err);
+switch_dso_func_t switch_dso_func_sym(switch_dso_lib_t lib, const char *sym, char **err);
+
+
+#endif
+
+/* For Emacs:
+ * Local Variables:
+ * mode:c
+ * indent-tabs-mode:t
+ * tab-width:4
+ * c-basic-offset:4
+ * End:
+ * For VIM:
+ * vim:set softtabstop=4 shiftwidth=4 tabstop=4
+ */
+
diff --git a/src/switch_dso.c b/src/switch_dso.c
new file mode 100644 (file)
index 0000000..2b569d7
--- /dev/null
@@ -0,0 +1,114 @@
+/* 
+ * Cross Platform dso/dll load abstraction
+ * Copyright(C) 2008 Michael Jerris
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so.
+ *
+ * This work is provided under this license on an "as is" basis, without warranty of any kind,
+ * either expressed or implied, including, without limitation, warranties that the covered code
+ * is free of defects, merchantable, fit for a particular purpose or non-infringing. The entire
+ * risk as to the quality and performance of the covered code is with you. Should any covered
+ * code prove defective in any respect, you (not the initial developer or any other contributor)
+ * assume the cost of any necessary servicing, repair or correction. This disclaimer of warranty
+ * constitutes an essential part of this license. No use of any covered code is authorized hereunder
+ * except under this disclaimer. 
+ *
+ */
+
+#include <switch.h>
+#include "switch_dso.h"
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef WIN32
+
+void switch_dso_destroy(switch_dso_lib_t *lib) {
+       if (lib && *lib) {
+               FreeLibrary(*lib);
+               *lib = NULL;
+       }
+}
+
+switch_dso_lib_t switch_dso_open(const char *path, int global, char **err) {
+    HINSTANCE lib;\r
+       
+       lib = LoadLibraryEx(path, NULL, 0);
+
+       if (!lib) {
+               LoadLibraryEx(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
+       }
+
+       if (!lib) {
+               DWORD error = GetLastError();
+               *err = switch_mprintf("dll open error [%ul]\n", error);
+       }
+
+       return lib;
+}
+
+switch_dso_func_t switch_dso_func_sym(switch_dso_lib_t lib, const char *sym, char **err) {
+       FARPROC func = GetProcAddress(lib, sym);
+       if (!func) {
+               DWORD error = GetLastError();
+               *err = switch_mprintf("dll sym error [%ul]\n", error);
+       }
+       return func;
+}
+
+#else
+/*
+** {========================================================================
+** This is an implementation of loadlib based on the dlfcn interface.
+** The dlfcn interface is available in Linux, SunOS, Solaris, IRIX, FreeBSD,
+** NetBSD, AIX 4.2, HPUX 11, and  probably most other Unix flavors, at least
+** as an emulation layer on top of native functions.
+** =========================================================================
+*/
+
+
+#include <dlfcn.h>
+
+void switch_dso_destroy(switch_dso_lib_t *lib) {
+       if (lib && *lib) {
+               dlclose(*lib);
+               *lib = NULL;
+       }
+}
+
+switch_dso_lib_t switch_dso_open(const char *path, int global, char **err) {
+       void *lib;
+       
+       if (global) {
+               lib = dlopen(path, RTLD_NOW | RTLD_GLOBAL);
+       } else {
+               lib = dlopen(path, RTLD_NOW | RTLD_LOCAL);
+       }
+
+       if (lib == NULL) {
+               *err = strdup(dlerror());
+       }
+       return lib;
+}
+
+void *switch_dso_func_sym(switch_dso_lib_t lib, const char *sym, char **err) {
+       void *func = dlsym(lib, sym);
+       if (!func) {
+               *err = strdup(dlerror());
+       }
+       return func;
+}
+#endif
+/* }====================================================== */
+
+/* For Emacs:
+ * Local Variables:
+ * mode:c
+ * indent-tabs-mode:t
+ * tab-width:4
+ * c-basic-offset:4
+ * End:
+ * For VIM:
+ * vim:set softtabstop=4 shiftwidth=4 tabstop=4
+ */
index 8f16ad0ed1f91001a6b563052677179cebae140d..744760e97d6228ff731ffdc9fc85e7291e8e4f95 100644 (file)
                                        />\r
                                </FileConfiguration>\r
                        </File>\r
+                       <File\r
+                               RelativePath="..\..\src\switch_dso.c"\r
+                               >\r
+                       </File>\r
                        <File\r
                                RelativePath="..\..\src\switch_event.c"\r
                                >\r
                                RelativePath="..\..\src\include\switch_cpp.h"\r
                                >\r
                        </File>\r
+                       <File\r
+                               RelativePath="..\..\src\include\switch_dso.h"\r
+                               >\r
+                       </File>\r
                        <File\r
                                RelativePath="..\..\src\include\switch_event.h"\r
                                >\r