if (instance) return;
instance = this;
initted = 0;
- state = 0;
+ isStandby = 0;
+ firstBoot = 1;
}
Command::~Command()
w->show();
viewman->add(w);
+ VConnect* vconnect = new VConnect();
+ viewman->add(vconnect);
+ vconnect->run();
-// handleCommand(Remote::TWO);
-// handleCommand(Remote::UP);
-// handleCommand(Remote::PLAY);
-// handleCommand(Remote::DOWN);
-// handleCommand(Remote::OK);
-
-// handleCommand(Remote::DOWN);
-// handleCommand(Remote::DOWN);
-// handleCommand(Remote::DOWN);
-// handleCommand(Remote::OK);
-
- // state values:
- // 0 = not connected
- // 1 = got servers
- // 2 = multiple servers, showing select box
- // 3 = a server has been selected
- // 4 = connected
- // 5 = standby
-
- int selectServer;
UCHAR button = 0;
while(irun)
{
- if (state != 4) // not really necessary, but chops out all the connecting rubbish if already connected
- {
- if (state == 0)
- {
- clearServerIPs();
- broadcastForServers();
- if (!irun) break;
- state = 1;
- }
-
- if (state == 1)
- {
- if (serverIPs.size() == 1)
- {
- selectServer = 0;
- state = 3;
- }
- else
- {
- selectServer = -1;
- state = 2;
- VServerSelect* vs = new VServerSelect(&serverIPs, &selectServer);
- vs->draw();
- vs->show();
- viewman->add(vs);
- }
- }
-
- if (state == 2)
- {
- // entering loop for 2nd time.. has a server been selected?
- if (selectServer != -1) state = 3;
- }
-
- if (state == 3)
- {
- logger->log("Command", Log::DEBUG, "Server selected: %i", selectServer);
-
- int success = connectToServer(selectServer);
- clearServerIPs();
-
- if (success)
- {
- VWelcome* vw = new VWelcome();
- vw->draw();
- vw->show();
- viewman->add(vw);
- state = 4;
-
- // test area for just after connect
- char* svideo = VDR::getInstance()->configLoad("TV", "S-Video");
-
- if (svideo)
- {
- if (!strcasecmp(svideo, "Yes"))
- {
- logger->log("Command", Log::INFO, "Switching to S-Video as S-Video=%s", svideo);
- video->setConnection(Video::SVIDEO);
- }
- else
- {
- logger->log("Command", Log::INFO, "Leaving video output as S-Video=%s", svideo);
- video->setConnection(Video::COMPOSITERGB);
- }
- }
- else
- {
- logger->log("Command", Log::INFO, "Config TV/S-Video not found");
- }
-
-/*
-
- if ((isWidescreen != NULL) && (!strcmp(isWidescreen, "Yes")))
- {
- logger->log("Command", Log::DEBUG, "Setting 16x9");
-
- int a = video->setAspectRatio(Video::ASPECT16X9);
- printf("success = %i\n", a);
- video->reset();
- }
- else
- {
- //temp
- logger->log("Command", Log::DEBUG, "Setting 4x3");
- int a = video->setAspectRatio(Video::ASPECT4X3);
- printf("success = %i\n", a);
- video->reset();
- }
-*/
-
- // end of test area
-
- }
- else
- {
- state = 0;
- }
- }
-
- if (state == 0) continue;
- // state can't be 1
- // if state == 2 then drop to remote handling below
- // state can't be 3
- // if state == 4 then drop through to main system, job done
- }
-
-
button = remote->getButtonPress(2); // FIXME why is this set to 2 and not 0? so it can quit
if ((button == Remote::NONE) || (button == Remote::UNKNOWN)) continue;
handleCommand(Remote::STOP); // an odd way of doing it, but so simple
break;
}
+ case Message::VDR_CONNECTED:
+ {
+ doJustConnected((VConnect*)m->from);
+ break;
+ }
}
}
-void Command::clearServerIPs()
-{
- // Clear the serverIPs vector
- for(UINT k = 0; k < serverIPs.size(); k++)
- {
- delete[] serverIPs[k];
- }
- serverIPs.clear();
-}
-
void Command::handleCommand(int button)
{
- if (state == 5 && (button != Remote::POWER)) return;
+ if (isStandby && (button != Remote::POWER)) return;
if (viewman->handleCommand(button)) return;
}
}
-void Command::broadcastForServers()
+void Command::doStandby()
{
- VInfo* viewWait = new VInfo();
- viewWait->setDimensions(200, 400);
- if (Video::getInstance()->getFormat() == Video::PAL)
+ if (isStandby)
{
- viewWait->setScreenPos(170, 200);
+ Video::getInstance()->signalOn();
+ Led::getInstance()->on();
+ isStandby = 0;
+
+
+ VConnect* vconnect = new VConnect();
+ viewman->add(vconnect);
+ vconnect->run();
}
else
{
- viewWait->setScreenPos(160, 150);
- }
- viewWait->setMainText("\n Locating server");
- viewWait->draw();
- viewWait->show();
- viewman->add(viewWait);
+ ViewMan* viewman = ViewMan::getInstance();
+ viewman->removeAll();
+ viewman->redrawAll();
- VDR* vdr = VDR::getInstance();
- vdr->findServers(serverIPs);
- if (!irun) return;
- viewman->removeView(viewWait);
+ VDR::getInstance()->configSave("General", "Last Power State", "Off");
+ VDR::getInstance()->disconnect();
+ Video::getInstance()->signalOff();
+ Led::getInstance()->off();
+ isStandby = 1;
+ }
}
-int Command::connectToServer(int vectorIndex)
+void Command::doReboot()
{
- char a[60];
- struct timespec ts;
+ VDR::getInstance()->disconnect();
+ // just kill it...
+ logger->log("Command", Log::NOTICE, "Reboot");
+ reboot(LINUX_REBOOT_CMD_RESTART);
+}
+void Command::doJustConnected(VConnect* vconnect)
+{
VDR* vdr = VDR::getInstance();
- vdr->setServerIP(serverIPs[vectorIndex]);
+ ViewMan* viewman = ViewMan::getInstance();
+ viewman->removeView(vconnect, 0, 1);
- logger->log("Command", Log::NOTICE, "Connecting to server at %s", serverIPs[vectorIndex]);
-
- VInfo* viewWait = new VInfo();
- viewWait->setDimensions(200, 400);
- if (Video::getInstance()->getFormat() == Video::PAL)
- {
- viewWait->setScreenPos(170, 200);
- }
- else
+ // Power off if first boot and config says so
+ if (firstBoot)
{
- viewWait->setScreenPos(160, 150);
- }
- viewWait->setMainText("\n Connecting to VDR");
- viewWait->draw();
- viewWait->show();
- viewman->add(viewWait);
+ firstBoot = 0;
- int success = vdr->connect();
-
- if (success)
- {
- logger->log("Command", Log::DEBUG, "Connected ok, doing login");
- success = vdr->doLogin();
+ char* powerAfterBoot = vdr->configLoad("General", "Power After Boot");
- if (success)
+ if (powerAfterBoot)
{
- strcpy(a, "\n Connected");
- ts.tv_sec = 0;
- ts.tv_nsec = 500000000;
+ if (!strcasecmp(powerAfterBoot, "On"))
+ {
+ logger->log("Command", Log::INFO, "Config says Power After Boot = On");
+ }
+ else if (!strcasecmp(powerAfterBoot, "Off"))
+ {
+ logger->log("Command", Log::INFO, "Config says Power After Boot = Off");
+ doStandby();
+ return; // quit here
+ }
+ else if (!strcasecmp(powerAfterBoot, "Last state"))
+ {
+ char* lastPowerState = vdr->configLoad("General", "Last Power State");
+ if (lastPowerState)
+ {
+ if (!strcasecmp(lastPowerState, "On"))
+ {
+ logger->log("Command", Log::INFO, "Config says Last Power State = On");
+ }
+ else if (!strcasecmp(lastPowerState, "Off"))
+ {
+ logger->log("Command", Log::INFO, "Config says Last Power State = Off");
+ doStandby();
+ return; // quit here
+ }
+ else
+ {
+ logger->log("Command", Log::INFO, "Config General/Last Power State not understood");
+ }
+ }
+ else
+ {
+ logger->log("Command", Log::INFO, "Config General/Last Power State not found");
+ }
+ }
+ else
+ {
+ logger->log("Command", Log::INFO, "Config/Power After Boot not understood");
+ }
}
else
{
- strcpy(a, "\n Login failed");
- ts.tv_sec = 3;
- ts.tv_nsec = 0;
+ logger->log("Command", Log::INFO, "Config General/Power After Boot not found");
}
}
- else
- {
- strcpy(a, "\n Connection failed");
- ts.tv_sec = 3;
- ts.tv_nsec = 0;
- }
-
- viewWait->setMainText(a);
- viewWait->draw();
- viewWait->show();
- if (irun) nanosleep(&ts, NULL); // only do the wait if we aren't shutting down
+ // Save power state = on
-/*
- vdr->configSave("Section Name This Is blah blah blah 495834509725049375032end", "thekey with this space ", "1234value");
- sleep(10);
+ vdr->configSave("General", "Last Power State", "On");
- char* conf = vdr->configLoad("fred", "bill");
- if (conf)
- {
- //printf("And the config value returned is %s\n", conf);
- delete[] conf;
- }
- else
- {
- //printf("Conf value return is NULL :(\n");
- }
-*/
- viewman->removeView(viewWait);
+ // Go S-Video if config says so
- return success;
-}
+ char* svideo = vdr->configLoad("TV", "S-Video");
-void Command::doStandby()
-{
- if (state == 5)
+ if (svideo)
{
- Video::getInstance()->signalOn();
- Led::getInstance()->on();
- state = 0;
+ if (!strcasecmp(svideo, "Yes"))
+ {
+ logger->log("Command", Log::INFO, "Switching to S-Video as S-Video=%s", svideo);
+ Video::getInstance()->setConnection(Video::SVIDEO);
+ }
+ else
+ {
+ logger->log("Command", Log::INFO, "Leaving video output as S-Video=%s", svideo);
+ Video::getInstance()->setConnection(Video::COMPOSITERGB);
+ }
}
else
{
- ViewMan* viewman = ViewMan::getInstance();
-
- viewman->removeAll();
- viewman->redrawAll();
-
-
- VDR::getInstance()->disconnect();
- Video::getInstance()->signalOff();
- Led::getInstance()->off();
- state = 5;
+ logger->log("Command", Log::INFO, "Config TV/S-Video not found");
}
-}
-void Command::doReboot()
-{
- VDR::getInstance()->disconnect();
- // just kill it...
- logger->log("Command", Log::NOTICE, "Reboot");
- reboot(LINUX_REBOOT_CMD_RESTART);
+ // s video done
+
+ VWelcome* vw = new VWelcome();
+ viewman->add(vw);
+ viewman->redrawAll();
}
--- /dev/null
+/*
+ Copyright 2004-2005 Chris Tallon
+
+ This file is part of VOMP.
+
+ VOMP is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ VOMP is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with VOMP; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#include "vconnect.h"
+
+VConnect::VConnect()
+{
+ vdr = VDR::getInstance();
+ logger = Log::getInstance();
+
+ setDimensions(200, 400);
+ if (Video::getInstance()->getFormat() == Video::PAL)
+ {
+ setScreenPos(170, 200);
+ }
+ else
+ {
+ setScreenPos(160, 150);
+ }
+
+ exitable = 0;
+ irun = 0;
+}
+
+VConnect::~VConnect()
+{
+ irun = 0;
+ vdr->cancelFindingServer();
+ threadStop();
+}
+
+void VConnect::draw()
+{
+ VInfo::draw();
+}
+
+int VConnect::handleCommand(int command)
+{
+ return 1;
+}
+
+void VConnect::run()
+{
+ threadStart();
+}
+
+void VConnect::threadMethod()
+{
+ struct timespec ts;
+ int success;
+ irun = 1;
+
+ ViewMan* viewman = ViewMan::getInstance();
+
+ do
+ {
+ setMainText("\n Locating server");
+ draw();
+ show();
+
+ vdr->findServers(serverIPs);
+ if (!irun) return;
+
+ if (serverIPs.size() == 1)
+ {
+ selectedServer = 0;
+ }
+ else
+ {
+ selectedServer = -1;
+ VServerSelect* vs = new VServerSelect(&serverIPs);
+ vs->setParent(this);
+ vs->draw();
+ vs->show();
+ viewman->add(vs);
+ threadWaitForSignal();
+ }
+
+ printf("server selected %i\n", selectedServer);
+
+ vdr->setServerIP(serverIPs[selectedServer]);
+
+ // Clear the serverIPs vector
+ for(UINT k = 0; k < serverIPs.size(); k++)
+ {
+ delete[] serverIPs[k];
+ }
+ serverIPs.clear();
+
+ logger->log("Command", Log::NOTICE, "Connecting to server at %s", serverIPs[selectedServer]);
+ setMainText("\n Connecting to VDR");
+ draw();
+ show();
+
+ success = vdr->connect();
+ if (success)
+ {
+ logger->log("Command", Log::DEBUG, "Connected ok, doing login");
+ success = vdr->doLogin();
+
+ if (success)
+ {
+ setMainText("\n Connected");
+ ts.tv_sec = 0;
+ ts.tv_nsec = 500000000;
+ }
+ else
+ {
+ vdr->disconnect();
+ setMainText("\n Login failed");
+ ts.tv_sec = 3;
+ ts.tv_nsec = 0;
+ }
+ }
+ else
+ {
+ setMainText("\n Connection failed");
+ ts.tv_sec = 3;
+ ts.tv_nsec = 0;
+ }
+
+ draw();
+ show();
+ nanosleep(&ts, NULL);
+
+ } while(!success);
+
+ Message* m = new Message();
+ m->from = this;
+ m->message = Message::VDR_CONNECTED;
+ Command::getInstance()->postMessage(m);
+}
+
+void VConnect::processMessage(Message* m)
+{
+ if (m->message == Message::SERVER_SELECTED)
+ {
+ selectedServer = m->parameter;
+ threadSignal();
+ }
+}