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);
203 video->setConnection(Video::COMPOSITERGB);
208 logger->log("Command", Log::INFO, "Config TV/S-Video not found");
213 if ((isWidescreen != NULL) && (!strcmp(isWidescreen, "Yes")))
215 logger->log("Command", Log::DEBUG, "Setting 16x9");
217 int a = video->setAspectRatio(Video::ASPECT16X9);
218 printf("success = %i\n", a);
224 logger->log("Command", Log::DEBUG, "Setting 4x3");
225 int a = video->setAspectRatio(Video::ASPECT4X3);
226 printf("success = %i\n", a);
240 if (state == 0) continue;
242 // if state == 2 then drop to remote handling below
244 // if state == 4 then drop through to main system, job done
248 button = remote->getButtonPress(2); // FIXME why is this set to 2 and not 0? so it can quit
249 if ((button == Remote::NONE) || (button == Remote::UNKNOWN)) continue;
251 if (button != Remote::SIGNAL) handleCommand(button);
252 processMessageQueue();
256 void Command::postMessage(Message* m)
258 MessageQueue::postMessage(m);
259 kill(mainPid, SIGURG);
262 void Command::processMessage(Message* m)
264 logger->log("Command", Log::DEBUG, "processing message %i", m->message);
268 case Message::STANDBY:
273 case Message::STOP_PLAYBACK:
275 handleCommand(Remote::STOP); // an odd way of doing it, but so simple
281 void Command::clearServerIPs()
283 // Clear the serverIPs vector
284 for(UINT k = 0; k < serverIPs.size(); k++)
286 delete[] serverIPs[k];
291 void Command::handleCommand(int button)
293 if (state == 5 && (button != Remote::POWER)) return;
295 if (viewman->handleCommand(button)) return;
297 // command was not handled
304 VVolume* v = new VVolume();
305 v->handleCommand(button); // this will draw+show
307 viewman->timedDelete(v, 2, 1);
312 VMute* v = new VMute();
316 viewman->timedDelete(v, 2, 1);
326 Osd::getInstance()->screenShot("/out.jpg");
332 void Command::broadcastForServers()
334 VInfo* viewWait = new VInfo();
335 viewWait->setDimensions(200, 400);
336 if (Video::getInstance()->getFormat() == Video::PAL)
338 viewWait->setScreenPos(170, 200);
342 viewWait->setScreenPos(160, 150);
344 viewWait->setMainText("\n Locating server");
347 viewman->add(viewWait);
350 VDR* vdr = VDR::getInstance();
351 vdr->findServers(serverIPs);
353 viewman->removeView(viewWait);
356 int Command::connectToServer(int vectorIndex)
361 VDR* vdr = VDR::getInstance();
362 vdr->setServerIP(serverIPs[vectorIndex]);
364 logger->log("Command", Log::NOTICE, "Connecting to server at %s", serverIPs[vectorIndex]);
366 VInfo* viewWait = new VInfo();
367 viewWait->setDimensions(200, 400);
368 if (Video::getInstance()->getFormat() == Video::PAL)
370 viewWait->setScreenPos(170, 200);
374 viewWait->setScreenPos(160, 150);
376 viewWait->setMainText("\n Connecting to VDR");
379 viewman->add(viewWait);
381 int success = vdr->connect();
385 logger->log("Command", Log::DEBUG, "Connected ok, doing login");
386 success = vdr->doLogin();
390 strcpy(a, "\n Connected");
392 ts.tv_nsec = 500000000;
396 strcpy(a, "\n Login failed");
403 strcpy(a, "\n Connection failed");
408 viewWait->setMainText(a);
412 if (irun) nanosleep(&ts, NULL); // only do the wait if we aren't shutting down
415 vdr->configSave("Section Name This Is blah blah blah 495834509725049375032end", "thekey with this space ", "1234value");
418 char* conf = vdr->configLoad("fred", "bill");
421 //printf("And the config value returned is %s\n", conf);
426 //printf("Conf value return is NULL :(\n");
430 viewman->removeView(viewWait);
435 void Command::doStandby()
439 Video::getInstance()->signalOn();
440 Led::getInstance()->on();
445 ViewMan* viewman = ViewMan::getInstance();
447 viewman->removeAll();
448 viewman->redrawAll();
451 VDR::getInstance()->disconnect();
452 Video::getInstance()->signalOff();
453 Led::getInstance()->off();
458 void Command::doReboot()
460 VDR::getInstance()->disconnect();
462 logger->log("Command", Log::NOTICE, "Reboot");
463 reboot(LINUX_REBOOT_CMD_RESTART);