MIRA
Classes | Public Member Functions | List of all members
ChannelManager Class Reference

An exception that occurred whenever a channel does not exist. More...

#include <fw/ChannelManager.h>

Classes

struct  ChannelInfo
 Informations about a channel that also provides ordering of channels by id. More...
 

Public Member Functions

 ChannelManager ()
 
 ~ChannelManager ()
 
template<typename Reflector >
void reflect (Reflector &r)
 Reflect method for serialization. More...
 
template<typename T >
ConcreteChannel< T > * publish (const std::string &channelID, const std::string &publisherID, bool internal, const Typename &type, bool noAutoPromoteCheck=false)
 Publishes a channel with the given id. More...
 
void enableAutoPromoteChannels (bool enable)
 Enable/disable automatic promotion of channel to typed in publish<void>(...) More...
 
bool autoPromoteChannelsEnabled ()
 Query if automatic promotion of channel to typed in publish<void>(...) is enabled. More...
 
void enableCheckChannelRegistrations (bool enable)
 Enable/disable check for registration of channel types in publish<T>(...) (T!=void) More...
 
bool checkChannelRegistrationsEnabled ()
 Query if check for channel registrations in publish<T>(...) is enabled. More...
 
template<typename T >
ConcreteChannel< T > * subscribe (const std::string &channelID, const std::string &subscriberID, const Duration &storageDuration, bool internal)
 Subscribes to a channel with the given id. More...
 
void removePublisherFromAllChannels (const std::string &publisherID, bool internal)
 Remove a publisher from the publisher lists of all channels it has published. More...
 
void removePublisher (const std::string &channelID, const std::string &publisherID, bool internal)
 Remove a publisher from the list of publishers of the given channel. More...
 
void removeSubscriberFromAllChannels (const std::string &subscriberID)
 Remove a subscriber from the subscriber lists of all channels it is subscribed on. More...
 
void removeSubscriber (const std::string &channelID, const std::string &subscriberID)
 Remove a subscriber from the subscriber list of channel channelID. More...
 
void deductNumSubscribers (const std::string &channelID)
 Reduce the number of registered subscribers (subscribed without callback) on the channel by 1, by calling AbstractChannel::removeSubscriber() More...
 
template<typename T >
ConcreteChannel< T > * getConcreteChannel (const std::string &channelID)
 Returns the existing channel with the given id. More...
 
std::set< std::string > getChannels () const
 Get a list of all channels managed by this manager. More...
 
std::set< std::string > getChannelList (bool publishedOnly=false, bool subscribedOnly=false) const
 Get a list of all channels managed by this manager, can be filtered for only those that have subscribers and/or publishers (any combination is possible). More...
 
std::set< std::string > getSubscribedChannels (bool includeInternal=false) const
 Get a list of all channels we have subscriptions on. More...
 
std::set< std::string > getSubscribedChannelsBy (const std::string &subscriberID) const
 Get a list of all channels that the given subscriber has subscribed on. More...
 
bool isSubscribedOn (const std::string &subscriberID, const std::string &channelID) const
 Returns true if the subscriber is subscribed to the given channel. More...
 
std::map< std::string, TypenamegetPublishedChannels (bool includeInternal=false) const
 Get a list of all channels and their types we have publishers for. More...
 
std::set< std::string > getPublishedChannelsBy (const std::string &publisherID) const
 Get a list of all channels that are currently published by the given publisher. More...
 
bool hasPublished (const std::string &publisherID, const std::string &channelID) const
 Returns true if the publisher has published the given channel. More...
 
std::list< std::pair< std::string, Typename > > getChannelsOfType (const Typename &type) const
 Returns a list of all channels that match the specified type. More...
 
template<typename T >
std::list< std::pair< std::string, Typename > > getChannelsOfType () const
 Returns a list of all channels that match the specified type. More...
 
bool hasSubscriber (const std::string &channelID) const
 Returns if we have at least one subscriber (including internal ones) for the given channel. More...
 
bool hasPublisher (const std::string &channelID, bool includeInternal) const
 Returns if we have a publisher for a given channel. More...
 
uint32 getNrPublishers (const std::string &channelID) const
 Get the number of publishers for that channel. More...
 
std::set< std::string > getPublishers (const std::string &channelID, bool includeInternal=false) const
 Get all publishers for that channel. More...
 
uint32 getNrSubscribers (const std::string &channelID) const
 Get the number of subscribers to that channel. More...
 
std::set< std::string > getSubscribers (const std::string &channelID, bool includeInternal=false) const
 Get all subscribers for that channel. More...
 
bool hasChannel (const std::string &channelID) const
 Returns true, if the specified channel with the fully qualified channelID exits. More...
 
int getTypeId (const std::string &channelID) const
 Returns the type id of the specified channel with the fully qualified channelID or -1, if the channel is untyped. More...
 
void setTypename (const std::string &channelID, const Typename &typenam)
 Sets the typename of the specified channel. More...
 
Typename getTypename (const std::string &channelID) const
 Returns the typename of the specified channel with the fully qualified channelID. More...
 
void setTypeMeta (const std::string &channelID, TypeMetaPtr meta)
 Sets the type meta information for the slots of the underlying channel buffer. More...
 
TypeMetaPtr getTypeMeta (const std::string &channelID) const
 Returns the type meta information of the channel. More...
 
Time getLastSlotTime (const std::string &channelID) const
 Returns the timestamp of the data in the slot that was last written to the channel with the fully qualified channelID or an invalid time when there was no data written at all. More...
 
std::size_t getNrOfSlots (const std::string &channelID) const
 Returns the number of slots in the channel. More...
 
uint64 getNrOfDataChanges (const std::string &channelID) const
 Returns the number of times data was written to the channel with the fully qualified channelID or an invalid time. More...
 
void ensureChannel (const std::string &channelID)
 Just make sure the specified channel exists (by creating it if needed), without changing any attributes. More...
 
void setStorageDuration (const std::string &channelID, const Duration &storageDuration)
 Sets storage duration for the specified channel. More...
 
void setAutoIncreaseStorageDuration (const std::string &channelID, bool increase)
 Sets whether to auto-increase storage duration for the specified channel. More...
 
void setMinSlots (const std::string &channelID, std::size_t minSlots)
 Sets desired minimum number of slots for the specified channel. More...
 
void setMaxSlots (const std::string &channelID, std::size_t maxSlots)
 Sets the maximum number of slots for the specified channel. More...
 
Duration getStorageDuration (const std::string &channelID)
 Query storage duration for the specified channel. More...
 
bool isAutoIncreasingStorageDuration (const std::string &channelID)
 Query whether specified channel is auto-increasing storage duration. More...
 
std::size_t getMinSlots (const std::string &channelID)
 Query desired minimum number of slots for the specified channel. More...
 
std::size_t getMaxSlots (const std::string &channelID)
 Query desired maximum number of slots for the specified channel. More...
 
void writeChannel (const std::string &channelID, const json::Value &value, Time time, std::string frameID, uint32 sequenceID)
 Writes a json value to the channel with given id. More...
 
void writeChannel (const std::string &channelID, const json::Value &value, Time time=Time::now())
 Writes a json value to the channel with given id. More...
 
void writeChannel (const std::string &channelID, const json::Value &value, std::string frameID, Time time=Time::now())
 Writes a json value to the channel with given id. More...
 
json::Value readChannel (const std::string &channelID)
 Reads data from the channel with given id. More...
 

Detailed Description

An exception that occurred whenever a channel does not exist.

This manager provides functionality to create, obtain and manage the channels in the framework. Channels provide a time ordered queue (history) of data slots (timestamp, value pairs).

Constructor & Destructor Documentation

◆ ChannelManager()

◆ ~ChannelManager()

Member Function Documentation

◆ reflect()

void reflect ( Reflector &  r)
inline

Reflect method for serialization.

◆ publish()

ConcreteChannel<T>* publish ( const std::string &  channelID,
const std::string &  publisherID,
bool  internal,
const Typename type,
bool  noAutoPromoteCheck = false 
)
inline

Publishes a channel with the given id.

If the channel does not exist it will be created. If the channel is a polymorphic channel (i.e. T is a pointer type of a polymorphic type) then publishing the channel will fixate the channels type and future publish() calls with different types will result in a XBadCast exception.

