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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
31 #include "vserverselect.h"
33 VConnect::VConnect(char* tServer)
35 boxstack = BoxStack::getInstance();
36 vdr = VDR::getInstance();
37 logger = Log::getInstance();
41 if (Video::getInstance()->getFormat() == Video::PAL)
43 setPosition(170, 200);
47 setPosition(160, 150);
58 vdr->cancelFindingServer();
65 logger->log("VConnect", Log::DEBUG, "Draw done");
68 int VConnect::handleCommand(int command)
78 void VConnect::threadMethod()
86 if (server) // Server is specified, fake a servers array
89 vdrserver.ip = new char[strlen(server)+1];
90 strcpy(vdrserver.ip, server);
91 vdrserver.name = new char[1];
92 vdrserver.name[0] = '\0';
93 vdrserver.port = 3024; // FIXME
94 servers.push_back(vdrserver);
98 setOneLiner(tr("Locating server"));
100 boxstack->update(this);
102 vdr->findServers(servers);
105 for(UINT k = 0; k < servers.size(); k++)
107 delete[] servers[k].ip;
108 delete[] servers[k].name;
115 if (servers.size() == 1)
122 VServerSelect* vs = new VServerSelect(servers, this);
125 boxstack->update(vs);
128 threadWaitForSignal();
134 for(UINT k = 0; k < servers.size(); k++)
136 delete[] servers[k].ip;
137 delete[] servers[k].name;
143 logger->log("VConnect", Log::NOTICE, "Connecting to server at %s %u", servers[selectedServer].ip, servers[selectedServer].port);
144 Wol::getInstance()->setWakeUpIP(servers[selectedServer].ip);
145 vdr->setServerIP(servers[selectedServer].ip);
146 vdr->setServerPort(servers[selectedServer].port);
148 // Clear the serverIPs vector
149 for(UINT k = 0; k < servers.size(); k++)
151 delete[] servers[k].ip;
152 delete[] servers[k].name;
157 setOneLiner(tr("Connecting to VDR"));
159 boxstack->update(this);
161 success = vdr->connect();
164 logger->log("VConnect", Log::DEBUG, "Connected ok, doing login");
165 unsigned int version_server,version_client;
166 success = vdr->doLogin(&version_server,&version_client);
171 if (version_server!=version_client) {
173 sprintf(buffer,"Protocoll mismatch s: %x c: %x",version_server,version_client);
176 setOneLiner(tr("Login failed"));
183 setOneLiner(tr("Connection failed"));
188 boxstack->update(this);
193 logger->log("VConnect", Log::INFO, "Send VDR connected message");
194 Message* m = new Message(); // Must be done after this thread ends
196 m->to = Command::getInstance();
197 m->message = Message::VDR_CONNECTED;
198 Command::getInstance()->postMessage(m);
201 void VConnect::processMessage(Message* m)
203 if (m->message == Message::SERVER_SELECTED)
205 selectedServer = m->parameter;