]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Add utility function to create SWIGTYPE_p objects
authorMichael Giagnocavo <mgg@giagnocavo.net>
Sat, 19 Sep 2009 00:37:58 +0000 (00:37 +0000)
committerMichael Giagnocavo <mgg@giagnocavo.net>
Sat, 19 Sep 2009 00:37:58 +0000 (00:37 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@14923 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/Util.cs [new file with mode: 0644]

index 33213a6caadb18df9fb866804b6a05a293aa5b91..e5c0995a5dfc9ef415658ad812c3ee6fe1540fb6 100644 (file)
@@ -58,6 +58,7 @@
     <Compile Include="PluginManager.cs" />\r
     <Compile Include="ScriptPluginManager.cs" />\r
     <Compile Include="swig.cs" />\r
+    <Compile Include="Util.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 160cf620e276e08108cdb7fa9d3ef5ee5a6c3984..845237d89502cda2dea4369e2537390828bca35f 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 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
 \r
 install: FreeSWITCH.Managed.dll\r
        $(INSTALL) FreeSWITCH.Managed.dll $(DESTDIR)$(MODINSTDIR)\r
diff --git a/src/mod/languages/mod_managed/managed/Util.cs b/src/mod/languages/mod_managed/managed/Util.cs
new file mode 100644 (file)
index 0000000..18c2d89
--- /dev/null
@@ -0,0 +1,50 @@
+/* \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
+ * Util.cs - misc functions\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
+\r
+namespace FreeSWITCH {\r
+    public static class FSUtil {\r
+        // IntPtr cPtr, bool futureUse\r
+        static readonly Type[] swigConstructorTypes = new [] { typeof(IntPtr), typeof(bool) };\r
+        public static T CreateSwigTypePointer<T>(this IntPtr cPtr) {\r
+            var ty = typeof(T);\r
+            var bflags = BindingFlags.Default | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance;\r
+            var cons = ty.GetConstructor(bflags, null, swigConstructorTypes, null);\r
+            if (cons == null) throw new ArgumentException(ty.Name + " constructor not found.");\r
+            return (T)cons.Invoke(new object[] { cPtr, false });\r
+        }\r
+    }\r
+}\r