From 41b33277b11c69ae0138e8b463a4c695e9a80d14 Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Fri, 28 Sep 2018 22:28:33 +0200 Subject: [PATCH] core: Use the Singleton mixin for the Core instance Instead of implementing the instance pointer manually, use the Singleton mixin. --- src/core/core.cpp | 15 +-------------- src/core/core.h | 5 ++--- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/src/core/core.cpp b/src/core/core.cpp index 9b7af58d..7f69869a 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -67,22 +67,10 @@ public: // ============================== // Core // ============================== -Core *Core::_instance{nullptr}; - -Core *Core::instance() -{ - return _instance; -} - Core::Core() + : Singleton{this} { - if (_instance) { - qWarning() << "Recreating core instance!"; - delete _instance; - } - _instance = this; - // Parent all QObject-derived attributes, so when the Core instance gets moved into another // thread, they get moved with it _server.setParent(this); @@ -97,7 +85,6 @@ Core::~Core() qDeleteAll(_connectingClients); qDeleteAll(_sessions); syncStorage(); - _instance = nullptr; } diff --git a/src/core/core.h b/src/core/core.h index 8d02d9ed..efbefa69 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -44,6 +44,7 @@ #include "message.h" #include "oidentdconfiggenerator.h" #include "sessionthread.h" +#include "singleton.h" #include "storage.h" #include "types.h" @@ -58,13 +59,11 @@ struct NetworkInfo; class AbstractSqlMigrationReader; class AbstractSqlMigrationWriter; -class Core : public QObject +class Core : public QObject, public Singleton { Q_OBJECT public: - static Core *instance(); - Core(); ~Core() override; -- 2.20.1