Esempio n. 1
0
 /// <summary>
 /// Cancel the pickUp process
 /// If this cancellation is due to changes in _target, then its state is not changed
 /// otherwise is set back to Idle.
 /// </summary>
 /// <param name="changeTargetState"></param>
 /// <returns></returns>
 public bool Cancel(bool changeTargetState = true)
 {
     if (State != FunctionState.Idle)
     {
         State = FunctionState.Idle;
         if (_Target != null)
         {
             _Target.TlfPosStateChanged -= OnTargetCallStateChanged;
             if (_TargetUris != null)
             {
                 foreach (string uri in _TargetUris)
                 {
                     SipAgent.DestroyDialogSubscription(uri);
                 }
             }
             if ((changeTargetState) || (_Target.State == TlfState.InProcess))
             {
                 _Target.State = TlfState.Idle;
             }
             _Target     = null;
             _TargetUris = null;
         }
         if (_Captured != null)
         {
             _Captured = null;
         }
         foreach (int pos in _Ringing.Keys)
         {
             Top.Tlf[pos].State = TlfState.Idle;
         }
         _Ringing.Clear();
         return(true);
     }
     return(false);
 }
Esempio n. 2
0
 /// <summary>
 /// Finaliza la captura de la llamada enviando un Invite con replaces y los datos del dialogo
 /// Se cancela la suscripcion
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public bool Capture(int id)
 {
     if (State == FunctionState.Idle)
     {
         return(false);
     }
     if (id < Tlf.NumDestinations + Tlf.NumIaDestinations)
     {
         _Captured = Top.Tlf[id];
         DialogData dialog;
         if (_Ringing.TryGetValue(id, out dialog))
         {
             //TODO que pasa si falla una captura, intento las otras?
             if (_Captured.CallPickUp(dialog))
             {
                 _IgnoreNotify = true;
                 if (_TargetUris != null)
                 {
                     foreach (string uri in _TargetUris)
                     {
                         SipAgent.DestroyDialogSubscription(uri);
                     }
                 }
                 _Captured.TlfPosStateChanged += OnCapturedCallStateChanged;
                 return(true);
             }
             else
             {
                 State = FunctionState.Error;
                 _Logger.Warn(String.Format("TlfPickUp:Capture pickUp failed: {0}", _Captured.Literal));
                 return(true);
             }
         }
         else
         {
             _Logger.Error(String.Format("TlfPickUp:Capture not ringing in captured destination: {0}", _Captured.Literal));
         }
     }
     else
     {
         _Logger.Error(String.Format("TlfPickUp:Capture out of range: {0}", id));
     }
     return(false);
 }
Esempio n. 3
0
        /// <summary>
        /// Receive data of present dialogs.
        /// With early dialogs it signals ringing state
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="xml"></param>
        /// <param name="len"></param>
        private void OnNotifyDialog(object sender, string xml)
        {
            string source = null;

            if ((State != FunctionState.Executing) || _IgnoreNotify)
            {
                return;
            }
            List <DialogData> dialogs = NotifyDialogParse(xml, out source);

            if (_Target != null)
            {
                try
                {
                    //it's for me
                    IEnumerable <DialogData> earlyDialogs = dialogs.Where <DialogData>(x => x.state == "early");
                    IEnumerable <DialogData> otherDialogs = dialogs.Where <DialogData>(x => x.state != "early");
                    foreach (DialogData dialog in otherDialogs)
                    {
                        TlfPosition tlf = Top.Tlf.GetTlfPosition(dialog.remoteId, dialog.display);
                        if ((tlf != null) && _Ringing.ContainsKey(tlf.Pos))
                        {
                            _Ringing.Remove(tlf.Pos);
                            //tlf.State = TlfState.Idle;
                            tlf.State = tlf.OldState;
                        }
                    }
                    foreach (DialogData dialog in earlyDialogs)
                    {
                        TlfPosition tlf = Top.Tlf.GetTlfPosition(dialog.remoteId, dialog.display);
                        if (tlf != null)
                        {
                            //No se tienen en cuenta las capturadas que ya estaban en entrantes
                            //en el sistema, tampoco se da por fallida la captura
                            // ej: captura de una linea pto a punto que suena en todos los puestos
                            if (tlf.State != TlfState.In)
                            {
                                tlf.State = TlfState.In;
                                _Ringing.Add(tlf.Pos, dialog);
                            }
                        }
                        else
                        {
                            //No hay hueco para la entrante
                            State = FunctionState.Error;
                            foreach (int pos in _Ringing.Keys)
                            {
                                Top.Tlf[pos].State = TlfState.Idle;
                            }
                            _Ringing.Clear();
                            //_Target.State = TlfState.Idle;
                            if (_TargetUris != null)
                            {
                                foreach (string uri in _TargetUris)
                                {
                                    SipAgent.DestroyDialogSubscription(uri);
                                }
                            }
                            General.SafeLaunchEvent(PickUpError, this, Resources.CaptureErrorCapacity);
                            break;
                        }
                    }
                    //if (_Ringing.Count > 0)
                    //    _Target.State = TlfState.Idle;

                    //State = FunctionState.Idle;
                }
                catch (Exception exc)
                {
                    _Logger.Error("NotifyDialog exception {0}", exc.Message);
                }
            }
            else
            {
                _Logger.Error("NotifyDialog not expected from {0}", source);
            }
        }