Add XmlSearchBinding

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@15406 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Michael Giagnocavo 2009-11-10 14:30:54 +00:00
parent 6e0c9bfb08
commit c4673ae333
3 changed files with 97 additions and 1 deletions

View File

@ -59,6 +59,7 @@
<Compile Include="ScriptPluginManager.cs" />
<Compile Include="swig.cs" />
<Compile Include="Util.cs" />
<Compile Include="XmlSearchBinding.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.

View File

@ -4,7 +4,7 @@ clean:
rm -fr FreeSWITCH.Managed.dll
FreeSWITCH.Managed.dll: AssemblyInfo.cs Extensions.cs Loader.cs Log.cs ManagedSession.cs PluginInterfaces.cs PluginManager.cs ScriptPluginManager.cs swig.cs
gmcs -target:library -out:FreeSWITCH.Managed.dll AssemblyInfo.cs Extensions.cs Loader.cs Log.cs ManagedSession.cs PluginInterfaces.cs PluginManager.cs ScriptPluginManager.cs ChannelVariables.cs Util.cs swig.cs
gmcs -target:library -out:FreeSWITCH.Managed.dll AssemblyInfo.cs Extensions.cs Loader.cs Log.cs ManagedSession.cs PluginInterfaces.cs PluginManager.cs ScriptPluginManager.cs ChannelVariables.cs Util.cs swig.cs XmlSearchBinding.cs
install: FreeSWITCH.Managed.dll
$(INSTALL) FreeSWITCH.Managed.dll $(DESTDIR)$(MODINSTDIR)

View File

@ -0,0 +1,95 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - mod_managed
* Copyright (C) 2008, Michael Giagnocavo <mgg@giagnocavo.net>
*
* 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_managed
*
* The Initial Developer of the Original Code is
* Michael Giagnocavo <mgg@giagnocavo.net>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Michael Giagnocavo <mgg@giagnocavo.net>
*
* XmlSearchBinding.cs - Helpers for switch_xml_bind_search_function
*
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Reflection;
using FreeSWITCH.Native;
namespace FreeSWITCH {
public class SwitchXmlSearchBinding : IDisposable {
public class XmlBindingArgs {
public string Section { get; set; }
public string TagName { get; set; }
public string KeyName { get; set; }
public string KeyValue { get; set; }
public switch_event Parameters { get; set; }
}
//typedef switch_xml_t (*switch_xml_search_function_t) (const char *section,
// const char *tag_name, const char *key_name, const char *key_value, switch_event_t *params,
// void *user_data);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate switch_xml switch_xml_search_function_delegate(string section, string tag_name, string key_name, string key_value, switch_event param, IntPtr user_data);
readonly switch_xml_search_function_delegate del; // Prevent GC
readonly SWIGTYPE_p_f_p_q_const__char_p_q_const__char_p_q_const__char_p_q_const__char_p_switch_event_t_p_void__p_switch_xml function;
private SwitchXmlSearchBinding(SWIGTYPE_p_f_p_q_const__char_p_q_const__char_p_q_const__char_p_q_const__char_p_switch_event_t_p_void__p_switch_xml function,
switch_xml_search_function_delegate origDelegate) {
this.function = function;
this.del = origDelegate;
}
bool disposed;
public void Dispose() {
dispose();
GC.SuppressFinalize(this);
}
void dispose() {
if (disposed) return;
freeswitch.switch_xml_unbind_search_function_ptr(this.function);
disposed = true;
}
~SwitchXmlSearchBinding() {
dispose();
}
public static IDisposable Bind(Func<XmlBindingArgs, string> f, switch_xml_section_enum_t sections) {
switch_xml_search_function_delegate boundFunc = (section, tag, key, keyval, param, userData) => {
var args = new XmlBindingArgs { Section = section, TagName = tag, KeyName = key, KeyValue = keyval, Parameters = param };
var xmlStr = f(args);
var fsxml = freeswitch.switch_xml_parse_str_dynamic(xmlStr, switch_bool_t.SWITCH_FALSE);
return fsxml;
};
var fp = Marshal.GetFunctionPointerForDelegate(boundFunc);
var swigFp = new SWIGTYPE_p_f_p_q_const__char_p_q_const__char_p_q_const__char_p_q_const__char_p_switch_event_t_p_void__p_switch_xml(fp, false);
var res = freeswitch.switch_xml_bind_search_function_ret(swigFp, (uint)sections, null, null);
if (res != switch_status_t.SWITCH_STATUS_SUCCESS) {
throw new InvalidOperationException("Call to switch_xml_bind_search_function_ret failed, result: " + res + ".");
}
return new SwitchXmlSearchBinding(swigFp, boundFunc);
}
}
}