Exceptions
XBadCastif the channel exists but the types do not match.
Parameters
[in]channelIDThe channel id
[in]publisherIDThe id of the publisher. If empty the channel will not be visible in a call to getPublishedChannels().
[in]internalThe internal flag specifies if the publisher counts not as a public publisher to that channel (e.g. remote publishers)
[in]typeThe typename of the channel's type
[in]noAutoPromoteCheckIf true, suppress checking for existence of a promoter for a typed channel
Returns
A concrete Channel object that the caller can convert to a channel by providing access flags

◆ enableAutoPromoteChannels()

void enableAutoPromoteChannels ( bool  enable)
inline

Enable/disable automatic promotion of channel to typed in publish<void>(...)

◆ autoPromoteChannelsEnabled()

bool autoPromoteChannelsEnabled ( )
inline

Query if automatic promotion of channel to typed in publish<void>(...) is enabled.

◆ enableCheckChannelRegistrations()

void enableCheckChannelRegistrations ( bool  enable)
inline

Enable/disable check for registration of channel types in publish<T>(...) (T!=void)

◆ checkChannelRegistrationsEnabled()

bool checkChannelRegistrationsEnabled ( )
inline

Query if check for channel registrations in publish<T>(...) is enabled.

◆ subscribe()

ConcreteChannel<T>* subscribe ( const std::string &  channelID,
const std::string &  subscriberID,
const Duration storageDuration,
bool  internal 
)
inline

Subscribes to a channel with the given id.

The channel is created if not exists.

Exceptions
XBadCastif the channel exists but the types do not match.
Parameters
[in]channelIDThe id of the data channel to subscribe to
[in]subscriberIDThe id of the subscriber. If empty the channel will not be visible in a call to getSubscribedChannels().
[in]storageDurationThe requested duration of how long data is stored in the channel (history). Note that the real history length may differ from this request because the number of slots in the channel is limited by its maximum length. Assuming we have only one writer to the channel that updates the channel each T milliseconds the real storage duration D can be computed by D = (maxSlots-1) * T.
[in]internalThe internal flag specifies if the subscriber counts not as a public subscriber to that channel (e.g. remote subscribers)
Returns
A concrete Channel object that the caller can convert to a channel by providing access flags

◆ removePublisherFromAllChannels()

void removePublisherFromAllChannels ( const std::string &  publisherID,
bool  internal 
)

Remove a publisher from the publisher lists of all channels it has published.

Parameters
[in]publisherIDThe id of the publisher.
[in]internalIs the publisher an internal one that does not count as a global publisher (only local in this framework)

◆ removePublisher()

void removePublisher ( const std::string &  channelID,
const std::string &  publisherID,
bool  internal 
)

Remove a publisher from the list of publishers of the given channel.

Parameters
[in]channelIDThe channel ID
[in]publisherIDThe id of the publisher.
[in]internalIs the publisher an internal one that does not count as a global publisher (only local in this framework)

◆ removeSubscriberFromAllChannels()

void removeSubscriberFromAllChannels ( const std::string &  subscriberID)

Remove a subscriber from the subscriber lists of all channels it is subscribed on.

◆ removeSubscriber()

void removeSubscriber ( const std::string &  channelID,
const std::string &  subscriberID 
)

Remove a subscriber from the subscriber list of channel channelID.

Parameters
[in]channelIDThe channel ID
[in]subscriberIDThe id of the subscriber.

◆ deductNumSubscribers()

void deductNumSubscribers ( const std::string &  channelID)

Reduce the number of registered subscribers (subscribed without callback) on the channel by 1, by calling AbstractChannel::removeSubscriber()

Parameters
[in]channelIDThe channel ID

◆ getConcreteChannel()

ConcreteChannel<T>* getConcreteChannel ( const std::string &  channelID)
inline

Returns the existing channel with the given id.

Parameters
[in]channelIDThe channel ID
Returns
Pointer to the channel
Exceptions
XBadCastif the channel exists but the types do not match.
XUnknownChannelif the channel does not exist.

◆ getChannels()

std::set<std::string> getChannels ( ) const

Get a list of all channels managed by this manager.

◆ getChannelList()

std::set<std::string> getChannelList ( bool  publishedOnly = false,
bool  subscribedOnly = false 
) const

Get a list of all channels managed by this manager, can be filtered for only those that have subscribers and/or publishers (any combination is possible).

