fixed start/stop of webinterface from GUI

This commit is contained in:
csoler 2019-11-13 21:06:20 +01:00
parent d19d1685de
commit 9007d266a8
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
6 changed files with 43 additions and 17 deletions

View File

@ -452,7 +452,22 @@ void JsonApiServer::setNewAccessRequestCallback(
const std::function<bool (const std::string&)>& callback )
{ mNewAccessRequestCallback = callback; }
void JsonApiServer::shutdown() { mService.stop(); }
void JsonApiServer::shutdown()
{
mService.stop();
RsThread::ask_for_stop();
std::cerr << "Stopping JsonApiServer" ;
while(isRunning())
{
sleep(1);
std::cerr << "." ;
std::cerr.flush();
}
std::cerr << std::endl;
}
bool JsonApiServer::requestNewTokenAutorization(const std::string& token)
{

View File

@ -144,7 +144,7 @@ public:
try
{
std::cerr << "Starting web service on port " << std::dec << _listening_port << std::endl;
std::cerr << "(II) Starting web service on port " << std::dec << _listening_port << std::endl;
_service->start( settings );
}
catch(std::exception& e)
@ -153,7 +153,7 @@ public:
return;
}
std::cerr << "(II) Shutting down webui service." << std::endl;
std::cerr << "(II) webui service stopped." << std::endl;
}
void stop()
{
@ -162,7 +162,10 @@ public:
RsThread::ask_for_stop();
while(isRunning())
sleep(1);
{
std::cerr << "(II) shutting down webui service." << std::endl;
rstime::rs_usleep(1000*1000);
}
}
void setListeningPort(uint16_t p) { _listening_port = p ; }

View File

@ -48,6 +48,7 @@ bool JsonApiPage::updateParams(QString &errmsg)
bool changed = false;
bool enabled = ui.enableCheckBox->isChecked();
if( enabled != Settings->getJsonApiEnabled())
{
Settings->setJsonApiEnabled(enabled);
@ -55,6 +56,7 @@ bool JsonApiPage::updateParams(QString &errmsg)
}
uint16_t port = static_cast<uint16_t>(ui.portSpinBox->value());
if(port != Settings->getJsonApiPort())
{
Settings->setJsonApiPort(port);
@ -106,14 +108,17 @@ QString JsonApiPage::helpText() const { return ""; }
/*static*/ void JsonApiPage::checkShutdownJsonApi()
{
JsonApiServer::instance().shutdown();
if(!JsonApiServer::instance().isRunning())
return;
JsonApiServer::instance().shutdown(); // this is a blocking call until the thread is terminated.
#ifdef SUSPENDED_CODE
/* It is important to make a copy of +jsonApiServer+ pointer so the old
* object can be deleted later, while the original pointer is
* reassigned */
QProgressDialog* pd = new QProgressDialog(
"Stopping JSON API Server", QString(), 0, 3000);
QProgressDialog* pd = new QProgressDialog("Stopping JSON API Server", QString(), 0, 3000);
QTimer* prtm = new QTimer;
prtm->setInterval(16); // 60 FPS
connect( prtm, &QTimer::timeout,
@ -131,6 +136,7 @@ QString JsonApiPage::helpText() const { return ""; }
prtm->deleteLater();
pd->deleteLater();
});
#endif
}
void JsonApiPage::onApplyClicked(bool)

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>521</width>
<height>393</height>
<width>545</width>
<height>569</height>
</rect>
</property>
<property name="windowTitle">
@ -123,7 +123,7 @@
<item>
<widget class="QPushButton" name="applyConfigPushButton">
<property name="text">
<string>Restart JSON API Server to apply settings</string>
<string>Apply settings</string>
</property>
</widget>
</item>

View File

@ -50,6 +50,8 @@ WebuiPage::WebuiPage(QWidget */*parent*/, Qt::WindowFlags /*flags*/)
connect(ui.password_LE, SIGNAL(textChanged(QString)), this, SLOT(onPasswordValueChanged(QString)));
connect(ui.startWebBrowser_PB, SIGNAL(clicked()), this, SLOT(onStartWebBrowserClicked()));
connect(ui.webInterfaceFilesDirectory_PB, SIGNAL(clicked()), this, SLOT(selectWebInterfaceDirectory()));
checkStartWebui();
}
WebuiPage::~WebuiPage()
@ -110,9 +112,9 @@ void WebuiPage::load()
whileBlocking(ui.port_SB)->setValue(Settings->getWebinterfacePort());
whileBlocking(ui.webInterfaceFiles_LE)->setText(Settings->getWebinterfaceFilesDirectory());
whileBlocking(ui.allIp_CB)->setChecked(Settings->getWebinterfaceAllowAllIps());
onEnableCBClicked(Settings->getWebinterfaceEnabled());
}
QString WebuiPage::helpText() const
{
return tr("<h1><img width=\"24\" src=\":/icons/help_64.png\">&nbsp;&nbsp;Webinterface</h1> \
@ -123,7 +125,7 @@ QString WebuiPage::helpText() const
/*static*/ bool WebuiPage::checkStartWebui()
{
if(!Settings->getWebinterfaceEnabled())
return true;
return false;
rsWebUI->setListeningPort(Settings->getWebinterfacePort());
rsWebUI->setHtmlFilesDirectory(Settings->getWebinterfaceFilesDirectory().toStdString());
@ -156,7 +158,11 @@ void WebuiPage::onEnableCBClicked(bool checked)
ui.apply_PB->setEnabled(checked);
ui.startWebBrowser_PB->setEnabled(checked);
QString S;
updateParams(S);
if(checked)
checkStartWebui();
else
checkShutdownWebui();
}
void WebuiPage::onPortValueChanged(int /*value*/)

View File

@ -572,10 +572,6 @@ feenableexcept(FE_INVALID | FE_DIVBYZERO);
notify->enable() ; // enable notification system after GUI creation, to avoid data races in Qt.
#ifdef RS_WEBUI
WebuiPage::checkStartWebui();
#endif // ENABLE_WEBUI
#ifdef RS_JSONAPI
JsonApiPage::checkStartJsonApi();
#endif // RS_JSONAPI