From 81371412ed2e1594f8f979c8a67a7c3bc0b9e05b Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Thu, 15 Nov 2007 19:22:02 +0000 Subject: [PATCH] Add -s option to select server --- command.cc | 10 ++++++---- command.h | 3 ++- main.cc | 8 ++++++-- vconnect.cc | 37 +++++++++++++++++++++++++------------ vconnect.h | 3 ++- 5 files changed, 41 insertions(+), 20 deletions(-) diff --git a/command.cc b/command.cc index 6600b2e..343832d 100644 --- a/command.cc +++ b/command.cc @@ -63,6 +63,7 @@ Command::Command() firstBoot = 1; connLost = NULL; crashed = false; + server = NULL; } Command::~Command() @@ -75,11 +76,12 @@ Command* Command::getInstance() return instance; } -int Command::init(bool tcrashed) +int Command::init(bool tcrashed, char* tServer) { if (initted) return 0; initted = 1; crashed = tcrashed; + server = tServer; logger = Log::getInstance(); boxstack = BoxStack::getInstance(); @@ -180,7 +182,7 @@ void Command::run() } else { - VConnect* vconnect = new VConnect(); + VConnect* vconnect = new VConnect(server); boxstack->add(vconnect); vconnect->run(); } @@ -491,7 +493,7 @@ void Command::doStandby() isStandby = 0; - VConnect* vconnect = new VConnect(); + VConnect* vconnect = new VConnect(server); boxstack->add(vconnect); vconnect->run(); } @@ -538,7 +540,7 @@ void Command::doFromTheTop(bool which) boxstack->removeAll(); boxstack->update(wallpaper); connLost = NULL; - VConnect* vconnect = new VConnect(); + VConnect* vconnect = new VConnect(server); boxstack->add(vconnect); vconnect->run(); } diff --git a/command.h b/command.h index 96078ed..af1b2e7 100644 --- a/command.h +++ b/command.h @@ -54,7 +54,7 @@ class Command : public MessageQueue ~Command(); static Command* getInstance(); - int init(bool crashed = false); + int init(bool crashed = false, char* server = NULL); int shutdown(); void run(); void stop(); @@ -93,6 +93,7 @@ class Command : public MessageQueue Boxx* wallpaper; VInfo* connLost; bool crashed; + char* server; UDP udp; diff --git a/main.cc b/main.cc index e241026..4ec8251 100644 --- a/main.cc +++ b/main.cc @@ -76,9 +76,10 @@ int main(int argc, char** argv) bool daemonize = true; bool debugEnabled = false; bool crashed = false; + char* setServer = NULL; int c; - while ((c = getopt(argc, argv, "cdn")) != -1) + while ((c = getopt(argc, argv, "cdns:")) != -1) { switch (c) { @@ -90,6 +91,9 @@ int main(int argc, char** argv) case 'n': daemonize = false; break; + case 's': + setServer = optarg; + break; case '?': printf("Unknown option\n"); return 1; @@ -304,7 +308,7 @@ int main(int argc, char** argv) shutdown(1); } - success = command->init(crashed); + success = command->init(crashed, setServer); if (success) { logger->log("Core", Log::INFO, "Command module initialised"); diff --git a/vconnect.cc b/vconnect.cc index b7323d8..ce754d0 100644 --- a/vconnect.cc +++ b/vconnect.cc @@ -30,7 +30,7 @@ #include "wol.h" #include "vserverselect.h" -VConnect::VConnect() +VConnect::VConnect(char* tServer) { boxstack = BoxStack::getInstance(); vdr = VDR::getInstance(); @@ -49,6 +49,7 @@ VConnect::VConnect() exitable = 0; irun = 0; + server = tServer; } VConnect::~VConnect() @@ -82,20 +83,32 @@ void VConnect::threadMethod() do { - setOneLiner(tr("Locating server")); - draw(); - boxstack->update(this); - - vdr->findServers(servers); - if (!irun) + if (server) // Server is specified, fake a servers array { - for(UINT k = 0; k < servers.size(); k++) + VDRServer vdrserver; + vdrserver.ip = new char[strlen(server)+1]; + strcpy(vdrserver.ip, server); + vdrserver.name = new char[1]; + vdrserver.name[0] = '\0'; + servers.push_back(vdrserver); + } + else + { + setOneLiner(tr("Locating server")); + draw(); + boxstack->update(this); + + vdr->findServers(servers); + if (!irun) { - delete[] servers[k].ip; - delete[] servers[k].name; + for(UINT k = 0; k < servers.size(); k++) + { + delete[] servers[k].ip; + delete[] servers[k].name; + } + servers.clear(); + return; } - servers.clear(); - return; } if (servers.size() == 1) diff --git a/vconnect.h b/vconnect.h index 3f4704e..496238d 100644 --- a/vconnect.h +++ b/vconnect.h @@ -41,7 +41,7 @@ class Message; class VConnect : public VInfo, public Thread_TYPE { public: - VConnect(); + VConnect(char* server); ~VConnect(); int handleCommand(int command); @@ -61,6 +61,7 @@ class VConnect : public VInfo, public Thread_TYPE Log* logger; std::vector servers; int selectedServer; + char* server; }; #endif -- 2.39.5