Skip to content

Commit

Permalink
Improved HyperHDR web server startup (awawa-dev#351)
Browse files Browse the repository at this point in the history
* Improved webserver start

* Wait for the start report from all instances

* Fix web page loader
  • Loading branch information
awawa-dev authored and chbartsch committed Nov 29, 2022
1 parent 2baef95 commit 2b62659
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 11 deletions.
4 changes: 4 additions & 0 deletions assets/webconfig/js/ui_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ function loadContent(event, forceRefresh)
if ((typeof lastSelectedInstance !== 'undefined') &&
(typeof window.serverInfo.instance[lastSelectedInstance] !== 'undefined') &&
typeof(window.serverInfo.instance[lastSelectedInstance].running) !== 'undefined' && window.serverInfo.instance[lastSelectedInstance].running)
{
$("#page-content").off();
instanceSwitch(lastSelectedInstance);
return;
}
else
removeStorage('lastSelectedInstance', false);

Expand Down
8 changes: 5 additions & 3 deletions include/base/HyperHdrIManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class HyperHdrIManager : public QObject
static HyperHdrIManager* getInstance() { return HIMinstance; }
static HyperHdrIManager* HIMinstance;
QString getRootPath() { return _rootPath; }
bool areInstancesReady();

public slots:
bool isCEC();
Expand Down Expand Up @@ -193,11 +194,12 @@ private slots:
private:
Logger* _log;
InstanceTable* _instanceTable;
const QString _rootPath;
const QString _rootPath;
QMap<quint8, HyperHdrInstance*> _runningInstances;
QList<quint8> _startQueue;
QList<quint8> _startQueue;

bool _readonlyMode;
bool _readonlyMode;
int _fireStarter;

/// All pending requests
QMap<quint8, PendingRequests> _pendingRequests;
Expand Down
15 changes: 14 additions & 1 deletion sources/base/HyperHdrIManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ HyperHdrIManager::HyperHdrIManager(const QString& rootPath, QObject* parent, boo
, _instanceTable(new InstanceTable(rootPath, this, readonlyMode))
, _rootPath(rootPath)
, _readonlyMode(readonlyMode)
, _fireStarter(0)
{
HIMinstance = this;
qRegisterMetaType<InstanceState>("InstanceState");
Expand Down Expand Up @@ -59,9 +60,21 @@ QVector<QVariantMap> HyperHdrIManager::getInstanceData() const
return instances;
}

bool HyperHdrIManager::areInstancesReady()
{
if (_fireStarter > 0)
_fireStarter--;

return (_fireStarter < 1);
}

void HyperHdrIManager::startAll()
{
for (const auto& entry : _instanceTable->getAllInstances(true))
auto instanceList = _instanceTable->getAllInstances(true);

_fireStarter = instanceList.count();

for (const auto& entry : instanceList)
{
startInstance(entry["instance"].toInt());
}
Expand Down
14 changes: 12 additions & 2 deletions sources/hyperhdr/hyperhdr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,18 @@ HyperHdrDaemon::HyperHdrDaemon(const QString& rootPath, QObject* parent, bool lo

void HyperHdrDaemon::instanceStateChanged(InstanceState state, quint8 instance, const QString& name)
{
// start web server if needed
if (state == InstanceState::H_STARTED)
{
if (_instanceManager->areInstancesReady())
{
if (_webserver != nullptr && !_webserver->thread()->isRunning())
_webserver->thread()->start();
if (_sslWebserver != nullptr && !_sslWebserver->thread()->isRunning())
_sslWebserver->thread()->start();
}
}

// cec
updateCEC();
}
Expand Down Expand Up @@ -331,7 +343,6 @@ void HyperHdrDaemon::startNetworkServices()
connect(wsThread, &QThread::started, _webserver, &WebServer::initServer);
connect(wsThread, &QThread::finished, _webserver, &WebServer::deleteLater);
connect(this, &HyperHdrDaemon::settingsChanged, _webserver, &WebServer::handleSettingsUpdate);
wsThread->start();

// Create SSL Webserver in thread
_sslWebserver = new WebServer(getSetting(settings::type::WEBSERVER), true);
Expand All @@ -341,7 +352,6 @@ void HyperHdrDaemon::startNetworkServices()
connect(sslWsThread, &QThread::started, _sslWebserver, &WebServer::initServer);
connect(sslWsThread, &QThread::finished, _sslWebserver, &WebServer::deleteLater);
connect(this, &HyperHdrDaemon::settingsChanged, _sslWebserver, &WebServer::handleSettingsUpdate);
sslWsThread->start();

// Create SSDP server in thread
_ssdp = new SSDPHandler(_webserver,
Expand Down
5 changes: 0 additions & 5 deletions sources/hyperhdr/hyperhdr.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,6 @@ class HyperHdrDaemon : public QObject
HyperHdrDaemon(const QString& rootPath, QObject* parent, bool logLvlOverwrite, bool readonlyMode = false, QStringList params = QStringList());
~HyperHdrDaemon();

///
/// @brief Get webserver pointer (systray)
///
WebServer* getWebServerInstance() { return _webserver; }

///
/// @brief get the settings
///
Expand Down

0 comments on commit 2b62659

Please sign in to comment.