2013-08-22 22:06:13 +02:00
|
|
|
// C++ includes
|
|
|
|
#include <csignal>
|
|
|
|
|
2013-08-13 11:10:45 +02:00
|
|
|
// QT includes
|
|
|
|
#include <QCoreApplication>
|
2013-08-24 11:51:52 +02:00
|
|
|
#include <QResource>
|
2013-08-13 11:10:45 +02:00
|
|
|
|
2013-08-14 10:54:49 +02:00
|
|
|
// Json-Schema includes
|
|
|
|
#include <utils/jsonschema/JsonFactory.h>
|
|
|
|
|
2013-08-13 11:10:45 +02:00
|
|
|
// Hyperion includes
|
2013-08-14 10:54:49 +02:00
|
|
|
#include <hyperion/Hyperion.h>
|
2013-08-25 18:20:19 +02:00
|
|
|
|
|
|
|
// Bootsequence includes
|
|
|
|
#include <bootsequence/BootSequenceFactory.h>
|
2013-08-13 11:10:45 +02:00
|
|
|
|
2013-08-17 16:12:42 +02:00
|
|
|
// Dispmanx grabber includes
|
|
|
|
#include <dispmanx-grabber/DispmanxWrapper.h>
|
|
|
|
|
2013-08-23 20:44:53 +02:00
|
|
|
// XBMC Video checker includes
|
|
|
|
#include <xbmcvideochecker/XBMCVideoChecker.h>
|
|
|
|
|
2013-08-17 15:39:29 +02:00
|
|
|
// JsonServer includes
|
|
|
|
#include <jsonserver/JsonServer.h>
|
|
|
|
|
2013-10-13 14:48:59 +02:00
|
|
|
// ProtoServer includes
|
|
|
|
#include <protoserver/ProtoServer.h>
|
|
|
|
|
2013-08-22 22:06:13 +02:00
|
|
|
void signal_handler(const int signum)
|
|
|
|
{
|
|
|
|
QCoreApplication::quit();
|
|
|
|
}
|
|
|
|
|
2013-08-24 11:51:52 +02:00
|
|
|
Json::Value loadConfig(const std::string & configFile)
|
|
|
|
{
|
|
|
|
// make sure the resources are loaded (they may be left out after static linking)
|
|
|
|
Q_INIT_RESOURCE(resource);
|
|
|
|
|
|
|
|
// read the json schema from the resource
|
|
|
|
QResource schemaData(":/hyperion-schema");
|
|
|
|
assert(schemaData.isValid());
|
|
|
|
|
|
|
|
Json::Reader jsonReader;
|
|
|
|
Json::Value schemaJson;
|
|
|
|
if (!jsonReader.parse(reinterpret_cast<const char *>(schemaData.data()), reinterpret_cast<const char *>(schemaData.data()) + schemaData.size(), schemaJson, false))
|
|
|
|
{
|
|
|
|
throw std::runtime_error("Schema error: " + jsonReader.getFormattedErrorMessages()) ;
|
|
|
|
}
|
|
|
|
JsonSchemaChecker schemaChecker;
|
|
|
|
schemaChecker.setSchema(schemaJson);
|
|
|
|
|
|
|
|
const Json::Value jsonConfig = JsonFactory::readJson(configFile);
|
|
|
|
schemaChecker.validate(jsonConfig);
|
|
|
|
|
|
|
|
return jsonConfig;
|
|
|
|
}
|
|
|
|
|
2013-08-13 11:10:45 +02:00
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
2013-08-15 21:11:02 +02:00
|
|
|
// Initialising QCoreApplication
|
2013-08-13 11:10:45 +02:00
|
|
|
QCoreApplication app(argc, argv);
|
2013-08-15 21:11:02 +02:00
|
|
|
std::cout << "QCoreApplication initialised" << std::endl;
|
2013-08-13 11:10:45 +02:00
|
|
|
|
2013-08-22 22:06:13 +02:00
|
|
|
signal(SIGINT, signal_handler);
|
|
|
|
signal(SIGTERM, signal_handler);
|
|
|
|
|
2013-08-21 16:25:27 +02:00
|
|
|
if (argc < 2)
|
2013-08-14 10:54:49 +02:00
|
|
|
{
|
2013-08-21 16:25:27 +02:00
|
|
|
std::cout << "Missing required configuration file. Usage:" << std::endl;
|
|
|
|
std::cout << "hyperiond [config.file]" << std::endl;
|
2013-10-10 09:51:18 +02:00
|
|
|
return 1;
|
2013-08-14 10:54:49 +02:00
|
|
|
}
|
|
|
|
|
2013-08-22 07:57:46 +02:00
|
|
|
const std::string configFile = argv[1];
|
2013-08-21 16:25:27 +02:00
|
|
|
std::cout << "Selected configuration file: " << configFile.c_str() << std::endl;
|
2013-08-24 11:51:52 +02:00
|
|
|
const Json::Value config = loadConfig(configFile);
|
2013-08-21 16:25:27 +02:00
|
|
|
|
2013-08-24 11:51:52 +02:00
|
|
|
Hyperion hyperion(config);
|
2013-08-15 21:11:02 +02:00
|
|
|
std::cout << "Hyperion created and initialised" << std::endl;
|
2013-08-13 11:10:45 +02:00
|
|
|
|
2013-10-13 14:48:59 +02:00
|
|
|
// create boot sequence if the configuration is present
|
|
|
|
BootSequence * bootSequence = nullptr;
|
|
|
|
if (config.isMember("bootsequence"))
|
2013-08-25 18:20:19 +02:00
|
|
|
{
|
2013-10-13 14:48:59 +02:00
|
|
|
bootSequence = BootSequenceFactory::createBootSequence(&hyperion, config["bootsequence"]);
|
2013-10-16 23:19:40 +02:00
|
|
|
|
2013-10-16 18:04:43 +02:00
|
|
|
if (bootSequence != nullptr)
|
|
|
|
{
|
|
|
|
bootSequence->start();
|
2013-10-16 23:19:40 +02:00
|
|
|
std::cout << "Boot sequence created and started" << std::endl;
|
2013-10-16 18:04:43 +02:00
|
|
|
}
|
2013-08-25 18:20:19 +02:00
|
|
|
}
|
2013-08-23 18:24:10 +02:00
|
|
|
|
2013-10-13 14:48:59 +02:00
|
|
|
// create XBMC video checker if the configuration is present
|
|
|
|
XBMCVideoChecker * xbmcVideoChecker = nullptr;
|
|
|
|
if (config.isMember("xbmcVideoChecker"))
|
|
|
|
{
|
|
|
|
const Json::Value & videoCheckerConfig = config["xbmcVideoChecker"];
|
|
|
|
xbmcVideoChecker = new XBMCVideoChecker(
|
2013-09-24 21:45:27 +02:00
|
|
|
videoCheckerConfig["xbmcAddress"].asString(),
|
|
|
|
videoCheckerConfig["xbmcTcpPort"].asUInt(),
|
|
|
|
1000,
|
|
|
|
videoCheckerConfig["grabVideo"].asBool(),
|
|
|
|
videoCheckerConfig["grabPictures"].asBool(),
|
|
|
|
videoCheckerConfig["grabAudio"].asBool(),
|
|
|
|
videoCheckerConfig["grabMenu"].asBool());
|
2013-10-13 14:48:59 +02:00
|
|
|
|
|
|
|
xbmcVideoChecker->start();
|
2013-08-24 11:51:52 +02:00
|
|
|
std::cout << "XBMC video checker created and started" << std::endl;
|
|
|
|
}
|
2013-08-23 20:44:53 +02:00
|
|
|
|
2013-10-13 14:48:59 +02:00
|
|
|
// Construct and start the frame-grabber if the configuration is present
|
|
|
|
DispmanxWrapper * dispmanx = nullptr;
|
|
|
|
if (config.isMember("framegrabber"))
|
|
|
|
{
|
|
|
|
const Json::Value & frameGrabberConfig = config["framegrabber"];
|
|
|
|
dispmanx = new DispmanxWrapper(
|
2013-08-25 18:20:19 +02:00
|
|
|
frameGrabberConfig["width"].asUInt(),
|
|
|
|
frameGrabberConfig["height"].asUInt(),
|
|
|
|
frameGrabberConfig["frequency_Hz"].asUInt(),
|
|
|
|
&hyperion);
|
2013-08-13 11:10:45 +02:00
|
|
|
|
2013-10-13 14:48:59 +02:00
|
|
|
if (xbmcVideoChecker != nullptr)
|
|
|
|
{
|
|
|
|
QObject::connect(xbmcVideoChecker, SIGNAL(grabbingMode(GrabbingMode)), dispmanx, SLOT(setGrabbingMode(GrabbingMode)));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dispmanx->setGrabbingMode(GRABBINGMODE_VIDEO);
|
|
|
|
}
|
|
|
|
|
|
|
|
dispmanx->start();
|
|
|
|
std::cout << "Frame grabber created and started" << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create Json server if configuration is present
|
|
|
|
JsonServer * jsonServer = nullptr;
|
|
|
|
if (config.isMember("jsonServer"))
|
|
|
|
{
|
|
|
|
const Json::Value & jsonServerConfig = config["jsonServer"];
|
|
|
|
jsonServer = new JsonServer(&hyperion, jsonServerConfig["port"].asUInt());
|
|
|
|
std::cout << "Json server created and started on port " << jsonServer->getPort() << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create Proto server if configuration is present
|
|
|
|
ProtoServer * protoServer = nullptr;
|
|
|
|
if (config.isMember("protoServer"))
|
|
|
|
{
|
|
|
|
const Json::Value & protoServerConfig = config["protoServer"];
|
|
|
|
protoServer = new ProtoServer(&hyperion, protoServerConfig["port"].asUInt());
|
|
|
|
std::cout << "Proto server created and started on port " << protoServer->getPort() << std::endl;
|
|
|
|
}
|
2013-08-17 15:39:29 +02:00
|
|
|
|
2013-08-24 11:51:52 +02:00
|
|
|
// run the application
|
|
|
|
int rc = app.exec();
|
2013-10-16 23:19:40 +02:00
|
|
|
std::cout << "Application closed with code " << rc << std::endl;
|
2013-08-25 18:20:19 +02:00
|
|
|
|
2013-08-22 22:06:13 +02:00
|
|
|
// Clear all colors (switchting off all leds)
|
|
|
|
hyperion.clearall();
|
2013-08-24 11:51:52 +02:00
|
|
|
|
2013-10-13 14:48:59 +02:00
|
|
|
// Delete all component
|
|
|
|
delete bootSequence;
|
|
|
|
delete dispmanx;
|
|
|
|
delete xbmcVideoChecker;
|
|
|
|
delete jsonServer;
|
|
|
|
delete protoServer;
|
|
|
|
|
|
|
|
// leave application
|
2013-08-24 11:51:52 +02:00
|
|
|
return rc;
|
2013-08-13 11:10:45 +02:00
|
|
|
}
|