[Freeswitch-svn] [commit] r9831 - freeswitch/trunk/src/mod/languages/mod_managed/managed

Freeswitch SVN michaelgg at freeswitch.org
Sat Oct 4 05:36:53 EDT 2008


Author: michaelgg
Date: Sat Oct  4 05:36:52 2008
New Revision: 9831

Modified:
   freeswitch/trunk/src/mod/languages/mod_managed/managed/Loader.cs
   freeswitch/trunk/src/mod/languages/mod_managed/managed/ManagedSession.cs
   freeswitch/trunk/src/mod/languages/mod_managed/managed/swig.cs

Log:
Tweak input/error handling

Modified: freeswitch/trunk/src/mod/languages/mod_managed/managed/Loader.cs
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_managed/managed/Loader.cs	(original)
+++ freeswitch/trunk/src/mod/languages/mod_managed/managed/Loader.cs	Sat Oct  4 05:36:52 2008
@@ -57,6 +57,14 @@
                 return false;
             }
 
+            AppDomain.CurrentDomain.AssemblyResolve += (_, rargs) => {
+                Log.WriteLine(LogLevel.Debug, "Trying to resolve assembly '{0}'.", rargs.Name);
+                if (rargs.Name == Assembly.GetExecutingAssembly().FullName) return Assembly.GetExecutingAssembly();
+                var path = Path.Combine(managedDir, rargs.Name + ".dll");
+                Log.WriteLine(LogLevel.Debug, "Resolving to: '" + path + "'.");
+                return File.Exists(path) ? Assembly.LoadFile(path) : null;
+            };
+
             // This is a simple one-time loader to get things in memory
             // Some day we should allow reloading of modules or something
             loadAssemblies(managedDir)
@@ -109,6 +117,7 @@
             {
                 string f = Path.Combine(managedDir, s);
                 try {
+                    Log.WriteLine(LogLevel.Debug, "Loading '{0}'.", f);
                     System.Reflection.Assembly.LoadFile(f);
                 }
                 catch (Exception ex) {

Modified: freeswitch/trunk/src/mod/languages/mod_managed/managed/ManagedSession.cs
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_managed/managed/ManagedSession.cs	(original)
+++ freeswitch/trunk/src/mod/languages/mod_managed/managed/ManagedSession.cs	Sat Oct  4 05:36:52 2008
@@ -76,7 +76,6 @@
             }
             catch (Exception ex) {
                 Log.WriteLine(LogLevel.Warning, "Exception in hangupCallback: {0}", ex.ToString());
-                throw;
             }
         }
 
@@ -86,35 +85,36 @@
 
         string inputCallback(IntPtr input, Native.switch_input_type_t inputType)
         {
-            switch (inputType) {
-                case FreeSWITCH.Native.switch_input_type_t.SWITCH_INPUT_TYPE_DTMF:
-                    using (var dtmf = new Native.switch_dtmf_t(input, false)) {
-                        return dtmfCallback(dtmf);
-                    }
-                case FreeSWITCH.Native.switch_input_type_t.SWITCH_INPUT_TYPE_EVENT:
-                    using (var swevt = new Native.switch_event(input, false)) {
-                        return eventCallback(swevt);
-                    }
-                default:
-                    return "";
+            try {
+                switch (inputType) {
+                    case FreeSWITCH.Native.switch_input_type_t.SWITCH_INPUT_TYPE_DTMF:
+                        using (var dtmf = new Native.switch_dtmf_t(input, false)) {
+                            return dtmfCallback(dtmf);
+                        }
+                    case FreeSWITCH.Native.switch_input_type_t.SWITCH_INPUT_TYPE_EVENT:
+                        using (var swevt = new Native.switch_event(input, false)) {
+                            return eventCallback(swevt);
+                        }
+                    default:
+                        return "";
+                }
+            } catch (Exception ex) {
+                Log.WriteLine(LogLevel.Error, "InputCallback threw exception: " + ex.ToString());
+                return "-ERR InputCallback Exception: " + ex.Message;
             }
         }
 
-        string dtmfCallback(Native.switch_dtmf_t dtmf)
-        {
+        string dtmfCallback(Native.switch_dtmf_t dtmf) {
             var f = DtmfReceivedFunction;
-            return f == null ?
-                "-ERR No DtmfReceivedFunction set." :
-                f(((char)(byte)dtmf.digit), TimeSpan.FromMilliseconds(dtmf.duration));
+            return f == null ? "" 
+                : f(((char)(byte)dtmf.digit), TimeSpan.FromMilliseconds(dtmf.duration));
         }
 
-        string eventCallback(Native.switch_event swevt)
-        {
+        string eventCallback(Native.switch_event swevt) {
             using (var evt = new FreeSWITCH.Native.Event(swevt, 0)) {
                 var f = EventReceivedFunction;
-                return f == null ?
-                    "-ERR No EventReceivedFunction set." :
-                    f(evt);
+                return f == null ? "" 
+                    : f(evt);
             }
         }
 

Modified: freeswitch/trunk/src/mod/languages/mod_managed/managed/swig.cs
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_managed/managed/swig.cs	(original)
+++ freeswitch/trunk/src/mod/languages/mod_managed/managed/swig.cs	Sat Oct  4 05:36:52 2008
@@ -2758,7 +2758,7 @@
     return ret;
   }
 
-  public static switch_status_t switch_ivr_detect_speech(SWIGTYPE_p_switch_core_session session, string mod_name, string grammar, string path, string dest, switch_asr_handle ah) {
+  public static switch_status_t oh(SWIGTYPE_p_switch_core_session session, string mod_name, string grammar, string path, string dest, switch_asr_handle ah) {
     switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_ivr_detect_speech(SWIGTYPE_p_switch_core_session.getCPtr(session), mod_name, grammar, path, dest, switch_asr_handle.getCPtr(ah));
     return ret;
   }



More information about the Freeswitch-svn mailing list