Class ILLIXR::switchboard
ClassList > ILLIXR > switchboard
A manager for typesafe, threadsafe, named event-streams (called topics). More...
#include <switchboard.hpp>
Inherits the following classes: ILLIXR::phonebook::service
Classes
Type | Name |
---|---|
class | buffered_reader <typename Specific_event> |
class | event Virtual class for event types. |
class | event_wrapper <typename Underlying_type> Helper class for making event types. |
class | network_writer <typename Serializable_event> |
class | reader <typename Specific_event> A handle which can read the latest event on a topic. |
class | writer <typename Specific_event> A handle which can publish events to a topic. |
Public Types
Type | Name |
---|---|
typedef std::shared_ptr< Specific_event > | ptr The type of shared pointer returned by switchboard. |
Public Attributes
Type | Name |
---|---|
coordinate_system | root_coordinates |
Public Functions
Type | Name |
---|---|
std::vector< std::string > | env_names () const Get a vector of the currently known environment variables. |
buffered_reader< Specific_event > | get_buffered_reader (const std::string & topic_name) |
std::string | get_env (const std::string & var, std::string _default="") Switchboard access point for environment variables. |
bool | get_env_bool (const std::string & var, const std::string & def="false") Get the boolean value of the given environment variable. |
const char * | get_env_char (const std::string & var, const std::string _default="") Get a char* of the given environment variable. |
network_writer< Specific_event > | get_network_writer (const std::string & topic_name, network::topic_config config={}) |
reader< Specific_event > | get_reader (const std::string & topic_name) Gets a handle to read to the latest value from the topic topic_name . |
topic & | get_topic (const std::string & topic_name) |
writer< Specific_event > | get_writer (const std::string & topic_name) Gets a handle to publish to the topic topic_name . |
void | schedule (plugin_id_t plugin_id, std::string topic_name, std::function< void(ptr< const Specific_event > &&, std::size_t)> fn) Schedules the callback fn every time an event is published totopic_name . |
void | set_env (const std::string & var, const std::string & val) Set the local environment variable to the given value. |
void | stop () Stops calling switchboard callbacks. |
switchboard (const phonebook * pb) |
|
bool | topic_exists (const std::string & topic_name) |
Public Functions inherited from ILLIXR::phonebook::service
See ILLIXR::phonebook::service
Type | Name |
---|---|
virtual | ~service () = default |
Detailed Description
- Writing: One can write to a topic (in any thread) through the object returned by
get_writer()
. - There are two ways of reading: asynchronous reading and synchronous reading:
- Asynchronous reading returns the most-recent event on the topic (idempotently). One can do this through (in any thread) the object returned by
get_reader()
. - Synchronous reading schedules a callback to be executed on every event which gets published. One can schedule computation by
schedule()
, which will run the computation in a thread managed by switchboard.
// Get a reader on topic1
switchboard::reader<topic1_type> topic1 = switchboard.get_reader<topic1_type>("topic1");
// Get a writer on topic2
switchboard::writer<topic2_type> topic2 = switchboard.get_writer<topic2_type>("topic2");
while (true) {
// Read topic 1
switchboard::ptr<topic1_type> event1 = topic1.get_rw();
// Write to topic 2 using topic 1 input
topic2.put(topic2.allocate<topic2_type>( do_something(event1->foo) ));
}
// Read topic 3 synchronously
switchboard.schedule<topic3_type>(plugin_id, "topic3", [&](switchboard::ptr<topic3_type> event3, std::size_t it) {
// This is a lambda expression
// https://en.cppreference.com/w/cpp/language/lambda
std::cout << "Got a new event on topic3: " << event3->foo << " for iteration " << it << std::endl;
});
Public Types Documentation
typedef ptr
The type of shared pointer returned by switchboard.
using ILLIXR::switchboard::ptr = std::shared_ptr<Specific_event>;
TODO: Make this agnostic to the type of ptr
Currently, it depends on ptr
== shared_ptr
Public Attributes Documentation
variable root_coordinates
coordinate_system ILLIXR::switchboard::root_coordinates;
Public Functions Documentation
function env_names
Get a vector of the currently known environment variables.
inline std::vector< std::string > ILLIXR::switchboard::env_names () const
function get_buffered_reader
template<typename Specific_event>
inline buffered_reader< Specific_event > ILLIXR::switchboard::get_buffered_reader (
const std::string & topic_name
)
function get_env
Switchboard access point for environment variables.
inline std::string ILLIXR::switchboard::get_env (
const std::string & var,
std::string _default=""
)
If the given variable var
has a non-empty entry in the map, that value is returned. If the entry is empty then the system getenv is called. If this is non-empty then that value is stored and returned, otherwise the default value is returned (not stored).
function get_env_bool
Get the boolean value of the given environment variable.
inline bool ILLIXR::switchboard::get_env_bool (
const std::string & var,
const std::string & def="false"
)
function get_env_char
Get a char* of the given environment variable.
inline const char * ILLIXR::switchboard::get_env_char (
const std::string & var,
const std::string _default=""
)
function get_network_writer
template<typename Specific_event>
inline network_writer< Specific_event > ILLIXR::switchboard::get_network_writer (
const std::string & topic_name,
network::topic_config config={}
)
function get_reader
Gets a handle to read to the latest value from the topic topic_name
.
template<typename Specific_event>
inline reader < Specific_event > ILLIXR::switchboard::get_reader (
const std::string & topic_name
)
This is safe to be called from any thread.
Exception:
If
topic already exists, and its type does not match theevent
.
function get_topic
inline topic & ILLIXR::switchboard::get_topic (
const std::string & topic_name
)
function get_writer
Gets a handle to publish to the topic topic_name
.
template<typename Specific_event>
inline writer < Specific_event > ILLIXR::switchboard::get_writer (
const std::string & topic_name
)
This is safe to be called from any thread.
Exception:
If
topic already exists, and its type does not match theevent
.
function schedule
Schedules the callback fn
every time an event is published totopic_name
.
template<typename Specific_event>
inline void ILLIXR::switchboard::schedule (
plugin_id_t plugin_id,
std::string topic_name,
std::function< void( ptr < const Specific_event > &&, std::size_t)> fn
)
Switchboard maintains a threadpool to call fn
.
This is safe to be called from any thread.
Exception:
if
topic already exists and its type does not match theevent
.
function set_env
Set the local environment variable to the given value.
inline void ILLIXR::switchboard::set_env (
const std::string & var,
const std::string & val
)
function stop
Stops calling switchboard callbacks.
inline void ILLIXR::switchboard::stop ()
This is safe to be called from any thread.
Leave topics in place, so existing reader/writer handles will not crash.
function switchboard
inline explicit ILLIXR::switchboard::switchboard (
const phonebook * pb
)
If pb
is null, then logging is disabled.
function topic_exists
inline bool ILLIXR::switchboard::topic_exists (
const std::string & topic_name
)
The documentation for this class was generated from the following file /home/friedel/devel/ILLIXR/include/illixr/switchboard.hpp