48 #ifndef _MIRA_CHANNELLOCKEDREADWRITE_H_ 49 #define _MIRA_CHANNELLOCKEDREADWRITE_H_ 52 #include <boost/shared_ptr.hpp> 53 #include <boost/thread/shared_mutex.hpp> 54 #include <boost/thread/locks.hpp> 71 template <
typename ConcreteChannelReadWrite>
83 template<
typename DerivedContainer>
105 #if __cplusplus >= 201703L 106 if(std::uncaught_exceptions() == 0)
108 if(!std::uncaught_exception())
111 DerivedContainer::finish(
this);
115 catch(std::exception& ex) {
119 MIRA_LOG(
ERROR) <<
"Unknown error in ChannelRead/Write::finish()";
122 DerivedContainer::discard(
this);
147 template<
typename Derived>
191 static std::string emptyString;
192 return shared.get()!=NULL ?
shared->channel->getID() : emptyString;
196 return shared.get()!=NULL ?
shared->channel->getTypename() :
"";
205 return shared->slot->timestamp();
225 return shared->slot->flags;
235 shared->slot->flags |= moreFlags;
243 MIRA_THROW(XAccessViolation,
"Trying to access ChannelRead / " 244 "ChannelWrite that was not assigned with valid data");
246 if(!
shared->lock.owns_lock())
247 MIRA_THROW(XAccessViolation,
"Trying to access data of ChannelRead " 248 "/ ChannelWrite after losing the lock");
258 shared->channel->getBuffer()->readSerializedValue(
shared->slot);
268 assert(!res.
empty());
274 return shared->channel->getBuffer()->readSerializedValue(
shared->slot, formatVersion, orLower);
280 return shared->channel->getBuffer()->readSerializedValue(
shared->slot, codecs);
284 uint8 formatVersion,
bool orLower) {
286 return shared->channel->getBuffer()->readSerializedValue(
shared->slot, codecs,
287 formatVersion, orLower);
292 shared->channel->getBuffer()->readJSON(
shared->slot, oValue);
297 shared->channel->getBuffer()->readJSON(
shared->slot, oValue, serializer);
304 shared->channel->getBuffer()->writeSerializedValue(
shared->slot, std::move(data));
309 shared->channel->getBuffer()->writeJSON(
shared->slot, value);
314 shared->channel->getBuffer()->writeJSON(
shared->slot, deserializer);
319 shared->channel->getBuffer()->writeXML(
shared->slot, node);
328 template<
typename Derived,
typename T>
358 return this->
shared->slot->data;
368 return this->
shared->slot->data;
378 template<
typename Derived>
408 return this->
shared->channel->getBuffer()->getStampedHeader(this->
shared->slot);
418 return this->
shared->channel->getBuffer()->getStampedHeader(this->
shared->slot);
528 uint8 formatVersion,
bool orLower) {
567 if(
shared->lock.owns_lock())
748 if(
shared->lock.owns_lock()) {
759 if(
shared->lock.owns_lock()) {
777 typedef boost::shared_lock<boost::shared_mutex>
Lock;
786 typedef boost::unique_lock<boost::shared_mutex>
Lock;
798 typedef boost::shared_lock<boost::shared_mutex>
Lock;
807 typedef boost::unique_lock<boost::shared_mutex>
Lock;
static void finish(Shared *shared)
Definition: ChannelReadWrite.h:565
Serializer for serializing objects in JSON format.
Definition: JSONSerializer.h:93
AbstractChannel ChannelType
Definition: ChannelReadWrite.h:795
Base::Shared Shared
Definition: ChannelReadWrite.h:336
Base::ValueType ValueType
Definition: ChannelReadWrite.h:339
ChannelReadWriteBase()
Constructs an empty (invalid) ChannelReadWriteBase object.
Definition: ChannelReadWrite.h:344
Base::ChannelTypePtr ChannelTypePtr
Definition: ChannelReadWrite.h:387
Base::Shared Shared
Definition: ChannelReadWrite.h:386
void finish()
Releases the lock explicitly.
Definition: ChannelReadWrite.h:548
boost::shared_lock< boost::shared_mutex > Lock
Definition: ChannelReadWrite.h:777
~ChannelReadWriteShared()
Definition: ChannelReadWrite.h:100
void discard()
Releases the lock explicitly WITHOUT informing the Channel and without signaling the subscribers...
Definition: ChannelReadWrite.h:727
Definition: SyncTimedRead.h:62
An exception that occurs whenever a channel has no data.
Definition: Channel.h:88
const Buffer< uint8 > & readSerializedValue(uint8 formatVersion, bool orLower)
Definition: ChannelReadWrite.h:272
void readJSON(JSONValue &oValue)
Definition: ChannelReadWrite.h:290
ChannelReadWriteCommonBase< Derived > Base
Definition: ChannelReadWrite.h:383
ChannelBuffer< T >::ValueType ValueType
Definition: ChannelReadWrite.h:785
Slot * slot
the slot in that channel we are pointing on (this pointer is valid unless the channel's buffer is des...
Definition: ChannelReadWrite.h:134
ChannelBuffer< void >::Slot SlotType
Definition: ChannelReadWrite.h:796
uint32 getFlags() const
For internal use only.
Definition: ChannelReadWrite.h:223
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
Shared::ChannelType ChannelType
Definition: ChannelReadWrite.h:156
Base::ChannelTypePtr ChannelTypePtr
Definition: ChannelReadWrite.h:606
static void discard(Shared *shared)
Definition: ChannelReadWrite.h:571
const ValueType & internalValue() const
Returns a const reference on the data.
Definition: ChannelReadWrite.h:416
An object that allows exclusive write access to data of a channel.
Definition: ChannelReadWrite.h:599
const ValueType & operator=(const ValueType &value)
Definition: ChannelReadWrite.h:659
#define MIRA_LOG(level)
Use this macro to log data.
Definition: LoggingCore.h:529
Base::ChannelTypePtr ChannelTypePtr
Definition: ChannelReadWrite.h:448
ChannelBuffer< T >::Slot SlotType
Definition: ChannelReadWrite.h:784
ChannelBuffer< T >::Slot SlotType
Definition: ChannelReadWrite.h:775
ChannelBuffer< T >::ValueType ValueType
Definition: ChannelReadWrite.h:776
Base::Shared Shared
Definition: ChannelReadWrite.h:447
ChannelReadWriteShared(ChannelTypePtr iChannel, Slot *iSlot)
Definition: ChannelReadWrite.h:97
AbstractChannel ChannelType
Definition: ChannelReadWrite.h:804
ChannelBuffer< void >::Slot SlotType
Definition: ChannelReadWrite.h:805
void addFlags(uint32 moreFlags) const
For internal use only.
Definition: ChannelReadWrite.h:233
boost::unique_lock< boost::shared_mutex > Lock
Definition: ChannelReadWrite.h:786
void writeSerializedValue(Buffer< uint8 > data)
Definition: ChannelReadWrite.h:689
Definition: ChannelReadWrite.h:65
ChannelReadWriteBase()
Constructs an empty (invalid) ChannelReadWriteBase object.
Definition: ChannelReadWrite.h:394
void writeJSON(JSONDeserializer &deserializer)
Definition: ChannelReadWrite.h:697
An object that allows read access to data of a channel.
Definition: ChannelReadWrite.h:440
void readJSON(JSONValue &oValue, JSONSerializer &serializer)
Definition: ChannelReadWrite.h:295
#define MIRA_THROW(ex, msg)
Macro for throwing an exception.
Definition: Exception.h:82
Internally used by ChannelReadWriteBase! It contains the information about the channel and slot that ...
Definition: ChannelReadWrite.h:84
void finish()
Releases the lock explicitly and informs the Channel to signal all Subscribers that new data is avail...
Definition: ChannelReadWrite.h:713
Base::Shared Shared
Definition: ChannelReadWrite.h:605
void writeJSON(const JSONValue &value)
Definition: ChannelReadWrite.h:307
ChannelBuffer< void >::ValueType ValueType
Definition: ChannelReadWrite.h:806
const ValueType & internalValue() const
Returns a const reference on the data.
Definition: ChannelReadWrite.h:366
Const sibling_iterator for iterating over xml nodes that have the same parent (siblings) ...
Definition: XMLDom.h:671
Base::Slot Slot
Definition: ChannelReadWrite.h:338
Wrapper class for boost::posix_time::ptime for adding more functionality to it.
Definition: Time.h:416
ChannelReadWriteCommonBase< Derived > Base
Definition: ChannelReadWrite.h:333
const Buffer< uint8 > & readSerializedValue()
Definition: ChannelReadWrite.h:515
ValueType * operator->()
Returns a pointer on the data.
Definition: ChannelReadWrite.h:684
ValueType & internalValue()
Returns a reference on the data.
Definition: ChannelReadWrite.h:406
bool isValid() const
Returns true, if data was assigned to the ChannelRead or ChannelWrite and if this data is locked...
Definition: ChannelReadWrite.h:183
Definition: ChannelReadWrite.h:72
boost::shared_ptr< Shared > SharedPtr
Definition: ChannelReadWrite.h:153
ChannelWrite()
Default constructor that constructs a ChannelWrite object that is invalid at the beginning and contai...
Definition: ChannelReadWrite.h:622
Deserializer for serializing objects from JSON format.
Definition: JSONSerializer.h:400
ChannelReadWriteTraits< DerivedContainer >::Lock Lock
Definition: ChannelReadWrite.h:88
void writeJSON(JSONDeserializer &deserializer)
Definition: ChannelReadWrite.h:312
void writeXML(const XMLDom::const_iterator &node)
Definition: ChannelReadWrite.h:317
Base::Slot Slot
Definition: ChannelReadWrite.h:449
Shared::Slot Slot
Definition: ChannelReadWrite.h:158
Definition: AbstractChannel.h:70
Base::Slot Slot
Definition: ChannelReadWrite.h:388
const ValueType & operator*() const
Returns a const reference on the data.
Definition: ChannelReadWrite.h:489
ChannelRead()
Default constructor that constructs a ChannelRead object that is invalid at the beginning and contain...
Definition: ChannelReadWrite.h:463
ChannelReadWriteBase< ChannelWrite< T >, T > Base
Definition: ChannelReadWrite.h:602
bool empty() const
Checks if the buffer is empty (used size == 0).
Definition: Buffer.h:303
ValueType & operator*()
Returns a reference on the data.
Definition: ChannelReadWrite.h:651
TypeMetaPtr getTypeMeta() const
Definition: ChannelReadWrite.h:199
ChannelReadWriteShared< Derived > Shared
Definition: ChannelReadWrite.h:152
int getUseCount() const
Returns the number of shared instances for this data, may be useful for debugging purposes...
Definition: ChannelReadWrite.h:212
void writeXML(const XMLDom::const_iterator &node)
Definition: ChannelReadWrite.h:701
ChannelReadWriteBase< ChannelRead< T >, T > Base
Definition: ChannelReadWrite.h:444
const std::string & getChannelID()
Definition: ChannelReadWrite.h:190
Mix in for adding a time stamp, an optional frame id and an optional sequence id to data types like P...
Definition: Stamped.h:149
Shared::ChannelTypePtr ChannelTypePtr
Definition: ChannelReadWrite.h:157
boost::shared_ptr< TypeMeta > TypeMetaPtr
Definition: MetaSerializer.h:309
Definition: ChannelReadWrite.h:148
Buffer< uint8 > readSerializedValue(std::list< BinarySerializerCodecPtr > &codecs, uint8 formatVersion, bool orLower)
Definition: ChannelReadWrite.h:283
const Buffer< uint8 > & readSerializedValue()
Definition: ChannelReadWrite.h:255
void writeSerializedValue(Buffer< uint8 > data)
Definition: ChannelReadWrite.h:302
ChannelType * ChannelTypePtr
Definition: ChannelReadWrite.h:92
ChannelReadWriteTraits< DerivedContainer >::SlotType Slot
Definition: ChannelReadWrite.h:89
void checkValid() const
checks if we are still locked, if not it throws a XAccessViolation
Definition: ChannelReadWrite.h:241
ConcreteChannel< T > ChannelType
Definition: ChannelReadWrite.h:783
Container for storing a single data element in the linked list.
Definition: ChannelBuffer.h:166
Lock lock
a shared lock for that data in the channel's buffer
Definition: ChannelReadWrite.h:137
const ValueType * operator->() const
Returns a const pointer on the data.
Definition: ChannelReadWrite.h:510
static void discard(Shared *shared)
Definition: ChannelReadWrite.h:756
#define MIRA_LOG_EXCEPTION(level, ex)
Log the specified exception, including all information that the exception object carries.
Definition: LoggingAux.h:107
Channel< T > getChannel()
Returns a read-only channel proxy object of the underlying channel.
ChannelReadWriteCommonBase()
Constructs an empty (invalid) ChannelReadWriteBase object.
Definition: ChannelReadWrite.h:164
std::string getTypename() const
Definition: ChannelReadWrite.h:195
ChannelTypePtr channel
pointer to the channel our data/slot belongs to
Definition: ChannelReadWrite.h:128
ChannelReadWriteBase(ChannelTypePtr channel, Slot *slot)
Constructs a valid ChannelReadWriteBase object that is assigned to a channel and slot.
Definition: ChannelReadWrite.h:347
static Time now() static Time eternity()
Returns the current utc based time.
Definition: Time.h:479
ChannelWrite(ChannelTypePtr channel, Slot *slot)
Is called by Channel to construct a valid ChannelWrite object with the corresponding data...
Definition: ChannelReadWrite.h:630
ConcreteChannel< T > ChannelType
Definition: ChannelReadWrite.h:774
Base::ValueType ValueType
Definition: ChannelReadWrite.h:389
boost::shared_lock< boost::shared_mutex > Lock
Definition: ChannelReadWrite.h:798
void readJSON(JSONValue &oValue)
Definition: ChannelReadWrite.h:533
Shared::ValueType ValueType
Definition: ChannelReadWrite.h:159
SharedPtr shared
Definition: ChannelReadWrite.h:323
Base::ValueType ValueType
Definition: ChannelReadWrite.h:450
Base::Slot Slot
Definition: ChannelReadWrite.h:607
boost::unique_lock< boost::shared_mutex > Lock
Definition: ChannelReadWrite.h:807
void writeJSON(const JSONValue &value)
Definition: ChannelReadWrite.h:693
ChannelReadWriteBase(ChannelTypePtr channel, Slot *slot)
Constructs a valid ChannelReadWriteBase object that is assigned to a channel and slot.
Definition: ChannelReadWrite.h:397
ValueType & internalValue()
Returns a reference on the data.
Definition: ChannelReadWrite.h:356
Buffer< uint8 > readSerializedValue(std::list< BinarySerializerCodecPtr > &codecs)
Definition: ChannelReadWrite.h:523
void readJSON(JSONValue &oValue, JSONSerializer &serializer)
Definition: ChannelReadWrite.h:537
Base::ChannelTypePtr ChannelTypePtr
Definition: ChannelReadWrite.h:337
ChannelBuffer< void >::ValueType ValueType
Definition: ChannelReadWrite.h:797
Definition: LoggingCore.h:75
json::Value JSONValue
Imports the json::Value type into mira namespace.
Definition: JSON.h:363
Base class for all framework channels.
ChannelReadWriteTraits< DerivedContainer >::ValueType ValueType
Definition: ChannelReadWrite.h:90
ChannelReadWriteCommonBase(ChannelTypePtr channel, Slot *slot)
Constructs a valid ChannelReadWriteBase object that is assigned to a channel and slot.
Definition: ChannelReadWrite.h:167
Definition: ChannelReadWrite.h:329
Base::ValueType ValueType
Definition: ChannelReadWrite.h:608
Buffer< uint8 > readSerializedValue(std::list< BinarySerializerCodecPtr > &codecs, uint8 formatVersion, bool orLower)
Definition: ChannelReadWrite.h:527
Channel< T > getChannel()
Returns a write-only channel proxy object of the underlying channel.
Buffer< uint8 > readSerializedValue(std::list< BinarySerializerCodecPtr > &codecs)
Same as above, but allows to specify codecs for serialization.
Definition: ChannelReadWrite.h:278
ChannelRead(ChannelTypePtr channel, Slot *slot)
Is called by Channel to construct a ChannelRead object.
Definition: ChannelReadWrite.h:470
const Time & getTimestamp() const
Definition: ChannelReadWrite.h:203
static void finish(Shared *shared)
Definition: ChannelReadWrite.h:745
ChannelReadWriteTraits< DerivedContainer >::ChannelType ChannelType
Definition: ChannelReadWrite.h:87
const Buffer< uint8 > & readSerializedValue(uint8 formatVersion, bool orLower)
Definition: ChannelReadWrite.h:519