fixed compilation by modifying wrappers to account for the shared_ptr mService

This commit is contained in:
csoler 2019-11-23 15:11:22 +01:00
parent 009ed54ce2
commit b8b7d103e1
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
9 changed files with 33 additions and 57 deletions

View File

@ -55,7 +55,7 @@ $%callbackParamsSerialization%$
sStream << "data: " << compactJSON << ctx.mJson << "\n\n"; sStream << "data: " << compactJSON << ctx.mJson << "\n\n";
const std::string message = sStream.str(); const std::string message = sStream.str();
mService.schedule( [weakSession, message]() mService->schedule( [weakSession, message]()
{ {
auto session = weakSession.lock(); auto session = weakSession.lock();
if(!session || session->is_closed()) return; if(!session || session->is_closed()) return;

View File

@ -326,7 +326,7 @@ int main(int argc, char *argv[])
QString sessionDelayedClose; QString sessionDelayedClose;
if(hasMultiCallback) if(hasMultiCallback)
sessionDelayedClose = "RsThread::async( [=](){ std::this_thread::sleep_for(std::chrono::seconds(maxWait+120)); mService.schedule( [=](){ auto session = weakSession.lock(); if(session && session->is_open()) session->close(); } ); } );"; sessionDelayedClose = "RsThread::async( [=](){ std::this_thread::sleep_for(std::chrono::seconds(maxWait+120)); mService->schedule( [=](){ auto session = weakSession.lock(); if(session && session->is_open()) session->close(); } ); } );";
QString callbackParamsSerialization; QString callbackParamsSerialization;

View File

@ -337,7 +337,7 @@ JsonApiServer::JsonApiServer(): configMutex("JsonApiServer config")
std::function<void(std::shared_ptr<const RsEvent>)> multiCallback = std::function<void(std::shared_ptr<const RsEvent>)> multiCallback =
[this, weakSession, hId](std::shared_ptr<const RsEvent> event) [this, weakSession, hId](std::shared_ptr<const RsEvent> event)
{ {
mService.schedule( [weakSession, hId, event]() mService->schedule( [weakSession, hId, event]()
{ {
auto session = weakSession.lock(); auto session = weakSession.lock();
if(!session || session->is_closed()) if(!session || session->is_closed())
@ -601,9 +601,9 @@ void JsonApiServer::handleCorsOptions(
const std::shared_ptr<restbed::Session> session ) const std::shared_ptr<restbed::Session> session )
{ session->close(rb::NO_CONTENT, corsOptionsHeaders); } { session->close(rb::NO_CONTENT, corsOptionsHeaders); }
int JsonApiServer::status() const int JsonApiServer::status()
{ {
if(RestbedService::isRunning() && RestbedService::isClient(this)) if(RestbedService::isRunning())
return JSONAPI_STATUS_RUNNING; return JSONAPI_STATUS_RUNNING;
else else
return JSONAPI_STATUS_NOT_RUNNING; return JSONAPI_STATUS_NOT_RUNNING;

View File

@ -69,10 +69,11 @@ public:
bool restart() override { return RestbedService::restart(); } bool restart() override { return RestbedService::restart(); }
bool stop() override { return RestbedService::stop();} bool stop() override { return RestbedService::stop();}
int status() const override; int status() override;
void setListeningPort(uint16_t port) override { return RestbedService::setListeningPort(port); } void setListeningPort(uint16_t port) override { return RestbedService::setListeningPort(port); }
void setBindingAddress(const std::string& bind_address) override { return RestbedService::setBindAddress(bind_address); } void setBindingAddress(const std::string& bind_address) override { return RestbedService::setBindAddress(bind_address); }
uint16_t listeningPort() const override { return RestbedService::listeningPort() ; }
virtual void connectToConfigManager(p3ConfigMgr *cfgmgr); virtual void connectToConfigManager(p3ConfigMgr *cfgmgr);
@ -189,6 +190,6 @@ private:
} }
std::vector<std::shared_ptr<rb::Resource> > _resources; std::vector<std::shared_ptr<rb::Resource> > _resources;
std::set<JsonApiResourceProvider *> _resource_providers; std::set<const JsonApiResourceProvider *> _resource_providers;
}; };

View File

@ -31,7 +31,7 @@ RestbedService::RestbedService()
mBindingAddress = "127.0.0.1"; mBindingAddress = "127.0.0.1";
} }
void RestbedService::stop() bool RestbedService::stop()
{ {
mService->stop(); mService->stop();
@ -42,19 +42,15 @@ void RestbedService::stop()
std::cerr << "(II) shutting down restbed service." << std::endl; std::cerr << "(II) shutting down restbed service." << std::endl;
rstime::rs_usleep(1000*1000); rstime::rs_usleep(1000*1000);
} }
return true;
} }
uint16_t RestbedService::listeningPort() const { return mListeningPort ; }
void RestbedService::setListeningPort(uint16_t p) { mListeningPort = p ; } void RestbedService::setListeningPort(uint16_t p) { mListeningPort = p ; }
void RestbedService::setBindAddress(const std::string& bindAddress) { mBindingAddress = bindAddress ; } void RestbedService::setBindAddress(const std::string& bindAddress) { mBindingAddress = bindAddress ; }
uint16_t RestbedService::listeningPort() const { return mListeningPort;}
void RestbedService::runloop() override void RestbedService::runloop()
{ {
if(_resources.empty())
{
RsErr() << "(EE) please call RestbedService::setResources() before launching the service!" << std::endl;
return;
}
auto settings = std::make_shared< restbed::Settings >( ); auto settings = std::make_shared< restbed::Settings >( );
settings->set_port( mListeningPort ); settings->set_port( mListeningPort );
settings->set_bind_address( mBindingAddress ); settings->set_bind_address( mBindingAddress );

View File

@ -35,10 +35,11 @@ public:
bool restart(); bool restart();
bool stop(); bool stop();
bool isRunning(); bool isRunning() const;
void setListeningPort(uint16_t port) ; void setListeningPort(uint16_t port) ;
void setBindAddress(const std::string& bind_address); void setBindAddress(const std::string& bind_address);
uint16_t listeningPort() const ;
// should be overloaded by sub-class in order to provide resources to the restbed Service. // should be overloaded by sub-class in order to provide resources to the restbed Service.
@ -47,9 +48,9 @@ public:
protected: protected:
void runloop() override; void runloop() override;
private:
std::shared_ptr<restbed::Service> mService; // managed by RestbedService because it needs to be properly deleted when restarted. std::shared_ptr<restbed::Service> mService; // managed by RestbedService because it needs to be properly deleted when restarted.
private:
uint16_t mListeningPort; uint16_t mListeningPort;
std::string mBindingAddress; std::string mBindingAddress;
}; };

View File

@ -42,6 +42,7 @@ public:
virtual void setBindingAddress(const std::string& address) =0; virtual void setBindingAddress(const std::string& address) =0;
virtual void setListeningPort(uint16_t port) =0; virtual void setListeningPort(uint16_t port) =0;
virtual uint16_t listeningPort() const =0;
virtual void connectToConfigManager(p3ConfigMgr *cfgmgr)=0; virtual void connectToConfigManager(p3ConfigMgr *cfgmgr)=0;
@ -54,7 +55,7 @@ public:
* @jsonapi{development} * @jsonapi{development}
* @return the status picked in the enum JSONAPI_STATUS_UNKNOWN/RUNNING/NOT_RUNNING * @return the status picked in the enum JSONAPI_STATUS_UNKNOWN/RUNNING/NOT_RUNNING
*/ */
virtual int status() const=0; virtual int status() =0;
//=============================================================================================// //=============================================================================================//
// API methods that are also accessible through http // // API methods that are also accessible through http //

View File

@ -45,7 +45,6 @@ WebuiPage::WebuiPage(QWidget */*parent*/, Qt::WindowFlags /*flags*/)
{ {
ui.setupUi(this); ui.setupUi(this);
connect(ui.enableWebUI_CB, SIGNAL(clicked(bool)), this, SLOT(onEnableCBClicked(bool))); connect(ui.enableWebUI_CB, SIGNAL(clicked(bool)), this, SLOT(onEnableCBClicked(bool)));
connect(ui.port_SB, SIGNAL(valueChanged(int)), this, SLOT(onPortValueChanged(int)));
connect(ui.allIp_CB, SIGNAL(clicked(bool)), this, SLOT(onAllIPCBClicked(bool))); connect(ui.allIp_CB, SIGNAL(clicked(bool)), this, SLOT(onAllIPCBClicked(bool)));
connect(ui.apply_PB, SIGNAL(clicked()), this, SLOT(onApplyClicked())); connect(ui.apply_PB, SIGNAL(clicked()), this, SLOT(onApplyClicked()));
connect(ui.password_LE, SIGNAL(textChanged(QString)), this, SLOT(onPasswordValueChanged(QString))); connect(ui.password_LE, SIGNAL(textChanged(QString)), this, SLOT(onPasswordValueChanged(QString)));
@ -75,8 +74,6 @@ bool WebuiPage::updateParams(QString &errmsg)
bool changed = false; bool changed = false;
if(ui.enableWebUI_CB->isChecked() != Settings->getWebinterfaceEnabled()) if(ui.enableWebUI_CB->isChecked() != Settings->getWebinterfaceEnabled())
changed = true; changed = true;
if(ui.port_SB->value() != Settings->getWebinterfacePort())
changed = true;
if(ui.allIp_CB->isChecked() != Settings->getWebinterfaceAllowAllIps()) if(ui.allIp_CB->isChecked() != Settings->getWebinterfaceAllowAllIps())
changed = true; changed = true;
if(ui.webInterfaceFiles_LE->text() != Settings->getWebinterfaceFilesDirectory()) if(ui.webInterfaceFiles_LE->text() != Settings->getWebinterfaceFilesDirectory())
@ -86,7 +83,6 @@ bool WebuiPage::updateParams(QString &errmsg)
{ {
// store config // store config
Settings->setWebinterfaceEnabled(ui.enableWebUI_CB->isChecked()); Settings->setWebinterfaceEnabled(ui.enableWebUI_CB->isChecked());
Settings->setWebinterfacePort(ui.port_SB->value());
Settings->setWebinterfaceAllowAllIps(ui.allIp_CB->isChecked()); Settings->setWebinterfaceAllowAllIps(ui.allIp_CB->isChecked());
Settings->setWebinterfaceFilesDirectory(ui.webInterfaceFiles_LE->text()); Settings->setWebinterfaceFilesDirectory(ui.webInterfaceFiles_LE->text());
} }
@ -123,7 +119,6 @@ void WebuiPage::load()
{ {
std::cerr << "WebuiPage::load()" << std::endl; std::cerr << "WebuiPage::load()" << std::endl;
whileBlocking(ui.enableWebUI_CB)->setChecked(Settings->getWebinterfaceEnabled()); whileBlocking(ui.enableWebUI_CB)->setChecked(Settings->getWebinterfaceEnabled());
whileBlocking(ui.port_SB)->setValue(Settings->getWebinterfacePort());
whileBlocking(ui.webInterfaceFiles_LE)->setText(Settings->getWebinterfaceFilesDirectory()); whileBlocking(ui.webInterfaceFiles_LE)->setText(Settings->getWebinterfaceFilesDirectory());
whileBlocking(ui.allIp_CB)->setChecked(Settings->getWebinterfaceAllowAllIps()); whileBlocking(ui.allIp_CB)->setChecked(Settings->getWebinterfaceAllowAllIps());
@ -149,9 +144,7 @@ QString WebuiPage::helpText() const
if(!Settings->getWebinterfaceEnabled()) if(!Settings->getWebinterfaceEnabled())
return false; return false;
rsWebUI->setListeningPort(Settings->getWebinterfacePort());
rsWebUI->setHtmlFilesDirectory(Settings->getWebinterfaceFilesDirectory().toStdString()); rsWebUI->setHtmlFilesDirectory(Settings->getWebinterfaceFilesDirectory().toStdString());
rsWebUI->restart(); rsWebUI->restart();
return true; return true;
@ -215,5 +208,6 @@ void WebuiPage::onApplyClicked()
void WebuiPage::onStartWebBrowserClicked() void WebuiPage::onStartWebBrowserClicked()
{ {
QDesktopServices::openUrl(QUrl(QString("http://localhost:")+QString::number(ui.port_SB->value()))); QDesktopServices::openUrl(QUrl(QString("http://localhost:")+QString::number(rsJsonAPI->listeningPort())));
} }

View File

@ -33,33 +33,27 @@
<item> <item>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="port_Label"> <widget class="QLabel" name="label_2">
<property name="text"> <property name="text">
<string>Listening port:</string> <string>Password:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="1" column="0">
<widget class="QSpinBox" name="port_SB">
<property name="minimum">
<number>1024</number>
</property>
<property name="maximum">
<number>65535</number>
</property>
<property name="value">
<number>1984</number>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="text"> <property name="text">
<string>Web interface directory:</string> <string>Web interface directory:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="1"> <item row="0" column="1">
<widget class="QLineEdit" name="password_LE">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<item> <item>
<widget class="QLineEdit" name="webInterfaceFiles_LE"> <widget class="QLineEdit" name="webInterfaceFiles_LE">
@ -84,24 +78,13 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Password:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="password_LE">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
<item> <item>
<widget class="QCheckBox" name="allIp_CB"> <widget class="QCheckBox" name="allIp_CB">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text"> <property name="text">
<string>Allow access from all IP addresses (Default: localhost only)</string> <string>Allow access from all IP addresses (Default: localhost only)</string>
</property> </property>