mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-02-12 21:24:14 +00:00
(MODLANG-83) mod_mono Linux build & embedding
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@9576 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
260ebb8338
commit
19811e4f08
16
src/mod/languages/mod_mono/Makefile
Normal file
16
src/mod/languages/mod_mono/Makefile
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#MOD_CFLAGS=`pkg-config --cflags --libs mono`
|
||||||
|
MOD_CFLAGS=-D_REENTRANT -pthread -I/opt/mono-1.9/lib/pkgconfig/../../include/mono-1.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -lmono
|
||||||
|
#LDFLAGS=`pkg-config --libs mono`
|
||||||
|
BASE=../../../..
|
||||||
|
VERBOSE=1
|
||||||
|
include $(BASE)/build/modmake.rules
|
||||||
|
LOCAL_OBJS=freeswitch_mono.o freeswitch_wrap.o
|
||||||
|
local_depend: $(LOCAL_OBJS)
|
||||||
|
|
||||||
|
freeswitch_mono.o: freeswitch_mono.h freeswitch_mono.cpp
|
||||||
|
|
||||||
|
freeswitch_wrap.o: freeswitch_wrap.cpp
|
||||||
|
|
||||||
|
freeswitch_wrap.cpp: freeswitch_wrap.cxx
|
||||||
|
cp freeswitch_wrap.cxx freeswitch_wrap.cpp
|
||||||
|
|
@ -107,6 +107,7 @@
|
|||||||
%ignore switch_core_session_get_event_hooks;
|
%ignore switch_core_session_get_event_hooks;
|
||||||
%ignore switch_inet_pton;
|
%ignore switch_inet_pton;
|
||||||
%ignore switch_xml_idx;
|
%ignore switch_xml_idx;
|
||||||
|
%ignore switch_xml_pi;
|
||||||
|
|
||||||
// Real header includes now
|
// Real header includes now
|
||||||
%import switch_platform.i // This will give us all the macros we need to compile the other stuff
|
%import switch_platform.i // This will give us all the macros we need to compile the other stuff
|
||||||
|
@ -44,6 +44,7 @@ struct mod_mono_globals {
|
|||||||
MonoDomain *domain;
|
MonoDomain *domain;
|
||||||
MonoAssembly *mod_mono_asm;
|
MonoAssembly *mod_mono_asm;
|
||||||
switch_memory_pool_t *pool;
|
switch_memory_pool_t *pool;
|
||||||
|
switch_bool_t embedded;
|
||||||
|
|
||||||
MonoMethod *loadMethod;
|
MonoMethod *loadMethod;
|
||||||
MonoMethod *unloadMethod;
|
MonoMethod *unloadMethod;
|
||||||
|
@ -47,12 +47,18 @@ SWITCH_BEGIN_EXTERN_C
|
|||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#include <shlobj.h>
|
#include <shlobj.h>
|
||||||
#define EXPORT __declspec(dllexport)
|
#define EXPORT __declspec(dllexport)
|
||||||
#elif
|
#else
|
||||||
#define EXPORT
|
#define EXPORT
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define MOD_MONO_MANAGED_DLL "mod_mono_managed.dll"
|
#define MOD_MONO_MANAGED_DLL "mod_mono_managed.dll"
|
||||||
|
|
||||||
|
#define MOD_MONO_MANAGED_ASM_NAME "mod_mono_managed"
|
||||||
|
#define MOD_MONO_MANAGED_ASM_V1 1
|
||||||
|
#define MOD_MONO_MANAGED_ASM_V2 0
|
||||||
|
#define MOD_MONO_MANAGED_ASM_V3 0
|
||||||
|
#define MOD_MONO_MANAGED_ASM_V4 0
|
||||||
|
|
||||||
mod_mono_globals globals =
|
mod_mono_globals globals =
|
||||||
{ 0 };
|
{ 0 };
|
||||||
|
|
||||||
@ -120,7 +126,7 @@ switch_status_t setMonoDirs()
|
|||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif
|
#else
|
||||||
// On other platforms, it should just work if it hasn't been relocated
|
// On other platforms, it should just work if it hasn't been relocated
|
||||||
mono_set_dirs(NULL, NULL);
|
mono_set_dirs(NULL, NULL);
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
@ -137,20 +143,41 @@ switch_status_t loadModMonoManaged()
|
|||||||
switch_snprintf(filename, 256, "%s%s%s", SWITCH_GLOBAL_dirs.mod_dir, SWITCH_PATH_SEPARATOR, MOD_MONO_MANAGED_DLL);
|
switch_snprintf(filename, 256, "%s%s%s", SWITCH_GLOBAL_dirs.mod_dir, SWITCH_PATH_SEPARATOR, MOD_MONO_MANAGED_DLL);
|
||||||
globals.domain = mono_jit_init(filename);
|
globals.domain = mono_jit_init(filename);
|
||||||
|
|
||||||
if (!globals.domain) {
|
/* Already got a Mono domain? */
|
||||||
|
if ((globals.domain = mono_get_root_domain())) {
|
||||||
|
mono_thread_attach(globals.domain);
|
||||||
|
globals.embedded = SWITCH_TRUE;
|
||||||
|
} else {
|
||||||
|
if (!(globals.domain = mono_jit_init(filename))) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "mono_jit_init failed.\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "mono_jit_init failed.\n");
|
||||||
return SWITCH_STATUS_FALSE;
|
return SWITCH_STATUS_FALSE;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Already loaded? */
|
||||||
|
MonoAssemblyName name;
|
||||||
|
name.name = MOD_MONO_MANAGED_ASM_NAME;
|
||||||
|
name.major = MOD_MONO_MANAGED_ASM_V1;
|
||||||
|
name.minor = MOD_MONO_MANAGED_ASM_V2;
|
||||||
|
name.revision = MOD_MONO_MANAGED_ASM_V3;
|
||||||
|
name.build = MOD_MONO_MANAGED_ASM_V4;
|
||||||
|
name.culture = "";
|
||||||
|
name.hash_value = "";
|
||||||
|
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Calling mono_assembly_loaded");
|
||||||
|
|
||||||
|
if (!(globals.mod_mono_asm = mono_assembly_loaded(&name))) {
|
||||||
/* Open the assembly */
|
/* Open the assembly */
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Calling mono_domain_assembly_open");
|
||||||
globals.mod_mono_asm = mono_domain_assembly_open(globals.domain, filename);
|
globals.mod_mono_asm = mono_domain_assembly_open(globals.domain, filename);
|
||||||
|
|
||||||
if (!globals.mod_mono_asm) {
|
if (!globals.mod_mono_asm) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "mono_domain_assembly_open failed.\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "mono_domain_assembly_open failed.\n");
|
||||||
return SWITCH_STATUS_FALSE;
|
return SWITCH_STATUS_FALSE;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MonoMethod * getMethod(const char *name, MonoClass * klass)
|
MonoMethod * getMethod(const char *name, MonoClass * klass)
|
||||||
@ -226,7 +253,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_mono_load)
|
|||||||
/* Not sure if this is necesary on the loading thread */
|
/* Not sure if this is necesary on the loading thread */
|
||||||
mono_thread_attach(globals.domain);
|
mono_thread_attach(globals.domain);
|
||||||
|
|
||||||
mono_add_internal_call("FreeSWITCH.Native.MonoSession::InitMonoSession", InitMonoSession);
|
mono_add_internal_call("FreeSWITCH.Native.MonoSession::InitMonoSession", (void *)InitMonoSession);
|
||||||
|
|
||||||
/* Run loader */
|
/* Run loader */
|
||||||
MonoObject * objResult;
|
MonoObject * objResult;
|
||||||
@ -360,9 +387,9 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_mono_shutdown)
|
|||||||
mono_print_unhandled_exception(ex);
|
mono_print_unhandled_exception(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
mono_runtime_set_shutting_down();
|
if (!globals.embedded) {
|
||||||
mono_runtime_cleanup(globals.domain);
|
mono_jit_cleanup(globals.domain);
|
||||||
mono_runtime_quit();
|
}
|
||||||
|
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
5
src/mod/languages/mod_mono/runswig.sh
Normal file
5
src/mod/languages/mod_mono/runswig.sh
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
swig -I../../../include -v -O -c++ -csharp -namespace FreeSWITCH.Native -dllimport mod_mono freeswitch.i
|
||||||
|
rm -f ../mod_mono_managed/swig.cs
|
||||||
|
cat *.cs > ../mod_mono_managed/swig.cs
|
||||||
|
rm -f *.cs
|
@ -14,6 +14,20 @@ typedef unsigned long in_addr_t;
|
|||||||
// we define char as byte.
|
// we define char as byte.
|
||||||
// TODO: Possible? It'd be nice to do the whole char*->IntPtr->Marshal/Free thing here instead of swigStringFix
|
// TODO: Possible? It'd be nice to do the whole char*->IntPtr->Marshal/Free thing here instead of swigStringFix
|
||||||
|
|
||||||
|
%typemap(imtype, out="string") char ** "ref string"
|
||||||
|
%typemap(cstype, out="string") char ** "ref string"
|
||||||
|
%typemap(csin) char ** "ref $csinput"
|
||||||
|
%typemap(csvarin) char **
|
||||||
|
%{
|
||||||
|
set { $imcall; }
|
||||||
|
%}
|
||||||
|
%typemap(csvarout) char **
|
||||||
|
%{
|
||||||
|
get {
|
||||||
|
return $imcall;
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
||||||
#define SWITCH_DECLARE(type) type
|
#define SWITCH_DECLARE(type) type
|
||||||
#define SWITCH_DECLARE_NONSTD(type) type
|
#define SWITCH_DECLARE_NONSTD(type) type
|
||||||
#define SWITCH_MOD_DECLARE(type) type
|
#define SWITCH_MOD_DECLARE(type) type
|
||||||
|
@ -100,22 +100,22 @@ namespace FreeSWITCH
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static List<Assembly> loadAssemblies(string managedDir)
|
static Assembly[] loadAssemblies(string managedDir)
|
||||||
{
|
{
|
||||||
return Directory.GetFiles(managedDir, "*.dll", SearchOption.AllDirectories)
|
// load the modules in the mod/mono directory
|
||||||
.Select(f => Path.Combine(managedDir, f))
|
Log.WriteLine(LogLevel.Notice, "loadAssemblies: {0}", managedDir);
|
||||||
.Select(f => {
|
foreach (string s in Directory.GetFiles(managedDir, "*.dll", SearchOption.AllDirectories))
|
||||||
|
{
|
||||||
|
string f = Path.Combine(managedDir, s);
|
||||||
try {
|
try {
|
||||||
return System.Reflection.Assembly.LoadFile(f);
|
System.Reflection.Assembly.LoadFile(f);
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
Log.WriteLine(LogLevel.Notice, "Assembly.LoadFile failed; skipping {0} ({1})", f, ex.Message);
|
Log.WriteLine(LogLevel.Notice, "Assembly.LoadFile failed; skipping {0} ({1})", f, ex.Message);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
.Where(a => a != null)
|
|
||||||
.Concat(new[] { System.Reflection.Assembly.GetExecutingAssembly() }) // Add in our own to load Demo or built-in things if added
|
return AppDomain.CurrentDomain.GetAssemblies(); // Includes anything else already loaded
|
||||||
.ToList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Unload()
|
public static void Unload()
|
||||||
|
13
src/mod/languages/mod_mono_managed/Makefile
Normal file
13
src/mod/languages/mod_mono_managed/Makefile
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
all: Debug Debug/mod_mono_managed.dll
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -fr Debug
|
||||||
|
|
||||||
|
Debug:
|
||||||
|
mkdir Debug
|
||||||
|
|
||||||
|
Debug/mod_mono_managed.dll: Loader.cs MonoSession.cs ApiFunction.cs AppFunction.cs Extensions.cs Log.cs Demo.cs swig.cs
|
||||||
|
gmcs -target:library -out:Debug/mod_mono_managed.dll -d:DEBUG Loader.cs MonoSession.cs ApiFunction.cs AppFunction.cs Extensions.cs Log.cs Demo.cs swig.cs
|
||||||
|
|
||||||
|
install: Debug/mod_mono_managed.dll
|
||||||
|
install Debug/mod_mono_managed.dll /usr/local/freeswitch/mod
|
Loading…
x
Reference in New Issue
Block a user