Inexor
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Public Attributes | Private Attributes | List of all members
inexor::util::Metasystem Class Reference

A metasystem is a collection of multiple subsystems. More...

#include <Subsystem.hpp>

Inheritance diagram for inexor::util::Metasystem:
inexor::util::Subsystem

Public Types

typedef std::function< void()> tick_cb
 
typedef std::function
< std::unique_ptr< Subsystem >)> 
Starter
 A function that starts a subsystem and returns a pointer to the instance this exists for the register: we can not store classes at run time, so we instead store these functions as proxies to the Constructors. More...
 

Public Member Functions

 Metasystem ()
 Start this Metasystem with no subsystems. More...
 
 ~Metasystem () override
 
bool is_running (const std::string &sub) noexcept
 Check whether the given subsystem is running or not. More...
 
void start (const std::string &sub)
 Start a subsystem by name. More...
 
void stop (const std::string &sub)
 Stop a subsystem by name. More...
 
void tick () override
 Forwarded to all subsystems. More...
 
void initialize (int argc, char **argv) override
 Forwarded to all subsystems. More...
 
void initialize (const std::string &sub, int argc, char **argv)
 Initialize a specific subsystem. More...
 
void next_tick (tick_cb f)
 Execute code on the next tick. More...
 

Public Attributes

std::unordered_map
< std::string, std::unique_ptr
< Subsystem > > 
subsystems
 
bool is_initialized = false
 

Private Attributes

 next_tick_queue
 

Detailed Description

A metasystem is a collection of multiple subsystems.

All the calls are simply distributed to all subsystems this contains.

Member Typedef Documentation

typedef std::function<std::unique_ptr<Subsystem>)> inexor::util::Subsystem::Starter
inherited

A function that starts a subsystem and returns a pointer to the instance this exists for the register: we can not store classes at run time, so we instead store these functions as proxies to the Constructors.

We create these as lambdas in the SUBSYSTEM_REGISTER macro;

typedef std::function<void()> inexor::util::Metasystem::tick_cb

Constructor & Destructor Documentation

inexor::util::Metasystem::Metasystem ( )
inline

Start this Metasystem with no subsystems.

inexor::util::Metasystem::~Metasystem ( )
inlineoverride

References next_tick_queue.

Member Function Documentation

void inexor::util::Metasystem::initialize ( int  argc,
char **  argv 
)
inlineoverridevirtual

Forwarded to all subsystems.

Reimplemented from inexor::util::Subsystem.

References subsystems.

Referenced by main().

void inexor::util::Metasystem::initialize ( const std::string sub,
int  argc,
char **  argv 
)
inline

Initialize a specific subsystem.

References subsystems.

bool inexor::util::Metasystem::is_running ( const std::string sub)
inlinenoexcept

Check whether the given subsystem is running or not.

References subsystems.

Referenced by start(), and stop().

void inexor::util::Metasystem::next_tick ( tick_cb  f)
inline

Execute code on the next tick.

This will take a function and execute once on the next tick. If you want to execute something multiple times, use a submodule.

The function will definitely be called. Even if the Metasystem is destructed, the functions will be invoked in the destructor.

References next_tick_queue.

void inexor::util::Metasystem::start ( const std::string sub)
inline

Start a subsystem by name.

If the subsystem is already running, no change will be done.

The subsystem will be started during the next tick. This means there might be some delay.

Exceptions
NoSuchSubsystem

References inexor::util::Subsystem::Register::EnsureExist(), inexor::util::Subsystem::Register::Get(), is_running(), and subsystems.

Referenced by main().

void inexor::util::Metasystem::stop ( const std::string sub)
inline

Stop a subsystem by name.

If the subsystem is not running, no change will be applied.

The subsystem will be started during the next tick. This means there might be some delay.

Exceptions
NoSuchSubsystem

References inexor::util::Subsystem::Register::EnsureExist(), is_running(), and subsystems.

Referenced by server::cleanupserver(), and quit().

void inexor::util::Metasystem::tick ( )
inlineoverridevirtual

Forwarded to all subsystems.

Reimplemented from inexor::util::Subsystem.

References next_tick_queue, and subsystems.

Referenced by main(), and server::serverslice().

Member Data Documentation

bool inexor::util::Subsystem::is_initialized = false
inherited
inexor::util::Metasystem::next_tick_queue
private

Referenced by next_tick(), tick(), and ~Metasystem().

std::unordered_map< std::string, std::unique_ptr<Subsystem> > inexor::util::Metasystem::subsystems

Referenced by initialize(), is_running(), start(), stop(), and tick().


The documentation for this class was generated from the following file: