提交 18adf282 authored 作者: Michael Jerris's avatar Michael Jerris

remove mod_dotnet* (replaced by now merged mod_mono into mod_managed)

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@9816 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 f07c5301
%module freeswitch
/** insert the following includes into generated code so it compiles */
%{
#include "switch.h"
#include "switch_cpp.h"
#include "freeswitch_mono.h"
%}
%typemap(csclassmodifiers) MonoSession "public partial class"
%typemap(csclassmodifiers) Event "public partial class"
%typemap(csclassmodifiers) Stream "public partial class"
// Allow bitwise compare on flag fields
%typemap(csclassmodifiers) session_flag_t "[System.Flags] public enum"
%typemap(csclassmodifiers) switch_application_flag_enum_t "[System.Flags] public enum"
%typemap(csclassmodifiers) switch_asr_flag_enum_t "[System.Flags] public enum"
%typemap(csclassmodifiers) switch_bind_flag_enum_t "[System.Flags] public enum"
%typemap(csclassmodifiers) switch_caller_profile_flag_enum_t "[System.Flags] public enum"
%typemap(csclassmodifiers) switch_channel_flag_enum_t "[System.Flags] public enum"
%typemap(csclassmodifiers) switch_codec_flag_enum_t "[System.Flags] public enum"
%typemap(csclassmodifiers) switch_core_flag_enum_t "[System.Flags] public enum"
%typemap(csclassmodifiers) switch_core_session_message_flag_enum_t "[System.Flags] public enum"
%typemap(csclassmodifiers) switch_directory_flag_enum_t "[System.Flags] public enum"
%typemap(csclassmodifiers) switch_eavesdrop_flag_enum_t "[System.Flags] public enum"
%typemap(csclassmodifiers) switch_file_flag_enum_t "[System.Flags] public enum"
%typemap(csclassmodifiers) switch_frame_flag_enum_t "[System.Flags] public enum"
%typemap(csclassmodifiers) switch_io_flag_enum_t "[System.Flags] public enum"
%typemap(csclassmodifiers) switch_media_bug_flag_enum_t "[System.Flags] public enum"
%typemap(csclassmodifiers) switch_media_flag_enum_t "[System.Flags] public enum"
%typemap(csclassmodifiers) switch_originate_flag_enum_t "[System.Flags] public enum"
%typemap(csclassmodifiers) switch_port_flag_enum_t "[System.Flags] public enum"
%typemap(csclassmodifiers) switch_rtp_flag_enum_t "[System.Flags] public enum"
%typemap(csclassmodifiers) switch_scheduler_flag_enum_t "[System.Flags] public enum"
%typemap(csclassmodifiers) switch_speech_flag_enum_t "[System.Flags] public enum"
%typemap(csclassmodifiers) switch_timer_flag_enum_t "[System.Flags] public enum"
%typemap(csclassmodifiers) switch_unicast_flag_enum_t "[System.Flags] public enum"
%typemap(csclassmodifiers) switch_vad_flag_enum_t "[System.Flags] public enum"
%typemap(csclassmodifiers) switch_xml_flag_t "[System.Flags] public enum"
%typemap(csclassmodifiers) switch_xml_section_enum_t "[System.Flags] public enum"
// Some things we dont want exposed to managed users directly, since
// we're gonna handle them with our own internalcall methods
%ignore dtmfDelegateHandle;
%ignore hangupDelegateHandle;
%ignore setHangupHook;
%ignore beginAllowThreads;
%ignore endAllowThreads;
%ignore process_callback_result;
%ignore run_dtmf_callback;
%ignore setDTMFCallback;
// Rename some things to make them more .NET-like
//%csmethodmodifiers CoreSession::hangup "internal";
%rename (Answer) CoreSession::answer;
%rename (Hangup) CoreSession::hangup;
%rename (Ready) CoreSession::ready;
%rename (Transfer) CoreSession::transfer;
%rename (Originate) CoreSession::originate;
%rename (SetVariable) CoreSession::setVariable;
%rename (GetVariable) CoreSession::getVariable;
%rename (SetPrivate) CoreSession::setPrivate;
%rename (GetPrivate) CoreSession::getPrivate;
%rename (Say) CoreSession::say;
%rename (SayPhrase) CoreSession::sayPhrase;
%rename (RecordFile) CoreSession::recordFile;
%rename (SetCallerData) CoreSession::setCallerData;
%rename (CollectDigits) CoreSession::collectDigits;
%rename (GetDigits) CoreSession::getDigits;
%rename (PlayAndGetDigits) CoreSession::playAndGetDigits;
%rename (StreamFile) CoreSession::streamFile;
%rename (Execute) CoreSession::execute;
%rename (GetUuid) CoreSession::get_uuid;
%rename (HookState) CoreSession::hook_state;
%rename (InternalSession) CoreSession::session;
%rename (Speak) CoreSession::speak;
%rename (SetTtsParameters) CoreSession::set_tts_parms;
%rename (SetAutoHangup) CoreSession::setAutoHangup;
%rename (Serialize) Event::serialize;
%rename (SetPriority) Event::setPriority;
%rename (GetHeader) Event::getHeader;
%rename (GetBody) Event::getBody;
%rename (GetEventType) Event::getType;
%rename (AddBody) Event::addBody;
%rename (AddHeader) Event::addHeader;
%rename (DeleteHeader) Event::delHeader;
%rename (Fire) Event::fire;
%rename (InternalEvent) Event::event;
%rename (Write) Stream::write;
%rename (GetData) Stream::getData;
%rename (Api) API;
%rename (Execute) API::execute;
%rename (ExecuteString) API::executeString;
%rename (IvrMenu) IVRMenu;
%rename (Execute) IVRMenu::execute;
%rename (ExecuteString) API::executeString;
// Causes C2564, todo
%ignore switch_ivr_menu_action_function_t;
// todo, other errors
%ignore switch_core_session_get_event_hooks;
%ignore switch_inet_pton;
%ignore switch_xml_idx;
// Real header includes now
%import switch_platform.i // This will give us all the macros we need to compile the other stuff
%include switch.h
%include switch_types.h
%include switch_core_db.h
%include switch_regex.h
%include switch_core.h
//%include switch_loadable_module.h // todo: Sort out some linking issues
%include switch_console.h // Has unsupported varargs functions
%include switch_utils.h
%include switch_caller.h
%include switch_frame.h
%include switch_module_interfaces.h
%include switch_channel.h
%include switch_buffer.h
%include switch_event.h // Varargs omitted
%include switch_resample.h
%include switch_ivr.h
%include switch_rtp.h
%include switch_log.h // switch_log_printf is omitted (varargs)
%include switch_xml.h
%include switch_core_event_hook.h
%include switch_scheduler.h
%include switch_config.h
%include switch_cpp.h
%include freeswitch_mono.h
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - mod_dotnet
* Copyright (C) 2008, Michael Giagnocavo <mgg@packetrino.com>
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - mod_dotnet
*
* The Initial Developer of the Original Code is
* Michael Giagnocavo <mgg@packetrino.com>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Michael Giagnocavo <mgg@packetrino.com>
* Jeff Lenk <jlenk@frontiernet.net> - Modified class to support Dotnet
*
* freeswitch_mono.cpp -- Dotnet-specific CoreSession subclass
*
*/
#include <switch.h>
#include <switch_cpp.h>
#include "freeswitch_mono.h"
MonoSession::MonoSession():CoreSession()
{
}
MonoSession::MonoSession(char *uuid):CoreSession(uuid)
{
}
MonoSession::MonoSession(switch_core_session_t *session):CoreSession(session)
{
}
MonoSession::~MonoSession()
{
// Do auto-hangup ourselves because CoreSession can't call check_hangup_hook
// after MonoSession destruction (cause at point it's pure virtual)
if (session) {
channel = switch_core_session_get_channel(session);
if (switch_test_flag(this, S_HUP) && !switch_channel_test_flag(channel, CF_TRANSFER)) {
switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
setAutoHangup(0);
}
// Don't let any callbacks use this CoreSession anymore
switch_channel_set_private(channel, "CoreSession", NULL);
}
}
bool MonoSession::begin_allow_threads()
{
return true;
}
bool MonoSession::end_allow_threads()
{
return true;
}
void MonoSession::check_hangup_hook()
{
if (!hangupDelegateHandle) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "hangupDelegateHandle didn't get an object.");
return;
}
hangupDelegateHandle();
}
switch_status_t MonoSession::run_dtmf_callback(void *input, switch_input_type_t itype)
{
if (!dtmfDelegateHandle) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "dtmfDelegateHandle didn't get an object.");
return SWITCH_STATUS_FALSE;;
}
char* result = dtmfDelegateHandle(input, itype);
switch_status_t status = process_callback_result(result);
return status;
}
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - mod_dotnet
* Copyright (C) 2008, Michael Giagnocavo <mgg@packetrino.com>
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - mod_dotnet
*
* The Initial Developer of the Original Code is
* Michael Giagnocavo <mgg@packetrino.com>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Michael Giagnocavo <mgg@packetrino.com>
* Jeff Lenk <jlenk@frontiernet.net> - Modified class to support Dotnet
*
* freeswitch_mono.h -- Header for MonoSession and globals
*
*/
#ifndef FREESWITCH_MONO_H
#define FREESWITCH_MONO_H
SWITCH_BEGIN_EXTERN_C
#include <switch.h>
#include <switch_cpp.h>
typedef char* (CALLBACK* inputtype)(void * input, switch_input_type_t type);
typedef void (CALLBACK* hanguptype)();
SWITCH_END_EXTERN_C
using namespace System;
using namespace System::Reflection;
using namespace System::Runtime::InteropServices;
delegate void HangupMethod();
public ref class FreeSwitchManaged
{
public:
static Assembly^ mod_dotnet_managed;
static MethodInfo^ loadMethod;
static MethodInfo^ unloadMethod;
static MethodInfo^ runMethod;
static MethodInfo^ executeMethod;
static MethodInfo^ executeBackgroundMethod;
};
class MonoSession : public CoreSession
{
public:
MonoSession();
MonoSession(char *uuid);
MonoSession(switch_core_session_t *session);
virtual ~MonoSession();
virtual bool begin_allow_threads();
virtual bool end_allow_threads();
virtual void check_hangup_hook();
virtual switch_status_t run_dtmf_callback(void *input, switch_input_type_t itype);
inputtype dtmfDelegateHandle; // GCHandle to the input delegate
hanguptype hangupDelegateHandle; // GCHandle to the hangup delegate
};
#endif
\ No newline at end of file
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="mod_dotnet"
ProjectGUID="{7B42BDA1-72C0-4378-A9B6-5C530F8CD61E}"
RootNamespace="mod_dotnet"
Keyword="Win32Proj"
TargetFrameworkVersion="196613"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="2"
InheritedPropertySheets="..\..\..\..\w32\module_debug.vsprops"
CharacterSet="2"
ManagedExtensions="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="&quot;C:\Program Files\Mono\lib\glib-2.0\include&quot;;&quot;C:\Program Files\Mono\include\glib-2.0&quot;;&quot;C:\Program Files\Mono\include\mono-1.0&quot;;..\..\..\..\libs\apr\include"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;MOD_MONO_EXPORTS"
MinimalRebuild="false"
BasicRuntimeChecks="0"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="4"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
DisableSpecificWarnings="4505"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="shlwapi.lib mscoree.lib"
LinkIncremental="2"
ModuleDefinitionFile=""
GenerateDebugInformation="true"
AssemblyDebug="1"
SubSystem="0"
DataExecutionPrevention="1"
TargetMachine="0"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="2"
InheritedPropertySheets="..\..\..\..\w32\module_release.vsprops"
CharacterSet="1"
ManagedExtensions="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="..\..\..\..\libs\apr\include"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;MOD_MONO_EXPORTS"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkIncremental="1"
ModuleDefinitionFile=""
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\freeswitch_mono.cpp"
>
</File>
<File
RelativePath=".\freeswitch_wrap.cxx"
>
</File>
<File
RelativePath=".\mod_dotnet.cpp"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\freeswitch_mono.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
<File
RelativePath=".\freeswitch.i"
>
</File>
<File
RelativePath=".\switch_platform.i"
>
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
差异被折叠。
// MANUALLY GENERATED
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned long uint32_t;
typedef unsigned long long uint64_t;
typedef signed char int8_t;
typedef short int16_t;
typedef int int32_t;
typedef long long int64_t;
typedef unsigned long in_addr_t;
// TODO: C# chars are 2 bytes, C is one. The marshalling copies two bytes (Value+whatever) into the C# char
// causing corruption. We should figure this out. It's as simple as ((char)(byte)<thebyte>) whever
// we define char as byte.
// TODO: Possible? It'd be nice to do the whole char*->IntPtr->Marshal/Free thing here instead of swigStringFix
#define SWITCH_DECLARE(type) type
#define SWITCH_DECLARE_NONSTD(type) type
#define SWITCH_MOD_DECLARE(type) type
#define SWITCH_DECLARE_DATA
#define SWITCH_MOD_DECLARE_DATA
#define SWITCH_THREAD_FUNC
#define SWITCH_DECLARE_CONSTRUCTOR SWITCH_DECLARE_DATA
#define _In_
#define _In_z_
#define _In_opt_z_
#define _In_opt_
#define _Printf_format_string_
#define _Ret_opt_z_
#define _Ret_z_
#define _Out_opt_
#define _Out_
#define _Check_return_
#define _Inout_
#define _Inout_opt_
#define _In_bytecount_(x)
#define _Out_opt_bytecapcount_(x)
#define _Out_bytecapcount_(x)
#define _Ret_
#define _Post_z_
#define _Out_cap_(x)
#define _Out_z_cap_(x)
#define _Out_ptrdiff_cap_(x)
#define _Out_opt_ptrdiff_cap_(x)
\ No newline at end of file
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - mod_mono
* Copyright (C) 2008, Michael Giagnocavo <mgg@packetrino.com>
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - mod_mono
*
* The Initial Developer of the Original Code is
* Michael Giagnocavo <mgg@packetrino.com>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Michael Giagnocavo <mgg@packetrino.com>
*
* AppFunction.cs -- Base class for API functions
*
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FreeSWITCH
{
public abstract class ApiFunction
{
protected static bool Load() { return true; }
protected static void Unload() { }
public abstract void ExecuteBackground(string args);
public abstract void Execute(FreeSWITCH.Native.Stream stream, FreeSWITCH.Native.Event evt, string args);
}
}
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - mod_mono
* Copyright (C) 2008, Michael Giagnocavo <mgg@packetrino.com>
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - mod_mono
*
* The Initial Developer of the Original Code is
* Michael Giagnocavo <mgg@packetrino.com>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Michael Giagnocavo <mgg@packetrino.com>
*
* AppFunction.cs -- Base class for applications
*
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace FreeSWITCH
{
public abstract class AppFunction
{
protected static bool Load() { return true; }
protected static void Unload() { }
protected Native.MonoSession Session { get; private set; }
protected string Arguments { get; private set; }
public bool IsAvailable
{
get
{
if (this.Session == null) return false;
return this.Session.Ready();
}
}
/// <summary>Determines if the thread used for Run will have Abort called on it on hangup. Defaults to false.</summary>
protected virtual bool AbortOnHangup { get { return false; } }
bool abortable = false;
readonly object abortLock = new object();
Thread runThread;
internal void AbortRun()
{
if (!AbortOnHangup) return;
if (runThread == Thread.CurrentThread) {
Log.WriteLine(LogLevel.Warning, "Thread will not be aborted because Hangup was called from the Run thread.");
return;
}
lock (abortLock) {
if (abortable) {
Log.WriteLine(LogLevel.Critical, "Aborting run thread.");
runThread.Abort();
}
}
}
protected Guid Uuid { get; private set; }
internal void RunInternal(FreeSWITCH.Native.MonoSession session, string args)
{
this.Session = session;
this.Arguments = args;
Session.AppToAbort = this;
try { this.Uuid = new Guid(Session.GetUuid()); }
catch { }
try {
runThread = Thread.CurrentThread;
lock (abortLock) abortable = true;
Run();
}
catch (ThreadAbortException) {
Log.WriteLine(LogLevel.Critical, "Run thread aborted.");
Thread.ResetAbort();
}
finally {
lock (abortLock) { abortable = false; }
if (runThread.ThreadState == ThreadState.AbortRequested) {
try { Thread.ResetAbort(); }
catch { }
}
}
}
protected abstract void Run();
}
}
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - mod_mono
* Copyright (C) 2008, Michael Giagnocavo <mgg@packetrino.com>
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - mod_mono
*
* The Initial Developer of the Original Code is
* Michael Giagnocavo <mgg@packetrino.com>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Michael Giagnocavo <mgg@packetrino.com>
*
* Demo.cs -- mod_mono demo classes
*
*/
#if DEBUG
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FreeSWITCH.Demo
{
public class AppDemo : AppFunction
{
new protected static bool Load()
{
Log.WriteLine(LogLevel.Info, "Inside AppDemo::Load.");
return true;
}
new protected static void Unload()
{
Log.WriteLine(LogLevel.Info, "Inside AppDemo::Unload.");
}
protected override void Run()
{
Session.Answer();
Session.DtmfReceivedFunction = (d, t) => {
Log.WriteLine(LogLevel.Info, "Received {0} for {1}.", d, t);
return "";
};
Log.WriteLine(LogLevel.Info, "Inside AppDemo.Run (args '{0}'); HookState is {1}. Now will collect digits.", Arguments, Session.HookState);
Session.CollectDigits(5000); // Hanging up here will cause an abort and the next line won't be written
Log.WriteLine(LogLevel.Info, "AppDemo is finishing its run and will now hang up.");
Session.Hangup("USER_BUSY");
}
void hangupHook()
{
Log.WriteLine(LogLevel.Debug, "AppDemo hanging up, UUID: {0}.", this.Uuid);
}
protected override bool AbortOnHangup { get { return true; } }
}
public class ApiDemo : ApiFunction
{
new protected static bool Load()
{
Log.WriteLine(LogLevel.Debug, "Inside ApiDemo::Load.");
return true;
}
new protected static void Unload()
{
Log.WriteLine(LogLevel.Debug, "Inside ApiDemo::Unload.");
}
public override void ExecuteBackground(string args)
{
Log.WriteLine(LogLevel.Debug, "ApiDemo on a background thread #({0}), with args '{1}'.",
System.Threading.Thread.CurrentThread.ManagedThreadId,
args);
}
public override void Execute(Native.Stream stream, Native.Event evt, string args)
{
stream.Write(string.Format("ApiDemo executed with args '{0}' and event type {1}.",
args, evt == null ? "<none>" : evt.GetEventType()));
}
}
}
#endif
\ No newline at end of file
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - mod_mono
* Copyright (C) 2008, Michael Giagnocavo <mgg@packetrino.com>
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - mod_mono
*
* The Initial Developer of the Original Code is
* Michael Giagnocavo <mgg@packetrino.com>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Michael Giagnocavo <mgg@packetrino.com>
*
* Extensions.cs -- Helper extensions
*
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace System.Linq
{
internal static class EnumerableExtensions
{
public static void ForEach<T>(this IEnumerable<T> source, Action<T> f)
{
foreach (var item in source) {
f(item);
}
}
}
}
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - mod_mono
* Copyright (C) 2008, Michael Giagnocavo <mgg@packetrino.com>
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - mod_mono
*
* The Initial Developer of the Original Code is
* Michael Giagnocavo <mgg@packetrino.com>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Michael Giagnocavo <mgg@packetrino.com>
*
* Log.cs -- Log wrappers
*
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FreeSWITCH
{
public static class Log
{
public static void Write(LogLevel level, string message)
{
Native.freeswitch.console_log(level.ToLogString(), message);
}
public static void Write(LogLevel level, string format, params object[] args)
{
Native.freeswitch.console_log(level.ToLogString(), string.Format(format, args));
}
public static void WriteLine(LogLevel level, string message)
{
Native.freeswitch.console_log(level.ToLogString(), message + Environment.NewLine);
}
public static void WriteLine(LogLevel level, string format, params object[] args)
{
Native.freeswitch.console_log(level.ToLogString(), string.Format(format, args) + Environment.NewLine);
}
static string ToLogString(this LogLevel level)
{
switch (level) {
case LogLevel.Alert: return "ALERT";
case LogLevel.Critical: return "CRIT";
case LogLevel.Debug: return "DEBUG";
case LogLevel.Error: return "ERR";
case LogLevel.Info: return "INFO";
case LogLevel.Notice: return "NOTICE";
case LogLevel.Warning: return "WARNING";
default:
System.Diagnostics.Debug.Fail("Invalid LogLevel: " + level.ToString() + " (" + (int)level+ ").");
return "INFO";
}
}
}
/*switch_log.c:
tatic const char *LEVELS[] = {
"CONSOLE",
"ALERT",
"CRIT",
"ERR",
"WARNING",
"NOTICE",
"INFO",
"DEBUG",
NULL
};*/
public enum LogLevel
{
Debug,
Info,
Error,
Critical,
Alert,
Warning,
Notice,
}
}
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - mod_mono
* Copyright (C) 2008, Michael Giagnocavo <mgg@packetrino.com>
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - mod_mono
*
* The Initial Developer of the Original Code is
* Michael Giagnocavo <mgg@packetrino.com>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Michael Giagnocavo <mgg@packetrino.com>
* Jeff Lenk <jlenk@frontiernet.net> - Modified class to support Dotnet
*
* MonoSession.cs -- MonoSession additional functions
*
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace FreeSWITCH.Native
{
public partial class MonoSession
{
public delegate void hangupDelegate();
hangupDelegate hangupDel;
System.Runtime.InteropServices.GCHandle gcHangup;
IntPtr hangupFuncPtr;
public delegate string dtmfDelegate(IntPtr input, Native.switch_input_type_t inputType);
dtmfDelegate dtmfDel;
System.Runtime.InteropServices.GCHandle gcDtmf;
IntPtr dtmfFuncPtr;
[DllImport("mod_dotnet", EntryPoint = "InitDotnetSession")]
public static extern void InitDotnetSession(IntPtr sessionPtr, IntPtr dtmfDelegate, IntPtr hangupDelegate);
/// <summary>Initializes the native MonoSession. Must be called after Originate.</summary>
public void Initialize()
{
hangupDel = new hangupDelegate(hangupCallback);
//Calling the Alloc function to make sure the managed object is not garbage collected
gcHangup = GCHandle.Alloc(hangupDel);
hangupFuncPtr = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(hangupDel);
dtmfDel = new dtmfDelegate(inputCallback);
//Calling the Alloc function to make sure the managed object is not garbage collected
gcDtmf = GCHandle.Alloc(dtmfDel);
dtmfFuncPtr = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(dtmfDel);
InitDotnetSession(MonoSession.getCPtr(this).Handle, dtmfFuncPtr, hangupFuncPtr);
}
/// <summary>Function to execute when this session hangs up.</summary>
public Action HangupFunction { get; set; }
/// <summary>Sets the application that should have it's run thread aborted (if enabled) when this session is hungup.</summary>
internal AppFunction AppToAbort { get; set; }
void hangupCallback()
{
Log.WriteLine(LogLevel.Debug, "AppFunction is in hangupCallback.");
try {
if (AppToAbort != null) AppToAbort.AbortRun();
var f = HangupFunction;
if (f != null) f();
}
catch (Exception ex) {
Log.WriteLine(LogLevel.Warning, "Exception in hangupCallback: {0}", ex.ToString());
throw;
}
}
public Func<Char, TimeSpan, string> DtmfReceivedFunction { get; set; }
public Func<Native.Event, string> EventReceivedFunction { get; set; }
string inputCallback(IntPtr input, Native.switch_input_type_t inputType)
{
switch (inputType) {
case FreeSWITCH.Native.switch_input_type_t.SWITCH_INPUT_TYPE_DTMF:
using (var dtmf = new Native.switch_dtmf_t(input, false)) {
return dtmfCallback(dtmf);
}
case FreeSWITCH.Native.switch_input_type_t.SWITCH_INPUT_TYPE_EVENT:
using (var swevt = new Native.switch_event(input, false)) {
return eventCallback(swevt);
}
default:
return "";
}
}
string dtmfCallback(Native.switch_dtmf_t dtmf)
{
var f = DtmfReceivedFunction;
return f == null ?
"-ERR No DtmfReceivedFunction set." :
f(((char)(byte)dtmf.digit), TimeSpan.FromMilliseconds(dtmf.duration));
}
string eventCallback(Native.switch_event swevt)
{
using (var evt = new FreeSWITCH.Native.Event(swevt, 0)) {
var f = EventReceivedFunction;
return f == null ?
"-ERR No EventReceivedFunction set." :
f(evt);
}
}
}
}
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("mod_mono_managed")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("mod_mono_managed")]
[assembly: AssemblyCopyright("Copyright © 2008")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("b66ea632-ec95-4c9e-9cf7-7c0805a50526")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.21022</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{C95B7C7D-77F3-4DF7-9FB6-A44CBEF47B35}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>mod_dotnet_managed</RootNamespace>
<AssemblyName>mod_dotnet_managed</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<StartupObject>
</StartupObject>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\..\..\Debug\mod\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\..\..\Release\mod\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data.DataSetExtensions">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Compile Include="MonoSession.cs" />
<Compile Include="Loader.cs" />
<Compile Include="Extensions.cs" />
<Compile Include="Log.cs" />
</ItemGroup>
<ItemGroup>
<Compile Include="ApiFunction.cs" />
<Compile Include="AppFunction.cs" />
<Compile Include="Demo.cs" />
<Compile Include="swig.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论