diff --git a/libretroshare/src/jsonapi/jsonapi.cpp b/libretroshare/src/jsonapi/jsonapi.cpp index 2ad54c8ac..3b3ab0e6f 100644 --- a/libretroshare/src/jsonapi/jsonapi.cpp +++ b/libretroshare/src/jsonapi/jsonapi.cpp @@ -452,7 +452,22 @@ void JsonApiServer::setNewAccessRequestCallback( const std::function& 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) { diff --git a/libretroshare/src/rsserver/p3webui.cc b/libretroshare/src/rsserver/p3webui.cc index 557b02a4d..8384bb8f5 100644 --- a/libretroshare/src/rsserver/p3webui.cc +++ b/libretroshare/src/rsserver/p3webui.cc @@ -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 ; } diff --git a/retroshare-gui/src/gui/settings/JsonApiPage.cc b/retroshare-gui/src/gui/settings/JsonApiPage.cc index d7d10a8c5..f8a045dff 100644 --- a/retroshare-gui/src/gui/settings/JsonApiPage.cc +++ b/retroshare-gui/src/gui/settings/JsonApiPage.cc @@ -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(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) diff --git a/retroshare-gui/src/gui/settings/JsonApiPage.ui b/retroshare-gui/src/gui/settings/JsonApiPage.ui index 0408c8403..d2a1ab16b 100644 --- a/retroshare-gui/src/gui/settings/JsonApiPage.ui +++ b/retroshare-gui/src/gui/settings/JsonApiPage.ui @@ -6,8 +6,8 @@ 0 0 - 521 - 393 + 545 + 569 @@ -123,7 +123,7 @@ - Restart JSON API Server to apply settings + Apply settings diff --git a/retroshare-gui/src/gui/settings/WebuiPage.cpp b/retroshare-gui/src/gui/settings/WebuiPage.cpp index 1fa8f4ddc..84a3e38ee 100644 --- a/retroshare-gui/src/gui/settings/WebuiPage.cpp +++ b/retroshare-gui/src/gui/settings/WebuiPage.cpp @@ -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("

  Webinterface

\ @@ -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*/) diff --git a/retroshare-gui/src/main.cpp b/retroshare-gui/src/main.cpp index 7cca199be..3b17e2e76 100644 --- a/retroshare-gui/src/main.cpp +++ b/retroshare-gui/src/main.cpp @@ -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