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"
38 boxstack = BoxStack::getInstance();
39 vdr = VDR::getInstance();
40 logger = Log::getInstance();
44 if (Video::getInstance()->getFormat() == Video::PAL)
46 setPosition(170, 200);
50 setPosition(160, 150);
66 logger->log("VConnect", Log::DEBUG, "Draw done");
69 int VConnect::handleCommand(int /* command */)
77 threadReqQuit = false;
78 connectThread = std::thread([this]
91 vdr->abortConnect(); // If this and vdr are connecting, cancel it
92 threadCond.notify_one();
97 void VConnect::threadMethod()
99 logger->log("VConnect", Log::DEBUG, "start threadMethod");
104 std::unique_lock<std::mutex> ul(threadMutex, std::defer_lock);
106 const std::string& commandLineServer = getCommandLineServer();
110 logger->log("VConnect", Log::CRIT, "Failed to init VDPC");
116 if (!commandLineServer.empty()) // Server is specified, fake a servers array
118 //servers.emplace_back(commandLineServer, "", 3024, 0);
119 vdpc.TEMPaddCLIServer(commandLineServer); // FIXME move to new config system NCONFIG
123 setOneLiner(tr("Locating server"));
125 boxstack->update(this);
127 if (threadReqQuit) return;
130 for (ULONG i = 0; i < vdpc.numServers(); i++)
131 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);
133 if (vdpc.numServers() == 1)
140 VServerSelect* vs = new VServerSelect(vdpc, this);
143 boxstack->update(vs);
146 if (threadReqQuit) { ul.unlock(); return; }
151 if (threadReqQuit) return;
153 logger->log("VConnect", Log::NOTICE, "Connecting to server at %s %u", vdpc[selectedServer].ip.c_str(), vdpc[selectedServer].port);
154 Wol::getInstance()->setWakeUpIP(vdpc[selectedServer].ip.c_str());
155 vdr->setServerIP(vdpc[selectedServer].ip.c_str());
156 vdr->setServerPort(vdpc[selectedServer].port);
158 setOneLiner(tr("Connecting to VDR"));
160 boxstack->update(this);
162 if (threadReqQuit) return;
163 success = vdr->connect();
164 if (threadReqQuit) return;
168 logger->log("VConnect", Log::DEBUG, "Connected ok, doing login");
169 unsigned int version_server_min, version_server_max, version_client;
171 success = vdr->doLogin(&version_server_min, &version_server_max, &version_client, Control::getInstance()->getASLList(), subtitles);
172 Control::getInstance()->setSubDefault(subtitles);
177 if (version_server_min >version_client || version_client > version_server_max) {
179 sprintf(buffer,"Version error: s min: %x s max: %x c: %x",version_server_min,version_server_max,version_client);
182 setOneLiner(tr("Login failed"));
189 setOneLiner(tr("Connection failed"));
194 boxstack->update(this);
196 MILLISLEEP(delay); // FIXME wait on cond?
197 if (threadReqQuit) return;
200 logger->log("VConnect", Log::INFO, "Send VDR connected message");
201 Message* m = new Message(); // Must be done after this thread ends
203 m->p_to = Message::CONTROL;
204 m->message = Message::VDR_CONNECTED;
205 MessageQueue::getInstance()->postMessage(m);
208 void VConnect::processMessage(Message* m)
210 if (m->message == Message::SERVER_SELECTED)
212 selectedServer = m->parameter;
213 threadCond.notify_one();