Esempio n. 1
0
void CAdZapMenu::Init()
{
	CChannelList *channelList = CNeutrinoApp::getInstance()->channelList;
	channelId = channelList ? channelList->getActiveChannel_ChannelID() : -1;
	if(channelList)
		channelName = channelList->getActiveChannelName();
	evtlist.clear();
	CEitManager::getInstance()->getEventsServiceKey(channelId & 0xFFFFFFFFFFFFULL, evtlist);
	monitorLifeTime.tv_sec = 0;
	if (!evtlist.empty())
	{
		sort(evtlist.begin(), evtlist.end(), sortByDateTime);
		monitorLifeTime.tv_sec = getMonitorLifeTime();
		Update();
	}
	printf("CAdZapMenu::%s: monitorLifeTime.tv_sec: %d\n", __func__, (uint) monitorLifeTime.tv_sec);
}
Esempio n. 2
0
void CAdZapMenu::Settings()
{
    CChannelList *channelList = CNeutrinoApp::getInstance()->channelList;
    channelId =
	channelList ? channelList->getActiveChannel_ChannelID() : -1;
    if (channelId < 0)
	return;
    channelName = channelList->getActiveChannelName();

    CMenuWidget *menu =
	new CMenuWidget(LOCALE_ADZAP, "settings", width);
    menu->addItem(new
		  CMenuSeparator(CMenuSeparator::LINE |
				 CMenuSeparator::STRING,
				 LOCALE_ADZAP_SWITCHBACK));
    neutrino_locale_t minute = LOCALE_ADZAP_MINUTE;
    for (int shortcut = 1; shortcut < 10; shortcut++) {
	char actionKey[2];
	actionKey[0] = '0' + shortcut;
	actionKey[1] = 0;
	bool selected = g_settings.adzap_zapBackPeriod == 60 * shortcut;
	menu->addItem(new
		      CMenuForwarder(minute, true, "", this, actionKey,
				     CRCInput::convertDigitToKey
				     (shortcut)), selected);
	minute = LOCALE_ADZAP_MINUTES;
    }

    menu->addItem(new
		  CMenuSeparator(CMenuSeparator::LINE |
				 CMenuSeparator::STRING,
				 LOCALE_ADZAP_COMMIT));
    menu->addItem(new
		  CMenuForwarder(LOCALE_ADZAP_ENABLE, true, "", this,
				 "enable", CRCInput::RC_green,
				 NEUTRINO_ICON_BUTTON_GREEN));
    menu->addItem(new
		  CMenuForwarder(LOCALE_ADZAP_DISABLE, true, "", this,
				 "disable", CRCInput::RC_red,
				 NEUTRINO_ICON_BUTTON_RED));

    CChannelEventList evtlist;
    sectionsd_getEventsServiceKey(azm->channelId & 0xFFFFFFFFFFFFULL,
				  evtlist);
    azm->monitorLifeTime.tv_sec = 0;
    if (!evtlist.empty()) {
	sort(evtlist.begin(), evtlist.end(), sortByDateTime);
	CChannelEventList::iterator eli;
	struct timespec ts;
	clock_gettime(CLOCK_REALTIME, &ts);
	for (eli = evtlist.begin(); eli != evtlist.end(); ++eli) {
	    if ((uint) eli->startTime + eli->duration > ts.tv_sec) {
		azm->monitorLifeTime.tv_sec =
		    (uint) eli->startTime + eli->duration;
		azm->Update();
		break;
	    }
	}
    }

    menu->addItem(new
		  CMenuForwarder(LOCALE_ADZAP_MONITOR,
				 azm->monitorLifeTime.tv_sec, "", this,
				 "monitor", CRCInput::RC_blue,
				 NEUTRINO_ICON_BUTTON_BLUE));

    monitor = false;
    menu->exec(NULL, "");
    menu->hide();
    delete menu;
    Update();
}
Esempio n. 3
0
void *CAdZapMenu::Run(void *)
{
    while (azm->running) {
	CChannelList *channelList = NULL;
	t_channel_id curChannelId;

	if (azm->monitor) {
	    struct timespec ts;
	    clock_gettime(CLOCK_REALTIME, &ts);
	    ts.tv_sec += 1;

	    sem_timedwait(&azm->sem, &ts);

	    if (azm->monitor && (azm->monitorLifeTime.tv_sec > ts.tv_sec)) {
		channelList = CNeutrinoApp::getInstance()->channelList;
		curChannelId =
		    channelList ? channelList->getActiveChannel_ChannelID()
		    : -1;
		if (!azm->armed && (azm->channelId != curChannelId)) {
		    azm->armed = true;
		    clock_gettime(CLOCK_REALTIME, &azm->zapBackTime);
		    azm->zapBackTime.tv_sec +=
			g_settings.adzap_zapBackPeriod -
			ZAPBACK_ALERT_PERIOD;
		    azm->alerted = false;
		} else if (azm->channelId == curChannelId) {
		    azm->armed = false;
		    azm->alerted = false;
		}
	    } else {
		azm->monitor = false;
		azm->armed = false;
		azm->alerted = false;
	    }
	} else if (azm->armed)
	    sem_timedwait(&azm->sem, &azm->zapBackTime);
	else
	    sem_wait(&azm->sem);

	if (azm->armed) {
	    struct timespec ts;
	    clock_gettime(CLOCK_REALTIME, &ts);
	    if (ts.tv_sec >= azm->zapBackTime.tv_sec) {
		if (!channelList) {
		    channelList = CNeutrinoApp::getInstance()->channelList;
		    curChannelId =
			channelList ?
			channelList->getActiveChannel_ChannelID() : -1;
		}
		if (!azm->alerted) {
		    if (azm->channelId != curChannelId) {
			std::string name =
			    g_Locale->getText(LOCALE_ADZAP_ANNOUNCE);
			name += "\n" + azm->channelName;
			ShowHintUTF(LOCALE_ADZAP, name.c_str());
		    }
		    azm->alerted = true;
		    azm->zapBackTime.tv_sec += ZAPBACK_ALERT_PERIOD;
		} else {
		    azm->alerted = false;
		    if (channelList)
			channelList->zapTo_ChannelID(azm->channelId);
		    azm->armed = false;
		}
	    }
	}
    }
    return NULL;
}
Esempio n. 4
0
void CAdZapMenu::Run()
{
	set_threadname("CAdZapMenu::Run");
	while (true)
	{
		CChannelList *channelList = NULL;
		t_channel_id curChannelId = -1;

		if (monitor)
		{
			clock_gettime(CLOCK_REALTIME, &ts);
			ts.tv_sec += 1;

			sem_timedwait(&sem, &ts);

			if (monitor && (monitorLifeTime.tv_sec > ts.tv_sec))
			{
				channelList = CNeutrinoApp::getInstance()->channelList;
				curChannelId = channelList ? channelList->getActiveChannel_ChannelID() : -1;
				if (!armed && (channelId != curChannelId))
				{
					armed = true;
					clock_gettime(CLOCK_REALTIME, &zapBackTime);
					zapBackTime.tv_sec += g_settings.adzap_zapBackPeriod - ZAPBACK_ALERT_PERIOD;
					alerted = false;
				}
				else if (channelId == curChannelId)
				{
					armed = false;
					alerted = false;
				}
			}
			else
			{
				monitor = false;
				armed = false;
				alerted = false;
			}
		}
		else if (armed)
		{
			if (g_settings.adzap_writeData)
			{
				clock_gettime(CLOCK_REALTIME, &ts);
				ts.tv_sec += 1;

				sem_timedwait(&sem, &ts);
			}
			else
				sem_timedwait(&sem, &zapBackTime);
		}
		else
			sem_wait(&sem);

		if (armed)
		{
			clock_gettime(CLOCK_REALTIME, &ts);
			if (ts.tv_sec >= zapBackTime.tv_sec)
			{
				if (!channelList)
				{
					channelList = CNeutrinoApp::getInstance()->channelList;
					curChannelId = channelList ? channelList->getActiveChannel_ChannelID() : -1;
				}
				if (!alerted)
				{
					if (channelId != curChannelId)
					{
						char name[1024];
						snprintf(name, sizeof(name)-1, g_Locale->getText(LOCALE_ADZAP_ANNOUNCE), ZAPBACK_ALERT_PERIOD, channelName.c_str());
						ShowHint(LOCALE_ADZAP, name);
					}
					alerted = true;
					zapBackTime.tv_sec += ZAPBACK_ALERT_PERIOD;
				}
				else
				{
					alerted = false;
					if ((channelId != curChannelId) && channelList)
						channelList->zapTo_ChannelID(channelId);
					armed = false;
				}
			}
		}

		if (g_settings.adzap_writeData && (monitor || armed))
			WriteData();
		else
			RemoveData();
	}
}