Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
appbase::channel< Data, DispatchPolicy > Class Template Referencefinal

#include <channel.hpp>

Classes

class  handle
 

Public Member Functions

void publish (int priority, const Data &data)
 
template<typename Callback >
handle subscribe (Callback cb)
 
auto set_dispatcher (const DispatchPolicy &policy) -> std::enable_if_t< std::is_copy_constructible< DispatchPolicy >::value, void >
 
bool has_subscribers ()
 

Friends

class appbase::application
 

Detailed Description

template<typename Data, typename DispatchPolicy>
class appbase::channel< Data, DispatchPolicy >

A channel is a loosely bound asynchronous data pub/sub concept.

This removes the need to tightly couple different plugins in the application for the use-case of sending data around

Data passed to a channel is copied, consider using a shared_ptr if the use-case allows it

Template Parameters
Data- the type of data to publish

Definition at line 47 of file channel.hpp.

Member Function Documentation

◆ has_subscribers()

template<typename Data , typename DispatchPolicy >
bool appbase::channel< Data, DispatchPolicy >::has_subscribers ( )
inline

Returns whether or not there are subscribers

Definition at line 129 of file channel.hpp.

129 {
130 auto connections = _signal.num_slots();
131 return connections > 0;
132 }

◆ publish()

template<typename Data , typename DispatchPolicy >
void appbase::channel< Data, DispatchPolicy >::publish ( int priority,
const Data & data )

Publish data to a channel. This data is copied on publish.

Parameters
priority- the priority to use for post
data- the data to publish

Definition at line 335 of file application.hpp.

335 {
336 if (has_subscribers()) {
337 // this will copy data into the lambda
338 app().post( priority, [this, data]() {
339 _signal(data);
340 });
341 }
342 }
auto post(int priority, Func &&func)
bool has_subscribers()
Definition channel.hpp:129
application & app()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_dispatcher()

template<typename Data , typename DispatchPolicy >
auto appbase::channel< Data, DispatchPolicy >::set_dispatcher ( const DispatchPolicy & policy) -> std::enable_if_t<std::is_copy_constructible<DispatchPolicy>::value,void>
inline

set the dispatcher according to the DispatchPolicy this can be used to set a stateful dispatcher

This method is only available when the DispatchPolicy is copy constructible due to implementation details

Parameters
policy- the DispatchPolicy to copy

Definition at line 121 of file channel.hpp.

122 {
123 _signal.set_combiner(policy);
124 }

◆ subscribe()

template<typename Data , typename DispatchPolicy >
template<typename Callback >
handle appbase::channel< Data, DispatchPolicy >::subscribe ( Callback cb)
inline

subscribe to data on a channel

Template Parameters
Callbackthe type of the callback (functor|lambda)
Parameters
cbthe callback
Returns
handle to the subscription

Definition at line 109 of file channel.hpp.

109 {
110 return handle(_signal.connect(cb));
111 }

Friends And Related Symbol Documentation

◆ appbase::application

template<typename Data , typename DispatchPolicy >
friend class appbase::application
friend

Definition at line 173 of file channel.hpp.


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