]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Add XmlSearchBinding
authorMichael Giagnocavo <mgg@giagnocavo.net>
Tue, 10 Nov 2009 14:30:54 +0000 (14:30 +0000)
committerMichael Giagnocavo <mgg@giagnocavo.net>
Tue, 10 Nov 2009 14:30:54 +0000 (14:30 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@15406 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/languages/mod_managed/managed/FreeSWITCH.Managed.csproj
src/mod/languages/mod_managed/managed/Makefile
src/mod/languages/mod_managed/managed/XmlSearchBinding.cs [new file with mode: 0644]

index e5c0995a5dfc9ef415658ad812c3ee6fe1540fb6..c9947dd82c6e126408945b49a07b970a31910848 100644 (file)
@@ -59,6 +59,7 @@
     <Compile Include="ScriptPluginManager.cs" />\r
     <Compile Include="swig.cs" />\r
     <Compile Include="Util.cs" />\r
+    <Compile Include="XmlSearchBinding.cs" />\r
   </ItemGroup>\r
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />\r
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. \r
index 845237d89502cda2dea4369e2537390828bca35f..ef3c94d949444a7a69dbc0aee3ef47898ecdae27 100644 (file)
@@ -4,7 +4,7 @@ clean:
        rm -fr FreeSWITCH.Managed.dll\r
 \r
 FreeSWITCH.Managed.dll: AssemblyInfo.cs Extensions.cs Loader.cs Log.cs ManagedSession.cs PluginInterfaces.cs PluginManager.cs ScriptPluginManager.cs swig.cs\r
-       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\r
+       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\r
 \r
 install: FreeSWITCH.Managed.dll\r
        $(INSTALL) FreeSWITCH.Managed.dll $(DESTDIR)$(MODINSTDIR)\r
diff --git a/src/mod/languages/mod_managed/managed/XmlSearchBinding.cs b/src/mod/languages/mod_managed/managed/XmlSearchBinding.cs
new file mode 100644 (file)
index 0000000..fc2fdb0
--- /dev/null
@@ -0,0 +1,95 @@
+/* \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