]> git.vomp.tv Git - vompclient.git/commitdiff
Add -s option to select server
authorChris Tallon <chris@vomp.tv>
Thu, 15 Nov 2007 19:22:02 +0000 (19:22 +0000)
committerChris Tallon <chris@vomp.tv>
Thu, 15 Nov 2007 19:22:02 +0000 (19:22 +0000)
command.cc
command.h
main.cc
vconnect.cc
vconnect.h

index 6600b2ed7b5732cdbba640fd70b5fcff73faebc2..343832dadce9138774f23ae14331819e625197b7 100644 (file)
@@ -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();
   }
index 96078edb90002508bcf08dccc3ce4f67e65db72f..af1b2e7ef381cf8d0e2c758755e4fb5be5d0a1b2 100644 (file)
--- 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 e241026b8b7c723b4e888f7cc8f8e82d0050e9fc..4ec825183d75a513d6bff5dea00c69578508e26e 100644 (file)
--- 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");
index b7323d8462c09b85ef695565ac1b424d1a260c16..ce754d0fec24455057e8b45bb9bc71a883dd6fdc 100644 (file)
@@ -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)
index 3f4704ef1bf8afd8ecbf0af37b0d7d2f1298d262..496238d46a441c9bd24f29e5b8cffe916cbf12e9 100644 (file)
@@ -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<VDRServer> servers;
     int selectedServer;
+    char* server;
 };
 
 #endif