2 Copyright 2004-2005 Chris Tallon
4 This file is part of VOMP.
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.
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.
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
23 Command* Command::instance = NULL;
38 Command* Command::getInstance()
45 if (initted) return 0;
48 logger = Log::getInstance();
49 viewman = ViewMan::getInstance();
50 remote = Remote::getInstance();
52 if (!logger || !viewman || !remote)
61 int Command::shutdown()
63 if (!initted) return 0;
70 VDR::getInstance()->cancelFindingServer();
81 UCHAR screenSize = Osd::getInstance()->getScreenSize();
83 // moved from startup because surface delete doesn't work
86 Video::getInstance()->signalOn();
87 Led::getInstance()->on();
91 v->setDimensions(Osd::getInstance()->getScreenHeight(), Osd::getInstance()->getScreenWidth());
92 v->setBackgroundColour(Colour::VIDEOBLUE);
96 viewman->removeView(v);
99 VWallpaper* w = new VWallpaper();
100 if (screenSize == Osd::PAL)
102 Log::getInstance()->log("Command", Log::DEBUG, "PAL wallpaper selected");
103 w->init("/wallpaperPAL.jpg");
107 Log::getInstance()->log("Command", Log::DEBUG, "NTSC wallpaper selected");
108 w->init("/wallpaperNTSC.jpg");
115 // handleCommand(Remote::TWO);
116 // handleCommand(Remote::UP);
117 // handleCommand(Remote::PLAY);
119 // handleCommand(Remote::DOWN);
120 // handleCommand(Remote::OK);
122 // handleCommand(Remote::DOWN);
123 // handleCommand(Remote::DOWN);
124 // handleCommand(Remote::DOWN);
125 // handleCommand(Remote::OK);
130 // 2 = multiple servers, showing select box
131 // 3 = a server has been selected
139 if (state != 4) // not really necessary, but chops out all the connecting rubbish if already connected
144 broadcastForServers();
151 if (serverIPs.size() == 1)
160 VServerSelect* vs = new VServerSelect(&serverIPs, &selectServer);
169 // entering loop for 2nd time.. has a server been selected?
170 if (selectServer != -1) state = 3;
175 Log::getInstance()->log("Command", Log::DEBUG, "Server selected: %i", selectServer);
177 int success = connectToServer(selectServer);
182 VWelcome* vw = new VWelcome();
194 if (state == 0) continue;
196 // if state == 2 then drop to remote handling below
198 // if state == 4 then drop through to main system, job done
202 button = remote->getButtonPress(2); // FIXME why is this set to 2 and not 0? so it can quit
203 if ((button == Remote::NONE) || (button == Remote::UNKNOWN)) continue;
205 if (button != Remote::SIGNAL) handleCommand(button);
206 processMessageQueue();
210 void Command::postMessage(Message* m)
212 MessageQueue::postMessage(m);
213 kill(mainPid, SIGURG);
216 void Command::processMessage(Message* m)
218 Log::getInstance()->log("Command", Log::DEBUG, "processing message %i", m->message);
222 case Message::STANDBY:
227 case Message::STOP_PLAYBACK:
229 handleCommand(Remote::STOP); // an odd way of doing it, but so simple
235 void Command::clearServerIPs()
237 // Clear the serverIPs vector
238 for(UINT k = 0; k < serverIPs.size(); k++)
240 delete[] serverIPs[k];
245 void Command::handleCommand(int button)
247 if (state == 5 && (button != Remote::POWER)) return;
249 if (viewman->handleCommand(button)) return;
251 // command was not handled
258 VVolume* v = new VVolume();
259 v->handleCommand(button); // this will draw+show
261 viewman->timedDelete(v, 2, 1);
266 VMute* v = new VMute();
270 viewman->timedDelete(v, 2, 1);
280 Osd::getInstance()->screenShot("/out.jpg");
286 void Command::broadcastForServers()
288 VInfo* viewWait = new VInfo();
289 viewWait->setDimensions(200, 400);
290 if (Osd::getInstance()->getScreenSize() == Osd::PAL)
292 viewWait->setScreenPos(170, 200);
296 viewWait->setScreenPos(160, 150);
298 viewWait->setMainText("\n Locating server");
301 viewman->add(viewWait);
304 VDR* vdr = VDR::getInstance();
305 vdr->findServers(serverIPs);
307 viewman->removeView(viewWait);
310 int Command::connectToServer(int vectorIndex)
315 VDR* vdr = VDR::getInstance();
316 vdr->setServerIP(serverIPs[vectorIndex]);
318 logger->log("Command", Log::NOTICE, "Connecting to server at %s", serverIPs[vectorIndex]);
320 VInfo* viewWait = new VInfo();
321 viewWait->setDimensions(200, 400);
322 if (Osd::getInstance()->getScreenSize() == Osd::PAL)
324 viewWait->setScreenPos(170, 200);
328 viewWait->setScreenPos(160, 150);
330 viewWait->setMainText("\n Connecting to VDR");
333 viewman->add(viewWait);
335 int success = vdr->connect();
339 Log::getInstance()->log("Command", Log::DEBUG, "Connected ok, doing login");
340 success = vdr->doLogin();
344 strcpy(a, "\n Connected");
346 ts.tv_nsec = 500000000;
350 strcpy(a, "\n Login failed");
357 strcpy(a, "\n Connection failed");
362 viewWait->setMainText(a);
366 if (irun) nanosleep(&ts, NULL); // only do the wait if we aren't shutting down
369 vdr->configSave("Section Name This Is blah blah blah 495834509725049375032end", "thekey with this space ", "1234value");
372 char* conf = vdr->configLoad("fred", "bill");
375 //printf("And the config value returned is %s\n", conf);
380 //printf("Conf value return is NULL :(\n");
384 viewman->removeView(viewWait);
389 void Command::doStandby()
393 Video::getInstance()->signalOn();
394 Led::getInstance()->on();
399 ViewMan* viewman = ViewMan::getInstance();
401 viewman->removeAll();
402 viewman->redrawAll();
405 VDR::getInstance()->disconnect();
406 Video::getInstance()->signalOff();
407 Led::getInstance()->off();
412 void Command::doReboot()
414 VDR::getInstance()->disconnect();
416 logger->log("Command", Log::NOTICE, "Reboot");
417 reboot(LINUX_REBOOT_CMD_RESTART);