예제 #1
0
void cTimerThread::Action(void)
{
    m_Active = true;
    if (EPGSearchConfig.useExternalSVDRP && !cSVDRPClient::SVDRPSendCmd)
    {
	LogFile.eSysLog("ERROR - SVDRPSend script not specified or does not exist (use -f option)");
	m_Active = false;
	return;
    }
    while (m_Active)
    {
	if (!Running()) 
        {
            m_Active=false;
            break;
        }
	if (Timers.BeingEdited())
	{
	    sleepSec(1);
	    continue;
	}
	bool bSuccess = SendViaSVDRP(m_cmd);
	if (!bSuccess)
	{
	    Epgsearch_osdmessage_v1_0* service_data = new Epgsearch_osdmessage_v1_0;
	    service_data->message = strdup(tr("Programming timer failed!"));
	    service_data->type = mtError;
	    cPluginManager::CallFirstService("Epgsearch-osdmessage-v1.0", service_data);
	    delete service_data;
	}
	else
	  {
	    gl_TimerProgged = 1;
	    if (gl_timerStatusMonitor) gl_timerStatusMonitor->SetConflictCheckAdvised();
	  }
	m_Active = false;
    };
}
void cSwitchTimerThread::Action(void)
{
  m_Active = true;

  // let VDR do its startup
  if (!cPluginEpgsearch::VDR_readyafterStartup)
    LogFile.Log(2, "SwitchTimerThread: waiting for VDR to become ready...");
  while(m_Active && !cPluginEpgsearch::VDR_readyafterStartup)
    Wait.Wait(1000);

   time_t nextUpdate = time(NULL);
   while (m_Active)
   {
      time_t now = time(NULL);
      if (now >= nextUpdate)
      {
         LogFile.Log(3,"locking switch timers");
         SwitchTimers.Lock();
         LogFile.Log(3,"switch timer check started");
         cSwitchTimer* switchTimer = SwitchTimers.First();
         while (switchTimer && m_Active && Running())
         {
            if (switchTimer->startTime - now < switchTimer->switchMinsBefore*60 + MSG_DELAY + 1)
            {
               cChannel *channel = Channels.GetByChannelID(switchTimer->channelID, true, true);
               bool doSwitch = (switchTimer->mode == 0);
               bool doAsk = (switchTimer->mode == 2);
	       bool doUnmute = switchTimer->unmute;
               SwitchTimers.Del(switchTimer);

  	       const cEvent* event = switchTimer->Event();
               if (event && channel && (event->EndTime() >= now))
               {
                  cString Message = cString::sprintf("%s: %s - %s", event->Title(),
						     CHANNELNAME(channel), GETTIMESTRING(event));
		  cString SwitchCmd = cString::sprintf("CHAN %d", channel->Number());
                  // switch
                  if (doSwitch)
                  {
                     LogFile.Log(1,"switching to channel %d", channel->Number());
		     if (cDevice::CurrentChannel() != channel->Number())
		       SendViaSVDRP(SwitchCmd);

		     if (doUnmute && cDevice::PrimaryDevice()->IsMute())
		       cDevice::PrimaryDevice()->ToggleMute();
                  }
		  if (!doAsk)
		    SendMsg(Message);

		  if (doAsk)
		    {
		      cString Message = cString::sprintf(tr("Switch to (%d) '%s'?"), channel->Number(), event->Title());
		      if(SendMsg(Message, true, MSG_DELAY) == kOk)
			{
			  LogFile.Log(1,"switching to channel %d", channel->Number());
			  if (cDevice::CurrentChannel() != channel->Number())
			    SendViaSVDRP(SwitchCmd);

			  if (doUnmute && cDevice::PrimaryDevice()->IsMute())
			    cDevice::PrimaryDevice()->ToggleMute();

			}
		    }

                  if (m_Active && Running())
		    Wait.Wait(1000 * MSG_DELAY);
               }
               SwitchTimers.Save();
               break;
            }
            switchTimer = SwitchTimers.Next(switchTimer);
         }
	 SwitchTimers.Unlock();
         LogFile.Log(3,"switch timer check finished");
         if (m_Active && Running())
	    Wait.Wait(1000 * MSG_DELAY);
         m_lastUpdate = time(NULL);
         nextUpdate = long(m_lastUpdate/60)*60+ 60 - MSG_DELAY ; // check at each full minute minus 5sec
         if (SwitchTimers.Count() == 0)
            m_Active = false;
         if (!Running())
            m_Active = false;
      }
      while (m_Active && time(NULL)%MSG_DELAY != 0) // sync heart beat to MSG_DELAY
	Wait.Wait(1000);
      Wait.Wait(1000);
   };
   m_Instance = NULL;
}
예제 #3
0
void cSearchTimerThread::DelRecording(int index)
{
  cString cmdbuf = cString::sprintf("DELR %d", index);
  LogFile.Log(2, "delete recording %d", index);
  SendViaSVDRP(cmdbuf);
}
예제 #4
0
bool cSearchTimerThread::AddModTimer(cTimer* Timer, int index, cSearchExt* searchExt, const cEvent* pEvent, int Prio, int Lifetime, char* Summary, uint timerMod)
{
   char *cmdbuf = NULL;

   static char bufStart[25];
   static char bufEnd[25];

   struct tm tm_r;    time_t eStart = pEvent->StartTime();
   time_t eStop = pEvent->EndTime();
   time_t start = eStart - (searchExt->MarginStart * 60);
   time_t stop  = eStop + (searchExt->MarginStop * 60);
   int Flags = Timer->Flags();
   if (searchExt->useVPS && pEvent->Vps() && Setup.UseVps)
   {
      start = pEvent->Vps();
      stop = start + pEvent->Duration();
   }
   else
      Flags = 1; // don't use VPS, if not set in this search

   // already done the same timer?
   if (!EPGSearchConfig.TimerProgRepeat && index == 0 && TimersDone.InList(start, stop, pEvent, -1))
   {
      LogFile.Log(2,"skip timer for '%s~%s' (%s - %s); search timer: '%s' - already done", pEvent->Title(), pEvent->ShortText()?pEvent->ShortText():"", GETDATESTRING(pEvent), GETTIMESTRING(pEvent), searchExt->search);
      return false;
   }

   strftime(bufStart, sizeof(bufStart), "%H%M", localtime_r(&start, &tm_r));
   strftime(bufEnd, sizeof(bufEnd), "%H%M", localtime_r(&stop, &tm_r));

   // add additonal info
   char* tmpSummary = NULL;
   if (Summary)
   {
      tmpSummary = strdup(Summary);
      strreplace(tmpSummary, '\n', '|');
   }
   else
      tmpSummary = SummaryExtended(searchExt, Timer, pEvent);

   if (index==0)
      msprintf(&cmdbuf, "NEWT %d:%d:%s:%s:%s:%d:%d:%s:%s",
               Flags,
               Timer->Channel()->Number(),
               *Timer->PrintDay(start, Timer->WeekDays(), true),
               bufStart,
               bufEnd,
               Prio,
               Lifetime,
               Timer->File(),
               tmpSummary?tmpSummary:"");
   else
      msprintf(&cmdbuf, "MODT %d %d:%d:%s:%s:%s:%d:%d:%s:%s",
               index,
               Flags,
               Timer->Channel()->Number(),
               *Timer->PrintDay(start, Timer->WeekDays(), true),
               bufStart,
               bufEnd,
               Prio,
               Lifetime,
               Timer->File(),
               tmpSummary?tmpSummary:"");

   if (!SendViaSVDRP(cmdbuf))
     return false;

   if (gl_timerStatusMonitor) gl_timerStatusMonitor->SetConflictCheckAdvised();

   cTimerDone* timerdone = new cTimerDone(start, stop, pEvent, searchExt->ID);
   if (index==0)
     TimersDone.Add(timerdone);
   else
     TimersDone.Update(start, stop, pEvent, searchExt->ID, timerdone);

   if (EPGSearchConfig.sendMailOnSearchtimers)
     {
       if (index==0) // new
         mailNotifier.AddNewTimerNotification(pEvent->EventID(), pEvent->ChannelID());
       else
	 mailNotifier.AddModTimerNotification(pEvent->EventID(), pEvent->ChannelID(), timerMod);
     }
   free(cmdbuf);
   if (tmpSummary) free(tmpSummary);

   return true;
}