Esempio n. 1
0
void CControlAPI::SendTimers(CWebserverRequest* request)
{
	CTimerd::TimerList timerlist;             // List of bouquets

	timerlist.clear();
	Parent->Timerd->getTimerList(timerlist);

	CZapitClient::BouquetChannelList channellist;     
	channellist.clear();

	CTimerd::TimerList::iterator timer = timerlist.begin();
	for(; timer != timerlist.end();timer++)
	{
      // Add Data
		char zAddData[20+1]={0};
		switch(timer->eventType)
		{
			case CTimerd::TIMER_NEXTPROGRAM :
			case CTimerd::TIMER_ZAPTO :
			case CTimerd::TIMER_RECORD :
            {
				if(channellist.size()==0)
				{
					Parent->Zapit->getChannels(channellist);
				}
				CZapitClient::BouquetChannelList::iterator channel = channellist.begin();
				for(; channel != channellist.end();channel++)
				{
					if(channel->channel_id==timer->channel_id)
					{
						strncpy(zAddData, channel->name, 20);
						zAddData[20]=0;
						break;
					}
				}
				if(channel == channellist.end())
					strcpy(zAddData,"Unknown");
			}
            break;
			
			case CTimerd::TIMER_STANDBY :
            {
               sprintf(zAddData,"Standby: %s",(timer->standby_on ? "ON" : "OFF"));
            }
            break;
         default:{}
		}
		request->printf("%d %d %d %d %d %d %s\n",timer->eventID,(int)timer->eventType,
             (int)timer->eventRepeat,(int)timer->announceTime,
             (int)timer->alarmTime,(int)timer->stopTime,zAddData);
	}
}
int CFollowScreenings::exec(CMenuTarget* /*parent*/, const std::string & actionKey)
{
	unsigned long a;
	if (1 == sscanf(actionKey.c_str(), "%lu", &a)) {
		int ix = 0;
		CChannelEventList::iterator e;
		for (e = followlist.begin(); e != followlist.end(); e++, ix++)
			if ((time_t)a == e->startTime) {
				time_t start = e->startTime - (ANNOUNCETIME + 120);
				time_t stop = e->startTime + e->duration;
				CTimerd::TimerList overlappingTimers = Timer.getOverlappingTimers(start, stop);
				CTimerd::TimerList::iterator i;
				for (i = overlappingTimers.begin(); i != overlappingTimers.end(); i++)
					if (i->eventType == CTimerd::TIMER_RECORD) {
						if (channel_id == i->channel_id && e->startTime == i->epg_starttime) {
							Timer.removeTimerEvent(i->eventID);
							if (!forwarders.empty())
								forwarders[ix]->iconName_Info_right = "";
#if 0
							else
								ShowMsg(LOCALE_TIMER_EVENTREMOVED_TITLE, LOCALE_TIMER_EVENTREMOVED_MSG,
									CMessageBox::mbrBack, CMessageBox::mbBack, NEUTRINO_ICON_INFO);
#endif
							return menu_return::RETURN_REPAINT;
						}
						if (!SAME_TRANSPONDER(channel_id, i->channel_id)) {
							if (!askUserOnTimerConflict(start, stop, channel_id))
								return menu_return::RETURN_REPAINT;
						}
					}

				if (g_Timerd->addRecordTimerEvent(channel_id, e->startTime, e->startTime + e->duration, e->eventID,
								  e->startTime, e->startTime - (ANNOUNCETIME + 120 ), apids, true, e->startTime - (ANNOUNCETIME + 120) > time(NULL), recDir, true) == -1) {
					//FIXME -- no error handling, but this shouldn't happen ...
				} else {
					if (!forwarders.empty())
						forwarders[ix]->iconName_Info_right = NEUTRINO_ICON_REC;
#if 0
					else
						ShowMsg(LOCALE_TIMER_EVENTRECORD_TITLE, LOCALE_TIMER_EVENTRECORD_MSG,
							CMessageBox::mbrBack, CMessageBox::mbBack, NEUTRINO_ICON_INFO);
#endif
					return menu_return::RETURN_REPAINT;
				}
				break; // for
			}
		return menu_return::RETURN_EXIT_ALL;
	}
	show();
	return menu_return::RETURN_EXIT_ALL;
}
void CFollowScreenings::updateRightIcon(int ix, time_t start, unsigned int duration) {
	time_t stop = start + duration;
	start -= (ANNOUNCETIME + 120);
	CTimerd::TimerList overlappingTimers = Timer.getOverlappingTimers(start, stop);
	start += (ANNOUNCETIME + 120);
	CTimerd::TimerList::iterator i;
	for (i = overlappingTimers.begin(); i != overlappingTimers.end(); i++)
		if (i->eventType == CTimerd::TIMER_RECORD) {
			if (channel_id == i->channel_id && start == i->epg_starttime) {
				forwarders[ix]->iconName_Info_right = NEUTRINO_ICON_REC;
				return;
			}
			if (!SAME_TRANSPONDER(channel_id, i->channel_id)) {
				forwarders[ix]->iconName_Info_right = NEUTRINO_ICON_IMPORTANT;
				return;
			}
		}
}
/*
int CTimerdClient::addTimerEvent( CTimerEventTypes evType, void* data , int min, int hour, int day, int month, CTimerd::CTimerEventRepeat evrepeat)
{
	time_t actTime_t;
	time(&actTime_t);
	struct tm* actTime = localtime(&actTime_t);

	actTime->tm_min = min;
	actTime->tm_hour = hour;

	if (day > 0)
		actTime->tm_mday = day;
	if (month > 0)
		actTime->tm_mon = month -1; 
	
	addTimerEvent(evType,true,data,0,mktime(actTime),0);
}
*/
bool CTimerdClient::checkDouble(CTimerd::CTimerEventTypes evType, void* data, time_t announcetime, time_t alarmtime,time_t stoptime,
				  CTimerd::CTimerEventRepeat evrepeat, uint32_t repeatcount)
{
	if (evType != CTimerd::TIMER_RECORD && evType != CTimerd::TIMER_ZAPTO)
		return false;//skip check not zap and record timer

	CTimerd::TimerList timerlist;
	getTimerList(timerlist);
	for (CTimerd::TimerList::iterator it = timerlist.begin(); it != timerlist.end();++it)
	{
		if ( (it->eventType == CTimerd::TIMER_RECORD || it->eventType == CTimerd::TIMER_ZAPTO ) &&
			(it->alarmTime  == alarmtime && it->announceTime == announcetime && it->stopTime == stoptime && it->eventRepeat == evrepeat && it->repeatCount == repeatcount ) )
		{
			if( it->eventType == CTimerd::TIMER_ZAPTO )
			{
				CTimerd::EventInfo *ei=static_cast<CTimerd::EventInfo*>(data);
				if( ei->channel_id == it->channel_id )
				{
					if(( ei->epgID != 0 && ei->epgID != it->epgID ) || ( ei->epg_starttime != 0 && it->epg_starttime != ei->epg_starttime) )
					{
						return false;//not double
					}
					return true;
				}
			}
			else if(it->eventType == CTimerd::TIMER_RECORD)
			{
				CTimerd::RecordingInfo *ri=static_cast<CTimerd::RecordingInfo*>(data);
				if(ri->channel_id == it->channel_id && ri->apids == it->apids && !strncmp(ri->recordingDir, it->recordingDir, RECORD_DIR_MAXLEN-1) )
				{
					if( ( ri->epgID != 0 && ri->epgID != it->epgID ) || ( ri->epg_starttime != 0 && it->epg_starttime != ri->epg_starttime) )
					{
						return false;//not double
					}
					return true;
				}
			}
		}
	}
	return false;//not double
}
void CTimerdClient::getTimerList(CTimerd::TimerList &timerlist)
{
        CTimerdMsg::generalInteger responseInteger;
	CTimerd::responseGetTimer  response;

	send(CTimerdMsg::CMD_GETTIMERLIST);

	timerlist.clear();

        if (CBasicClient::receive_data((char* )&responseInteger, sizeof(responseInteger)))
        {
                while (responseInteger.number-- > 0)
                {
                        if (CBasicClient::receive_data((char*)&response, sizeof(response)))
				if (response.eventState != CTimerd::TIMERSTATE_TERMINATED)
					timerlist.push_back(response);
                };
        }

	close_connection();
}
CTimerd::TimerList CTimerdClient::getOverlappingTimers(time_t& startTime, time_t& stopTime)
{
	CTimerd::TimerList timerlist; 
	CTimerd::TimerList overlapping;
	int timerPre;
	int timerPost;

	getTimerList(timerlist);
	getRecordingSafety(timerPre,timerPost);

	for (CTimerd::TimerList::iterator it = timerlist.begin();
	     it != timerlist.end();++it)
	{
		if(it->stopTime != 0 && stopTime != 0)
		{
			// Check if both timers have start and end. In this case do not show conflict, if endtime is the same than the starttime of the following timer
			if ((stopTime+timerPost > it->alarmTime) && (startTime-timerPre < it->stopTime))
			{
				overlapping.push_back(*it);
			}
		}
		else
		{
			if (!((stopTime < it->announceTime) || (startTime > it->stopTime)))
			{
				overlapping.push_back(*it);
			}
		}
	}
	return overlapping;
}
Esempio n. 7
0
//-------------------------------------------------------------------------
// Template 1:classname, 2:zAlarmTime, 3: zStopTime, 4:zRep, 5:zRepCouunt
//		6:zType, 7:sAddData, 8:timer->eventID, 9:timer->eventID
//-------------------------------------------------------------------------
std::string  CNeutrinoYParser::func_get_timer_list(CyhookHandler *, std::string para)
{
	std::string yresult;
	CTimerd::TimerList timerlist;				// List of bouquets

	timerlist.clear();
	NeutrinoAPI->Timerd->getTimerList(timerlist);
	sort(timerlist.begin(), timerlist.end());

	CZapitClient::BouquetChannelList channellist_tv;
	CZapitClient::BouquetChannelList channellist_radio;
	channellist_tv.clear();
	channellist_radio.clear();

	int i = 1;
	char classname= 'a';
	CTimerd::TimerList::iterator timer = timerlist.begin();
	for(; timer != timerlist.end();++timer)
	{
		classname = (i++&1)?'a':'b';

		// build alarm/stoptime
		char zAlarmTime[25] = {0};
		struct tm *alarmTime = localtime(&(timer->alarmTime));
		strftime(zAlarmTime,20,"%d.%m. %H:%M",alarmTime);

		char zAnnounceTime[25] = {0};
		struct tm *announceTime = localtime(&(timer->announceTime));
		strftime(zAnnounceTime,20,"%d.%m. %H:%M",announceTime);

		char zStopTime[25] = {0};
		if(timer->stopTime > 0)
		{
			struct tm *stopTime = localtime(&(timer->stopTime));
			strftime(zStopTime,20,"%d.%m. %H:%M",stopTime);
		}
		// repeat
		std::string zRep = NeutrinoAPI->timerEventRepeat2Str(timer->eventRepeat);
		std::string zRepCount;
		if (timer->eventRepeat == CTimerd::TIMERREPEAT_ONCE)
			zRepCount = "-";
		else
			zRepCount = (timer->repeatCount == 0) ? "&#x221E;" : string_printf("%dx",timer->repeatCount);
		// timer type
		std::string zType = NeutrinoAPI->timerEventType2Str(timer->eventType);
		// Add Data
		std::string sAddData="";
		switch(timer->eventType)
		{
			//case CTimerd::TIMER_NEXTPROGRAM :
			case CTimerd::TIMER_ZAPTO :
			case CTimerd::TIMER_RECORD :
			{
				sAddData = NeutrinoAPI->GetServiceName(timer->channel_id);
				if (sAddData.empty())
					sAddData = CServiceManager::getInstance()->IsChannelTVChannel(timer->channel_id) ? "Unknown TV-Channel" : "Unknown Radio-Channel";

				if( timer->apids != TIMERD_APIDS_CONF)
				{
					std::string separator = "";
					sAddData += '(';
					if( timer->apids & TIMERD_APIDS_STD )
					{
						sAddData += "STD";
						separator = "/";
					}
					if( timer->apids & TIMERD_APIDS_ALT )
					{
						sAddData += separator;
						sAddData += "ALT";
						separator = "/";
					}
					if( timer->apids & TIMERD_APIDS_AC3 )
					{
						sAddData += separator;
						sAddData += "AC3";
						separator = "/";
					}
					sAddData += ')';
				}
				if(timer->epgID!=0)
				{
					CEPGData epgdata;
					if (CEitManager::getInstance()->getEPGid(timer->epgID, timer->epg_starttime, &epgdata))
						sAddData+="<br/>" + epgdata.title;
					else
						sAddData+=std::string("<br/>")+timer->epgTitle;
				}
				else
					sAddData+=std::string("<br/>")+timer->epgTitle;
			}
			break;
			case CTimerd::TIMER_STANDBY :
			{
				sAddData = "Standby: ";
				if(timer->standby_on)
					sAddData+= "An";
				else
					sAddData+="Aus";
			}
			break;
			case CTimerd::TIMER_REMIND :
				sAddData = std::string(timer->message).substr(0,20);
				break;
			case CTimerd::TIMER_EXEC_PLUGIN :
				sAddData = std::string(timer->pluginName);
				break;

			default:{}
		}
		yresult += string_printf(para.c_str(), classname, zAlarmTime, zStopTime, zRep.c_str(), zRepCount.c_str(),
					zType.c_str(), sAddData.c_str(),timer->eventID,timer->eventID);
	}
	//classname = (i++&1)?'a':'b';

	return yresult;
}
//-------------------------------------------------------------------------
int CTimerdClient::addTimerEvent( CTimerd::CTimerEventTypes evType, void* data, time_t announcetime, time_t alarmtime,time_t stoptime,
				  CTimerd::CTimerEventRepeat evrepeat, uint32_t repeatcount,bool forceadd)
{
	if(checkDouble(evType, data, announcetime,  alarmtime, stoptime, evrepeat,  repeatcount))//check if timer is add double
		return -1;

	if (!forceadd)
	{
		//printf("[CTimerdClient] checking for overlapping timers\n");
		CTimerd::TimerList overlappingTimer;
		overlappingTimer = getOverlappingTimers(alarmtime, stoptime);
		if (!overlappingTimer.empty())
		{
			// timerd starts eventID at 0 so we can return -1
			return -1;
		}
	}
	bool adzaptimer = false;
	if(evType == CTimerd::TIMER_ADZAP){
		evType = CTimerd::TIMER_ZAPTO;
		adzaptimer = true;
	}
	CTimerd::TransferEventInfo tei; 
	CTimerd::TransferRecordingInfo tri;
	CTimerdMsg::commandAddTimer msgAddTimer;
	VALGRIND_PARANOIA(tei);
	VALGRIND_PARANOIA(tri);
	VALGRIND_PARANOIA(msgAddTimer);
	msgAddTimer.alarmTime  = alarmtime;
	msgAddTimer.announceTime = announcetime;
	msgAddTimer.stopTime   = stoptime;
	msgAddTimer.eventType = evType;
	msgAddTimer.eventRepeat = evrepeat;
	msgAddTimer.repeatCount = repeatcount;
	int length;
	if( evType == CTimerd::TIMER_SHUTDOWN || evType == CTimerd::TIMER_SLEEPTIMER )
	{
		length = 0;
	}
	/* else if(evType == CTimerd::TIMER_NEXTPROGRAM || evType == CTimerd::TIMER_ZAPTO || */
	else if (evType == CTimerd::TIMER_ZAPTO ||
		evType == CTimerd::TIMER_IMMEDIATE_RECORD || 
		evType == CTimerd::TIMER_ADZAP)
	{
		CTimerd::EventInfo *ei=static_cast<CTimerd::EventInfo*>(data); 
		tei.apids = ei->apids;
		tei.channel_id = ei->channel_id;
		tei.epg_starttime	= ei->epg_starttime;
		tei.epgID = ei->epgID;
		tei.recordingSafety = ei->recordingSafety;
		length = sizeof( CTimerd::TransferEventInfo);
		data = &tei;
	}
	else if(evType == CTimerd::TIMER_RECORD)
	{
		CTimerd::RecordingInfo *ri=static_cast<CTimerd::RecordingInfo*>(data); 
		tri.apids = ri->apids;
		tri.channel_id = ri->channel_id;
		tri.epg_starttime	= ri->epg_starttime;
		tri.epgID = ri->epgID;
		tri.recordingSafety = ri->recordingSafety;
		strncpy(tri.recordingDir, ri->recordingDir, RECORD_DIR_MAXLEN-1);
		length = sizeof( CTimerd::TransferRecordingInfo);
		data = &tri;
	}
	else if(evType == CTimerd::TIMER_STANDBY)
	{
		length = sizeof(CTimerdMsg::commandSetStandby);
	}
	else if(evType == CTimerd::TIMER_REMIND)
	{
		length = sizeof(CTimerdMsg::commandRemind);
	}
	else if(evType == CTimerd::TIMER_EXEC_PLUGIN)
	{
		length = sizeof(CTimerdMsg::commandExecPlugin);
	}
	else
	{
		length = 0;
	}

	send(CTimerdMsg::CMD_ADDTIMER, (char*)&msgAddTimer, sizeof(msgAddTimer));

	if((data != NULL) && (length > 0))
		send_data((char*)data, length);

	CTimerdMsg::responseAddTimer response;
	receive_data((char*)&response, sizeof(response));
	close_connection();
	
	if(adzaptimer){
		adzap_eventID = response.eventID;//set adzap flag
	}
	return( response.eventID);
}