diff --git a/lib/controller.cpp b/lib/controller.cpp index 99a281c..f0a2dfd 100644 --- a/lib/controller.cpp +++ b/lib/controller.cpp @@ -24,7 +24,9 @@ #include #include +#ifndef USE_BOTAN2 #include +#endif #include "controller.h" #include "encryptor.h" @@ -44,7 +46,7 @@ Controller::Controller(Profile _profile, { #ifndef USE_BOTAN2 try { - Botan::LibraryInitializer::initialize("thread_safe"); + botanInit = std::make_unique("thread_safe"); } catch (std::exception &e) { qFatal("Failed to initialise Botan library: %s", e.what()); } @@ -99,9 +101,6 @@ Controller::~Controller() if (tcpServer->isListening()) { stop(); } -#ifndef USE_BOTAN2 - Botan::LibraryInitializer::deinitialize(); -#endif } bool Controller::start() diff --git a/lib/controller.h b/lib/controller.h index 9c4058d..88524fa 100644 --- a/lib/controller.h +++ b/lib/controller.h @@ -31,6 +31,12 @@ #include "profile.h" #include "udprelay.h" +#ifndef USE_BOTAN2 +namespace Botan { +class LibraryInitializer; +} +#endif + namespace QSS { class QSS_EXPORT Controller : public QObject @@ -71,6 +77,12 @@ public slots: bool start(); // Return true if start successfully, otherwise return false void stop(); +private: +#ifndef USE_BOTAN2 + // This needs to be destructed in the end + std::unique_ptr botanInit; +#endif + protected: // The total bytes recevied or sent by/from all TCP and UDP connections. uint64_t bytesReceived;