Parameters
[in]publishedOnlyOnly return channels that have (local) publishers. If false, this will not exclude any channels.
[in]subscribedOnlyOnly return channels that have (local) subscribers (excluding internal subscribers). If false, this will not exclude any channels.
Returns
List of channels matching the requested criteria.

◆ getSubscribedChannels()

std::set<std::string> getSubscribedChannels ( bool  includeInternal = false) const

Get a list of all channels we have subscriptions on.

Parameters
[in]includeInternalIf set to false (default) the returned list excludes channels that have only internal subscribers
Returns
List of subscribed channels

◆ getSubscribedChannelsBy()

std::set<std::string> getSubscribedChannelsBy ( const std::string &  subscriberID) const

Get a list of all channels that the given subscriber has subscribed on.

Parameters
[in]subscriberIDSubscriber name
Returns
List of subscribed channels

Note: only works correctly for subscribers in the local framework. For remote subscribers, use AbstractAuthority::getSubscribedChannels (access the Authority e.g. using AuthorityManager).

◆ isSubscribedOn()

bool isSubscribedOn ( const std::string &  subscriberID,
const std::string &  channelID 
) const

Returns true if the subscriber is subscribed to the given channel.

◆ getPublishedChannels()

std::map<std::string, Typename> getPublishedChannels ( bool  includeInternal = false) const

Get a list of all channels and their types we have publishers for.

Parameters
[in]includeInternalIf set to false (default) the returned list excludes channels that have only internal publishers
Returns
List of published channels

◆ getPublishedChannelsBy()

std::set<std::string> getPublishedChannelsBy ( const std::string &  publisherID) const

Get a list of all channels that are currently published by the given publisher.

Parameters
[in]publisherIDPublisher name
Returns
List of published channels

Note: only works correctly for publishers in the local framework. For remote publishers, use AbstractAuthority::getPublishedChannels (access the Authority e.g. using AuthorityManager).

◆ hasPublished()

bool hasPublished ( const std::string &  publisherID,
const std::string &  channelID 
) const

Returns true if the publisher has published the given channel.

◆ getChannelsOfType() [1/2]

std::list<std::pair<std::string, Typename> > getChannelsOfType ( const Typename type) const

Returns a list of all channels that match the specified type.

Each list item is a pair where the first entry specifies the full qualified name of the channel and the second entry specifies the type of the channel.

◆ getChannelsOfType() [2/2]

std::list<std::pair<std::string, Typename> > getChannelsOfType ( ) const
inline

Returns a list of all channels that match the specified type.

Each list item is a pair where the first entry specifies the full qualified name of the channel and the second entry specifies the type of the channel.

◆ hasSubscriber()

bool hasSubscriber ( const std::string &  channelID) const

Returns if we have at least one subscriber (including internal ones) for the given channel.

Parameters
[in]channelIDThe channel id
Returns
true if we have a subscriber for this channel, false otherwise or if channel does not exist

◆ hasPublisher()

bool hasPublisher ( const std::string &  channelID,
bool  includeInternal 
) const

Returns if we have a publisher for a given channel.

Parameters
[in]channelIDThe channel id
[in]includeInternalIf true also internal publishers will count as a publisher for that channel.
Returns
true if channel has at least one publisher, false if not

◆ getNrPublishers()

uint32 getNrPublishers ( const std::string &  channelID) const

Get the number of publishers for that channel.

◆ getPublishers()

std::set<std::string> getPublishers ( const std::string &  channelID,
bool  includeInternal = false 
) const

Get all publishers for that channel.

◆ getNrSubscribers()

uint32 getNrSubscribers ( const std::string &  channelID) const

Get the number of subscribers to that channel.

◆ getSubscribers()

std::set<std::string> getSubscribers ( const std::string &  channelID,
bool  includeInternal = false 
) const

Get all subscribers for that channel.

◆ hasChannel()

bool hasChannel ( const std::string &  channelID) const

Returns true, if the specified channel with the fully qualified channelID exits.

◆ getTypeId()

int getTypeId ( const std::string &  channelID) const

Returns the type id of the specified channel with the fully qualified channelID or -1, if the channel is untyped.

◆ setTypename()

void setTypename ( const std::string &  channelID,
const Typename typenam 
)

Sets the typename of the specified channel.

◆ getTypename()

Typename getTypename ( const std::string &  channelID) const

