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);
323 template<
typename Derived,
typename T>
353 return this->
shared->slot->data;
363 return this->
shared->slot->data;
373 template<
typename Derived>
403 return this->
shared->channel->getBuffer()->getStampedHeader(this->
shared->slot);
413 return this->
shared->channel->getBuffer()->getStampedHeader(this->
shared->slot);
523 uint8 formatVersion,
bool orLower) {
562 if(
shared->lock.owns_lock())
739 if(
shared->lock.owns_lock()) {
750 if(
shared->lock.owns_lock()) {
768 typedef boost::shared_lock<boost::shared_mutex>
Lock;
777 typedef boost::unique_lock<boost::shared_mutex>
Lock;
789 typedef boost::shared_lock<boost::shared_mutex>
Lock;
798 typedef boost::unique_lock<boost::shared_mutex>
Lock;
static void finish(Shared *shared)
Definition: ChannelReadWrite.h:560
Serializer for serializing objects in JSON format.
Definition: JSONSerializer.h:93
AbstractChannel ChannelType
Definition: ChannelReadWrite.h:786
Base::Shared Shared
Definition: ChannelReadWrite.h:331
Base::ValueType ValueType
Definition: ChannelReadWrite.h:334
ChannelReadWriteBase()
Constructs an empty (invalid) ChannelReadWriteBase object.
Definition: ChannelReadWrite.h:339
Base::ChannelTypePtr ChannelTypePtr
Definition: ChannelReadWrite.h:382
Base::Shared Shared
Definition: ChannelReadWrite.h:381
void finish()
Releases the lock explicitly.
Definition: ChannelReadWrite.h:543
boost::shared_lock< boost::shared_mutex > Lock
Definition: ChannelReadWrite.h:768
~ChannelReadWriteShared()
Definition: ChannelReadWrite.h:100
void discard()
Releases the lock explicitly WITHOUT informing the Channel and without signaling the subscribers...
Definition: ChannelReadWrite.h:718
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:378
ChannelBuffer< T >::ValueType ValueType
Definition: ChannelReadWrite.h:776
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:787
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:601
static void discard(Shared *shared)
Definition: ChannelReadWrite.h:566
const ValueType & internalValue() const
Returns a const reference on the data.
Definition: ChannelReadWrite.h:411
An object that allows exclusive write access to data of a channel.
Definition: ChannelReadWrite.h:594
const ValueType & operator=(const ValueType &value)
Definition: ChannelReadWrite.h:654
#define MIRA_LOG(level)
Use this macro to log data.
Definition: LoggingCore.h:528
Base::ChannelTypePtr ChannelTypePtr
Definition: ChannelReadWrite.h:443
ChannelBuffer< T >::Slot SlotType
Definition: ChannelReadWrite.h:775
ChannelBuffer< T >::Slot SlotType
Definition: ChannelReadWrite.h:766
ChannelBuffer< T >::ValueType ValueType
Definition: ChannelReadWrite.h:767
Base::Shared Shared
Definition: ChannelReadWrite.h:442
ChannelReadWriteShared(ChannelTypePtr iChannel, Slot *iSlot)
Definition: ChannelReadWrite.h:97
AbstractChannel ChannelType
Definition: ChannelReadWrite.h:795
ChannelBuffer< void >::Slot SlotType
Definition: ChannelReadWrite.h:796
void addFlags(uint32 moreFlags) const
For internal use only.
Definition: ChannelReadWrite.h:233
boost::unique_lock< boost::shared_mutex > Lock
Definition: ChannelReadWrite.h:777
void writeSerializedValue(Buffer< uint8 > data)
Definition: ChannelReadWrite.h:684
Definition: ChannelReadWrite.h:65
ChannelReadWriteBase()
Constructs an empty (invalid) ChannelReadWriteBase object.
Definition: ChannelReadWrite.h:389
void writeJSON(JSONDeserializer &deserializer)
Definition: ChannelReadWrite.h:692
An object that allows read access to data of a channel.
Definition: ChannelReadWrite.h:435
void readJSON(JSONValue &oValue, JSONSerializer &serializer)
Definition: ChannelReadWrite.h:295
#define MIRA_THROW(ex, msg)
Macro for throwing an exception.
Definition: Exception.h:81
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:704
Base::Shared Shared
Definition: ChannelReadWrite.h:600
void writeJSON(const JSONValue &value)
Definition: ChannelReadWrite.h:307
ChannelBuffer< void >::ValueType ValueType
Definition: ChannelReadWrite.h:797
const ValueType & internalValue() const
Returns a const reference on the data.
Definition: ChannelReadWrite.h:361
Base::Slot Slot
Definition: ChannelReadWrite.h:333
Wrapper class for boost::posix_time::ptime for adding more functionality to it.
Definition: Time.h:421
ChannelReadWriteCommonBase< Derived > Base
Definition: ChannelReadWrite.h:328
const Buffer< uint8 > & readSerializedValue()
Definition: ChannelReadWrite.h:510
ValueType * operator->()
Returns a pointer on the data.
Definition: ChannelReadWrite.h:679
ValueType & internalValue()
Returns a reference on the data.
Definition: ChannelReadWrite.h:401
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:617
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
Base::Slot Slot
Definition: ChannelReadWrite.h:444
Shared::Slot Slot
Definition: ChannelReadWrite.h:158
Definition: AbstractChannel.h:70
Base::Slot Slot
Definition: ChannelReadWrite.h:383
const ValueType & operator*() const
Returns a const reference on the data.
Definition: ChannelReadWrite.h:484
ChannelRead()
Default constructor that constructs a ChannelRead object that is invalid at the beginning and contain...
Definition: ChannelReadWrite.h:458
ChannelReadWriteBase< ChannelWrite< T >, T > Base
Definition: ChannelReadWrite.h:597
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:646
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
ChannelReadWriteBase< ChannelRead< T >, T > Base
Definition: ChannelReadWrite.h:439
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:774
Container for storing a single data element in the linked list.
Definition: ChannelBuffer.h:165
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:505
static void discard(Shared *shared)
Definition: ChannelReadWrite.h:747
#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:342
static Time now() static Time eternity()
Returns the current utc based time.
Definition: Time.h:484
ChannelWrite(ChannelTypePtr channel, Slot *slot)
Is called by Channel to construct a valid ChannelWrite object with the corresponding data...
Definition: ChannelReadWrite.h:625
ConcreteChannel< T > ChannelType
Definition: ChannelReadWrite.h:765
Base::ValueType ValueType
Definition: ChannelReadWrite.h:384
boost::shared_lock< boost::shared_mutex > Lock
Definition: ChannelReadWrite.h:789
void readJSON(JSONValue &oValue)
Definition: ChannelReadWrite.h:528
Shared::ValueType ValueType
Definition: ChannelReadWrite.h:159
SharedPtr shared
Definition: ChannelReadWrite.h:318
Base::ValueType ValueType
Definition: ChannelReadWrite.h:445
Base::Slot Slot
Definition: ChannelReadWrite.h:602
boost::unique_lock< boost::shared_mutex > Lock
Definition: ChannelReadWrite.h:798
void writeJSON(const JSONValue &value)
Definition: ChannelReadWrite.h:688
ChannelReadWriteBase(ChannelTypePtr channel, Slot *slot)
Constructs a valid ChannelReadWriteBase object that is assigned to a channel and slot.
Definition: ChannelReadWrite.h:392
ValueType & internalValue()
Returns a reference on the data.
Definition: ChannelReadWrite.h:351
Buffer< uint8 > readSerializedValue(std::list< BinarySerializerCodecPtr > &codecs)
Definition: ChannelReadWrite.h:518
void readJSON(JSONValue &oValue, JSONSerializer &serializer)
Definition: ChannelReadWrite.h:532
Base::ChannelTypePtr ChannelTypePtr
Definition: ChannelReadWrite.h:332
ChannelBuffer< void >::ValueType ValueType
Definition: ChannelReadWrite.h:788
Definition: LoggingCore.h:74
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:324
Base::ValueType ValueType
Definition: ChannelReadWrite.h:603
Buffer< uint8 > readSerializedValue(std::list< BinarySerializerCodecPtr > &codecs, uint8 formatVersion, bool orLower)
Definition: ChannelReadWrite.h:522
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:465
const Time & getTimestamp() const
Definition: ChannelReadWrite.h:203
static void finish(Shared *shared)
Definition: ChannelReadWrite.h:736
ChannelReadWriteTraits< DerivedContainer >::ChannelType ChannelType
Definition: ChannelReadWrite.h:87
const Buffer< uint8 > & readSerializedValue(uint8 formatVersion, bool orLower)
Definition: ChannelReadWrite.h:514