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/>.
31 #include "vserverselect.h"
32 #include "messagequeue.h"
37 static const char* TAG = "VConnect";
41 boxstack = BoxStack::getInstance();
42 vdr = VDR::getInstance();
43 logger = LogNT::getInstance();
47 if (Video::getInstance()->getFormat() == Video::PAL)
49 setPosition(170, 200);
53 setPosition(160, 150);
69 logger->debug(TAG, "Draw done");
72 int VConnect::handleCommand(int /* command */)
80 threadReqQuit = false;
81 connectThread = std::thread([this]
94 vdr->abortConnect(); // If this and vdr are connecting, cancel it
95 threadCond.notify_one();
100 void VConnect::threadMethod()
102 logger->debug(TAG, "start threadMethod");
107 std::unique_lock<std::mutex> ul(threadMutex, std::defer_lock);
109 std::string commandLineServer;
110 Config::getInstance()->getString("main", "argv_server", commandLineServer);
114 logger->crit(TAG, "Failed to init VDPC");
120 if (!commandLineServer.empty()) // Server is specified, fake a servers array
122 //servers.emplace_back(commandLineServer, "", 3024, 0);
123 vdpc.TEMPaddCLIServer(commandLineServer); // FIXME move to new config system NCONFIG
127 setOneLiner(tr("Locating server"));
129 boxstack->update(this);
131 if (threadReqQuit) return;
134 for (ULONG i = 0; i < vdpc.numServers(); i++)
135 logger->info(TAG, "Found server: {} {} {} {}", vdpc[i].ipVersion, vdpc[i].ip.c_str(), vdpc[i].name.c_str(), vdpc[i].port, vdpc[i].version);
137 if (vdpc.numServers() == 1)
144 VServerSelect* vs = new VServerSelect(vdpc, this);
147 boxstack->update(vs);
150 if (threadReqQuit) { ul.unlock(); return; }
155 if (threadReqQuit) return;
157 logger->info(TAG, "Connecting to server at {} {}", vdpc[selectedServer].ip.c_str(), vdpc[selectedServer].port);
158 Wol::getInstance()->setWakeUpIP(vdpc[selectedServer].ip.c_str());
159 vdr->setServerIP(vdpc[selectedServer].ip.c_str());
160 vdr->setServerPort(vdpc[selectedServer].port);
162 setOneLiner(tr("Connecting to VDR"));
164 boxstack->update(this);
166 if (threadReqQuit) return;
167 success = vdr->connect();
168 if (threadReqQuit) return;
172 logger->debug(TAG, "Connected ok, doing login");
173 unsigned int version_server_min, version_server_max, version_client;
175 success = vdr->doLogin(&version_server_min, &version_server_max, &version_client, Control::getInstance()->getASLList(), subtitles);
176 Control::getInstance()->setSubDefault(subtitles);
181 if (version_server_min >version_client || version_client > version_server_max) {
183 sprintf(buffer,"Version error: s min: %x s max: %x c: %x",version_server_min,version_server_max,version_client);
186 setOneLiner(tr("Login failed"));
193 setOneLiner(tr("Connection failed"));
198 boxstack->update(this);
200 MILLISLEEP(delay); // FIXME wait on cond?
201 if (threadReqQuit) return;
204 logger->info(TAG, "Send VDR connected message");
205 Message* m = new Message(); // Must be done after this thread ends
207 m->p_to = Message::CONTROL;
208 m->message = Message::VDR_CONNECTED;
209 MessageQueue::getInstance()->postMessage(m);
212 void VConnect::processMessage(Message* m)
214 if (m->message == Message::SERVER_SELECTED)
216 selectedServer = m->parameter;
217 threadCond.notify_one();