Inexor
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Namespaces | Macros | Functions
Subsystem.hpp File Reference
#include <string>
#include <unordered_map>
#include <functional>
#include <queue>
#include "inexor/util/InexorException.hpp"
#include "inexor/compat/make_unique.hpp"
#include "inexor/util/util.hpp"

Go to the source code of this file.

Classes

class  inexor::util::Subsystem
 Subsystems are loosely coupled parts of inexor. More...
 
class  inexor::util::Subsystem::Register
 
class  inexor::util::Metasystem
 A metasystem is a collection of multiple subsystems. More...
 

Namespaces

 inexor
 Show stacktrace on unix, do not include directly.
 
 inexor::util
 

Macros

#define __SUBSYSTEM_DUMMY(name)   subsystem_register_stub_for_ ## name
 
#define SUBSYSTEM_REGISTER(name,...)
 Register a subsystem so it can later be started by name in a Metasystem. More...
 
#define SUBSYSTEM_REQUIRE(name)
 Make sure that a specific subsystem is included. More...
 

Functions

 inexor::util::IEXCEPTION (SubsystemException,"Some problem with the ""subsystems occurred.")
 
 inexor::util::EXCEPTION (NoSuchSubsystem, SubsystemException,"The subsystem you're trying to start does not exist.")
 
 inexor::util::EXCEPTION (SubsystemAlreadyRunning, SubsystemException,"The subsystem you're trying to start is already running.")
 
 inexor::util::EXCEPTION (SubsystemNotRunning, SubsystemException,"The subsystem you're trying to stop is not running.")
 

Macro Definition Documentation

#define __SUBSYSTEM_DUMMY (   name)    subsystem_register_stub_for_ ## name
#define SUBSYSTEM_REGISTER (   name,
  ... 
)
Value:
::inexor::util::Subsystem::Register::Set( #name, \
[](){ return ::inexor::util::dynamic_pointer_cast<::inexor::util::Subsystem>( \
::inexor::compat::make_unique<__VA_ARGS__>()); }) \
, 0);
#define INEXOR_ATTR_UNUSED
INEXOR_ATTR_UNUSED: Prevent the compiler from optimizing variables that are never used away...
Definition: util.hpp:87
#define __SUBSYSTEM_DUMMY(name)
Definition: Subsystem.hpp:224

Register a subsystem so it can later be started by name in a Metasystem.

NOTE: DO NOT call SUBSYSTEM_REGISTER in headers. This is because in order to register a subsystem we need to execute some code. And since we usually can not execute code outside main() we need to use a trick: We create a dummy variable and use the assignments right side to execute code. If you were to call this in a header, a subsystem would be registered for every include (or never if not included) and we would create that variable in multiple files.

NOTE: This must be called in the GLOBAL namespace! TODO: Can we get rid of that restriction?

Parameters
nameThe name to register the subsystem as
...The class of the subsystem (its an argument list because macros are dump and can't handle template lists otherwise, since they contain ",").
#define SUBSYSTEM_REQUIRE (   name)
Value:
{ \
extern int __SUBSYSTEM_DUMMY(name); \
__SUBSYSTEM_DUMMY(name) = 0; \
}
#define __SUBSYSTEM_DUMMY(name)
Definition: Subsystem.hpp:224

Make sure that a specific subsystem is included.

NOTE: This must be called in a function in the global namespace!

Parameters
nameThe name of the subsystem to require

Referenced by main().