Ejemplo n.º 1
0
 protected CardAllocationBase(TvBusinessLayer businessLayer, TVController controller)
 {      
   _businessLayer = businessLayer;
   _controller = controller;
   //_tuningChannelMapping = new Dictionary<int, IList<IChannel>>();
   //_channelMapping = new Dictionary<int, bool>();
 }
    public ControllerActiveStandbyHandler(IController controller)
    {
      // Save controller
      _controller = controller as TVController;

      // Register handler for TV server events
      _controller.OnTvServerEvent += OnTvServerEvent;
    }
    public ScheduledRecordingsWakeupHandler(IController controller)
    {
      // Save controller
      _controller = controller as TVController;

      // Register handler for TV server events
      _controller.OnTvServerEvent += OnTvServerEvent;
    }
Ejemplo n.º 4
0
    /// <summary>
    /// Constructor
    /// </summary>
    /// <param name="controller">instance of a TVController</param>
    /// <param name="card">The card</param>
    public EpgCard(TVController controller, Card card)
    {
      _card = card;
      _user = new User("epg", false, -1);

      _tvController = controller;
      _grabStartTime = DateTime.MinValue;
      _state = EpgState.Idle;

      _epgTimer.Interval = 30000;
      _epgTimer.Elapsed += _epgTimer_Elapsed;
      _eventHandler = controller_OnTvServerEvent;
      _dbUpdater = new EpgDBUpdater(_tvController, "IdleEpgGrabber", true);
    }
 public AdvancedCardAllocationTicket(TvBusinessLayer businessLayer, TVController controller, IEnumerable<ICardTuneReservationTicket> tickets)
   : base(businessLayer, controller)
 {
   _tickets = new Dictionary<int, ICardTuneReservationTicket>();
   foreach (ICardTuneReservationTicket cardTuneReservationTicket in tickets)
   {
     if (cardTuneReservationTicket != null)
     {
       int idCard = cardTuneReservationTicket.CardId;
       if (!_tickets.ContainsKey(idCard))
       {
         _tickets.Add(idCard, cardTuneReservationTicket);
       }
     }
   }
 }   
Ejemplo n.º 6
0
 public void Start(IController controller)
 {
   _tvController = new TVController();
   StartStopTimer(true);
 }
 public ControllerActiveHandler(IController controller)
 {
   _controller = controller as TVController;
 }
Ejemplo n.º 8
0
    private void DoSetChannelStates(Dictionary<int, ITvCardHandler> cards, ICollection<Channel> channels,
                                    bool checkTransponders, IList<IUser> allUsers, TVController tvController)
    {
      Stopwatch stopwatch = Stopwatch.StartNew();
      try
      {
        //construct list of all cards we can use to tune to the new channel
        Log.Debug("Controller: DoSetChannelStates for {0} channels", channels.Count);

        if (allUsers == null || allUsers.Count == 0)
        {
          return; // no users, no point in continuing.
        }

        TvBusinessLayer layer = new TvBusinessLayer();

        Dictionary<int, ChannelState> TSandRecStates = null;

        Dictionary<int, ITvCardHandler>.ValueCollection cardHandlers = cards.Values;

        IDictionary<int, IList<int>> channelMapping = GetChannelMapping();
        IDictionary<int, IList<IChannel>> tuningChannelMapping = GetTuningChannels();
        foreach (Channel ch in channels)
        {
          if (!ch.VisibleInGuide)
          {
            UpdateChannelStateUsers(allUsers, ChannelState.nottunable, ch.IdChannel);
            continue;
          }

          //get the tuning details for the channel
          IList<IChannel> tuningDetails;
          tuningChannelMapping.TryGetValue(ch.IdChannel, out tuningDetails);
          bool isValidTuningDetails = IsValidTuningDetails(tuningDetails);
          if (!isValidTuningDetails)
          {
            UpdateChannelStateUsers(allUsers, ChannelState.nottunable, ch.IdChannel);
            continue;
          }

          foreach (IChannel tuningDetail in tuningDetails)
          {
            foreach (ITvCardHandler cardHandler in cardHandlers)
            {
              int cardId = cardHandler.DataBaseCard.IdCard;

              //check if card is enabled
              if (!cardHandler.DataBaseCard.Enabled)
              {
                //not enabled, so skip the card
                //Log.Info("Controller:    card:{0} type:{1} is disabled", cardId, tvcard.Type);
                UpdateChannelStateUsers(allUsers, ChannelState.nottunable, ch.IdChannel);
                continue;
              }

              if (!cardHandler.Tuner.CanTune(tuningDetail))
              {
                //card cannot tune to this channel, so skip it
                //Log.Info("Controller:    card:{0} type:{1} cannot tune to channel", cardId, tvcard.Type);
                UpdateChannelStateUsers(allUsers, ChannelState.nottunable, ch.IdChannel);
                continue;
              }

              //check if channel is mapped to this card and that the mapping is not for "Epg Only"
              bool isChannelMappedToCard = IsChannelMappedToCard(ch, cardHandler.DataBaseCard, channelMapping);
              if (!isChannelMappedToCard)
              {
                UpdateChannelStateUsers(allUsers, ChannelState.nottunable, ch.IdChannel);
                continue;
              }

              if (!tuningDetail.FreeToAir && !cardHandler.DataBaseCard.CAM)
              {
                UpdateChannelStateUsers(allUsers, ChannelState.nottunable, ch.IdChannel);
                continue;
              }

              //ok card could be used to tune to this channel
              //now we check if its free...                              
              int decryptLimit = cardHandler.DataBaseCard.DecryptLimit;
              CheckTransponderAllUsers(ch, allUsers, cards, cardHandler, decryptLimit, cardId, tuningDetail,
                                       checkTransponders);
            } //while card end
          } //foreach tuningdetail end              

          //only query once
          if (TSandRecStates == null)
          {
            Stopwatch stopwatchTsRec = Stopwatch.StartNew();
            TSandRecStates = tvController.GetAllTimeshiftingAndRecordingChannels();
            stopwatchTsRec.Stop();
            Log.Info("ChannelStates.GetAllTimeshiftingAndRecordingChannels took {0} msec",
                     stopwatchTsRec.ElapsedMilliseconds);
          }
          UpdateRecOrTSChannelStateForUsers(ch, allUsers, TSandRecStates);
        }

        RemoveAllTunableChannelStates(allUsers);
      }
      catch (InvalidOperationException tex)
      {
        Log.Error("ChannelState: Possible race condition occured setting channel states - {0}", tex.StackTrace);
      }
      catch (Exception ex)
      {
        Log.Error("ChannelState: An unknown error occured while setting channel states - {0}\n{1}", ex.Message,
                  ex.StackTrace);
      }
      finally
      {
        stopwatch.Stop();
        Log.Info("ChannelStates.DoSetChannelStates took {0} msec", stopwatch.ElapsedMilliseconds);
      }
    }
Ejemplo n.º 9
0
    public void OnStop()
    {
      if (!_started)
        return;

      Log.WriteFile("TV Service: stopping");

      // Reset "Global\MPTVServiceInitializedEvent"
      if (_InitializedEvent != null)
      {
        _InitializedEvent.Reset();
      }

      // Stop the plugins
      StopPlugins();

      // Stop remoting and deinit the TvController
      StopRemoting();
      RemoteControl.Clear();
      if (_controller != null)
      {
        _controller.DeInit();
        _controller = null;
      }

      // Terminate the power event thread
      if (_powerEventThreadId != 0)
      {
        Log.Debug("TV Service: OnStop asking PowerEventThread to exit");
        PostThreadMessage(_powerEventThreadId, WM_QUIT, IntPtr.Zero, IntPtr.Zero);
        _powerEventThread.Join();
      }
      _powerEventThreadId = 0;
      _powerEventThread = null;

      _started = false;
      Log.WriteFile("TV Service: stopped");
    }
Ejemplo n.º 10
0
    public void OnStop()
    {
      if (!Started)
        return;
      Log.WriteFile("TV Service: stopping");

      if (_InitializedEvent != null)
      {
        _InitializedEvent.Reset();
      }
      StopRemoting();
      RemoteControl.Clear();
      if (_controller != null)
      {
        _controller.DeInit();
        _controller = null;
      }

      StopPlugins();
      if (_powerEventThreadId != 0)
      {
        Log.Debug("TV Service: OnStop asking PowerEventThread to exit");
        PostThreadMessage(_powerEventThreadId, WM_QUIT, IntPtr.Zero, IntPtr.Zero);
        _powerEventThread.Join();
      }
      _powerEventThreadId = 0;
      _powerEventThread = null;
      _started = false;
      Log.WriteFile("TV Service: stopped");
    }
Ejemplo n.º 11
0
 public ChannelStates(TvBusinessLayer businessLayer, TVController controller)
   : base(businessLayer, controller)
 {
   LogEnabled = false;
 }
 protected CardAllocationBase(TvBusinessLayer businessLayer, TVController controller)
 {
   _businessLayer = businessLayer;
   Controller = controller;
 }
Ejemplo n.º 13
0
 public CardReservationRec(TVController tvController) : base(tvController) { }
