From 82272fc7e6cabe7cdf1617c6489b2199705f8b7f Mon Sep 17 00:00:00 2001 From: Philipp Jungkamp Date: Tue, 22 Aug 2023 16:10:22 +0200 Subject: [PATCH] api: web: Do proper shutdown if startup was interrupted Signed-off-by: Philipp Jungkamp --- include/villas/web.hpp | 6 ++++-- lib/api.cpp | 3 ++- lib/web.cpp | 5 +++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/include/villas/web.hpp b/include/villas/web.hpp index 12a372056..2129fa738 100644 --- a/include/villas/web.hpp +++ b/include/villas/web.hpp @@ -24,9 +24,9 @@ namespace node { /* Forward declarations */ class Api; -class Web { +class Web final { -protected: +private: enum State state; Logger logger; @@ -55,6 +55,8 @@ public: */ Web(Api *a = nullptr); + ~Web(); + void start(); void stop(); diff --git a/lib/api.cpp b/lib/api.cpp index 4a1c01317..289e9e457 100644 --- a/lib/api.cpp +++ b/lib/api.cpp @@ -33,7 +33,8 @@ Api::Api(SuperNode *sn) : Api::~Api() { - assert(state != State::STARTED); + if (state == State::STARTED) + stop(); } void Api::start() diff --git a/lib/web.cpp b/lib/web.cpp index c4bc4db67..d81acd317 100644 --- a/lib/web.cpp +++ b/lib/web.cpp @@ -185,6 +185,11 @@ Web::Web(Api *a) : lws_set_log_level(lwsLogLevel(logging.getLevel()), lwsLogger); } +Web::~Web() { + if(state == State::STARTED) + stop(); +} + int Web::parse(json_t *json) { int ret, enabled = 1;