]> git.vomp.tv Git - vompclient.git/blob - remotewin.cc
Prebuffering
[vompclient.git] / remotewin.cc
1 /*
2     Copyright 2004-2005 Chris Tallon
3
4     This file is part of VOMP.
5
6     VOMP is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     VOMP is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with VOMP; if not, write to the Free Software
18     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20
21 #include "remotewin.h"
22
23
24 RemoteWin::RemoteWin()
25 {
26   initted = 0;
27   curevent=NA_NONE;
28   signal=false;
29 }
30
31 RemoteWin::~RemoteWin()
32 {
33 }
34
35 int RemoteWin::init(char* devName)
36 {
37   if (initted) return 0;
38   initted = 1;
39   event = CreateEvent(NULL,/*FALSE*/TRUE,FALSE,NULL);
40
41
42   return 1;
43 }
44
45 int RemoteWin::shutdown()
46 {
47   if (!initted) return 0;
48   CloseHandle(event);
49   initted = 0;
50   return 1;
51 }
52
53 UCHAR RemoteWin::getButtonPress(int waitType)
54 {
55   /* how = 0 - block
56      how = 1 - start new wait
57      how = 2 - continue wait
58      how = 3 - no wait
59   */
60   DWORD wait;
61
62   if (curevent!=NA_NONE) {
63     UCHAR temp=curevent;
64     curevent=NA_NONE;
65     return temp;
66   }
67   if (waitType==3) {
68     return NA_NONE;
69   }
70   if (waitType==0) {
71     wait=INFINITE;
72   } else { //We do not distingish between 2 and 3
73     wait=1000;
74
75   }
76   WaitForSingleObject(event,wait);
77   ResetEvent(event);
78   if (curevent==NA_NONE) {
79     if (signal) {
80       signal=false;
81     return NA_SIGNAL; //Since we have no signals on windows, we simulate this
82     } else {
83       return NA_NONE;
84     }
85   }
86   UCHAR temp2=curevent;
87   curevent=NA_NONE;
88   return temp2;
89
90 }
91
92 void RemoteWin::clearBuffer()
93 {
94 }
95
96 int RemoteWin::ReceiveButtonVK(UINT button) {
97   UCHAR pb=NA_NONE;
98   //should we use a translation table ? No APPCOMMAND iS DWORD!
99   switch (button) { //Processing VK_Messages
100   case VK_DOWN:
101     pb=DOWN; break;
102   case VK_RETURN:
103   case VK_SPACE:
104     pb=OK;break;
105   case VK_LEFT:
106     pb=LEFT;break;
107   case '9':
108   case VK_NUMPAD9:
109     pb=NINE;break;
110   case '8':
111   case VK_NUMPAD8:
112     pb=EIGHT;break;
113   case '7':
114   case VK_NUMPAD7:
115     pb=SEVEN;break;
116   case '6':
117   case VK_NUMPAD6:
118     pb=SIX;break;
119   case '5':
120   case VK_NUMPAD5:
121     pb=FIVE;break;
122   case '4':
123   case VK_NUMPAD4:
124     pb=FOUR;break;
125   case '3':
126   case VK_NUMPAD3:
127     pb=THREE;break;
128   case '2':
129   case VK_NUMPAD2:
130     pb=TWO;break;
131   case '1':
132   case VK_NUMPAD1:
133     pb=ONE;break;
134   case '0':
135   case VK_NUMPAD0:
136     pb=ZERO;break;
137   case VK_RIGHT:
138     pb=RIGHT;break;
139   case VK_UP:
140     pb=UP;break;
141   case VK_MULTIPLY:
142     pb=STAR;break;
143   case 'J'://j for JUMP TO instead of go to
144     pb=GO;break;
145   case VK_ESCAPE:
146     pb=POWER;break;
147   case VK_BACK:
148     pb=BACK;break;
149   case 'M':
150     pb=MENU;break;
151   case 'R':
152     pb=RED;break;
153   case 'G':
154     pb=GREEN;break;
155   case 'Y':
156     pb=YELLOW;break;
157   case 'B':
158     pb=BLUE; break;
159
160
161   }; //All other commands are process via APPCOMMAND_MESSAGES
162   if (pb==NA_NONE) return 0;
163   curevent=pb;
164   //PulseEvent(event);
165   SetEvent(event);
166   return 1;
167 }
168
169 int RemoteWin::ReceiveButtonAP(UINT button) {
170   UCHAR pb=NA_NONE;
171   //should we use a translation table ? No APPCOMMAND iS DWORD!
172   switch (button) { //Processing VK_Messages
173   case APPCOMMAND_MEDIA_CHANNEL_DOWN:
174     pb=CHANNELDOWN;break;
175   case APPCOMMAND_MEDIA_CHANNEL_UP:
176     pb=CHANNELUP;break;
177   case APPCOMMAND_MEDIA_FAST_FORWARD:
178     pb=FORWARD;break;
179   case APPCOMMAND_VOLUME_MUTE:
180     pb=MUTE;break;
181   case APPCOMMAND_MEDIA_PAUSE:
182     pb=PAUSE;break;
183   case APPCOMMAND_MEDIA_PLAY:
184     pb=PLAY;break;
185   case APPCOMMAND_MEDIA_RECORD:
186     pb=RECORD;break;
187   case APPCOMMAND_MEDIA_PREVIOUSTRACK:
188     pb=SKIPBACK;break;
189   case APPCOMMAND_MEDIA_REWIND:
190     pb=REVERSE;break;
191   case APPCOMMAND_MEDIA_NEXTTRACK:
192     pb=SKIPFORWARD;break;
193   case APPCOMMAND_MEDIA_STOP:
194     pb=STOP;break;
195   case APPCOMMAND_VOLUME_DOWN:
196     pb=VOLUMEDOWN;break;
197   case APPCOMMAND_VOLUME_UP:
198     pb=VOLUMEUP;break;
199   };
200   if (pb==NA_NONE) return 0;
201   curevent=pb;
202   //PulseEvent(event);
203   SetEvent(event);
204   return 1;
205 }
206
207 void RemoteWin::Signal() {
208   signal=true;
209   //PulseEvent(event);
210   SetEvent(event);
211 }