Class sh::base::SingletonInitializer

class sh::base::SingletonInitializer

Takes care of initialization and shutdown of infrastructure singletons.

It is a very early part of shallot core infrastructure. Singletons typically participate by using those macros:

DECLARE_SINGLETON(STYPE): Used inside the singleton class definition. STYPE is the singleton’s class. It must be a subclass of sh::base::Singleton. It will get a static std::shared_ptr<STYPE> instance() method by that.

REGISTER_SINGLETON(NS, STYPE, GROUPNAME): Used inside the source file. NS is the namespace of the singleton. STYPE is the singleton’s class. GROUPNAME is the singleton group name (used for dependency handling, see later).

For singleton groups, there is REGISTER_SINGLETON_GROUP(GROUPNAME, ...): GROUPNAME is the group name used for grouping singletons together. Additional arguments are other group names; those groups are considered as dependencies, which must be fulfilled before this group can.

For just initializing stuff via static methods (without a singleton instance), use REGISTER_STATICINIT(NS, STYPE, GROUPNAME): NS is the namespace of the class to initialize. STYPE is the class to initialize. It must provide public static void doInitialize() and static void doShutdown(). GROUPNAME is the group name.

Public Functions

void callInitializers()

Executes all create-callbacks at first, then all init-callbacks. In both runs, the callbacks with lower index come first. Afterwards, the singletons are considered as up and running.

SingletonInitializer()

Constructed only by the infrastructure and made available otherwise.

~SingletonInitializer()
void shutdown()

Executes all shutdown-callbacks at first, then all remove-callbacks. The callback order is the reversed one of callInitializers. Afterwards, the singletons are considered as shut down and removed.

Public Static Functions

char registerGroup(QString groupname, QStringList groupdeps)

Registers a singleton group.

You should typically use REGISTER_SINGLETON_GROUP. See SingletonInitializer.

char registerSingleton(QString name, std::function<std::shared_ptr<Singleton>()> instancefctQString groupname, )

Registers a singleton.

You should typically use DECLARE_SINGLETON and REGISTER_SINGLETON. See SingletonInitializer.

QThread *initializerThread()
bool isShutdown()

If the singletons are completely shut down and removed.

Private Types

std::tuple< QString, QString, std::function< std::shared_ptr< Singleton >)> > SingletonTuple
typedef std::tuple<QString, QStringList> SingletonGroupTuple

Private Static Functions

bool dependsOn(QString group, QString depgroup)

Private Static Attributes

QList<SingletonTuple> *_singletons
QHash<QString, SingletonGroupTuple> *_groups
bool _isshutdown = false
QMutex shutdownmutex