jconfig.clear();
std::ifstream configFile("config.json");
-
- Json::CharReaderBuilder builder;
- builder["collectComments"] = false;
- builder["allowTrailingCommas"] = true; // FIXME
- std::string errs;
-
- bool ok = Json::parseFromStream(builder, configFile, &jconfig, &errs);
- if (!ok)
+ if (configFile.is_open())
{
- std::cout << errs << std::endl;
- return false;
+ Json::CharReaderBuilder builder;
+ builder["collectComments"] = false;
+ builder["allowTrailingCommas"] = true; // FIXME
+ std::string errs;
+
+ bool ok = Json::parseFromStream(builder, configFile, &jconfig, &errs);
+ if (!ok)
+ {
+ std::cout << errs << std::endl;
+ return false;
+ }
}
applyDefaults();
"level": "debug"
},
+ "server":
+ {
+ // "server" has no defaults
+ // Normally vompclient will use IPv4 UDP broadcasts and IPv6 multicast to find servers
+ // Entering an address and optionally a port will disable discovery
+
+ "address": "vdrserver.example.com",
+ "port": 3024
+ }
+
"input":
{
"mod_cec_enabled": true,
"input_lirc":
{
- // This is an example input_lirc section
+ // input_lirc has no defaults
"lirc_ip": "192.0.2.0",
"lirc_port": 8765,
}
else
{
- VConnect* vconnect = new VConnect();
+ VConnect* vconnect = new VConnect(); // FIXME never deleted?
boxstack->add(vconnect);
vconnect->run();
}
case Message::VDR_CONNECTED:
{
- doJustConnected(static_cast<VConnect*>(m->from));
+ doJustConnected(static_cast<VConnect*>(m->from)); // FIXME delete from here?
break;
}
case Message::SCREENSHOT:
// at this point, everything should be reset to first-go
- VConnect* vconnect = new VConnect();
+ VConnect* vconnect = new VConnect(); // FIXME never deleted?
boxstack->add(vconnect);
vconnect->run();
}
if (movieID == 0 && seriesID == 0)
{
vdr->getScraperEventType(channelid, id, movieID, seriesID, episodeID, epgImage);
- LogNT::getInstance()->debug(TAG, "Got Scraper EventType {} {}, {} {} {} {}",
+ LogNT::getInstance()->debug(TAG, "Got Scraper EventType {} {}, {} {} {}",
id, channelid, movieID, seriesID, episodeID);
}
}
*outstream << " " << std::this_thread::get_id() << " " << TAG << " - ";
- fmt::print(*outstream, fmtString, args...);
+
+ try
+ {
+ fmt::print(*outstream, fmtString, args...);
+ }
+ catch (std::exception& e)
+ {
+ fmt::print(*outstream, "<<< EXCEPTION GENERATED BY THIS LOG MESSAGE >>>");
+ }
+
+
*outstream << std::endl;
}
config->set("main", "daemonize", false);
break;
case 's':
- config->set("main", "argv_server", optarg);
+ config->set("server", "address", optarg);
break;
case '?':
printf("Vompclient\n\n");
std::unique_lock<std::mutex> ul(threadMutex, std::defer_lock);
- std::string commandLineServer;
- Config::getInstance()->getString("main", "argv_server", commandLineServer);
+ VDRServer configServerStr;
+ const VDRServer* selectedServerStr = NULL;
- if (!vdpc.init())
+ bool serverFromConfig{}; // FIXME Redesign all this.
+
+ if (Config::getInstance()->getString("server", "address", configServerStr.ip))
{
- logger->crit(TAG, "Failed to init VDPC");
- return;
- }
+ configServerStr.port = 3024;
+ int newPort;
+ if (Config::getInstance()->getInt("server", "port", newPort))
+ {
+ configServerStr.port = newPort;
+ }
- do
+ selectedServerStr = &configServerStr;
+ serverFromConfig = true;
+ }
+ else // No server specified in config. Start VDPC
{
- if (!commandLineServer.empty()) // Server is specified, fake a servers array
+ if (!vdpc.init())
{
- //servers.emplace_back(commandLineServer, "", 3024, 0);
- vdpc.TEMPaddCLIServer(commandLineServer); // FIXME move to new config system NCONFIG
+ logger->crit(TAG, "Failed to init VDPC");
+ return;
}
- else
+ }
+
+
+ do
+ {
+ if (!selectedServerStr)
{
setOneLiner(tr("Locating server"));
draw();
boxstack->update(this);
vdpc.go();
if (threadReqQuit) return;
- }
- for (ULONG i = 0; i < vdpc.numServers(); i++)
- logger->info(TAG, "Found server: {} {} {} {}", vdpc[i].ipVersion, vdpc[i].ip.c_str(), vdpc[i].name.c_str(), vdpc[i].port, vdpc[i].version);
+ for (ULONG i = 0; i < vdpc.numServers(); i++)
+ logger->info(TAG, "Found server: {} {} {} {}", vdpc[i].ipVersion, vdpc[i].ip.c_str(), vdpc[i].name.c_str(), vdpc[i].port, vdpc[i].version);
- if (vdpc.numServers() == 1)
- {
- selectedServer = 0;
- }
- else
- {
- selectedServer = -1;
- VServerSelect* vs = new VServerSelect(vdpc, this);
- vs->draw();
- boxstack->add(vs);
- boxstack->update(vs);
-
- ul.lock();
- if (threadReqQuit) { ul.unlock(); return; }
- threadCond.wait(ul);
- ul.unlock();
+ if (vdpc.numServers() == 1)
+ {
+ selectedServer = 0;
+ selectedServerStr = &vdpc[0];
+ }
+ else
+ {
+ selectedServer = -1;
+ VServerSelect* vs = new VServerSelect(vdpc, this); // FIXME is this deleted?
+ vs->draw();
+ boxstack->add(vs);
+ boxstack->update(vs);
+
+ ul.lock();
+ if (threadReqQuit) { ul.unlock(); return; }
+ threadCond.wait(ul);
+
+ // This thread has been notified by VServerSelect. selectedServer is now an index into vdpc of the chosen server
+
+ selectedServerStr = &vdpc[selectedServer];
+
+ ul.unlock();
+ }
+
+ if (threadReqQuit) return;
}
- if (threadReqQuit) return;
- logger->info(TAG, "Connecting to server at {} {}", vdpc[selectedServer].ip.c_str(), vdpc[selectedServer].port);
- Wol::getInstance()->setWakeUpIP(vdpc[selectedServer].ip.c_str());
- vdr->setServerIP(vdpc[selectedServer].ip.c_str());
- vdr->setServerPort(vdpc[selectedServer].port);
+ logger->info(TAG, "Connecting to server at {} {}", selectedServerStr->ip, selectedServerStr->port);
+ Wol::getInstance()->setWakeUpIP(selectedServerStr->ip.c_str());
+ vdr->setServerIP(selectedServerStr->ip.c_str());
+ vdr->setServerPort(selectedServerStr->port);
+
+ // In case of go around, clear selectedServerStr here if it was discovered
+ if (!serverFromConfig) selectedServerStr = NULL;
+
setOneLiner(tr("Connecting to VDR"));
draw();
static const char* TAG = "VDPC";
-void VDPC::TEMPaddCLIServer(const std::string& cliServer)
-{
- std::lock_guard<std::mutex> lg(serversLock);
- servers.emplace_back(4, cliServer, "", 3024, 0);
-}
-
bool VDPC::init()
{
AddServerCallback addFunc( [this] (int ipVersion, const char* ip, const char* name, USHORT port, ULONG version)
USHORT port;
ULONG version;
+ VDRServer() {}
+
VDRServer(int tipVersion, const std::string tip, const std::string tname, USHORT tport, ULONG tversion)
: ipVersion(tipVersion), ip(tip), name(tname), port(tport), version(tversion) {}
};
ULONG numServers() const;
const VDRServer& operator[](ULONG index) const;
- void TEMPaddCLIServer(const std::string&); // FIXME NCONFIG
-
private:
std::vector<VDRServer> servers;
std::mutex serversLock;