API Reference

class base_event : public tuber::events::event
#include <base_event.hpp>

Base class for events

Subclassed by tuber::core::logging::log_event

Public Functions

base_event()
base_event(const std::string &event_type)

Creates an event with the given type

Parameters
  • event_type: The type of the event

base_event(base_event &&other)
base_event &operator=(base_event &&other)
const std::string &get_event_identifier() const

Return
The identifier of the event

Private Members

std::string event_identifier
class base_logger : public tuber::core::logging::logger
#include <base_logger.hpp>

Base implementation for loggers

Subclassed by tuber::core::logging::console_logger

Public Functions

base_logger(events::event_bus &event_bus)
void log(const std::string &message, message_type type) = 0
class console_logger : public tuber::core::logging::base_logger
#include <console_logger.hpp>

Logger that logs to the standard output

Public Functions

console_logger(events::event_bus &event_bus)
void log(const std::string &message, message_type type)
class engine
#include <engine.hpp>

Main engine class, used to initialize the system

Public Functions

void start() const

Starts the engine

class event
#include <event.hpp>

Interface for events

Subclassed by tuber::events::base_event

Public Functions

virtual ~event()
virtual const std::string &get_event_identifier() const = 0

Return
The identifier of the event

class event_bus
#include <event_bus.hpp>

Dispatches events

Public Functions

event_bus()
~event_bus()
void start()

Starts the event bus thread

void stop()

Stops the event bus thread

template <typename event_type = event*, typename callable_type = std::function<void(event_type)>>
void register_handler(const std::string &event_identifier, callable_type &&handler)

Registers an event handler

Template Parameters
  • event_type: The type of the event to register
  • callable_type: The type of the callback method
Parameters
  • event_identifier: The identifier of the event
  • handler: The handler function

void post(std::unique_ptr<event> event)

Posts an event

Parameters
  • event: The event to post

Private Functions

void dispatch()

Dispatches the queued events

bool is_stopped() const

Private Members

std::unordered_map<std::string, std::list<handler_type>> event_handlers
std::queue<std::unique_ptr<event>> event_queue
std::thread thread
std::mutex dispatch_lock
std::condition_variable dispatch_condition
std::mutex post_lock
bool stopped
class log_event : public tuber::events::base_event
#include <log_event.hpp>

Event for logging messages

Public Functions

log_event()
log_event(const std::string &message, message_type type = message_type::INFO)

Creates a log event with the given message

Parameters
  • message: The message to log
  • type: The type of the message

log_event(log_event &&other)
log_event &operator=(log_event &&other)
const std::string &get_message() const

Return
The message to log

message_type get_type() const

Return
The type of the message

Private Members

std::string message
message_type type
class logger
#include <logger.hpp>

Interface for loggers

Subclassed by tuber::core::logging::base_logger

Public Functions

virtual ~logger()
virtual void log(const std::string &message, message_type type) = 0
namespace tuber
namespace core
namespace logging

Enums

enum message_type

Message types for log messages

Values:

INFO
DEBUG
ERROR
UNKNOWN

Functions

std::string message_type_to_string(message_type type)

Converts a message_type to a string

Return
The message_type as a string
Parameters
  • type: The message_type to convert

namespace events

Typedefs

using tuber::events::handler_type = typedef std::function<void(event*)>
file engine.hpp
file base_logger.hpp
#include “core/logging/logger.hpp”#include “events/event_bus.hpp”
file console_logger.hpp
#include “core/logging/base_logger.hpp”
file log_event.hpp
#include “events/base_event.hpp”#include “core/logging/message_type.hpp”
file logger.hpp
#include <string>#include “core/logging/message_type.hpp”
file message_type.hpp
#include <string>
file base_event.hpp
#include “events/event.hpp”
file event.hpp
#include <string>
file event_bus.hpp
#include <functional>#include <list>#include <queue>#include <thread>#include <mutex>#include <condition_variable>#include “events/event.hpp”
file engine.cpp
#include “core/engine.hpp”#include <iostream>
file base_logger.cpp
#include “core/logging/base_logger.hpp”#include “core/logging/log_event.hpp”
file console_logger.cpp
#include “core/logging/console_logger.hpp”#include <iostream>
file log_event.cpp
#include “core/logging/log_event.hpp”#include “core/logging/message_type.hpp”
file base_event.cpp
#include “events/base_event.hpp”
file event_bus.cpp
#include “events/event_bus.hpp”
dir /home/docs/checkouts/readthedocs.org/user_builds/tuber/checkouts/latest/src/tuber/core
dir /home/docs/checkouts/readthedocs.org/user_builds/tuber/checkouts/latest/include/tuber/core
dir /home/docs/checkouts/readthedocs.org/user_builds/tuber/checkouts/latest/src/tuber/events
dir /home/docs/checkouts/readthedocs.org/user_builds/tuber/checkouts/latest/include/tuber/events
dir /home/docs/checkouts/readthedocs.org/user_builds/tuber/checkouts/latest/include
dir /home/docs/checkouts/readthedocs.org/user_builds/tuber/checkouts/latest/src/tuber/core/logging
dir /home/docs/checkouts/readthedocs.org/user_builds/tuber/checkouts/latest/include/tuber/core/logging
dir /home/docs/checkouts/readthedocs.org/user_builds/tuber/checkouts/latest/src
dir /home/docs/checkouts/readthedocs.org/user_builds/tuber/checkouts/latest/src/tuber
dir /home/docs/checkouts/readthedocs.org/user_builds/tuber/checkouts/latest/include/tuber