2 Copyright 2004-2020 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, see <https://www.gnu.org/licenses/>.
30 #include "vserverselect.h"
31 #include "messagequeue.h"
37 boxstack = BoxStack::getInstance();
38 vdr = VDR::getInstance();
39 logger = Log::getInstance();
43 if (Video::getInstance()->getFormat() == Video::PAL)
45 setPosition(170, 200);
49 setPosition(160, 150);
65 logger->log("VConnect", Log::DEBUG, "Draw done");
68 int VConnect::handleCommand(int /* command */)
76 threadReqQuit = false;
77 connectThread = std::thread([this]
90 threadCond.notify_one();
95 void VConnect::threadMethod()
97 logger->log("VConnect", Log::DEBUG, "start threadMethod");
102 std::unique_lock<std::mutex> ul(threadMutex, std::defer_lock);
104 const std::string& commandLineServer = getCommandLineServer();
108 logger->log("VConnect", Log::CRIT, "Failed to init VDPC");
114 if (!commandLineServer.empty()) // Server is specified, fake a servers array
116 //servers.emplace_back(commandLineServer, "", 3024, 0);
117 vdpc.TEMPaddCLIServer(commandLineServer); // FIXME move to new config system NCONFIG
121 setOneLiner(tr("Locating server"));
123 boxstack->update(this);
125 if (threadReqQuit) return;
128 for (ULONG i = 0; i < vdpc.numServers(); i++)
129 logger->log("VConnect", Log::INFO, "Found server: %i %s %s %u", vdpc[i].ipVersion, vdpc[i].ip.c_str(), vdpc[i].name.c_str(), vdpc[i].port, vdpc[i].version);
131 if (vdpc.numServers() == 1)
138 VServerSelect* vs = new VServerSelect(vdpc, this);
141 boxstack->update(vs);
144 if (threadReqQuit) { ul.unlock(); return; }
149 if (threadReqQuit) return;
151 logger->log("VConnect", Log::NOTICE, "Connecting to server at %s %u", vdpc[selectedServer].ip.c_str(), vdpc[selectedServer].port);
152 Wol::getInstance()->setWakeUpIP(vdpc[selectedServer].ip.c_str());
153 vdr->setServerIP(vdpc[selectedServer].ip.c_str());
154 vdr->setServerPort(vdpc[selectedServer].port);
156 setOneLiner(tr("Connecting to VDR"));
158 boxstack->update(this);
160 success = vdr->connect();
163 logger->log("VConnect", Log::DEBUG, "Connected ok, doing login");
164 unsigned int version_server_min, version_server_max, version_client;
166 success = vdr->doLogin(&version_server_min, &version_server_max, &version_client, Control::getInstance()->getASLList(), subtitles);
167 Control::getInstance()->setSubDefault(subtitles);
172 if (version_server_min >version_client || version_client > version_server_max) {
174 sprintf(buffer,"Version error: s min: %x s max: %x c: %x",version_server_min,version_server_max,version_client);
177 setOneLiner(tr("Login failed"));
184 setOneLiner(tr("Connection failed"));
189 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->p_to = Message::CONTROL;
197 m->message = Message::VDR_CONNECTED;
198 MessageQueue::getInstance()->postMessage(m);
201 void VConnect::processMessage(Message* m)
203 if (m->message == Message::SERVER_SELECTED)
205 selectedServer = m->parameter;
206 threadCond.notify_one();