MIRA
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ChannelBuffer.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 by
3  * MetraLabs GmbH (MLAB), GERMANY
4  * and
5  * Neuroinformatics and Cognitive Robotics Labs (NICR) at TU Ilmenau, GERMANY
6  * All rights reserved.
7  *
8  * Contact: info@mira-project.org
9  *
10  * Commercial Usage:
11  * Licensees holding valid commercial licenses may use this file in
12  * accordance with the commercial license agreement provided with the
13  * software or, alternatively, in accordance with the terms contained in
14  * a written agreement between you and MLAB or NICR.
15  *
16  * GNU General Public License Usage:
17  * Alternatively, this file may be used under the terms of the GNU
18  * General Public License version 3.0 as published by the Free Software
19  * Foundation and appearing in the file LICENSE.GPL3 included in the
20  * packaging of this file. Please review the following information to
21  * ensure the GNU General Public License version 3.0 requirements will be
22  * met: http://www.gnu.org/copyleft/gpl.html.
23  * Alternatively you may (at your option) use any later version of the GNU
24  * General Public License if such license has been publicly approved by
25  * MLAB and NICR (or its successors, if any).
26  *
27  * IN NO EVENT SHALL "MLAB" OR "NICR" BE LIABLE TO ANY PARTY FOR DIRECT,
28  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
29  * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLAB" OR
30  * "NICR" HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * "MLAB" AND "NICR" SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
33  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
34  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
35  * ON AN "AS IS" BASIS, AND "MLAB" AND "NICR" HAVE NO OBLIGATION TO
36  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
37  */
38 
47 #ifndef _MIRA_CHANNELBUFFER_H_
48 #define _MIRA_CHANNELBUFFER_H_
49 
50 #include <string>
51 #include <list>
52 #include <type_traits>
53 
54 #ifndef Q_MOC_RUN
55 #include <boost/noncopyable.hpp>
56 #include <boost/thread/mutex.hpp>
57 #include <boost/thread/shared_mutex.hpp>
58 #endif
59 
60 #include <error/LoggingCore.h>
61 
62 #include <factory/TypeId.h>
63 
67 
68 #include <utils/Time.h>
69 #include <utils/Stamped.h>
70 #include <platform/Typename.h>
71 
72 #include <math/Eigen.h>
73 
74 #include <fw/FrameworkExports.h>
75 
76 namespace mira {
77 
79 
81 template <typename TargetType>
83 
85 template <typename TargetType>
87 
89 
95 {
98 
101 
104 };
105 
111 {
116 };
117 
119 
133 class MIRA_FRAMEWORK_EXPORT ChannelBufferBase : boost::noncopyable
134 {
135  template <typename TargetType>
137 
138  template <typename TargetType>
139  friend struct ChannelBufferPromoter;
140 
141 public:
142 
144  struct Slot;
145 
149  struct ListItem : boost::noncopyable
150  {
152  // creates empty list
153  next = (Slot*)this;
154  prev = (Slot*)this;
155  }
156 
157  // both will be locked by mutex in ChannelBuffer
160  };
161 
165  struct Slot : public ListItem
166  {
167  boost::shared_mutex lock; // locks the following data
168 
174  boost::mutex serializedValueLock;
175 
180 
186 
193  uint32 flags;
194 
195  const Time& timestamp() const {
196  assert(timestampPtr!=NULL); // pointer is set in ChannelBuffers allocateSlot
197  return *timestampPtr;
198  }
199  };
200 
201 public:
202 
209  mStorageDuration(Duration::seconds(0)),
210  mAutoIncreaseStorageDuration(true),
211  mMinSlots(0),
212  mMaxSlots(100),
213  mSize(0)
214  {
215  }
216 
217  virtual ~ChannelBufferBase();
218 
219 public:
220 
225  {
226  mMinSlots = other.mMinSlots;
227  mMaxSlots = other.mMaxSlots;
228  mStorageDuration = other.mStorageDuration;
229  mAutoIncreaseStorageDuration = other.mAutoIncreaseStorageDuration;
230  }
231 
232 public:
233 
242  void setStorageDuration(const Duration& storageDuration);
243 
244 
252  void setAutoIncreaseStorageDuration(bool increase);
253 
263  void setMinSlots(std::size_t minSlots);
264 
265 
275  void setMaxSlots(std::size_t maxSlots);
276 
277 public:
278 
280  std::size_t getSize() const;
281 
283  std::size_t getMaxSlots() const;
284 
286  std::size_t getMinSlots() const;
287 
289  Duration getStorageDuration() const;
290 
292  bool isAutoIncreasingStorageDuration() const;
293 
294 
295 public:
296 
298  virtual int getTypeId() const = 0;
299 
301  virtual bool isTyped() const = 0;
302 
304  virtual bool isPolymorphic() const = 0;
305 
311  virtual Typename getTypename() const = 0;
312 
316  virtual void setTypename(const Typename& name) = 0;
317 
322  virtual TypeMetaPtr createTypeMeta(Slot* s, MetaTypeDatabase& ioDB) = 0;
323 
327  TypeMetaPtr getTypeMeta() const { return mTypeMeta; }
328 
332  void setTypeMeta(TypeMetaPtr meta) { mTypeMeta = meta; }
333 
341  virtual void fixateType() = 0;
342 
344  virtual Slot* allocateSlot() = 0;
345 
347  virtual void freeSlot(Slot* s) = 0;
348 
352  virtual StampedHeader& getStampedHeader(Slot* s) = 0;
353 
358  virtual const Buffer<uint8>& readSerializedValue(Slot* s) = 0;
359 
366  virtual const Buffer<uint8>& readSerializedValue(Slot* s,
367  uint8 formatVersion, bool orLower) = 0;
368 
374  virtual Buffer<uint8> readSerializedValue(Slot* s,
375  std::list<BinarySerializerCodecPtr>& codecs) = 0;
376 
384  virtual Buffer<uint8> readSerializedValue(Slot* s,
385  std::list<BinarySerializerCodecPtr>& codecs,
386  uint8 formatVersion, bool orLower) = 0;
387 
392  virtual void writeSerializedValue(Slot* s, Buffer<uint8> data) = 0;
393 
401  virtual void readJSON(Slot* s, JSONValue& oValue) = 0;
402 
409  virtual void readJSON(Slot* s, JSONValue& oValue, JSONSerializer& serializer) = 0;
410 
418  virtual void writeJSON(Slot* s, const JSONValue& value) = 0;
419 
426  virtual void writeJSON(Slot* s, JSONDeserializer& value) = 0;
427 
428 public:
429 
431  // write access
432 
455  Slot* requestWriteSlot();
456 
465  bool finishWriteSlot(Slot* n, bool* dropped=NULL);
466 
471  void discardWriteSlot(Slot* n);
472 
473 
475  // read access
476 
482  Slot* readNewestSlot();
483 
490  Slot* readSlotAtTime(const Time& timestamp, SlotQueryMode mode);
491 
496  void readInterval(const Time& timestamp, std::size_t nrSlots,
497  std::size_t olderSlots, std::size_t newerSlots,
498  IntervalFillMode fillMode, std::list<Slot*>& oSlots);
499 
504  void readInterval(const Time& from, const Time& to, std::list<Slot*>& oSlots);
505 
506 public:
507 
516  template<typename TargetType>
517  ChannelBufferBase* promote();
518 
519 private:
520 
526  Slot* findFirstOlderSlot(const Time& timestamp, Slot* start=NULL);
527 
528 private:
529 
534  void splice(Slot* first, Slot* last, Slot* position) const;
535 
540  void splice(Slot* item, Slot* position) const {
541  splice(item,item,position);
542  }
543 
544  static bool isEmpty(const ListItem& list) { return list.next == &list; }
545  static Slot* begin(ListItem& list) { return list.next; }
546  static Slot* last(ListItem& list) { return list.prev; }
547  static Slot* end(ListItem& list) { return (Slot*)&list; }
548 
550  void deleteSlots(ListItem& list);
551 
552 protected:
553 
555  void clear();
556 
557 private:
558 
563  void resetSlot(Slot* s);
564 
565  // parameters:
566  Duration mStorageDuration;
567  bool mAutoIncreaseStorageDuration;
568  std::size_t mMinSlots;
569  std::size_t mMaxSlots;
570 
571 
572  // mutex that locks all actions when we change our lists
573  mutable boost::mutex mMutex;
574 
575  std::size_t mSize; // current number of slots we are using
576 
577  ListItem mBuffer;
578 
591  ListItem mWaitingOrFree;
592 
596  ListItem mWriting;
597 
598  TypeMetaPtr mTypeMeta;
599 
600 private:
601 
602  std::string dbgDumpList(ListItem& list, bool brief);
603 
604 public:
605 
606  void dbgDump(const std::string& prefix, bool brief=true);
607 
608  static void dbgCheckListIntegrity(const ListItem& list);
609  void dbgCheckIntegrity();
610 };
611 
613 
617 template <typename T>
619 {
620 public:
621 
623 
624 public:
625 
626  virtual ~TypedChannelBufferBase() { this->clear(); }
627 
628 public:
629 
631  struct Slot : public ChannelBufferBase::Slot {
634  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
635  };
636 
637 public:
638 
643  {
644  // cast abstract ChannelBufferBase::Slot to TypedChannelBufferBase<T>::Slot.
645  // this is safe since all slots were created by us in allocateSlot()
646  // as TypedChannelBufferBase<T>::Slots
647  return static_cast<Slot*>(s);
648  }
649 
650 public:
655  virtual int getTypeId() const { return typeId<T>(); }
656  virtual bool isTyped() const { return true; }
657  virtual bool isPolymorphic() const {return false; }
658  virtual Typename getTypename() const { return typeName<T>(); }
659  virtual void setTypename(const Typename& name) {
660  MIRA_THROW(XRuntime, "Cannot set Typename for typed channels");
661  }
663  MetaSerializer ms(ioDB);
664  Slot* slot = castSlot(s);
665  TypeMetaPtr meta = ms.addMeta(slot->data.internalValueRep());
666  return meta;
667  }
668 
669  virtual void fixateType() {} // doesn't do anything
671  Slot* slot = new Slot;
672  slot->timestampPtr = &slot->data.timestamp; // "connect" the timestamp ptr
673  return slot;
674  }
676  // casting s to our slot type ensures that the correct destructor is called
677  Slot* slot = castSlot(s);
678  delete slot;
679  }
680 
681 public:
682 
684  // we can safely cast here, since s is an object of our Slot type
685  Slot* slot = static_cast<Slot*>(s);
686  return stampedHeader(slot->data);
687  }
688 
690  {
691  // lock the serialization mutex to protect serializedValueLock
692  // (we or someone else may write it here)
693  boost::mutex::scoped_lock lock(s->serializedValueLock);
694 
695  // no serialized data yet, so serialize it now (lazy evaluation)
696  if(s->serializedValue.empty()) {
697  // we can safely cast here, since s is an object of our Slot type
698  Slot* slot = static_cast<Slot*>(s);
699 
700  // serialize the data
702  bs.serialize(slot->data.internalValueRep(), false);
703  }
704 
705  return s->serializedValue;
706  }
707 
708 
710  uint8 formatVersion, bool orLower)
711  {
712  uint8 serializerVersion = BinaryBufferSerializer::getSerializerFormatVersion();
713 
714  if (formatVersion == serializerVersion)
715  return readSerializedValue(s);
716 
717  if (formatVersion == 0) {
718  // lock the serialization mutex to protect serializedValueLock
719  // (we or someone else may write it here)
720  boost::mutex::scoped_lock lock(s->serializedValueLock);
721 
722  // no serialized data yet, so serialize it now (lazy evaluation)
723  if(s->serializedValue.empty()) {
724  // we can safely cast here, since s is an object of our Slot type
725  Slot* slot = static_cast<Slot*>(s);
726 
727  // serialize the data
729  bs.serialize(slot->data.internalValueRep(), false);
730  }
731 
732  return s->serializedValue;
733  }
734 
735  MIRA_THROW(XIO, "Requested serialized data of binary format version " << (int)formatVersion
736  << ". Only implemented for versions 0, " << (int)serializerVersion << ".");
737  }
738 
740  std::list<BinarySerializerCodecPtr>& codecs)
741  {
742  Buffer<uint8> serializedValue;
743 
744  // we can safely cast here, since s is an object of our Slot type
745  Slot* slot = static_cast<Slot*>(s);
746 
747  BinaryBufferSerializer bs(&serializedValue);
748 
749  // register codecs
750  foreach(BinarySerializerCodecPtr codec, codecs)
751  bs.registerCodec(codec);
752 
753  // serialize the data
754  bs.serialize(slot->data.internalValueRep(),false);
755 
756  return std::move(serializedValue);
757  }
758 
760  std::list<BinarySerializerCodecPtr>& codecs,
761  uint8 formatVersion, bool orLower)
762  {
763  uint8 serializerVersion = BinaryBufferSerializer::getSerializerFormatVersion();
764 
765  if (formatVersion == serializerVersion)
766  return readSerializedValue(s, codecs);
767 
768  if (formatVersion == 0) {
769  Buffer<uint8> serializedValue;
770 
771  // we can safely cast here, since s is an object of our Slot type
772  Slot* slot = static_cast<Slot*>(s);
773 
774  BinaryBufferSerializerLegacy bs(&serializedValue);
775 
776  // register codecs
777  foreach(BinarySerializerCodecPtr codec, codecs)
778  bs.registerCodec(codec);
779 
780  // serialize the data
781  bs.serialize(slot->data.internalValueRep(),false);
782 
783  return std::move(serializedValue);
784  }
785 
786  MIRA_THROW(XIO, "Requested serialized data of binary format version " << (int)formatVersion
787  << ". Only implemented for versions 0, " << (int)serializerVersion << ".");
788  }
789 
791  {
792  s->serializedValue = std::move(data);
793 
794  // we can safely cast here, since s is an object of our Slot type
795  Slot* slot = static_cast<Slot*>(s);
796 
797  // deserialize into our data
799 
800  {
801  boost::mutex::scoped_lock lock(mCodecsMutex);
802  bs.setCodecs(mCodecs);
803  }
804  bs.deserialize(slot->data.internalValueRep(), false);
805  {
806  boost::mutex::scoped_lock lock(mCodecsMutex);
807  mCodecs = bs.getCodecs();
808  }
809  }
810 
811  virtual void readJSON(ChannelBufferBase::Slot* s, JSONValue& oValue)
812  {
813  // we can safely cast here, since s is an object of our Slot type
814  Slot* slot = static_cast<Slot*>(s);
815 
816  JSONSerializer json;
817  oValue = json.serialize(slot->data.internalValueRep());
818  }
819 
820  virtual void readJSON(ChannelBufferBase::Slot* s, JSONValue& oValue,
821  JSONSerializer& serializer)
822  {
823  // we can safely cast here, since s is an object of our Slot type
824  Slot* slot = static_cast<Slot*>(s);
825 
826  oValue = serializer.serialize(slot->data.internalValueRep());
827  }
828 
829  virtual void writeJSON(ChannelBufferBase::Slot* s, const JSONValue& value)
830  {
831  // we can safely cast here, since s is an object of our Slot type
832  Slot* slot = static_cast<Slot*>(s);
833 
834  JSONDeserializer json(value);
835  json.deserialize(slot->data.internalValueRep());
836  }
837 
838  virtual void writeJSON(ChannelBufferBase::Slot* s, JSONDeserializer& deserializer)
839  {
840  // we can safely cast here, since s is an object of our Slot type
841  Slot* slot = static_cast<Slot*>(s);
842 
843  deserializer.deserialize(slot->data.internalValueRep());
844  }
846 
847 private:
848 
850  boost::mutex mCodecsMutex;
851 };
852 
853 
855 
859 template <typename T>
861 {};
862 
864 
869 template <>
871 {
872 public:
873 
875 
876 public:
877 
879  struct Slot : public ChannelBufferBase::Slot {
881  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
882  };
883 
884 public:
885 
890  {
891  // cast abstract ChannelBufferBase::Slot to TypedChannelBufferBase<T>::Slot.
892  // this is safe since all slots were created by us in allocateSlot()
893  // as TypedChannelBufferBase<T>::Slots
894  return static_cast<Slot*>(s);
895  }
896 
897 public:
898 
899  ChannelBuffer() : mTypename("") {}
900 
901  virtual ~ChannelBuffer() { this->clear(); }
902 
903 
904 public:
909  virtual int getTypeId() const { return -1; }
910  virtual bool isTyped() const { return false; }
911  virtual bool isPolymorphic() const {return false; }
912  virtual Typename getTypename() const { return mTypename; }
913  virtual void setTypename(const Typename& name);
915  MIRA_THROW(XRuntime, "Cannot create type meta for untyped channels");
916  // keep compiler happy
917  return TypeMetaPtr();
918  }
919  virtual void fixateType() {} // doesn't do anything
920 
922  Slot* slot = new Slot;
923  slot->timestampPtr = &slot->header.timestamp; // "connect" the timestamp ptr
924  return slot;
925  }
926 
928  // casting s to our slot type ensures that the correct destructor is called
929  Slot* slot = castSlot(s);
930  delete slot;
931  }
932 
933 public:
934 
936  // casting here is not safe, if we actually are a typed buffer,
937  // however, if we are, then the TypedChannelBuffer::getStampedHeader()
938  // of that class would have been called instead of us.
939  Slot* slot = static_cast<Slot*>(s);
940  return slot->header;
941  }
942 
944  {
945  return s->serializedValue;
946  }
947 
949  uint8 formatVersion, bool orLower)
950  {
951  BinaryBufferIstream stream(&(s->serializedValue));
952  uint8 dataVersion = BinaryBufferDeserializer::getDataFormatVersion(stream);
953  if ((!orLower && (dataVersion != formatVersion)) || (dataVersion > formatVersion)) {
954  MIRA_THROW(XIO, "Untyped channel contains serialized data of version " << (int)dataVersion
955  << ", cannot return data of version " << (int)formatVersion << ".");
956  }
957 
958  return readSerializedValue(s);
959  }
960 
961 
963  std::list<BinarySerializerCodecPtr>& codecs)
964  {
965  // we must ignore the codecs
966  return s->serializedValue;
967  }
968 
970  std::list<BinarySerializerCodecPtr>& codecs,
971  uint8 formatVersion, bool orLower)
972  {
973  // we must ignore the codecs
974  return readSerializedValue(s, formatVersion, orLower);
975  }
976 
978  {
979  s->serializedValue = std::move(data);
980  }
981 
982  virtual void readJSON(ChannelBufferBase::Slot* s, JSONValue& oValue);
983  virtual void readJSON(ChannelBufferBase::Slot* s, JSONValue& oValue, JSONSerializer& serializer);
984 
985  virtual void writeJSON(ChannelBufferBase::Slot* s, const JSONValue& value);
986  virtual void writeJSON(ChannelBufferBase::Slot* s, JSONDeserializer& deserializer);
988 
989 private:
990 
991  Typename mTypename;
992 };
993 
995 
1000 {
1002 
1003 public:
1004 
1007  mMostDerivedClass(NULL),
1008  mFixatedClass(NULL) {}
1009 
1010 public:
1015  virtual bool isPolymorphic() const {return true; }
1016 
1017  virtual int getTypeId() const;
1018 
1019  virtual Typename getTypename() const;
1020 
1021  virtual ChannelBufferBase::Slot* allocateSlot();
1022 
1023  virtual void freeSlot(ChannelBufferBase::Slot* s);
1024 
1025  virtual void fixateType();
1026 
1027  virtual void writeSerializedValue(ChannelBufferBase::Slot* s, Buffer<uint8> data);
1029 
1031  void promote(const Class* promotionClass);
1032 
1033 protected:
1034 
1037 };
1038 
1039 #ifndef MIRA_WINDOWS
1040 // declare template extern to speed up compilation time by several seconds
1041 extern template class TypedChannelBufferBase<Object*>;
1042 #endif
1043 
1045 
1050 template <typename T>
1052 {
1053  static_assert(std::is_base_of<mira::Object,T>::value,
1054  "In channels you can only use pointers of polymorphic "
1055  "classes that are derived from mira::Object. Pointers to "
1056  "other classes cannot be stored in a channel.");
1057 public:
1058  typedef Stamped<T*> ValueType;
1059 
1060 public:
1062  mMostDerivedClass = &T::CLASS();
1063  }
1064 };
1065 
1067 // Channel buffer promotion code
1068 
1075 template <typename U>
1076 struct ChannelBufferPromoterCommon
1077 {
1079  {
1080  assert(!buffer->isTyped() &&
1081  "Can promote untyped channels to typed channels only");
1082 
1083  if(!buffer->getTypename().empty() && buffer->getTypename()!=typeName<U>())
1084  MIRA_THROW(XBadCast, "Invalid promotion from untyped to typed "
1085  "ChannelBuffer. Typename does not match. ('" <<
1086  buffer->getTypename() << "' != '" << typeName<U>() << "'");
1087 
1088  typedef ChannelBufferBase::Slot Slot;
1089 
1090  // create a new typed buffer
1091  ChannelBuffer<U>* typedBuffer = new ChannelBuffer<U>;
1092 
1093  // copy all parameters
1094  typedBuffer->cloneParameters(*buffer);
1095 
1096  // copy all the serialized data from the untyped buffer into the
1097  // typed buffer and deserialize it into the value
1098 
1099  // now lock the whole buffer for reading ...
1100  for(Slot* s=ChannelBufferBase::begin(buffer->mBuffer);
1101  s!=ChannelBufferBase::end(buffer->mBuffer); s=s->next)
1102  s->lock.lock_shared();
1103 
1104  // ... and deserialize the content of each slot into the new buffer
1105  for(Slot* s=ChannelBufferBase::begin(buffer->mBuffer);
1106  s!=ChannelBufferBase::end(buffer->mBuffer); s=s->next)
1107  {
1108  Slot* n = typedBuffer->requestWriteSlot(); // obtain a new slot
1109 
1110  // ... copy the headers
1111  typedBuffer->getStampedHeader(n) = buffer->getStampedHeader(s);
1112 
1113  // ... and write the value into the new slot (this will deserialize the data there)
1114  typedBuffer->writeSerializedValue(n, s->serializedValue);
1115 
1116  typedBuffer->finishWriteSlot(n);
1117  }
1118 
1119  // free the read lock from above ...
1120  for(Slot* s=ChannelBufferBase::begin(buffer->mBuffer);
1121  s!=ChannelBufferBase::end(buffer->mBuffer); s=s->next)
1122  s->lock.unlock_shared();
1123 
1124  return typedBuffer;
1125  }
1126 };
1127 
1129 
1140 template <typename U>
1141 struct ChannelBufferPromoter : public ChannelBufferPromoterCommon<U>
1142 {
1145  {
1146  if(buffer->isTyped())
1147  return buffer; // we are promoted already, do nothing
1148  return Base::promoteUntyped(buffer);
1149  }
1150 };
1151 
1153 
1158 template <typename U>
1160 {
1163  {
1164  // if untyped, promote to typed first
1165  if(!buffer->isTyped())
1166  buffer = Base::promoteUntyped(buffer);
1167 
1168  PolymorphicChannelBuffer* polymorphicBuffer = dynamic_cast<PolymorphicChannelBuffer*>(buffer);
1169 
1170  assert(polymorphicBuffer!=NULL &&
1171  "We should never reach here if the buffer to promote is not "
1172  "polymorphic");
1173 
1174  // get class of U
1175  const Class* classU = &U::CLASS();
1176 
1177  // promote us (this will do error checking and might throw XBadCast)
1178  polymorphicBuffer->promote(classU);
1179 
1180  return polymorphicBuffer;
1181  }
1182 };
1183 
1185 
1186 template<typename U>
1188 {
1189  return ChannelBufferPromoter<U>::promote(this);
1190 }
1191 
1193 
1194 }
1195 
1196 #endif
Serializer for serializing objects in JSON format.
Definition: JSONSerializer.h:93
virtual void writeJSON(ChannelBufferBase::Slot *s, const JSONValue &value)
Writes data in json representation into the slot, using a default-instantiated JSONDeserializer.
Definition: ChannelBuffer.h:829
virtual void freeSlot(ChannelBufferBase::Slot *s)
Called to destroy the slot and free the used memory.
Definition: ChannelBuffer.h:675
Database that stores all meta type information and provides additional functions for accessing the da...
Definition: MetaSerializer.h:509
void deserialize(T &value)
Definition: JSONSerializer.h:414
boost::shared_mutex lock
Definition: ChannelBuffer.h:167
static ChannelBufferBase * promote(ChannelBufferBase *buffer)
Definition: ChannelBuffer.h:1162
Definition: BinarySerializer.h:324
const Time * timestampPtr
Pointer to the actual timestamp in the slot data for easy access.
Definition: ChannelBuffer.h:179
const Class * mFixatedClass
Definition: ChannelBuffer.h:1036
virtual TypeMetaPtr createTypeMeta(ChannelBufferBase::Slot *s, MetaTypeDatabase &ioDB)
Creates meta information for data in slot and stores all meta information in the given database...
Definition: ChannelBuffer.h:914
boost::mutex serializedValueLock
Lock for writing serializedValue in readSerializedData.
Definition: ChannelBuffer.h:174
const Class * mMostDerivedClass
Definition: ChannelBuffer.h:1035
Include file for all eigen related things.
static Slot * castSlot(ChannelBufferBase::Slot *s)
Cast an abstract slot to a typed slot.
Definition: ChannelBuffer.h:889
virtual ~ChannelBuffer()
Definition: ChannelBuffer.h:901
Typed slot derived from ChannelBufferBase::Slot.
Definition: ChannelBuffer.h:631
void promote(const Class *promotionClass)
Promotes the polymorphic type of the channel to the given class type.
The first slot with timestamp &lt; requested will be chosen.
Definition: ChannelBuffer.h:97
static Slot * castSlot(ChannelBufferBase::Slot *s)
Cast an abstract slot to a typed slot.
Definition: ChannelBuffer.h:642
virtual void writeSerializedValue(ChannelBufferBase::Slot *s, Buffer< uint8 > data)
Write the given buffer (that contains binary serialized data WITHOUT the StampedHeader) to the slot...
Definition: ChannelBuffer.h:977
virtual Buffer< uint8 > readSerializedValue(ChannelBufferBase::Slot *s, std::list< BinarySerializerCodecPtr > &codecs, uint8 formatVersion, bool orLower)
Returns a buffer containing the binary serialized data of the slot.
Definition: ChannelBuffer.h:759
std::string Typename
Definition: Typename.h:59
virtual ChannelBufferBase::Slot * allocateSlot()
Creates and returns a new slot.
Definition: ChannelBuffer.h:670
Specialization for polymorphic types (only classes derived from mira::Object are supported!) ...
Definition: ChannelBuffer.h:1051
ValueType header
Definition: ChannelBuffer.h:880
Time and Duration wrapper class.
Class object which supports some kind of class reflection.
Definition: Class.h:97
ListItem()
Definition: ChannelBuffer.h:151
Stamped class specialization for polymorphic pointers.
Definition: Stamped.h:238
StampedHeader & stampedHeader(Stamped< T > &data)
Helper to extract the header from stamped data.
Definition: Stamped.h:482
ChannelBufferBase * promote()
Promotes this buffer to the specified target type (if required).
Definition: ChannelBuffer.h:1187
Base class for typed channel buffers.
Definition: ChannelBuffer.h:618
virtual void fixateType()
Calling this method will fix the type of the ChannelBuffer.
Definition: ChannelBuffer.h:669
static ChannelBufferBase * promoteUntyped(ChannelBufferBase *buffer)
Definition: ChannelBuffer.h:1078
virtual int getTypeId() const
Returns typeid of the slot values, the allocator creates.
Definition: ChannelBuffer.h:909
Get compiler and platform independent typenames.
bool empty() const
Checks if the buffer is empty (used size == 0).
Definition: Buffer.h:303
Framework export macro declaration.
void serialize(const std::string &name, const T &value, const std::string &comment="")
Serializes the specified object value under the given name.
Definition: Serializer.h:204
#define MIRA_THROW(ex, msg)
Macro for throwing an exception.
Definition: Exception.h:91
void serialize(const T &value, bool enableTypeCheck=true)
Provides a special serialize interface for the BinarySerializer.
Definition: BinarySerializer.h:598
virtual Typename getTypename() const
Returns the Typename of the slot values, in contrast to getTypeId() the Typename is portable and uniq...
Definition: ChannelBuffer.h:912
virtual bool isTyped() const
Returns true, if the channel is typed and false, if it is untyped.
Definition: ChannelBuffer.h:656
TypeMetaPtr getTypeMeta() const
Returns the meta information for the slots type.
Definition: ChannelBuffer.h:327
Implements double-linked list item.
Definition: ChannelBuffer.h:149
virtual StampedHeader & getStampedHeader(ChannelBufferBase::Slot *s)
Returns a reference to the stamped header information.
Definition: ChannelBuffer.h:935
Wrapper class for boost::posix_time::ptime for adding more functionality to it.
Definition: Time.h:421
Slot * requestWriteSlot()
Returns a slot for writing, where the shared_mutex is already write locked.
virtual bool isPolymorphic() const
Returns true if the channel has a polymorphic type.
Definition: ChannelBuffer.h:657
ChannelBufferPromoterCommon< U > Base
Definition: ChannelBuffer.h:1161
virtual const Buffer< uint8 > & readSerializedValue(ChannelBufferBase::Slot *s, uint8 formatVersion, bool orLower)
Returns a buffer containing the binary serialized data of the slot.
Definition: ChannelBuffer.h:709
ChannelBuffer()
Definition: ChannelBuffer.h:1061
A channel buffer for polymorphic types (classes derived from mira::Object)
Definition: ChannelBuffer.h:999
Deserializer for serializing objects from JSON format.
Definition: JSONSerializer.h:387
virtual ~TypedChannelBufferBase()
Definition: ChannelBuffer.h:626
virtual bool isTyped() const
Returns true, if the channel is typed and false, if it is untyped.
Definition: ChannelBuffer.h:910
void setTypeMeta(TypeMetaPtr meta)
Sets the meta information of the slot&#39;s type.
Definition: ChannelBuffer.h:332
virtual bool isPolymorphic() const
Returns true if the channel has a polymorphic type.
Definition: ChannelBuffer.h:911
Binary serializer and deserializer.
PolymorphicChannelBuffer()
Constructor.
Definition: ChannelBuffer.h:1006
forward decl.
Definition: ChannelBuffer.h:82
void registerCodec(BinarySerializerCodecPtr codec)
Registers the specified codec instance in this binary serializer.
Definition: BinarySerializer.h:764
virtual Buffer< uint8 > readSerializedValue(ChannelBufferBase::Slot *s, std::list< BinarySerializerCodecPtr > &codecs)
Returns a buffer containing the binary serialized data of the slot.
Definition: ChannelBuffer.h:962
virtual void writeSerializedValue(ChannelBufferBase::Slot *s, Buffer< uint8 > data)
Write the given buffer (that contains binary serialized data WITHOUT the StampedHeader) to the slot...
Definition: ChannelBuffer.h:790
Definition: MetaSerializer.h:586
virtual TypeMetaPtr createTypeMeta(ChannelBufferBase::Slot *s, MetaTypeDatabase &ioDB)
Creates meta information for data in slot and stores all meta information in the given database...
Definition: ChannelBuffer.h:662
virtual StampedHeader & getStampedHeader(ChannelBufferBase::Slot *s)
Returns a reference to the stamped header information.
Definition: ChannelBuffer.h:683
#define MIRA_FRAMEWORK_EXPORT
Definition: FrameworkExports.h:61
Stamped< T * > ValueType
Definition: ChannelBuffer.h:1056
Core class of the logging library.
Use this class to represent time durations.
Definition: Time.h:104
The common header for all stamped data.
Definition: Stamped.h:62
Typed ChannelBuffer.
Definition: ChannelBuffer.h:860
The slot with smallest time difference to the requested will be chosen.
Definition: ChannelBuffer.h:103
virtual StampedHeader & getStampedHeader(Slot *s)=0
Returns a reference to the stamped header information.
ChannelBuffer()
Definition: ChannelBuffer.h:899
virtual const Buffer< uint8 > & readSerializedValue(ChannelBufferBase::Slot *s, uint8 formatVersion, bool orLower)
Returns a buffer containing the binary serialized data of the slot.
Definition: ChannelBuffer.h:948
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
boost::shared_ptr< TypeMeta > TypeMetaPtr
Definition: MetaSerializer.h:309
virtual void freeSlot(ChannelBufferBase::Slot *s)
Called to destroy the slot and free the used memory.
Definition: ChannelBuffer.h:927
Mix in for adding a timestamp to data types.
virtual Buffer< uint8 > readSerializedValue(ChannelBufferBase::Slot *s, std::list< BinarySerializerCodecPtr > &codecs, uint8 formatVersion, bool orLower)
Returns a buffer containing the binary serialized data of the slot.
Definition: ChannelBuffer.h:969
virtual void readJSON(ChannelBufferBase::Slot *s, JSONValue &oValue, JSONSerializer &serializer)
Reads data of that slot as json representation using the provided JSONSerializer. ...
Definition: ChannelBuffer.h:820
Stamped< T > ValueType
Definition: ChannelBuffer.h:622
Serializer for creating meta information out of types using serialization.
virtual bool isPolymorphic() const
Returns true if the channel has a polymorphic type.
Definition: ChannelBuffer.h:1015
void cloneParameters(const ChannelBufferBase &other)
Copies the parameters of other to this.
Definition: ChannelBuffer.h:224
forward decl.
Definition: ChannelBuffer.h:86
ValueType data
the actual data value, that is stored in this channel&#39;s slots
Definition: ChannelBuffer.h:633
Base class that manages the slots of channels by providing read and write access to them...
Definition: ChannelBuffer.h:133
Container for storing a single data element in the linked list.
Definition: ChannelBuffer.h:165
bool finishWriteSlot(Slot *n, bool *dropped=NULL)
Adds written slot into buffer at the right time position.
void setCodecs(const CodecsMap &codecs)
Set the map of known codecs.
Definition: BinarySerializer.h:1578
virtual void setTypename(const Typename &name)
Sets the Typename of the slot values.
Definition: ChannelBuffer.h:659
virtual void fixateType()
Calling this method will fix the type of the ChannelBuffer.
Definition: ChannelBuffer.h:919
Input stream adapter that can be assigned to any input stream and allows binary input using the &gt;&gt; st...
Definition: BinaryStream.h:523
Slot * next
Definition: ChannelBuffer.h:158
Buffer< uint8 > serializedValue
The data of this slot as serialized data.
Definition: ChannelBuffer.h:185
virtual void readJSON(ChannelBufferBase::Slot *s, JSONValue &oValue)
Reads data of that slot as json representation using a default-instantiated JSONSerializer.
Definition: ChannelBuffer.h:811
virtual const Buffer< uint8 > & readSerializedValue(ChannelBufferBase::Slot *s)
Returns a buffer containing the binary serialized data of the slot.
Definition: ChannelBuffer.h:943
void deserialize(T &value, bool enableTypeCheck=true, bool recursive=false)
Provides a special deserialize interface for the BinaryDeserializer.
Definition: BinarySerializer.h:1332
StampedHeader ValueType
Definition: ChannelBuffer.h:874
const CodecsMap & getCodecs() const
Return the map of currently known codecs.
Definition: BinarySerializer.h:1573
ChannelBufferPromoterCommon< U > Base
Definition: ChannelBuffer.h:1143
virtual ChannelBufferBase::Slot * allocateSlot()
Creates and returns a new slot.
Definition: ChannelBuffer.h:921
Prefer filling the interval with slots with timestamp &gt; requested.
Definition: ChannelBuffer.h:115
Prefer filling the interval with slots with timestamp &lt; requested.
Definition: ChannelBuffer.h:113
uint32 flags
Used to store internal flags that are especially used by the remote capability of the framework...
Definition: ChannelBuffer.h:193
static ChannelBufferBase * promote(ChannelBufferBase *buffer)
Definition: ChannelBuffer.h:1144
IntervalFillMode
Mode that is used to determine what slots should be added to the interval when not enough slots are a...
Definition: ChannelBuffer.h:110
virtual const Buffer< uint8 > & readSerializedValue(ChannelBufferBase::Slot *s)
Returns a buffer containing the binary serialized data of the slot.
Definition: ChannelBuffer.h:689
virtual Buffer< uint8 > readSerializedValue(ChannelBufferBase::Slot *s, std::list< BinarySerializerCodecPtr > &codecs)
Returns a buffer containing the binary serialized data of the slot.
Definition: ChannelBuffer.h:739
Specialization of ChannelBufferPromoter for polymorphic pointer channel buffers.
Definition: ChannelBuffer.h:1159
virtual Typename getTypename() const =0
Returns the Typename of the slot values, in contrast to getTypeId() the Typename is portable and uniq...
SlotQueryMode
Mode that is used to determine the slot obtained from a channel when no slot exists at the exact time...
Definition: ChannelBuffer.h:94
json::Value JSONValue
Imports the json::Value type into mira namespace.
Definition: JSON.h:363
void clear()
Deletes all slots in all lists and therefore clears the whole buffer.
Provides method for generating a unique id for any type.
virtual int getTypeId() const
Returns typeid of the slot values, the allocator creates.
Definition: ChannelBuffer.h:655
Slot * prev
Definition: ChannelBuffer.h:159
ChannelBufferBase()
Constructor.
Definition: ChannelBuffer.h:208
Serializer and Deserializer for JSON format.
const Time & timestamp() const
Definition: ChannelBuffer.h:195
TypeMetaPtr addMeta(T &v)
Definition: MetaSerializer.h:605
virtual void writeJSON(ChannelBufferBase::Slot *s, JSONDeserializer &deserializer)
Writes data from an initialized json deserializer into the slot.
Definition: ChannelBuffer.h:838
virtual bool isTyped() const =0
Returns true, if the channel is typed and false, if it is untyped.
virtual Typename getTypename() const
Returns the Typename of the slot values, in contrast to getTypeId() the Typename is portable and uniq...
Definition: ChannelBuffer.h:658
The first slot with timestamp &gt; requested will be chosen.
Definition: ChannelBuffer.h:100
std::map< TypeId, BinarySerializerCodecPtr > CodecsMap
A map of binary serialization codecs.
Definition: BinarySerializer.h:1262
boost::shared_ptr< BinarySerializerCodec > BinarySerializerCodecPtr
Shared pointer of BinarySerializerCodec.
Definition: BinarySerializerCodec.h:64