Revision
14923
Author
michaelgg
Date
2009-09-18 19:37:58 -0500 (Fri, 18 Sep 2009)

Log Message

Add utility function to create SWIGTYPE_p objects

Modified Paths

Added Paths

Diff

Modified: freeswitch/trunk/src/mod/languages/mod_managed/managed/FreeSWITCH.Managed.csproj (14922 => 14923)


--- freeswitch/trunk/src/mod/languages/mod_managed/managed/FreeSWITCH.Managed.csproj	2009-09-18 22:55:33 UTC (rev 14922)
+++ freeswitch/trunk/src/mod/languages/mod_managed/managed/FreeSWITCH.Managed.csproj	2009-09-19 00:37:58 UTC (rev 14923)
@@ -58,6 +58,7 @@
     <Compile Include="PluginManager.cs" />
     <Compile Include="ScriptPluginManager.cs" />
     <Compile Include="swig.cs" />
+    <Compile Include="Util.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. 

Modified: freeswitch/trunk/src/mod/languages/mod_managed/managed/Makefile (14922 => 14923)


--- freeswitch/trunk/src/mod/languages/mod_managed/managed/Makefile	2009-09-18 22:55:33 UTC (rev 14922)
+++ freeswitch/trunk/src/mod/languages/mod_managed/managed/Makefile	2009-09-19 00:37:58 UTC (rev 14923)
@@ -4,7 +4,7 @@
 	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 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
 
 install: FreeSWITCH.Managed.dll
 	$(INSTALL) FreeSWITCH.Managed.dll $(DESTDIR)$(MODINSTDIR)

Added: freeswitch/trunk/src/mod/languages/mod_managed/managed/Util.cs (0 => 14923)


--- freeswitch/trunk/src/mod/languages/mod_managed/managed/Util.cs	                        (rev 0)
+++ freeswitch/trunk/src/mod/languages/mod_managed/managed/Util.cs	2009-09-19 00:37:58 UTC (rev 14923)
@@ -0,0 +1,50 @@
+/* 
+ * 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>
+ * 
+ * Util.cs - misc functions
+ *
+ */
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Runtime.InteropServices;
+using System.Reflection;
+
+namespace FreeSWITCH {
+    public static class FSUtil {
+        // IntPtr cPtr, bool futureUse
+        static readonly Type[] swigConstructorTypes = new [] { typeof(IntPtr), typeof(bool) };
+        public static T CreateSwigTypePointer<T>(this IntPtr cPtr) {
+            var ty = typeof(T);
+            var bflags = BindingFlags.Default | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance;
+            var cons = ty.GetConstructor(bflags, null, swigConstructorTypes, null);
+            if (cons == null) throw new ArgumentException(ty.Name + " constructor not found.");
+            return (T)cons.Invoke(new object[] { cPtr, false });
+        }
+    }
+}