47 #ifndef _MIRA_CHANNELMANAGER_H_ 48 #define _MIRA_CHANNELMANAGER_H_ 85 internal(iInternal) {}
94 return id == other.
id;
105 template<
typename Reflector>
108 r.interface(
"IChannelManager");
110 "Writes a json representation to a channel of type T",
111 "channelID",
"ID of channel to write to",
"/robot/RobotFrame",
115 "Reads the latest channel data as json representation",
116 "channelID",
"ID of channel to read",
"/robot/RobotFrame");
118 "get list of channels",
119 "publishedOnly",
"if true, include only channels with (local) publishers",
false,
120 "subscribedOnly",
"if true, include only channels with (local) subscribers",
false);
146 const std::string& publisherID,
148 bool noAutoPromoteCheck =
false)
152 channel->fixateType();
154 if ( channel->isTyped() ) {
155 Typename channelType = channel->getTypename();
156 if ((channelType !=
type) &&
160 ((channelType[channelType.size()-1] !=
'*') || (typeName<T>() ==
"void")))
161 MIRA_THROW(XBadCast,
"Invalid publish<void> to typed channel '" << channelID <<
162 "'. Typename does not match. ('" <<
163 type <<
"' != '" << channel->getTypename() <<
"')");
165 if (mCheckChannelRegistrations && !noAutoPromoteCheck)
166 ChannelPromoteByTypename::instance().checkForPromoter(channel);
168 if (!channel->getTypename().empty() && (channel->getTypename() !=
type))
169 MIRA_THROW(XBadCast,
"Invalid publish<void> to untyped channel '" << channelID <<
170 "' (with set typename). Typename does not match. ('" <<
171 type <<
"' != '" << channel->getTypename() <<
"')");
173 channel->setTypename(
type);
177 insertPublishedChannel(channelID,
ChannelInfo(publisherID,
internal));
178 MIRA_LOG(
DEBUG) <<
"'" << publisherID <<
"' published channel '" << channelID <<
"'";
182 remotePublishChannel(channelID,
type);
225 const std::string& subscriberID,
226 const Duration& storageDuration,
bool internal)
230 assert(channel->getBuffer()!=NULL);
231 channel->getBuffer()->setStorageDuration(storageDuration);
232 insertSubscribedChannel(channelID,
ChannelInfo(subscriberID,
internal));
233 MIRA_LOG(
DEBUG) <<
"'" << subscriberID <<
"' subscribed to channel '" << channelID <<
"'";
236 remoteSubscribeChannel(channelID);
247 void unpublish(
const std::string& publisherID,
bool internal);
256 void unpublish(
const std::string& channelID,
const std::string& publisherID,
bool internal);
262 void unsubscribe(
const std::string& subscriberID);
269 void unsubscribe(
const std::string& channelID,
const std::string& subscriberID);
281 return channel_cast<T>(getAbstractChannel(channelID));
289 std::set<std::string> getChannels()
const;
302 std::set<std::string> getChannelList(
bool publishedOnly =
false,
303 bool subscribedOnly =
false)
const;
311 std::set<std::string> getSubscribedChannels(
bool includeInternal =
false)
const;
322 std::set<std::string> getSubscribedChannelsBy(
const std::string& subscriberID)
const;
327 bool isSubscribedOn(
const std::string& subscriberID,
328 const std::string& channelID)
const;
336 std::map<std::string, Typename> getPublishedChannels(
bool includeInternal =
false)
const;
347 std::set<std::string> getPublishedChannelsBy(
const std::string& publisherID)
const;
352 bool hasPublished(
const std::string& publisherID,
const std::string& channelID)
const;
360 std::list<std::pair<std::string, Typename>> getChannelsOfType(
const Typename&
type)
const;
368 template <
typename T>
370 return getChannelsOfType(typeName<T>());
380 bool hasSubscriber(
const std::string& channelID)
const;
389 bool hasPublisher(
const std::string& channelID,
bool includeInternal)
const;
394 uint32 getNrPublishers(
const std::string& channelID)
const;
399 std::set<std::string> getPublishers(
const std::string& channelID,
400 bool includeInternal =
false)
const;
405 uint32 getNrSubscribers(
const std::string& channelID)
const;
410 std::set<std::string> getSubscribers(
const std::string& channelID,
411 bool includeInternal =
false)
const;
417 bool hasChannel(
const std::string& channelID)
const;
423 int getTypeId(
const std::string& channelID)
const;
428 void setTypename(
const std::string& channelID,
const Typename& typenam);
434 Typename getTypename(
const std::string& channelID)
const;
440 void setTypeMeta(
const std::string& channelID,
TypeMetaPtr meta);
445 TypeMetaPtr getTypeMeta(
const std::string& channelID)
const;
452 Time getLastSlotTime(
const std::string& channelID)
const;
457 std::size_t getNrOfSlots(
const std::string& channelID)
const;
463 uint64 getNrOfDataChanges(
const std::string& channelID)
const;
473 obtainConcreteChannel<void>(channelID);
481 void setStorageDuration(
const std::string& channelID,
const Duration& storageDuration);
488 void setAutoIncreaseStorageDuration(
const std::string& channelID,
bool increase);
495 void setMinSlots(
const std::string& channelID, std::size_t minSlots);
502 void setMaxSlots(
const std::string& channelID, std::size_t maxSlots);
505 Duration getStorageDuration(
const std::string& channelID);
508 bool isAutoIncreasingStorageDuration(
const std::string& channelID);
511 std::size_t getMinSlots(
const std::string& channelID);
514 std::size_t getMaxSlots(
const std::string& channelID);
521 void writeChannel(
const std::string& channelID,
529 json::Value readChannel(
const std::string& channelID);
539 const AbstractChannel* getAbstractChannel(
const std::string& channelID)
const;
563 const AbstractChannel* getAbstractChannelNoLocking(
const std::string& channelID)
const;
575 boost::mutex::scoped_lock lock(mChannelsMutex);
580 channel = channel_cast<T>(getAbstractChannelNoLocking(channelID));
582 catch (XUnknownChannel&)
585 channel =
new ConcreteChannel<T>(channelID);
586 mChannels.insert(ChannelMap::value_type(channelID, channel));
593 void remotePublishChannel(
const std::string& channelID,
const Typename&
type);
594 void remoteUnpublishChannel(
const std::string& channelID);
595 void remoteSubscribeChannel(
const std::string& channelID);
596 void remoteUnsubscribeChannel(
const std::string& channelID);
602 void insertPublishedChannel(
const std::string& channelID,
const ChannelInfo& info);
603 void insertSubscribedChannel(
const std::string& channelID,
const ChannelInfo& info);
607 typedef std::map<std::string, AbstractChannelPtr > ChannelMap;
608 ChannelMap mChannels;
609 mutable boost::mutex mChannelsMutex;
614 mutable boost::mutex mSubscriberMutex;
615 mutable boost::mutex mPublisherMutex;
617 bool mAutoPromoteChannels;
618 bool mCheckChannelRegistrations;
Serializer for serializing objects in JSON format.
Definition: JSONSerializer.h:93
bool operator==(const ChannelInfo &other) const
Definition: ChannelManager.h:92
Typedefs for OS independent basic data types.
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
std::string Typename
Definition: Typename.h:60
#define MIRA_LOG(level)
Use this macro to log data.
Definition: LoggingCore.h:528
bool checkChannelRegistrationsEnabled()
Query if check for channel registrations in publish<T>(...) is enabled.
Definition: ChannelManager.h:199
#define MIRA_DEFINE_SERIALIZABLE_EXCEPTION(Ex, Base)
Macro for easily defining a new serializable exception class.
Definition: Exceptions.h:66
json::Value readChannel(const std::string &channelID)
Reads data from the channel with given id.
Definition: ChannelReadWrite.h:65
#define MIRA_THROW(ex, msg)
Macro for throwing an exception.
Definition: Exception.h:81
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.
Definition: ChannelManager.h:145
Wrapper class for boost::posix_time::ptime for adding more functionality to it.
Definition: Time.h:421
void enableAutoPromoteChannels(bool enable)
Enable/disable automatic promotion of channel to typed in publish<void>(...)
Definition: ChannelManager.h:188
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 subscrib...
ChannelInfo()
Definition: ChannelManager.h:81
void enableCheckChannelRegistrations(bool enable)
Enable/disable check for registration of channel types in publish<T>(...) (T!=void) ...
Definition: ChannelManager.h:196
void reflect(Reflector &r)
Reflect method for serialization.
Definition: ChannelManager.h:106
void writeChannel(const std::string &channelID, const json::Value &value, const Time &time=Time::now())
Writes a json value to the channel with given id.
Commonly used exception classes.
Includes, defines and functions for threads.
std::string id
Definition: ChannelManager.h:97
#define MIRA_FRAMEWORK_EXPORT
Definition: FrameworkExports.h:61
PropertyHint type(const std::string &t)
Sets the attribute "type" to the specified value.
Definition: PropertyHint.h:295
Definition: AbstractChannel.h:70
Use this class to represent time durations.
Definition: Time.h:104
bool autoPromoteChannelsEnabled()
Query if automatic promotion of channel to typed in publish<void>(...) is enabled.
Definition: ChannelManager.h:191
ChannelInfo(const std::string &iID, bool iInternal=false)
Definition: ChannelManager.h:83
ConcreteChannel< T > * subscribe(const std::string &channelID, const std::string &subscriberID, const Duration &storageDuration, bool internal)
Subscribes to a channel with the given id.
Definition: ChannelManager.h:224
boost::shared_ptr< TypeMeta > TypeMetaPtr
Definition: MetaSerializer.h:309
Framework channel classes.
Informations about a channel that also provides ordering of channels by id.
Definition: ChannelManager.h:79
json_spirit::mValue Value
A value is an abstract description of data in JSON (underlying data can either be one of the JSON bas...
Definition: JSON.h:176
static Time now() static Time eternity()
Returns the current utc based time.
Definition: Time.h:484
An exception that occurred whenever a channel does not exist.
Definition: ChannelManager.h:75
Typedefs for different Pose datatypes that are internally RigidTransforms.
Definition: LoggingCore.h:77
std::list< std::pair< std::string, Typename > > getChannelsOfType() const
Returns a list of all channels that match the specified type.
Definition: ChannelManager.h:369
bool operator<(const ChannelInfo &other) const
Definition: ChannelManager.h:87
void ensureChannel(const std::string &channelID)
Just make sure the specified channel exists (by creating it if needed), without changing any attribut...
Definition: ChannelManager.h:471
ConcreteChannel< T > * getConcreteChannel(const std::string &channelID)
Returns the existing channel with the given id.
Definition: ChannelManager.h:279