A manager for typesafe, threadsafe, named event-streams (called topics).
More...
#include <switchboard.hpp>
|
template<typename specific_event > |
using | ptr = std::shared_ptr< specific_event > |
| The type of shared pointer returned by switchboard. More...
|
|
|
| switchboard (const phonebook *pb) |
|
template<typename specific_event > |
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 to topic_name . More...
|
|
template<typename specific_event > |
writer< specific_event > | get_writer (const std::string &topic_name) |
| Gets a handle to publish to the topic topic_name . More...
|
|
template<typename specific_event > |
reader< specific_event > | get_reader (const std::string &topic_name) |
| Gets a handle to read to the latest value from the topic topic_name . More...
|
|
template<typename specific_event > |
buffered_reader< specific_event > | get_buffered_reader (const std::string &topic_name) |
|
void | stop () |
| Stops calling switchboard callbacks. More...
|
|
A manager for typesafe, threadsafe, named event-streams (called topics).
- 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.
switchboard::reader<topic1_type> topic1 =
switchboard.get_reader<topic1_type>(
"topic1");
switchboard::writer<topic2_type> topic2 =
switchboard.get_writer<topic2_type>(
"topic2");
while (true) {
switchboard::ptr<topic1_type> event1 = topic1.get_rw();
topic2.put(topic2.allocate<topic2_type>( do_something(event1->foo) ));
}
switchboard.schedule<topic3_type>(plugin_id,
"topic3", [&](switchboard::ptr<topic3_type> event3, std::size_t it) {
std::cout << "Got a new event on topic3: " << event3->foo << " for iteration " << it << std::endl;
});
switchboard(const phonebook *pb)
Definition: switchboard.hpp:621
◆ ptr
template<typename specific_event >
The type of shared pointer returned by switchboard.
TODO: Make this agnostic to the type of ptr
Currently, it depends on ptr
== shared_ptr
◆ switchboard()
ILLIXR::switchboard::switchboard |
( |
const phonebook * |
pb | ) |
|
|
inline |
If pb
is null, then logging is disabled.
◆ get_reader()
template<typename specific_event >
reader<specific_event> ILLIXR::switchboard::get_reader |
( |
const std::string & |
topic_name | ) |
|
|
inline |
Gets a handle to read to the latest value from the topic topic_name
.
This is safe to be called from any thread.
- Exceptions
-
If | topic already exists, and its type does not match the event . |
◆ get_writer()
template<typename specific_event >
writer<specific_event> ILLIXR::switchboard::get_writer |
( |
const std::string & |
topic_name | ) |
|
|
inline |
Gets a handle to publish to the topic topic_name
.
This is safe to be called from any thread.
- Exceptions
-
If | topic already exists, and its type does not match the event . |
◆ schedule()
template<typename specific_event >
void ILLIXR::switchboard::schedule |
( |
plugin_id_t |
plugin_id, |
|
|
std::string |
topic_name, |
|
|
std::function< void(ptr< const specific_event > &&, std::size_t)> |
fn |
|
) |
| |
|
inline |
Schedules the callback fn
every time an event is published to topic_name
.
Switchboard maintains a threadpool to call fn
.
This is safe to be called from any thread.
- Exceptions
-
if | topic already exists and its type does not match the event . |
◆ stop()
void ILLIXR::switchboard::stop |
( |
| ) |
|
|
inline |
Stops calling switchboard callbacks.
This is safe to be called from any thread.
Leave topics in place, so existing reader/writer handles will not crash.
The documentation for this class was generated from the following file: