From 454b9e36e14680a3b0c390d7d0dd4c23f7b8a139 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Fri, 20 Jan 2006 23:44:49 +0000 Subject: [PATCH] Display server names --- vconnect.cc | 34 +++++++++++++++++++++++----------- vconnect.h | 2 +- vdr.cc | 27 ++++++++++++++++++++------- vdr.h | 18 +++++++++++++++++- 4 files changed, 61 insertions(+), 20 deletions(-) diff --git a/vconnect.cc b/vconnect.cc index c86a5f3..6b19c27 100644 --- a/vconnect.cc +++ b/vconnect.cc @@ -76,22 +76,26 @@ void VConnect::threadMethod() draw(); viewman->updateView(this); - vdr->findServers(serverIPs); + vdr->findServers(servers); if (!irun) { - for(UINT k = 0; k < serverIPs.size(); k++) delete[] serverIPs[k]; - serverIPs.clear(); + for(UINT k = 0; k < servers.size(); k++) + { + delete[] servers[k].ip; + delete[] servers[k].name; + } + servers.clear(); return; } - if (serverIPs.size() == 1) + if (servers.size() == 1) { selectedServer = 0; } else { selectedServer = -1; - VServerSelect* vs = new VServerSelect(&serverIPs, this); + VServerSelect* vs = new VServerSelect(servers, this); vs->draw(); viewman->add(vs); // FIXME - do this better - perhaps post message to Command // Otherwise it will be using ViewMan without the Command mutex locked @@ -104,17 +108,25 @@ void VConnect::threadMethod() if (!irun) { - for(UINT k = 0; k < serverIPs.size(); k++) delete[] serverIPs[k]; - serverIPs.clear(); + for(UINT k = 0; k < servers.size(); k++) + { + delete[] servers[k].ip; + delete[] servers[k].name; + } + servers.clear(); return; } - logger->log("VConnect", Log::NOTICE, "Connecting to server at %s", serverIPs[selectedServer]); - vdr->setServerIP(serverIPs[selectedServer]); + logger->log("VConnect", Log::NOTICE, "Connecting to server at %s", servers[selectedServer].ip); + vdr->setServerIP(servers[selectedServer].ip); // Clear the serverIPs vector - for(UINT k = 0; k < serverIPs.size(); k++) delete[] serverIPs[k]; - serverIPs.clear(); + for(UINT k = 0; k < servers.size(); k++) + { + delete[] servers[k].ip; + delete[] servers[k].name; + } + servers.clear(); setOneLiner(tr("Connecting to VDR")); draw(); diff --git a/vconnect.h b/vconnect.h index 5cc6925..139550e 100644 --- a/vconnect.h +++ b/vconnect.h @@ -55,7 +55,7 @@ class VConnect : public VInfo, public Thread UCHAR irun; VDR* vdr; Log* logger; - std::vector serverIPs; + std::vector servers; int selectedServer; }; diff --git a/vdr.cc b/vdr.cc index 4f27a46..f5bd948 100644 --- a/vdr.cc +++ b/vdr.cc @@ -64,14 +64,13 @@ int VDR::shutdown() return 1; } -void VDR::findServers(vector& serverIPs) +void VDR::findServers(vector& servers) { findingServer = 1; - char* message = "VOMP CLIENT"; + char* message = "VOMP"; DatagramSocket ds(port); int haveAtLeastOne = 0; - char* newIP; int retval; int waitType = 1; while(findingServer) @@ -85,15 +84,28 @@ void VDR::findServers(vector& serverIPs) if (retval == 2) // we got a reply { - if (strcmp(ds.getData(), "VOMP SERVER")) // echo..... + if (!strcmp(ds.getData(), "VOMP")) // echo..... { waitType = 2; } else { - newIP = new char[16]; - strcpy(newIP, ds.getFromIPA()); - serverIPs.push_back(newIP); + VDRServer newServer; + newServer.ip = new char[16]; + strcpy(newServer.ip, ds.getFromIPA()); + + if (ds.getDataLength() == 0) + { + newServer.name = new char[1]; + newServer.name[0] = '\0'; + } + else + { + newServer.name = new char[strlen(ds.getData())+1]; + strcpy(newServer.name, ds.getData()); + } + + servers.push_back(newServer); waitType = 2; haveAtLeastOne = 1; } @@ -104,6 +116,7 @@ void VDR::findServers(vector& serverIPs) waitType = 1; } } + sort(servers.begin(), servers.end(), ServerSorter()); } void VDR::cancelFindingServer() diff --git a/vdr.h b/vdr.h index bf3fec5..d63b1f5 100644 --- a/vdr.h +++ b/vdr.h @@ -53,6 +53,22 @@ struct RecTimerSorter // : public binary_function } }; +struct VDRServer +{ + char* ip; + char* name; +}; + +struct ServerSorter +{ + bool operator() (const VDRServer a, const VDRServer b) + { + printf("%s %s\n", a.name, b.name); + if (strcmp(b.name, a.name) > 0) return true; + return false; + } +}; + class VDR { @@ -64,7 +80,7 @@ class VDR int init(int port); int shutdown(); - void findServers(vector& serverIPs); + void findServers(vector& servers); void cancelFindingServer(); void setServerIP(char*); int connect(); -- 2.39.5