Example #1
0
 private static void RemoveStopTicket(ITvCardHandler tvcard, ICardStopReservationTicket ticket, bool ticketFound)
 {
     if (ticketFound)
     {
         lock (tvcard.Tuner.CardReservationsLock)
         {
             Log.Debug("CardReservation.RemoveStopTicket: removed STOP reservation with id={0}", ticket.Id);
             tvcard.Tuner.ReservationsForStop.Remove(ticket);
             ResetCardStopStateToIdle(tvcard);
         }
     }
 }
Example #2
0
        private static ICardStopReservationTicket RequestCardStopReservation(ITvCardHandler tvcard, IUser user)
        {
            ICardStopReservationTicket cardStopReservation = null;

            CardTuneState cardTuneState;
            bool          hasMoreStopReservations;

            lock (tvcard.Tuner.CardReservationsLock)
            {
                bool isCardIdle          = (tvcard.Tuner.CardTuneState == CardTuneState.Idle);
                bool isCardTuned         = (tvcard.Tuner.CardTuneState == CardTuneState.Tuned);
                bool isCardTunePending   = (tvcard.Tuner.CardTuneState == CardTuneState.TunePending);
                bool isCardTuneCancelled = (tvcard.Tuner.CardTuneState == CardTuneState.TuneCancelled);

                bool isCardStopIdle = (tvcard.Tuner.CardStopState == CardStopState.Idle);
                bool isCardStopped  = (tvcard.Tuner.CardStopState == CardStopState.Stopped);

                bool isCardAvail = (isCardIdle || isCardTuned || isCardTunePending || isCardTuneCancelled) && (isCardStopped || isCardStopIdle);

                if (isCardAvail)
                {
                    tvcard.Tuner.CardStopState = CardStopState.StopPending;
                    cardStopReservation        = new CardStopReservationTicket();
                    tvcard.Tuner.ReservationsForStop.Add(cardStopReservation);
                }

                cardTuneState           = tvcard.Tuner.CardTuneState;
                hasMoreStopReservations = (tvcard.Tuner.ReservationsForStop.Count > 0);
            }

            if (cardStopReservation != null)
            {
                Log.Debug("CardTuner.RequestCardStopReservation: placed reservation with id={0}, user={1}", cardStopReservation.Id, user.Name);
            }
            else
            {
                if (hasMoreStopReservations)
                {
                    Log.Debug(
                        "CardTuner.RequestCardStopReservation: failed reservation user={0}, cardstate={1}, res id blocking={2}",
                        user.Name, cardTuneState, "n/a");
                }
                else
                {
                    Log.Debug(
                        "CardTuner.RequestCardStopReservation: failed reservation user={0}, cardstate={1}",
                        user.Name, cardTuneState);
                }
            }

            return(cardStopReservation);
        }
Example #3
0
        public static ICardStopReservationTicket RequestAndWaitForCardStopReservation(ITvCardHandler tvcard, IUser user)
        {
            ICardStopReservationTicket ticket = null;
            int tries = 0;

            while (ticket == null && tries < 10)
            {
                ticket = RequestCardStopReservation(tvcard, user);
                Thread.Sleep(100);
                tries++;
            }

            return(ticket);
        }
Example #4
0
        public static bool Stop(ITvCardHandler tvcard, ref IUser user, ICardStopReservationTicket ticket)
        {
            bool isStopPending;
            bool ticketFound;
            bool result = false;

            lock (tvcard.Tuner.CardReservationsLock)
            {
                isStopPending = (tvcard.Tuner.CardStopState == CardStopState.StopPending);
                ticketFound   = (tvcard.Tuner.ReservationsForStop.Contains(ticket));
                if (isStopPending)
                {
                    Log.Debug("CardTuner.Stop: ticket id={0}, found={1}", ticket.Id, ticketFound);
                    if (ticketFound)
                    {
                        tvcard.Tuner.CardStopState = CardStopState.Stopping;
                    }
                    else
                    {
                        Log.Debug("ticket not found!");
                    }
                }
            }

            try
            {
                if (isStopPending && ticketFound)
                {
                    Log.Info("Stop cardid={0}, ticket={1}, tunestate={2}, stopstate={3}", tvcard.DataBaseCard.IdCard, ticket.Id, tvcard.Tuner.CardTuneState, tvcard.Tuner.CardStopState);

                    result = tvcard.TimeShifter.Stop(ref user);

                    lock (tvcard.Tuner.CardReservationsLock)
                    {
                        if (result)
                        {
                            tvcard.Tuner.CardStopState = CardStopState.Stopped;
                            ResetCardTuneStateToIdle(tvcard);
                        }
                        else
                        {
                            if (tvcard.Tuner.ReservationsForStop.Count > 1)
                            {
                                tvcard.Tuner.CardStopState = CardStopState.StopPending;
                            }
                            else
                            {
                                tvcard.Tuner.CardStopState = CardStopState.StopFailed;
                            }
                        }
                    }
                }
                else // state is not tuning, some other card tune session is busy.
                {
                }
            }
            finally
            {
                RemoveStopTicket(tvcard, ticket, ticketFound);
            }

            return(result);
        }
    public static bool Stop(ITvCardHandler tvcard, ref IUser user, ICardStopReservationTicket ticket)
    {
      bool isStopPending;
      bool ticketFound;
      bool result = false;

      lock (tvcard.Tuner.CardReservationsLock)
      {        
        isStopPending = (tvcard.Tuner.CardStopState == CardStopState.StopPending);
        ticketFound = (tvcard.Tuner.ReservationsForStop.Contains(ticket));
        if (isStopPending)
        {
          Log.Debug("CardTuner.Stop: ticket id={0}, found={1}", ticket.Id, ticketFound);
          if (ticketFound)
          {
            tvcard.Tuner.CardStopState = CardStopState.Stopping;            
          }
          else
          {
            Log.Debug("ticket not found!");
          }
        }
      }

      try
      {
        if (isStopPending && ticketFound)
        {
          Log.Info("Stop cardid={0}, ticket={1}, tunestate={2}, stopstate={3}", tvcard.DataBaseCard.IdCard, ticket.Id, tvcard.Tuner.CardTuneState, tvcard.Tuner.CardStopState);

          result = tvcard.TimeShifter.Stop(ref user);

          lock (tvcard.Tuner.CardReservationsLock)
          {
            if (result)
            {              
              tvcard.Tuner.CardStopState = CardStopState.Stopped;              
              ResetCardTuneStateToIdle(tvcard);
            }
            else
            {              
              if (tvcard.Tuner.ReservationsForStop.Count > 1)
              {
                tvcard.Tuner.CardStopState = CardStopState.StopPending;                
              }
              else
              {
                tvcard.Tuner.CardStopState = CardStopState.StopFailed;                
              }
              
            }            
          }
        }
        else // state is not tuning, some other card tune session is busy.
        {
        }
      }
      finally
      {
        RemoveStopTicket(tvcard, ticket, ticketFound);
      }

      return result;
    }
 private static void RemoveStopTicket(ITvCardHandler tvcard, ICardStopReservationTicket ticket, bool ticketFound)
 {
   if (ticketFound)
   {
     lock (tvcard.Tuner.CardReservationsLock)
     {
       Log.Debug("CardReservation.RemoveStopTicket: removed STOP reservation with id={0}", ticket.Id);
       tvcard.Tuner.ReservationsForStop.Remove(ticket);
       ResetCardStopStateToIdle(tvcard);          
     }
   }
 }