forked from vdr-projects/vdr-plugin-live
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimerconflict.cpp
148 lines (124 loc) · 3.66 KB
/
timerconflict.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include <time.h>
#include <vector>
#include <vdr/plugin.h>
#include "tools.h"
#include "exception.h"
#include "epgsearch.h"
#include "epgsearch/services.h"
#include "timerconflict.h"
namespace vdrlive {
bool CheckEpgsearchVersion();
using namespace std;
static char ServiceInterface[] = "Epgsearch-services-v1.1";
bool operator<( TimerConflict const& left, TimerConflict const& right )
{
return left.conflictTime < right.conflictTime;
}
TimerConflict::TimerConflict()
{
Init();
}
void TimerConflict::Init()
{
conflictTime = 0;
}
TimerConflict::TimerConflict( string const& data )
{
Init();
vector< string > parts = StringSplit( data, ':' );
try {
vector< string >::const_iterator part = parts.begin();
if (parts.size() > 0) {
conflictTime = lexical_cast< time_t >( *part++ );
for ( int i = 1; part != parts.end(); ++i, ++part ) {
vector< string > timerparts = StringSplit( *part, '|' );
vector< string >::const_iterator timerpart = timerparts.begin();
TimerInConflict timer;
for ( int j = 0; timerpart != timerparts.end(); ++j, ++timerpart )
switch (j) {
case 0: timer.timerIndex = lexical_cast< int >( *timerpart ); break;
case 1: timer.percentage = lexical_cast< int >( *timerpart ); break;
case 2: {
vector< string > conctimerparts = StringSplit( *timerpart, '#' );
vector< string >::const_iterator conctimerpart = conctimerparts.begin();
for ( int k = 0; conctimerpart != conctimerparts.end(); ++k, ++conctimerpart )
timer.concurrentTimerIndices.push_back(lexical_cast< int >( *conctimerpart ));
break;
}
}
conflictingTimers.push_back(timer);
}
}
}
catch ( bad_lexical_cast const& ex ) {
}
}
TimerConflicts::TimerConflicts()
{
Epgsearch_services_v1_1 service;
if ( CheckEpgsearchVersion() && cPluginManager::CallFirstService(ServiceInterface, &service))
{
cServiceHandler_v1_1* handler = dynamic_cast<cServiceHandler_v1_1*>(service.handler.get());
if (handler)
{
list< string > conflicts = service.handler->TimerConflictList();
m_conflicts.assign( conflicts.begin(), conflicts.end() );
m_conflicts.sort();
}
}
}
bool TimerConflicts::CheckAdvised()
{
Epgsearch_services_v1_1 service;
if (CheckEpgsearchVersion() && cPluginManager::CallFirstService(ServiceInterface, &service))
{
cServiceHandler_v1_1* handler = dynamic_cast<cServiceHandler_v1_1*>(service.handler.get());
if (!handler)
return false;
else
return handler->IsConflictCheckAdvised();
}
else
return false;
}
TimerConflictNotifier::TimerConflictNotifier()
: lastCheck(0)
, lastTimerModification(0)
, conflicts()
{
}
TimerConflictNotifier::~TimerConflictNotifier()
{
}
bool TimerConflictNotifier::ShouldNotify()
{
time_t now = time(0);
bool reCheckAdvised((now - lastCheck) > CHECKINTERVAL);
bool recentTimerChange((now - lastTimerModification) <= CHECKINTERVAL);
if (recentTimerChange || (reCheckAdvised && TimerConflicts::CheckAdvised())) {
lastCheck = now;
conflicts.reset(new TimerConflicts());
return conflicts->size() > 0;
}
return false;
}
void TimerConflictNotifier::SetTimerModification()
{
lastTimerModification = time(0);
}
std::string TimerConflictNotifier::Message() const
{
int count = conflicts ? conflicts->size() : 0;
std::string msg = tr("Timer conflict check detected ");
msg += ConvertToString(count) + " ";
if (count == 1)
msg += tr("conflict");
else
msg += tr("conflicts");
return count > 0 ? msg + "!" : "";
}
std::string TimerConflictNotifier::Url() const
{
return "timerconflicts.html";
}
} // namespace vdrlive