2016-06-14 20:14:06 +02:00
|
|
|
#include "webconfig/WebConfig.h"
|
2016-06-12 22:27:24 +02:00
|
|
|
#include "StaticFileServing.h"
|
|
|
|
|
2016-06-13 22:54:08 +02:00
|
|
|
|
2016-06-17 01:25:40 +02:00
|
|
|
WebConfig::WebConfig(QObject * parent)
|
2016-06-14 20:14:06 +02:00
|
|
|
: QObject(parent)
|
|
|
|
, _port(WEBCONFIG_DEFAULT_PORT)
|
|
|
|
, _server(nullptr)
|
2016-06-13 22:54:08 +02:00
|
|
|
{
|
2016-06-17 01:25:40 +02:00
|
|
|
_hyperion = Hyperion::getInstance();
|
|
|
|
const Json::Value &config = _hyperion->getJsonConfig();
|
2016-06-13 22:54:08 +02:00
|
|
|
_baseUrl = QString::fromStdString(WEBCONFIG_DEFAULT_PATH);
|
2016-06-20 15:51:34 +02:00
|
|
|
_port = WEBCONFIG_DEFAULT_PORT;
|
2016-06-14 20:14:06 +02:00
|
|
|
|
2016-06-13 22:54:08 +02:00
|
|
|
bool webconfigEnable = true;
|
|
|
|
|
|
|
|
if (config.isMember("webConfig"))
|
|
|
|
{
|
|
|
|
const Json::Value & webconfigConfig = config["webConfig"];
|
|
|
|
webconfigEnable = webconfigConfig.get("enable", true).asBool();
|
|
|
|
_port = webconfigConfig.get("port", WEBCONFIG_DEFAULT_PORT).asUInt();
|
|
|
|
_baseUrl = QString::fromStdString( webconfigConfig.get("document_root", WEBCONFIG_DEFAULT_PATH).asString() );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( webconfigEnable )
|
|
|
|
start();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-12 22:27:24 +02:00
|
|
|
WebConfig::~WebConfig()
|
|
|
|
{
|
|
|
|
stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void WebConfig::start()
|
|
|
|
{
|
|
|
|
if ( _server == nullptr )
|
2016-06-14 20:14:06 +02:00
|
|
|
_server = new StaticFileServing (_hyperion, _baseUrl, _port, this);
|
2016-06-12 22:27:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebConfig::stop()
|
|
|
|
{
|
|
|
|
if ( _server != nullptr )
|
|
|
|
{
|
|
|
|
delete _server;
|
|
|
|
_server = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|