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 // moved from startup because surface delete doesn't work
84 Video::getInstance()->signalOn();
85 Led::getInstance()->on();
89 v->setDimensions(SCREENHEIGHT, SCREENWIDTH);
90 v->setBackgroundColour(0, 0, 150, 255);
94 viewman->removeView(v);
97 VWallpaper* w = new VWallpaper();
98 w->init("/wallpaper.jpg");
104 // handleCommand(Remote::TWO);
105 // handleCommand(Remote::UP);
106 // handleCommand(Remote::PLAY);
108 // handleCommand(Remote::DOWN);
109 // handleCommand(Remote::OK);
111 // handleCommand(Remote::DOWN);
112 // handleCommand(Remote::DOWN);
113 // handleCommand(Remote::DOWN);
114 // handleCommand(Remote::OK);
119 // 2 = multiple servers, showing select box
120 // 3 = a server has been selected
128 if (state != 4) // not really necessary, but chops out all the connecting rubbish if already connected
133 broadcastForServers();
140 if (serverIPs.size() == 1)
149 VServerSelect* vs = new VServerSelect(&serverIPs, &selectServer);
158 // entering loop for 2nd time.. has a server been selected?
159 if (selectServer != -1) state = 3;
164 Log::getInstance()->log("Command", Log::DEBUG, "Server selected: %i", selectServer);
166 int success = connectToServer(selectServer);
171 VWelcome* vw = new VWelcome();
183 if (state == 0) continue;
185 // if state == 2 then drop to remote handling below
187 // if state == 4 then drop through to main system, job done
191 button = remote->getButtonPress(2); // FIXME why is this set to 2 and not 0? so it can quit
192 if ((button == Remote::NONE) || (button == Remote::UNKNOWN)) continue;
194 if (button != Remote::SIGNAL) handleCommand(button);
195 processMessageQueue();
199 void Command::postMessage(Message* m)
201 MessageQueue::postMessage(m);
202 kill(mainPid, SIGURG);
205 void Command::processMessage(Message* m)
207 Log::getInstance()->log("Command", Log::DEBUG, "processing message %i", m->message);
211 case Message::STANDBY:
216 case Message::STOP_PLAYBACK:
218 handleCommand(Remote::STOP); // an odd way of doing it, but so simple
224 void Command::clearServerIPs()
226 // Clear the serverIPs vector
227 for(UINT k = 0; k < serverIPs.size(); k++)
229 delete[] serverIPs[k];
234 void Command::handleCommand(int button)
236 if (state == 5 && (button != Remote::POWER)) return;
238 if (viewman->handleCommand(button)) return;
240 // command was not handled
247 VVolume* v = new VVolume();
248 v->handleCommand(button); // this will draw+show
250 viewman->timedDelete(v, 2, 1);
255 VMute* v = new VMute();
259 viewman->timedDelete(v, 2, 1);
269 Osd::getInstance()->screenShot("/out.jpg");
275 void Command::broadcastForServers()
277 VInfo* viewWait = new VInfo();
278 viewWait->setDimensions(200, 400);
279 viewWait->setScreenPos(170, 200);
280 viewWait->setMainText("\n Locating server");
283 viewman->add(viewWait);
286 VDR* vdr = VDR::getInstance();
287 vdr->findServers(serverIPs);
289 viewman->removeView(viewWait);
292 int Command::connectToServer(int vectorIndex)
297 VDR* vdr = VDR::getInstance();
298 vdr->setServerIP(serverIPs[vectorIndex]);
300 logger->log("Command", Log::NOTICE, "Connecting to server at %s", serverIPs[vectorIndex]);
302 VInfo* viewWait = new VInfo();
303 viewWait->setDimensions(200, 400);
304 viewWait->setScreenPos(170, 200);
305 viewWait->setMainText("\n Connecting to VDR");
308 viewman->add(viewWait);
310 int success = vdr->connect();
314 Log::getInstance()->log("Command", Log::DEBUG, "Connected ok, doing login");
315 success = vdr->doLogin();
319 strcpy(a, "\n Connected");
321 ts.tv_nsec = 500000000;
325 strcpy(a, "\n Login failed");
332 strcpy(a, "\n Connection failed");
337 viewWait->setMainText(a);
341 if (irun) nanosleep(&ts, NULL); // only do the wait if we aren't shutting down
344 vdr->configSave("Section Name This Is blah blah blah 495834509725049375032end", "thekey with this space ", "1234value");
347 char* conf = vdr->configLoad("fred", "bill");
350 //printf("And the config value returned is %s\n", conf);
355 //printf("Conf value return is NULL :(\n");
359 viewman->removeView(viewWait);
364 void Command::doStandby()
368 Video::getInstance()->signalOn();
369 Led::getInstance()->on();
374 ViewMan* viewman = ViewMan::getInstance();
376 viewman->removeAll();
377 viewman->redrawAll();
380 VDR::getInstance()->disconnect();
381 Video::getInstance()->signalOff();
382 Led::getInstance()->off();
387 void Command::doReboot()
389 VDR::getInstance()->disconnect();
391 logger->log("Command", Log::NOTICE, "Reboot");
392 reboot(LINUX_REBOOT_CMD_RESTART);