--- /dev/null
+/* \r
+ * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - mod_managed\r
+ * Copyright (C) 2008, Michael Giagnocavo <mgg@giagnocavo.net>\r
+ *\r
+ * Version: MPL 1.1\r
+ *\r
+ * The contents of this file are subject to the Mozilla Public License Version\r
+ * 1.1 (the "License"); you may not use this file except in compliance with\r
+ * the License. You may obtain a copy of the License at\r
+ * http://www.mozilla.org/MPL/\r
+ *\r
+ * Software distributed under the License is distributed on an "AS IS" basis,\r
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License\r
+ * for the specific language governing rights and limitations under the\r
+ * License.\r
+ *\r
+ * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - mod_managed\r
+ *\r
+ * The Initial Developer of the Original Code is\r
+ * Michael Giagnocavo <mgg@giagnocavo.net>\r
+ * Portions created by the Initial Developer are Copyright (C)\r
+ * the Initial Developer. All Rights Reserved.\r
+ *\r
+ * Contributor(s):\r
+ * \r
+ * Michael Giagnocavo <mgg@giagnocavo.net>\r
+ * \r
+ * XmlSearchBinding.cs - Helpers for switch_xml_bind_search_function\r
+ *\r
+ */\r
+using System;\r
+using System.Collections.Generic;\r
+using System.Linq;\r
+using System.Text;\r
+using System.Runtime.InteropServices;\r
+using System.Reflection;\r
+using FreeSWITCH.Native;\r
+\r
+namespace FreeSWITCH {\r
+\r
+ public class SwitchXmlSearchBinding : IDisposable {\r
+\r
+ public class XmlBindingArgs {\r
+ public string Section { get; set; }\r
+ public string TagName { get; set; }\r
+ public string KeyName { get; set; }\r
+ public string KeyValue { get; set; }\r
+ public switch_event Parameters { get; set; }\r
+ }\r
+\r
+ //typedef switch_xml_t (*switch_xml_search_function_t) (const char *section,\r
+ // const char *tag_name, const char *key_name, const char *key_value, switch_event_t *params,\r
+ // void *user_data);\r
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]\r
+ 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);\r
+\r
+ readonly switch_xml_search_function_delegate del; // Prevent GC\r
+ 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;\r
+\r
+ 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,\r
+ switch_xml_search_function_delegate origDelegate) {\r
+ this.function = function;\r
+ this.del = origDelegate;\r
+ }\r
+ bool disposed;\r
+ public void Dispose() {\r
+ dispose();\r
+ GC.SuppressFinalize(this);\r
+ }\r
+ void dispose() {\r
+ if (disposed) return;\r
+ freeswitch.switch_xml_unbind_search_function_ptr(this.function);\r
+ disposed = true;\r
+ }\r
+ ~SwitchXmlSearchBinding() {\r
+ dispose();\r
+ }\r
+\r
+ public static IDisposable Bind(Func<XmlBindingArgs, string> f, switch_xml_section_enum_t sections) {\r
+ switch_xml_search_function_delegate boundFunc = (section, tag, key, keyval, param, userData) => {\r
+ var args = new XmlBindingArgs { Section = section, TagName = tag, KeyName = key, KeyValue = keyval, Parameters = param };\r
+ var xmlStr = f(args);\r
+ var fsxml = freeswitch.switch_xml_parse_str_dynamic(xmlStr, switch_bool_t.SWITCH_FALSE);\r
+ return fsxml;\r
+ };\r
+ var fp = Marshal.GetFunctionPointerForDelegate(boundFunc);\r
+ 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);\r
+ var res = freeswitch.switch_xml_bind_search_function_ret(swigFp, (uint)sections, null, null);\r
+ if (res != switch_status_t.SWITCH_STATUS_SUCCESS) {\r
+ throw new InvalidOperationException("Call to switch_xml_bind_search_function_ret failed, result: " + res + ".");\r
+ }\r
+ return new SwitchXmlSearchBinding(swigFp, boundFunc);\r
+ }\r
+ }\r
+}
\ No newline at end of file