86 lines
2.7 KiB
C++
86 lines
2.7 KiB
C++
#include "Toon/Bridge.h"
|
|
#include <INIReader.h>
|
|
#include <Logging.h>
|
|
#include <signal.h>
|
|
#include <iostream>
|
|
#include <sstream>
|
|
#include <string>
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
{
|
|
try
|
|
{
|
|
Logging::OpenLog();
|
|
Logging::SetLogMask(Logging::Severity::Info);
|
|
|
|
INIReader iniReader("ToonBridge.ini");
|
|
if (iniReader.ParseError() != 0)
|
|
throw std::runtime_error("Can't read ToonBridge.ini.");
|
|
|
|
Logging::Log(Logging::Severity::Info, "Starting ToonBridge");
|
|
|
|
int port = iniReader.GetInteger("ToonBridge", "Port", 0);
|
|
if (port == 0)
|
|
throw std::runtime_error("Port directive missing in ini file.");
|
|
|
|
ToonBridge::Toon::ToonSettings toonSettings;
|
|
toonSettings.agreementId = iniReader.Get("Toon", "AgreementID", "");
|
|
if (toonSettings.agreementId.empty())
|
|
throw std::runtime_error("Toon AgreementID directive missing in ini file.");
|
|
|
|
toonSettings.accessToken = iniReader.Get("Toon", "AccessToken", "");
|
|
if (toonSettings.accessToken.empty())
|
|
throw std::runtime_error("Toon AccessToken directive missing in ini file.");
|
|
|
|
toonSettings.displayCommonName = iniReader.Get("Toon", "DisplayCommonName", "");
|
|
if (toonSettings.displayCommonName.empty())
|
|
throw std::runtime_error("Toon DisplayCommonName directive missing in ini file.");
|
|
|
|
toonSettings.applicationId = iniReader.Get("Toon", "ApplicationID", "");
|
|
if (toonSettings.applicationId.empty())
|
|
throw std::runtime_error("Toon ApplicationID directive missing in ini file.");
|
|
|
|
toonSettings.callbackUrl = iniReader.Get("Toon", "CallbackURL", "");
|
|
if (toonSettings.callbackUrl.empty())
|
|
throw std::runtime_error("Toon CallbackURL directive missing in ini file.");
|
|
|
|
ToonBridge::Toon::MQTTSettings mqttSettings;
|
|
mqttSettings.hostname = iniReader.Get("MQTT", "Hostname", "");
|
|
if (mqttSettings.hostname.empty())
|
|
throw std::runtime_error("MQTT Hostname directive missing in ini file.");
|
|
|
|
mqttSettings.port = iniReader.GetInteger("MQTT", "Port", 0);
|
|
if (mqttSettings.port == 0)
|
|
throw std::runtime_error("MQTT Port directive missing in ini file.");
|
|
|
|
mqttSettings.topic = iniReader.Get("MQTT", "Topic", "");
|
|
if (mqttSettings.topic.empty())
|
|
throw std::runtime_error("MQTT Topic directive missing in ini file.");
|
|
|
|
ToonBridge::Toon::Bridge bridge(port, toonSettings, mqttSettings);
|
|
|
|
Logging::Log(Logging::Severity::Info, "Startup Complete");
|
|
bridge.Wait();
|
|
|
|
Logging::Log(Logging::Severity::Info, "Stopping ToonBridge...");
|
|
Logging::CloseLog();
|
|
}
|
|
catch (const std::exception& e)
|
|
{
|
|
std::cerr << "Exception caught" << std::endl;
|
|
|
|
std::stringstream ss;
|
|
ss << "Type : " << typeid(e).name() << std::endl;
|
|
ss << "ERROR: " << e.what() << std::endl;
|
|
|
|
Logging::Log(Logging::Severity::Error, ss.str());
|
|
|
|
Logging::CloseLog();
|
|
|
|
return -1;
|
|
}
|
|
|
|
return 0;
|
|
}
|