Ejemplo n.º 14
0
    public static IDictionary<CardDetail, ICardTuneReservationTicket> RequestCardReservations(IUser user, IEnumerable<CardDetail> availCardsForReservation, TVController tvController, ICardReservation cardResImpl, IEnumerable<CardDetail> ignoreCards, int idChannel)
    {
      IDictionary<CardDetail, ICardTuneReservationTicket> tickets = new Dictionary<CardDetail, ICardTuneReservationTicket>();
      ICollection<int> cardIds = new HashSet<int>();

      foreach (CardDetail cardDetail in availCardsForReservation)
      {
        ICardTuneReservationTicket ticket = null;
        int idCard = cardDetail.Card.IdCard;
        bool cardAlreadyHasTicket = cardIds.Contains(idCard);
        if (!cardAlreadyHasTicket)
        {
          bool foundIgnoredCard = ignoreCards.Contains(cardDetail);
          if (!foundIgnoredCard)
          {
            ticket = RequestCardReservation(user, cardDetail, tvController, cardResImpl, idChannel);
          }
          cardIds.Add(idCard);
        }
        tickets.Add(cardDetail, ticket);
      }
      return tickets;
    }
Ejemplo n.º 15
0
    public static ICardTuneReservationTicket RequestCardReservation(IUser user, CardDetail cardDetail, TVController tvController, ICardReservation cardResImpl, int idChannel)
    {
      ICardTuneReservationTicket ticket = null;
      int idCard = cardDetail.Card.IdCard;
      IUser userCopy = user.Clone() as User;
      if (userCopy != null)
      {
        IDictionary<int, ITvCardHandler> cards = tvController.CardCollection;
        userCopy.CardId = idCard;
        ITvCardHandler tvcard = cards[idCard];
        ticket = cardResImpl.RequestCardTuneReservation(tvcard, cardDetail.TuningDetail, userCopy, idChannel);
      }

      return ticket;
    }
Ejemplo n.º 16
0
    /// <summary>
    /// Gets a list of all channel states    
    /// </summary>    
    /// <returns>dictionary containing all channel states of the channels supplied</returns>
    public Dictionary<int, ChannelState> GetChannelStates(Dictionary<int, ITvCardHandler> cards, IList<Channel> channels,
                                                          ref IUser user, bool checkTransponders,
                                                          TVController tvController)
    {
      if (channels == null)
      {
        return null;
      }

      List<IUser> allUsers = new List<IUser>();
      allUsers.Add(user);

      DoSetChannelStates(cards, channels, checkTransponders, allUsers, tvController);

      if (allUsers.Count > 0)
      {
        return allUsers[0].ChannelStates;
      }
      return new Dictionary<int, ChannelState>();
    }
Ejemplo n.º 17
0
    public void SetChannelStates(Dictionary<int, ITvCardHandler> cards, IList<Channel> channels, bool checkTransponders,
                                 TVController tvController)
    {
      if (channels == null)
      {
        return;
      }

      //call the real work as a thread in order to avoid slower channel changes.
      // find all users      
      IList<IUser> allUsers = GetActiveUsers(cards);
      ThreadStart starter = delegate { DoSetChannelStates(cards, channels, checkTransponders, allUsers, tvController); };
      Thread setChannelStatesThread = new Thread(starter);
      setChannelStatesThread.Name = "Channel state thread";
      setChannelStatesThread.IsBackground = true;
      setChannelStatesThread.Priority = ThreadPriority.Lowest;
      setChannelStatesThread.Start();
    }
 public AdvancedCardAllocationStatic(TvBusinessLayer businessLayer, TVController controller)
   : base(businessLayer, controller)
 {      
 }    
 protected CardReservationBase(TVController tvController)
 {
   _tvController = tvController;
 }
 public CardReservationTimeshifting(TVController tvController) : base(tvController) {}
Ejemplo n.º 21
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="controller">instance of the TVController</param>
 public Scheduler(TVController controller)
 {
   _tvController = controller;
   LoadSettings();
 }
        /// Starts the plugin
        /// </summary>
        public void Start(IController controller)
        {
            Controller = controller as TvService.TVController;

              ITvServerEvent events = GlobalServiceProvider.Instance.Get<ITvServerEvent>();
              if (events != null)
              {
            events.OnTvServerEvent += new TvServerEventHandler(events_OnTvServerEvent);
              }

              try
              {
            httpChannel = new HttpChannel(9998);
            ChannelServices.RegisterChannel(httpChannel, false);
              }
              catch (Exception ex)
              {
            //Log.Error("TsBufferExtractor exception: {0}", ex);
              }

              try
              {
            RemotingConfiguration.RegisterWellKnownServiceType(typeof(TsBufferExtractorServer), "TsBufferExtractorServer",
             WellKnownObjectMode.SingleCall);
              }
              catch (Exception ex)
              {
            Log.Error("TsBufferExtractor exception: {0}", ex);
              }
              Log.Debug("TsBufferExtractor Started");
        }
