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 Video* video = Video::getInstance();
83 UCHAR screenSize = video->getFormat();
85 // moved from startup because surface delete doesn't work
89 Led::getInstance()->on();
93 v->setDimensions(video->getScreenHeight(), video->getScreenWidth());
94 v->setBackgroundColour(Colour::VIDEOBLUE);
98 viewman->removeView(v);
101 VWallpaper* w = new VWallpaper();
102 if (screenSize == Video::PAL)
104 logger->log("Command", Log::DEBUG, "PAL wallpaper selected");
105 w->init("/wallpaperPAL.jpg");
109 logger->log("Command", Log::DEBUG, "NTSC wallpaper selected");
110 w->init("/wallpaperNTSC.jpg");
117 // handleCommand(Remote::TWO);
118 // handleCommand(Remote::UP);
119 // handleCommand(Remote::PLAY);
121 // handleCommand(Remote::DOWN);
122 // handleCommand(Remote::OK);
124 // handleCommand(Remote::DOWN);
125 // handleCommand(Remote::DOWN);
126 // handleCommand(Remote::DOWN);
127 // handleCommand(Remote::OK);
132 // 2 = multiple servers, showing select box
133 // 3 = a server has been selected
141 if (state != 4) // not really necessary, but chops out all the connecting rubbish if already connected
146 broadcastForServers();
153 if (serverIPs.size() == 1)
162 VServerSelect* vs = new VServerSelect(&serverIPs, &selectServer);
171 // entering loop for 2nd time.. has a server been selected?
172 if (selectServer != -1) state = 3;
177 logger->log("Command", Log::DEBUG, "Server selected: %i", selectServer);
179 int success = connectToServer(selectServer);
184 VWelcome* vw = new VWelcome();
190 // test area for just after connect
191 char* svideo = VDR::getInstance()->configLoad("TV", "S-Video");
195 if (!strcasecmp(svideo, "Yes"))
197 logger->log("Command", Log::INFO, "Switching to S-Video as S-Video=%s", svideo);
198 video->setConnection(Video::SVIDEO);
202 logger->log("Command", Log::INFO, "Leaving video output as S-Video=%s", svideo);
207 logger->log("Command", Log::INFO, "Config TV/S-Video not found");
212 if ((isWidescreen != NULL) && (!strcmp(isWidescreen, "Yes")))
214 logger->log("Command", Log::DEBUG, "Setting 16x9");
216 int a = video->setAspectRatio(Video::ASPECT16X9);
217 printf("success = %i\n", a);
223 logger->log("Command", Log::DEBUG, "Setting 4x3");
224 int a = video->setAspectRatio(Video::ASPECT4X3);
225 printf("success = %i\n", a);
239 if (state == 0) continue;
241 // if state == 2 then drop to remote handling below
243 // if state == 4 then drop through to main system, job done
247 button = remote->getButtonPress(2); // FIXME why is this set to 2 and not 0? so it can quit
248 if ((button == Remote::NONE) || (button == Remote::UNKNOWN)) continue;
250 if (button != Remote::SIGNAL) handleCommand(button);
251 processMessageQueue();
255 void Command::postMessage(Message* m)
257 MessageQueue::postMessage(m);
258 kill(mainPid, SIGURG);
261 void Command::processMessage(Message* m)
263 logger->log("Command", Log::DEBUG, "processing message %i", m->message);
267 case Message::STANDBY:
272 case Message::STOP_PLAYBACK:
274 handleCommand(Remote::STOP); // an odd way of doing it, but so simple
280 void Command::clearServerIPs()
282 // Clear the serverIPs vector
283 for(UINT k = 0; k < serverIPs.size(); k++)
285 delete[] serverIPs[k];
290 void Command::handleCommand(int button)
292 if (state == 5 && (button != Remote::POWER)) return;
294 if (viewman->handleCommand(button)) return;
296 // command was not handled
303 VVolume* v = new VVolume();
304 v->handleCommand(button); // this will draw+show
306 viewman->timedDelete(v, 2, 1);
311 VMute* v = new VMute();
315 viewman->timedDelete(v, 2, 1);
325 Osd::getInstance()->screenShot("/out.jpg");
331 void Command::broadcastForServers()
333 VInfo* viewWait = new VInfo();
334 viewWait->setDimensions(200, 400);
335 if (Video::getInstance()->getFormat() == Video::PAL)
337 viewWait->setScreenPos(170, 200);
341 viewWait->setScreenPos(160, 150);
343 viewWait->setMainText("\n Locating server");
346 viewman->add(viewWait);
349 VDR* vdr = VDR::getInstance();
350 vdr->findServers(serverIPs);
352 viewman->removeView(viewWait);
355 int Command::connectToServer(int vectorIndex)
360 VDR* vdr = VDR::getInstance();
361 vdr->setServerIP(serverIPs[vectorIndex]);
363 logger->log("Command", Log::NOTICE, "Connecting to server at %s", serverIPs[vectorIndex]);
365 VInfo* viewWait = new VInfo();
366 viewWait->setDimensions(200, 400);
367 if (Video::getInstance()->getFormat() == Video::PAL)
369 viewWait->setScreenPos(170, 200);
373 viewWait->setScreenPos(160, 150);
375 viewWait->setMainText("\n Connecting to VDR");
378 viewman->add(viewWait);
380 int success = vdr->connect();
384 logger->log("Command", Log::DEBUG, "Connected ok, doing login");
385 success = vdr->doLogin();
389 strcpy(a, "\n Connected");
391 ts.tv_nsec = 500000000;
395 strcpy(a, "\n Login failed");
402 strcpy(a, "\n Connection failed");
407 viewWait->setMainText(a);
411 if (irun) nanosleep(&ts, NULL); // only do the wait if we aren't shutting down
414 vdr->configSave("Section Name This Is blah blah blah 495834509725049375032end", "thekey with this space ", "1234value");
417 char* conf = vdr->configLoad("fred", "bill");
420 //printf("And the config value returned is %s\n", conf);
425 //printf("Conf value return is NULL :(\n");
429 viewman->removeView(viewWait);
434 void Command::doStandby()
438 Video::getInstance()->signalOn();
439 Led::getInstance()->on();
444 ViewMan* viewman = ViewMan::getInstance();
446 viewman->removeAll();
447 viewman->redrawAll();
450 VDR::getInstance()->disconnect();
451 Video::getInstance()->signalOff();
452 Led::getInstance()->off();
457 void Command::doReboot()
459 VDR::getInstance()->disconnect();
461 logger->log("Command", Log::NOTICE, "Reboot");
462 reboot(LINUX_REBOOT_CMD_RESTART);