コード例 #1
0
        /// <summary>
        /// Performs originate. Returns ManagedSession on success, null on failure.
        /// onHangup is called as a state handler, after the channel is truly hungup (CS_REPORTING).
        /// </summary>
        public static ManagedSession OriginateHandleHangup(CoreSession aLegSession, string destination, TimeSpan timeout, Action <ManagedSession> onHangup)
        {
            var bleg = new ManagedSession();

            bleg.originate_ondestroy_delegate = bleg.originate_ondestroy_method;
            bleg.originate_onhangup_delegate  = CreateStateHandlerDelegate(bleg, sess_b => {
                if (onHangup != null)
                {
                    onHangup(sess_b);
                }
            });
            bleg.originate_table = new switch_state_handler_table();
            bleg.originate_table.on_reporting = WrapStateHandlerDelegate(bleg.originate_onhangup_delegate);
            bleg.originate_table.on_destroy   = WrapStateHandlerDelegate(bleg.originate_ondestroy_delegate);
            bleg.originate_table.flags        = (int)switch_state_handler_flag_t.SSH_FLAG_STICKY;
            var res = 0 == bleg.originate(aLegSession, destination, (int)timeout.TotalSeconds, bleg.originate_table);

            bleg.originate_keepalive_handle = GCHandle.Alloc(bleg, GCHandleType.Normal); // Prevent GC from eating the bleg
            if (res)
            {
                bleg.Initialize();
                return(bleg);
            }
            else
            {
                // Dispose to free the lock
                // The bleg lives on with its unmanaged memory freed
                // Until CS_DESTROY gets called
                bleg.Dispose();
                return(null);
            }
        }
コード例 #2
0
 public bool Execute(string args, IntPtr sessionHandle)
 {
     IncreaseUse();
     try {
         using (var session = new Native.ManagedSession(new Native.SWIGTYPE_p_switch_core_session(sessionHandle, false))) {
             session.Initialize();
             session.SetAutoHangup(false);
             try {
                 var plugin  = createPlugin();
                 var context = new AppContext(args, session);;
                 plugin.Run(context);
                 return(true);
             } catch (Exception ex) {
                 LogException("Run", Name, ex);
                 return(false);
             }
         }
     } finally {
         DecreaseUse();
     }
 }
コード例 #3
0
        /// <summary>
        /// Performs originate. Returns ManagedSession on success, null on failure.
        /// onHangup is called as a state handler, after the channel is truly hungup (CS_REPORTING).
        /// </summary>
        public static ManagedSession OriginateHandleHangup(CoreSession aLegSession, string destination, TimeSpan timeout, Action<ManagedSession> onHangup) {
            var bleg = new ManagedSession();

            bleg.originate_ondestroy_delegate = bleg.originate_ondestroy_method;
            bleg.originate_onhangup_delegate = CreateStateHandlerDelegate(sess_b => {
                if (onHangup != null) {
                    onHangup(sess_b);
                }
            });
            bleg.originate_table = new switch_state_handler_table();
            bleg.originate_table.on_reporting = WrapStateHandlerDelegate(bleg.originate_onhangup_delegate);
            bleg.originate_table.on_destroy = WrapStateHandlerDelegate(bleg.originate_ondestroy_delegate);
            bleg.originate_table.flags = (int)switch_state_handler_flag_t.SSH_FLAG_STICKY;
            var res = 0 == bleg.originate(aLegSession, destination, (int)timeout.TotalSeconds, bleg.originate_table);
            bleg.originate_keepalive_handle = GCHandle.Alloc(bleg, GCHandleType.Normal); // Prevent GC from eating the bleg
            if (res) {
                bleg.Initialize();
                return bleg;
            } else {
                // Dispose to free the lock
                // The bleg lives on with its unmanaged memory freed 
                // Until CS_DESTROY gets called
                bleg.Dispose(); 
                return null;
            }
        }