Ejemplo n.º 23
0
    public void OnStart()
    {
      //System.Diagnostics.Debugger.Launch();
      try
      {
        if (!Started)
        {
          Log.Info("TV service: Starting");

          Thread.CurrentThread.Name = "TVService";

          FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(Application.ExecutablePath);

          Log.WriteFile("TVService v" + versionInfo.FileVersion + " is starting up on " +
                        OSInfo.OSInfo.GetOSDisplayVersion());

          //Check for unsupported operating systems
          OSPrerequisites.OSPrerequisites.OsCheck(false);

          _powerEventThread = new Thread(PowerEventThread);
          _powerEventThread.Name = "PowerEventThread";
          _powerEventThread.IsBackground = true;
          _powerEventThread.Start();
          _controller = new TVController();
          _controller.Init();
          StartPlugins();

          StartRemoting();
          _started = true;
          if (_InitializedEvent != null)
          {
            _InitializedEvent.Set();
          }
          Log.Info("TV service: Started");
          while (true)
          {
            Thread.Sleep(1000);
          }
        }
      }
      catch (Exception ex)
      {
        //wait for thread to exit. eg. when stopping tvservice       
        Log.Error("TvService OnStart failed : {0}", ex.ToString());
        _started = true; // otherwise the onstop code will not complete.
        OnStop();
      }
    }
    public static ICollection<ICardTuneReservationTicket> RequestCardReservations(IUser user, IEnumerable<CardDetail> availCardsForReservation, TVController tvController, ICardReservation cardResImpl, IEnumerable<int> ignoreCards)
    {
      ICollection<ICardTuneReservationTicket> tickets = new List<ICardTuneReservationTicket>();
      IDictionary<int, ITvCardHandler> cards = tvController.CardCollection;

      foreach (CardDetail cardDetail in availCardsForReservation)
      {
        int idCard = cardDetail.Card.IdCard;
        bool foundIgnoredCard = ignoreCards.Contains(idCard);
        if (!foundIgnoredCard)
        {
          IUser userCopy = user.Clone() as User;
          if (userCopy != null)
          {
            userCopy.CardId = idCard;
            ITvCardHandler tvcard = cards[idCard];
            ICardTuneReservationTicket ticket = cardResImpl.RequestCardTuneReservation(tvcard, cardDetail.TuningDetail,
                                                                                   userCopy);
            if (ticket != null)
            {
              tickets.Add(ticket);
            }
          }          
        }
      }
      return tickets;
    }
Ejemplo n.º 25
0
    public void OnStart()
    {
      //System.Diagnostics.Debugger.Launch();
      try
      {
        if (!Started)
        {
          Log.Info("TV service: Starting");

          Thread.CurrentThread.Name = "TVService";

          // Log TvService start and versions
          FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(Application.ExecutablePath);
          Log.WriteFile("TVService v" + versionInfo.FileVersion + " is starting up on " +
            OSInfo.OSInfo.GetOSDisplayVersion());

          // Warn about unsupported operating systems
          OSPrerequisites.OSPrerequisites.OsCheck(false);

          // Start the power event thread
          _powerEventThread = new Thread(PowerEventThread);
          _powerEventThread.Name = "PowerEventThread";
          _powerEventThread.IsBackground = true;
          _powerEventThread.Start();

          // Init the TvController and start remoting
          _controller = new TVController();
          _controller.Init();
          StartRemoting();

          // Start the plugins
          StartPlugins();

          // Set "Global\MPTVServiceInitializedEvent"
          if (_InitializedEvent != null)
          {
            _InitializedEvent.Set();
          }
          _started = true;
          Log.Info("TV service: Started");

          // Wait for termination
          while (true)
          {
            Thread.Sleep(1000);
          }
        }
      }
      catch (ThreadAbortException)
      {
        Log.Info("TvService is being stopped");
      }
      catch (Exception ex)
      {
        if (_started)
          Log.Error("TvService terminated unexpectedly: {0}", ex.ToString());
        else
          Log.Error("TvService failed to start: {0}", ex.ToString());
      }
      finally
      {
        _started = true; // otherwise the onstop code will not complete.
        OnStop();
      }
    }
Ejemplo n.º 26
0
 public static void CardNotPresent(int cardId, TVController controller)
 {
   Isolate.WhenCalled(() => controller.CardPresent(cardId)).WillReturn(false);
 }