MIRA
Public Member Functions | Public Attributes | List of all members
ChannelVectorSynchronizer1< type0 > Class Template Reference

Class that can be registered as a filter when subscribing to more than one channel to only get a callback when all channels have data with a similar timestamp (differ only in the specified tolerance). More...

#include <filter/ChannelVectorSynchronizer.h>

Public Member Functions

 ChannelVectorSynchronizer1 ()
 
void unsubscribe (Authority &authority)
 Call this instead of Authority::unsubscribe(...) to unsubscribe all the channels of the synchronizer. More...
 
void subscribe (Authority &authority, const std::vector< std::string > &channelID0, const Duration &t=Duration::seconds(0))
 Call this instead of Authority::subscribe() Function provided for convenience (if no callback function is required). More...
 
void subscribe (Authority &authority, const std::vector< std::string > &channelID0, boost::function< void(std::vector< ChannelRead< type0 >>)> fn, const Duration &t=Duration::seconds(0))
 Call this instead of Authority::subscribe() More...
 
template<typename Class >
void subscribe (Authority &authority, const std::vector< std::string > &channelID0, void(Class::*f)(std::vector< ChannelRead< type0 >>), Class *obj, const Duration &t=Duration::seconds(0))
 Same as above but with a function and object pointer. More...
 
void callback0 (ChannelRead< type0 > ic)
 
void call (std::vector< ChannelRead< type0 >> c0)
 
boost::tuple< std::vector< ChannelRead< type0 > > > read ()
 Return (synchronized) ChannelRead objects. More...
 
bool isValid () const
 Return true if all ChannelRead objects contain valid data. More...
 
boost::tuple< std::vector< ChannelRead< type0 > > > waitForData (const Duration &timeout=Duration::infinity())
 Return the latest (synchronized) element once it is available. More...
 
bool waitForPublisher (const Duration &timeout=Duration::infinity()) const
 

Public Attributes

std::vector< TimemLast0
 
std::vector< Channel< type0 > > mChannel0
 
std::vector< ChannelRead< type0 > > mChannelRead0
 
Duration mTolerance
 
boost::function< void(std::vector< ChannelRead< type0 >>)> mFunction
 

Detailed Description

template<typename type0>
class mira::ChannelVectorSynchronizer1< type0 >

Class that can be registered as a filter when subscribing to more than one channel to only get a callback when all channels have data with a similar timestamp (differ only in the specified tolerance).

All channels have to be of the same type. To synchronize channels of differnt types, you have to use the ChannelVectorSynchronizer2, ChannelVectorSynchronizer3, ... template class. To synchronize arbitrary different types of channels, just define MIRA_CHANNEL_SYNCHRONIZER(MySynchronizerName, 5). Where MySynchronizerName defines the name of the template class which will be generated, the number will define the number of channels, which the synchronizer is using. After that you can use your MySynchronizerName class exactly the same way.

MyUnit : public MicroUnit
{
void initialize()
{
std::vector<std::string> mChannelNames;
mChannelNames.push_back("IntChannel0");
mChannelNames.push_back("IntChannel1");
mChannelNames.push_back("IntChannel2");
myFilter.subscribe(*this, mChannelNames,
&MyUnit::onCallback, this, Duration::milliseconds(500));
}
void onCallback(std::vector<ChannelRead<int>> channelReads)
{}
ChannelVectorSynchronizer<int> myFilter;
}

Constructor & Destructor Documentation

◆ ChannelVectorSynchronizer1()

Member Function Documentation

◆ unsubscribe()

void unsubscribe ( Authority authority)
inline

Call this instead of Authority::unsubscribe(...) to unsubscribe all the channels of the synchronizer.

◆ subscribe() [1/3]

void subscribe ( Authority authority,
const std::vector< std::string > &  channelID0,
const Duration t = Duration::seconds(0) 
)
inline

Call this instead of Authority::subscribe() Function provided for convenience (if no callback function is required).

◆ subscribe() [2/3]

void subscribe ( Authority authority,
const std::vector< std::string > &  channelID0,
boost::function< void(std::vector< ChannelRead< type0 >>)>  fn,
const Duration t = Duration::seconds(0) 
)
inline

Call this instead of Authority::subscribe()

Parameters
authorityThe authority that does the basic subscription
channelIDAThe ID of the channel A we are subscribing on
channelIDBThe ID of the channel B we are subscribing on
fnThe function that should be called when the filter matches
tMaximum time difference of the channels message timestamps for still being synchronous

◆ subscribe() [3/3]

void subscribe ( Authority authority,
const std::vector< std::string > &  channelID0,
void(Class::*)(std::vector< ChannelRead< type0 >>)  f,
Class obj,
const Duration t = Duration::seconds(0) 
)
inline

Same as above but with a function and object pointer.

Provided for convenience.

◆ callback0()

void callback0 ( ChannelRead< type0 >  ic)
inline

◆ call()

void call ( std::vector< ChannelRead< type0 >>  c0)
inline

◆ read()

boost::tuple< std::vector<ChannelRead<type0> > > read ( )
inline

Return (synchronized) ChannelRead objects.

The ChannelRead objects are always synchronized by the channel with the lowest update frequency. Please note that the ChannelRead objects may be invalid if no data has been published yet.

◆ isValid()

bool isValid ( ) const
inline

Return true if all ChannelRead objects contain valid data.

◆ waitForData()

boost::tuple< std::vector<ChannelRead<type0> > > waitForData ( const Duration timeout = Duration::infinity())
inline

Return the latest (synchronized) element once it is available.

If the functions times out, invalid channelRead objects will be returned. Please note that the function does not regard synchronized elements that were available BEFORE this function was called.

◆ waitForPublisher()

bool waitForPublisher ( const Duration timeout = Duration::infinity()) const
inline

Member Data Documentation

◆ mLast0

std::vector<Time> mLast0

◆ mChannel0

std::vector<Channel<type0> > mChannel0

◆ mChannelRead0

std::vector<ChannelRead<type0> > mChannelRead0

◆ mTolerance

Duration mTolerance

◆ mFunction

boost::function<void ( std::vector<ChannelRead<type0>>)> mFunction

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