forked from yavdr/vdr-plugin-restfulapi
-
Notifications
You must be signed in to change notification settings - Fork 3
/
remote.cpp
128 lines (116 loc) · 4 KB
/
remote.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
#include "remote.h"
using namespace std;
void RemoteResponder::reply(ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply)
{
QueryHandler::addHeader(reply);
if (request.method() != "POST") {
reply.httpReturn(403, "Only POST method is support by the remote control");
return;
}
if ( (int)request.url().find("/remote/switch") != -1 ) {
QueryHandler q("/remote/switch", request);
cChannel* channel = VdrExtension::getChannel(q.getParamAsString(0));
if ( channel == NULL ) {
reply.httpReturn(404, "Channel-Id is not valid.");
/*} else if ( !Channels.SwitchTo( channel->Number() ) ) {
reply.httpReturn(404, "Couldn't switch to channel.");
}*/
} else {
TaskScheduler::get()->SwitchableChannel(channel->GetChannelID());
}
return;
}
QueryHandler q("/remote", request);
string key = q.getParamAsString(0);
if (key.length() == 0) {
reply.httpReturn(404, "Please add a key to the parameter list, see API-file for more details.");
return;
}
if (!keyPairList->hitKey(key.c_str())) {
reply.httpReturn(404, "Remote Control does not support the requested key.");
}
}
KeyPairList::KeyPairList()
{
append( "up" , kUp );
append( "down" , kDown );
append( "menu" , kMenu );
append( "ok" , kOk );
append( "back" , kBack );
append( "left" , kLeft );
append( "right" , kRight );
append( "red" , kRed );
append( "green" , kGreen );
append( "yellow" , kYellow );
append( "blue" , kBlue );
append( "0" , k0 );
append( "1" , k1 );
append( "2" , k2 );
append( "3" , k3 );
append( "4" , k4 );
append( "5" , k5 );
append( "6" , k6 );
append( "7" , k7 );
append( "8" , k8 );
append( "9" , k9 );
append( "info" , kInfo );
append( "play" , kPlay );
append( "pause" , kPause );
append( "stop" , kStop );
append( "record" , kRecord );
append( "fastfwd" , kFastFwd );
append( "fastrew" , kFastRew );
append( "next" , kNext );
append( "prev" , kPrev );
append( "power" , kPower );
append( "chanup" , kChanUp );
append( "chandn" , kChanDn );
append( "chanprev", kChanPrev );
append( "volup" , kVolUp );
append( "voldn" , kVolDn );
append( "mute" , kMute );
append( "audio" , kAudio );
append( "subtitles" , kSubtitles );
append( "schedule" , kSchedule );
append( "channels" , kChannels );
append( "timers" , kTimers );
append( "recordings", kRecordings );
append( "setup" , kSetup );
append( "commands" , kCommands );
#if APIVERSNUM >= 10715
append( "user0" , kUser0 );
#endif
append( "user1" , kUser1 );
append( "user2" , kUser2 );
append( "user3" , kUser3 );
append( "user4" , kUser4 );
append( "user5" , kUser5 );
append( "user6" , kUser6 );
append( "user7" , kUser7 );
append( "user8" , kUser8 );
append( "user9" , kUser9 );
append( "none" , kNone );
append( "kbd" , kKbd );
}
KeyPairList::~KeyPairList()
{
}
bool KeyPairList::hitKey(string key)
{
for (int i=0;i<(int)key.length();i++) {
key[i] = tolower(key[i]);
}
for (int i=0;i<(int)keys.size();i++)
{
if (string(keys[i].str) == key) {
cRemote::Put(keys[i].key);
return true;
}
}
return false;
}
void KeyPairList::append(const char* str, eKeys key)
{
eKeyPair keyPair = { str, key };
keys.push_back(keyPair);
}