Returns the typename of the specified channel with the fully qualified channelID.

◆ setTypeMeta()

void setTypeMeta ( const std::string &  channelID,
TypeMetaPtr  meta 
)

Sets the type meta information for the slots of the underlying channel buffer.

◆ getTypeMeta()

TypeMetaPtr getTypeMeta ( const std::string &  channelID) const

Returns the type meta information of the channel.

◆ getLastSlotTime()

Time getLastSlotTime ( const std::string &  channelID) const

Returns the timestamp of the data in the slot that was last written to the channel with the fully qualified channelID or an invalid time when there was no data written at all.

◆ getNrOfSlots()

std::size_t getNrOfSlots ( const std::string &  channelID) const

Returns the number of slots in the channel.

◆ getNrOfDataChanges()

uint64 getNrOfDataChanges ( const std::string &  channelID) const

Returns the number of times data was written to the channel with the fully qualified channelID or an invalid time.

◆ ensureChannel()

void ensureChannel ( const std::string &  channelID)
inline

Just make sure the specified channel exists (by creating it if needed), without changing any attributes.

◆ setStorageDuration()

void setStorageDuration ( const std::string &  channelID,
const Duration storageDuration 
)

Sets storage duration for the specified channel.

Sets the desired storage duration (the history). This method can increase the duration only. If the specified duration is smaller than a previous set duration the call will be ignored.

Note
Duration can only be increased until the maximum number of slots is reached. Use setMaxSlots() to increase maximum number of slots.

◆ setAutoIncreaseStorageDuration()

void setAutoIncreaseStorageDuration ( const std::string &  channelID,
bool  increase 
)

Sets whether to auto-increase storage duration for the specified channel.

Sets whether the storage duration is automatically increased on read accesses. If true, any read access specifying a timestamp will automatically increase the storage duration to the time difference between the timestamp and the most recent data (trying to ensure data is kept long enough for further such requests). The default is true.

◆ setMinSlots()

void setMinSlots ( const std::string &  channelID,
std::size_t  minSlots 
)

Sets desired minimum number of slots for the specified channel.

Sets the desired min. number of slots for storing the history of a channel. This method can increase the min. number of slots only. Instead of specifying the min. number of slots you can also specify the desired storage duration using the setStorageDuration() method.

Note
The desired number of slots can be increased until the maximum number of slots is reached. Use setMaxSlots() to increase maximum number of slots.

◆ setMaxSlots()

void setMaxSlots ( const std::string &  channelID,
std::size_t  maxSlots 
)

Sets the maximum number of slots for the specified channel.

Sets the max. number of slots that are used for storing the history of a channel. maxSlots must at least be 1. The default is 100.

Note
There will only be as many slots as needed depending on the number of publishers and subscribers. The number of slots will also grow (history) if a storage duration is specified via setStorageDuration()

◆ getStorageDuration()

Duration getStorageDuration ( const std::string &  channelID)

Query storage duration for the specified channel.

◆ isAutoIncreasingStorageDuration()

bool isAutoIncreasingStorageDuration ( const std::string &  channelID)

Query whether specified channel is auto-increasing storage duration.

◆ getMinSlots()

std::size_t getMinSlots ( const std::string &  channelID)

Query desired minimum number of slots for the specified channel.

◆ getMaxSlots()

std::size_t getMaxSlots ( const std::string &  channelID)

Query desired maximum number of slots for the specified channel.

◆ writeChannel() [1/3]

void writeChannel ( const std::string &  channelID,
const json::Value value,
Time  time,
std::string  frameID,
uint32  sequenceID 
)

Writes a json value to the channel with given id.

◆ writeChannel() [2/3]

void writeChannel ( const std::string &  channelID,
const json::Value value,
Time  time = Time::now() 
)

Writes a json value to the channel with given id.

If data was published to the channel before, the frameID of the latest data is copied, and the sequenceID is incremented.

◆ writeChannel() [3/3]

void writeChannel ( const std::string &  channelID,
const json::Value value,
std::string  frameID,
Time  time = Time::now() 
)

Writes a json value to the channel with given id.

If data was published to the channel before, the sequenceID is incremented.

◆ readChannel()

json::Value readChannel ( const std::string &  channelID)

Reads data from the channel with given id.

If channel has type T it returns the json representation of T.


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