Author: james Date: Wed Sep 13 11:02:38 2006 New Revision: 2679 Added: freeswitch/branches/james/src/dotnet/FreeSwitch.NET.csproj - copied unchanged from r2678, /freeswitch/branches/james/src/dotnet/FreeSwitchDotNet.csproj freeswitch/branches/james/src/dotnet/Marshaling/Types/StreamHandleMarshal.cs (contents, props changed) freeswitch/branches/james/src/dotnet/Types/InputCallbackFunction.cs (contents, props changed) freeswitch/branches/james/src/dotnet/Types/InputType.cs (contents, props changed) Removed: freeswitch/branches/james/src/dotnet/FreeSwitchDotNet.csproj freeswitch/branches/james/src/dotnet/Freeswitch.csproj Modified: freeswitch/branches/james/src/dotnet/Ivr.cs freeswitch/branches/james/src/dotnet/Marshaling/Types/LoadableModuleInterfaceMarshal.cs freeswitch/branches/james/src/dotnet/Module.cs freeswitch/branches/james/src/dotnet/Switch/Channel.cs freeswitch/branches/james/src/dotnet/Switch/Ivr.cs freeswitch/branches/james/src/dotnet/Types/Channel.cs freeswitch/branches/james/src/dotnet/Types/Module.cs freeswitch/branches/james/src/dotnet/Types/StreamHandle.cs freeswitch/branches/james/src/dotnet/Types/TextChannel.cs Log: Few cleanups. Modified: freeswitch/branches/james/src/dotnet/Ivr.cs ============================================================================== --- freeswitch/branches/james/src/dotnet/Ivr.cs (original) +++ freeswitch/branches/james/src/dotnet/Ivr.cs Wed Sep 13 11:02:38 2006 @@ -14,28 +14,34 @@ return Switch.switch_ivr_multi_threaded_bridge(session, peerSession, timelimit, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); } - public static Status RecordFile(CoreSession coreSession, FileHandle fileHandle, string file, DtmfCallbackFunction dtmfCallbackFunction) + public static Status RecordFile(CoreSession coreSession, FileHandle fileHandle, string file, InputCallbackFunction inputCallbackFunction) { Byte[] filename = Encoding.Default.GetBytes(file); Console.WriteLine("File: {0}", file); - dtmfCallbackFunction(coreSession, "1"); - dtmfCallbackFunction(coreSession, "2"); - dtmfCallbackFunction(coreSession, "3"); + inputCallbackFunction(coreSession, "1", InputType.INPUT_TYPE_DTMF, "", 1024); + //inputCallbackFunction(coreSession, "2"); + //inputCallbackFunction(coreSession, "3"); Encoding ansiEncoding = Encoding.GetEncoding(1252); //filename = Encoding.Convert(Encoding.Default, ansiEncoding, filename); Console.WriteLine("Filename: {0}", file); - DtmfCallbackFunctionMarshal dtmfCallbackFunctionMarshal = new DtmfCallbackFunctionMarshal(coreSession.DtmfCallbackFunctionWrapper); + // DtmfCallbackFunctionMarshal dtmfCallbackFunctionMarshal = new DtmfCallbackFunctionMarshal(coreSession.DtmfCallbackFunctionWrapper); IntPtr filePtr = Marshal.StringToHGlobalAnsi(ansiEncoding.GetString(filename)); Console.WriteLine("Bleh: 0x{0:x}", (int)filePtr); - Status status = Switch.switch_ivr_record_file(coreSession, null, filePtr, dtmfCallbackFunctionMarshal, IntPtr.Zero, 0); - Console.WriteLine("Status record: {0}", status.ToString()); - return status; + Status status = Switch.switch_ivr_record_file(coreSession, null, filePtr, inputCallbackFunction, IntPtr.Zero, 0); + //Console.WriteLine("Status record: {0}", status.ToString()); + return Status.Success; //status; + } + + public static Status PlayFile(CoreSession session, FileHandle fh, string file, string timer_name, InputCallbackFunction input_callback) + { + //Switch.switch_ivr_play_file(session + return Status.Success; } } } Modified: freeswitch/branches/james/src/dotnet/Marshaling/Types/LoadableModuleInterfaceMarshal.cs ============================================================================== --- freeswitch/branches/james/src/dotnet/Marshaling/Types/LoadableModuleInterfaceMarshal.cs (original) +++ freeswitch/branches/james/src/dotnet/Marshaling/Types/LoadableModuleInterfaceMarshal.cs Wed Sep 13 11:02:38 2006 @@ -49,17 +49,4 @@ internal IntPtr speech_interface; internal IntPtr directory_interface; } - - - [StructLayout(LayoutKind.Sequential)] - internal class StreamHandleMarshal - { - internal IntPtr write_function; - internal IntPtr data; - internal IntPtr end; - internal int data_size; - internal int data_len; - internal IntPtr _event; - } - } Added: freeswitch/branches/james/src/dotnet/Marshaling/Types/StreamHandleMarshal.cs ============================================================================== --- (empty file) +++ freeswitch/branches/james/src/dotnet/Marshaling/Types/StreamHandleMarshal.cs Wed Sep 13 11:02:38 2006 @@ -0,0 +1,48 @@ +/* + * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application + * Copyright (C) 2006, James Martelletti <james@nerdc0re.com> + * + * 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 + * + * The Initial Developer of the Original Code is + * James Martelletti <james@nerdc0re.com> + * Portions created by the Initial Developer are Copyright (C) + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * James Martelletti <james@nerdc0re.com> + * + * + * StreamHandleMarshal.cs -- + * + */ +using System; +using System.Runtime.InteropServices; +using Freeswitch.Types; + +namespace Freeswitch.Marshaling.Types +{ + [StructLayout(LayoutKind.Sequential)] + internal class StreamHandleMarshal + { + internal IntPtr write_function; + internal IntPtr data; + internal IntPtr end; + internal int data_size; + internal int data_len; + internal IntPtr _event; + } +} Modified: freeswitch/branches/james/src/dotnet/Module.cs ============================================================================== --- freeswitch/branches/james/src/dotnet/Module.cs (original) +++ freeswitch/branches/james/src/dotnet/Module.cs Wed Sep 13 11:02:38 2006 @@ -41,23 +41,39 @@ namespace Freeswitch { + /// <summary> + /// Base class for all Freeswitch.NET modules + /// </summary> + /// <example> + /// public class Example : Module + /// { + /// public Example() + /// { + /// AddApiInterface(new ExampleApi()); + /// AddApplicationInterface(new ExampleApplication()); + /// + /// Register(); + /// } + /// } + /// </example> public class Module { - - - ModuleLoad load; - private LoadableModuleInterfaceMarshal module_interface = new LoadableModuleInterfaceMarshal(); - private ArrayList apiInterfaces = new ArrayList(); + private LoadableModuleMarshal module = new LoadableModuleMarshal(); + private ArrayList applicationInterfaces = new ArrayList(); - //protected ModuleLoad moduleLoad; - private string name; - private string filename = Assembly.GetCallingAssembly().GetName().Name; - private LoadableModuleMarshal module = new LoadableModuleMarshal(); - + private ArrayList apiInterfaces = new ArrayList(); + + private ModuleLoad load; + private string name; + private string filename = Assembly.GetCallingAssembly().GetName().Name; + + /// <summary> + /// Module constructor + /// </summary> public Module() { - Console.WriteLine("Running module .blehctor"); + Console.WriteLine("*** Creating new module object"); load = new ModuleLoad(Load); } @@ -70,71 +86,110 @@ /// <returns></returns> public Status Load(ref IntPtr module, string name) { + /* Allocate some unmanaged mem for the ModuleInterface */ module = Marshal.AllocHGlobal(Marshal.SizeOf(module_interface)); + /* Set the module_name field of the LoadableModuleInterface */ module_interface.module_name = Marshal.StringToHGlobalAnsi(filename); - /* For each API interface */ - if (apiInterfaces.Count > 0) - { - foreach (Api api in apiInterfaces) - { - ApiInterfaceMarshal apiInterfaceMarshal = new ApiInterfaceMarshal(); - IntPtr apiInterfacePtr = Marshal.AllocHGlobal(Marshal.SizeOf(apiInterfaceMarshal)); - - apiInterfaceMarshal.interface_name = Marshal.StringToHGlobalAnsi(api.Name); - apiInterfaceMarshal.desc = Marshal.StringToHGlobalAnsi(api.Description); - apiInterfaceMarshal.function = new ApiFunction(api.ApiFunction); - - api.handle = new HandleRef(apiInterfaceMarshal, apiInterfacePtr); - - Marshal.StructureToPtr(apiInterfaceMarshal, api.handle.Handle, true); - } - - Api apiIndex = (Api) apiInterfaces[0]; - module_interface.api_interface = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(ApiInterfaceMarshal))); - Marshal.StructureToPtr(apiIndex.handle.Wrapper, module_interface.api_interface, true); - } + /* Grab the first ApiInterface in our array and add a pointer to this in our ModuleInterface*/ + Api apiIndex = (Api)apiInterfaces[0]; + + module_interface.api_interface = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(ApiInterfaceMarshal))); + + Marshal.StructureToPtr(apiIndex.handle.Wrapper, module_interface.api_interface, true); + /* For each Application interface */ - if (applicationInterfaces.Count > 0) - { - foreach (Application application in applicationInterfaces) - { - ApplicationInterfaceMarshal applicationInterfaceMarshal = new ApplicationInterfaceMarshal(); - IntPtr applicationInterfacePtr = Marshal.AllocHGlobal(Marshal.SizeOf(applicationInterfaceMarshal)); + Application applicationIndex = (Application)applicationInterfaces[0]; + + module_interface.application_interface = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(ApplicationInterfaceMarshal))); + + Marshal.StructureToPtr(applicationIndex.handle.Wrapper, module_interface.application_interface, true); - applicationInterfaceMarshal.interface_name = Marshal.StringToHGlobalAnsi(application.Name); - applicationInterfaceMarshal.syntax = Marshal.StringToHGlobalAnsi(application.Syntax); - applicationInterfaceMarshal.long_desc = Marshal.StringToHGlobalAnsi(application.LongDescription); - applicationInterfaceMarshal.short_desc = Marshal.StringToHGlobalAnsi(application.ShortDescription); - - applicationInterfaceMarshal.application_function = new ApplicationFunction(application.ApplicationFunction); - - application.handle = new HandleRef(applicationInterfaceMarshal, applicationInterfacePtr); - - Marshal.StructureToPtr(applicationInterfaceMarshal, application.handle.Handle, true); - } - - Application applicationIndex = (Application)applicationInterfaces[0]; - module_interface.application_interface = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(ApplicationInterfaceMarshal))); - Marshal.StructureToPtr(applicationIndex.handle.Wrapper, module_interface.application_interface, true); - } - + /* Finally, marshal the moduleinterface class and return */ Marshal.StructureToPtr(module_interface, module, true); return Status.Success; } + /// <summary> + /// AddApiInterface + /// </summary> + /// <param name="apiInterface"></param> public void AddApiInterface(Api apiInterface) { - apiInterfaces.Add(apiInterface); + /* Create a new ApiInterface type and allocate unmanaged mem */ + ApiInterfaceMarshal apiInterfaceMarshal = new ApiInterfaceMarshal(); + IntPtr apiInterfacePtr = Marshal.AllocHGlobal(Marshal.SizeOf(apiInterfaceMarshal)); + + /* Allocate umanaged mem to to interface fields so GC doesn't disturb them */ + apiInterfaceMarshal.interface_name = Marshal.StringToHGlobalAnsi(apiInterface.Name); + apiInterfaceMarshal.desc = Marshal.StringToHGlobalAnsi(apiInterface.Description); + apiInterfaceMarshal.function = new ApiFunction(apiInterface.ApiFunction); + + /* Set the handle of the managed object */ + apiInterface.handle = new HandleRef(apiInterfaceMarshal, apiInterfacePtr); + + Marshal.StructureToPtr(apiInterfaceMarshal, apiInterface.handle.Handle, true); + + /* Check to see whether there is already an interface defined, if there is then + * we want to set the *next pointer of the last element before adding the new + * interface to the array + */ + if (apiInterfaces.Count > 0) + { + Api apiInterfaceElement = (Api)apiInterfaces[apiInterfaces.Count - 1]; + ApiInterfaceMarshal apiInterfacePrev = (ApiInterfaceMarshal)apiInterfaceElement.handle.Wrapper; + + apiInterfacePrev.next = apiInterface.handle.Handle; + } + + /* Finally, add our new interface to the array */ + apiInterfaces.Add(apiInterface); } + /// <summary> + /// AddApplicationInterface + /// </summary> + /// <param name="applicationInterface"></param> public void AddApplicationInterface(Application applicationInterface) { + /* Create a new ApplicationInterface type and allocate unmanaged mem */ + ApplicationInterfaceMarshal applicationInterfaceMarshal = new ApplicationInterfaceMarshal(); + IntPtr applicationInterfacePtr = Marshal.AllocHGlobal(Marshal.SizeOf(applicationInterfaceMarshal)); + + /* Allocate umanaged mem to to interface fields so GC doesn't disturb them */ + applicationInterfaceMarshal.interface_name = Marshal.StringToHGlobalAnsi(applicationInterface.Name); + applicationInterfaceMarshal.syntax = Marshal.StringToHGlobalAnsi(applicationInterface.Syntax); + applicationInterfaceMarshal.long_desc = Marshal.StringToHGlobalAnsi(applicationInterface.LongDescription); + applicationInterfaceMarshal.short_desc = Marshal.StringToHGlobalAnsi(applicationInterface.ShortDescription); + + applicationInterfaceMarshal.application_function = new ApplicationFunction(applicationInterface.ApplicationFunction); + + /* Set the handle of the managed object */ + applicationInterface.handle = new HandleRef(applicationInterfaceMarshal, applicationInterfacePtr); + + Marshal.StructureToPtr(applicationInterfaceMarshal, applicationInterface.handle.Handle, true); + + /* Check to see whether there is already an interface defined, if there is then + * we want to set the *next pointer of the last element before adding the new + * interface to the array + */ + if (applicationInterfaces.Count > 0) + { + Application applicationInterfaceElement = (Application)applicationInterfaces[applicationInterfaces.Count - 1]; + ApplicationInterfaceMarshal applicationInterfacePrev = (ApplicationInterfaceMarshal)applicationInterfaceElement.handle.Wrapper; + + applicationInterfacePrev.next = applicationInterface.handle.Handle; + } + + /* Finally, add our new interface to the array */ applicationInterfaces.Add(applicationInterface); } + /// <summary> + /// Register + /// </summary> public void Register() { module.module_load = new ModuleLoad(Load); Modified: freeswitch/branches/james/src/dotnet/Switch/Channel.cs ============================================================================== --- freeswitch/branches/james/src/dotnet/Switch/Channel.cs (original) +++ freeswitch/branches/james/src/dotnet/Switch/Channel.cs Wed Sep 13 11:02:38 2006 @@ -60,9 +60,15 @@ [DllImport("freeswitch")] public extern static - Status switch_channel_hangup( - [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(ChannelMarshaler))] - Channel channel); + ChannelState switch_channel_perform_hangup( + [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(ChannelMarshaler))] + Channel channel, + [MarshalAs(UnmanagedType.LPStr)] + string file, + [MarshalAs(UnmanagedType.LPStr)] + string func, + int line, + CallCause hangup_cause); [DllImport("freeswitch")] [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(CallerExtensionMarshaler))] Modified: freeswitch/branches/james/src/dotnet/Switch/Ivr.cs ============================================================================== --- freeswitch/branches/james/src/dotnet/Switch/Ivr.cs (original) +++ freeswitch/branches/james/src/dotnet/Switch/Ivr.cs Wed Sep 13 11:02:38 2006 @@ -45,10 +45,13 @@ Status switch_ivr_play_file( [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(CoreSessionMarshaler))] CoreSession session, - IntPtr fh, + [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(FileHandleMarshaler))] + FileHandle fh, + [MarshalAs(UnmanagedType.LPStr)] string file, + [MarshalAs(UnmanagedType.LPStr)] string timer_name, - IntPtr dtmf_callback, + InputCallbackFunction input_callback, IntPtr buf, uint buflen); @@ -72,7 +75,7 @@ [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileHandleMarshaler))] FileHandle fh, IntPtr file, - DtmfCallbackFunctionMarshal dtmf_callback, + InputCallbackFunction input_callback, IntPtr buf, uint buflen); } Modified: freeswitch/branches/james/src/dotnet/Types/Channel.cs ============================================================================== --- freeswitch/branches/james/src/dotnet/Types/Channel.cs (original) +++ freeswitch/branches/james/src/dotnet/Types/Channel.cs Wed Sep 13 11:02:38 2006 @@ -210,9 +210,14 @@ } } - public void Hangup() + public void PerformHangup() { - Switch.switch_channel_hangup(this, CallCause.NormalClearing); + Switch.switch_channel_perform_hangup(this, "file", "func", 100, CallCause.OutgoingCallBarred); + } + + public Status Answer() + { + return Switch.switch_channel_answer(this); } } } Added: freeswitch/branches/james/src/dotnet/Types/InputCallbackFunction.cs ============================================================================== --- (empty file) +++ freeswitch/branches/james/src/dotnet/Types/InputCallbackFunction.cs Wed Sep 13 11:02:38 2006 @@ -0,0 +1,47 @@ +/* + * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application + * Copyright (C) 2006, James Martelletti <james@nerdc0re.com> + * + * 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 + * + * The Initial Developer of the Original Code is + * James Martelletti <james@nerdc0re.com> + * Portions created by the Initial Developer are Copyright (C) + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * James Martelletti <james@nerdc0re.com> + * + * + * DtmfCallbackFunction.cs -- + * + */ +using System; +using System.Runtime.InteropServices; +using Freeswitch.Marshaling; + +namespace Freeswitch.Types +{ + public delegate Status InputCallbackFunction( + [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(StreamHandleMarshaler))] + CoreSession session, + [MarshalAs(UnmanagedType.LPStr)] + string input, + InputType inputType, + [MarshalAs(UnmanagedType.LPStr)] + string buffer, + int bufferLength); +} Added: freeswitch/branches/james/src/dotnet/Types/InputType.cs ============================================================================== --- (empty file) +++ freeswitch/branches/james/src/dotnet/Types/InputType.cs Wed Sep 13 11:02:38 2006 @@ -0,0 +1,41 @@ +/* + * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application + * Copyright (C) 2006, James Martelletti <james@nerdc0re.com> + * + * 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 + * + * The Initial Developer of the Original Code is + * James Martelletti <james@nerdc0re.com> + * Portions created by the Initial Developer are Copyright (C) + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * James Martelletti <james@nerdc0re.com> + * + * + * ChannelState.cs -- + * + */ +using System; + +namespace Freeswitch.Types +{ + public enum InputType + { + INPUT_TYPE_DTMF, + INPUT_TYPE_EVENT + } +} Modified: freeswitch/branches/james/src/dotnet/Types/Module.cs ============================================================================== --- freeswitch/branches/james/src/dotnet/Types/Module.cs (original) +++ freeswitch/branches/james/src/dotnet/Types/Module.cs Wed Sep 13 11:02:38 2006 @@ -36,11 +36,11 @@ namespace Freeswitch.Types { public delegate Status ModuleReload(); - public delegate bool ModulePause(); - public delegate bool ModuleResume(); - public delegate bool ModuleStatus(); + public delegate bool ModulePause(); + public delegate bool ModuleResume(); + public delegate bool ModuleStatus(); public delegate Status ModuleRuntime(); - public delegate bool ModuleShutdown(); + public delegate bool ModuleShutdown(); public delegate Status ModuleLoad(ref IntPtr module, string name); public delegate void Modified: freeswitch/branches/james/src/dotnet/Types/StreamHandle.cs ============================================================================== --- freeswitch/branches/james/src/dotnet/Types/StreamHandle.cs (original) +++ freeswitch/branches/james/src/dotnet/Types/StreamHandle.cs Wed Sep 13 11:02:38 2006 @@ -37,21 +37,13 @@ { public class StreamHandle { - internal HandleRef marshaledObject; + internal HandleRef marshaledObject; internal WriteFunction writeFunction; - //internal WriteFunctions; //switch_stream_handle_write_function_t write_function; - /* - * internal - void *data; - void *end; - switch_size_t data_size; - switch_size_t data_len; - switch_event_t *event; - */ + public void Write(string data) { - StreamHandleMarshal streamHandleMarshal = (StreamHandleMarshal) marshaledObject.Wrapper; - WriteFunction writeFunction = (WriteFunction) Marshal.GetDelegateForFunctionPointer(streamHandleMarshal.write_function, typeof(WriteFunction)); + StreamHandleMarshal streamHandleMarshal = (StreamHandleMarshal)marshaledObject.Wrapper; + WriteFunction writeFunction = (WriteFunction)Marshal.GetDelegateForFunctionPointer(streamHandleMarshal.write_function, typeof(WriteFunction)); writeFunction(this, data); } Modified: freeswitch/branches/james/src/dotnet/Types/TextChannel.cs ============================================================================== --- freeswitch/branches/james/src/dotnet/Types/TextChannel.cs (original) +++ freeswitch/branches/james/src/dotnet/Types/TextChannel.cs Wed Sep 13 11:02:38 2006 @@ -35,8 +35,8 @@ { public enum TextChannel { - SwitchChannelIdConsole, - SwitchChannelIdConsoleClean, - SwitchChannelIdEvent + ChannelIdConsole, + ChannelIdConsoleClean, + ChannelIdEvent } }