vdr-plugin-skindesigner/extensions/timers.c

135 lines
4.0 KiB
C
Raw Normal View History

2014-09-27 09:25:14 +02:00
#include "timers.h"
#include "../services/epgsearch.h"
#include "../services/remotetimers.h"
static int CompareTimers(const void *a, const void *b) {
return (*(const cTimer **)a)->Compare(**(const cTimer **)b);
}
2016-03-13 16:02:26 +01:00
cGlobalSortedTimers::cGlobalSortedTimers(int timerCount, bool forceRefresh) : cVector<const cTimer*>(timerCount) {
2014-09-27 09:25:14 +02:00
static bool initial = true;
static cRemoteTimerRefresh *remoteTimerRefresh = NULL;
localTimer = NULL;
2014-09-27 09:25:14 +02:00
if (forceRefresh)
initial = true;
//check if remotetimers plugin is available
static cPlugin* pRemoteTimers = cPluginManager::GetPlugin("remotetimers");
2016-03-13 16:02:26 +01:00
#if defined (APIVERSNUM) && (APIVERSNUM >= 20301)
LOCK_TIMERS_READ;
LOCK_SCHEDULES_READ;
const cTimers* timers = Timers;
const cSchedules* schedules = Schedules;
#else
const cTimers* timers = &Timers;
cSchedulesLock schedulesLock;
const cSchedules* schedules = (cSchedules*)cSchedules::Schedules(schedulesLock);
#endif
2014-09-27 09:25:14 +02:00
if (pRemoteTimers && initial) {
cString errorMsg;
pRemoteTimers->Service("RemoteTimers::RefreshTimers-v1.0", &errorMsg);
initial = false;
}
2016-03-13 16:02:26 +01:00
for (const cTimer *Timer = timers->First(); Timer; Timer = timers->Next(Timer)) {
2014-10-28 23:30:38 +01:00
if (Timer->HasFlags(tfActive))
Append(Timer);
}
2014-09-27 09:25:14 +02:00
//if remotetimers plugin is available, take timers also from him
if (pRemoteTimers) {
cTimer* remoteTimer = NULL;
while (pRemoteTimers->Service("RemoteTimers::ForEach-v1.0", &remoteTimer) && remoteTimer != NULL) {
2016-03-13 16:02:26 +01:00
remoteTimer->SetEventFromSchedule(schedules); // make sure the event is current
if (remoteTimer->HasFlags(tfActive))
Append(remoteTimer);
2014-09-27 09:25:14 +02:00
}
}
Sort(CompareTimers);
int numTimers = Size();
if (numTimers > 0) {
localTimer = new bool[numTimers];
for (int i=0; i < numTimers; i++) {
if (!pRemoteTimers) {
localTimer[i] = true;
} else {
localTimer[i] = false;
2016-03-13 16:02:26 +01:00
for (const cTimer *Timer = timers->First(); Timer; Timer = timers->Next(Timer)) {
if (Timer == At(i)) {
localTimer[i] = true;
break;
}
}
}
}
}
2014-09-27 09:25:14 +02:00
if (pRemoteTimers && (remoteTimerRefresh == NULL))
remoteTimerRefresh = new cRemoteTimerRefresh();
}
cGlobalSortedTimers::~cGlobalSortedTimers(void) {
if (localTimer) {
delete[] localTimer;
}
}
bool cGlobalSortedTimers::IsRemoteTimer(int i) {
if (!localTimer)
return true;
if (i >= Size())
return true;
return !(localTimer[i]);
}
2014-09-27 09:25:14 +02:00
int cGlobalSortedTimers::NumTimerConfilicts(void) {
int numConflicts = 0;
cPlugin *p = cPluginManager::GetPlugin("epgsearch");
if (p) {
Epgsearch_lastconflictinfo_v1_0 *serviceData = new Epgsearch_lastconflictinfo_v1_0;
if (serviceData) {
serviceData->nextConflict = 0;
serviceData->relevantConflicts = 0;
serviceData->totalConflicts = 0;
p->Service("Epgsearch-lastconflictinfo-v1.0", serviceData);
if (serviceData->relevantConflicts > 0) {
numConflicts = serviceData->relevantConflicts;
}
delete serviceData;
}
}
return numConflicts;
}
cRemoteTimerRefresh::cRemoteTimerRefresh(): cThread("skindesigner: RemoteTimers::RefreshTimers") {
Start();
}
cRemoteTimerRefresh::~cRemoteTimerRefresh(void) {
Cancel(-1);
while (Active())
cCondWait::SleepMs(10);
}
void cRemoteTimerRefresh::Action(void) {
2016-03-13 16:02:26 +01:00
#define REFESH_INTERVALL_MS 30000
2014-09-27 09:25:14 +02:00
while (Running()) {
2016-03-13 16:02:26 +01:00
cCondWait::SleepMs(REFESH_INTERVALL_MS);
// make sure that no timer is currently being edited
if (!cOsd::IsOpen()) {
2014-09-27 09:25:14 +02:00
cGlobalSortedTimers(true);
2016-03-13 16:02:26 +01:00
#if defined (APIVERSNUM) && (APIVERSNUM >= 20301)
LOCK_TIMERS_WRITE;
Timers->SetModified();
#else
2014-09-27 09:25:14 +02:00
Timers.SetModified();
2016-03-13 16:02:26 +01:00
#endif
2014-09-27 09:25:14 +02:00
}
}
}