MIRA
Channel.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 
48 #ifndef _MIRA_CHANNEL_H_
49 #define _MIRA_CHANNEL_H_
50 
51 #ifndef _MIRA_FRAMEWORK_H_
52 # error "Channel.h must be included via the Framework.h. You must not include it directly. Use #include <fw/Framework.h> instead"
53 #endif
54 
55 #ifndef Q_MOC_RUN
56 #include <boost/shared_ptr.hpp>
57 #include <boost/type_traits/is_polymorphic.hpp>
58 #endif
59 
60 #include <error/Exceptions.h>
61 
62 #include <factory/TypeId.h>
63 
64 #include <utils/EnumToFlags.h>
66 
67 #include <fw/Framework.h>
68 
69 #include <fw/AbstractChannel.h>
70 #include <fw/ChannelSubscriber.h>
71 #include <fw/ChannelReadWrite.h>
72 #include <fw/ChannelReadInterval.h>
74 
75 namespace mira {
76 
78 
82 MIRA_DEFINE_SERIALIZABLE_EXCEPTION(XInvalidRead, XRuntime)
83 
84 
87 template <typename T>
88 class Channel;
89 
91 
93 
98 template<typename T>
99 class ConcreteChannel : public AbstractChannel
100 {
101 public:
102 
103  typedef ChannelBuffer<T> Buffer;
104  typedef typename Buffer::ValueType ValueType;
105  typedef typename Buffer::Slot Slot;
106 
107  typedef ChannelSubscriber<T, ChannelRead<T> > Subscriber;
108  typedef boost::shared_ptr<Subscriber> SubscriberPtr;
109 
110 public:
111 
112  ConcreteChannel(const std::string& id) :
113  AbstractChannel(id, new ChannelBuffer<T>)
114  {
115  // make sure, that our ConcreteChannel class has the same size
116  // as AbstractChannel and that we are not polymorphic. Both is
117  // important for our channel_cast to work as expected.
118  static_assert(sizeof(ConcreteChannel)==sizeof(AbstractChannel),
119  "ConcreteChannel must have the same size as AbstractChannel");
120 
121  static_assert(boost::is_polymorphic<ConcreteChannel>::value==false,
122  "ConcreateChannel and AbstractChannel must not be polymorphic");
123  }
124 
125 public:
126 
131  void addSubscriber()
132  {
133  boost::mutex::scoped_lock lock(mSubscribersMutex);
134  mNrOfSubscribersWithoutChannelSubscriber++;
135  }
136 
141  void addSubscriber(SubscriberPtr subscriber)
142  {
143  boost::mutex::scoped_lock lock(mSubscribersMutex);
144  mSubscribers.push_back(subscriber);
145  subscriber->attachChannel(this);
146  }
147 
148 public:
149 
157  ChannelRead<T> read();
158 
169  ChannelRead<T> read(const Time& timestamp, SlotQueryMode mode = NEAREST_SLOT,
170  const Duration& tolerance = Duration::infinity());
171 
195  ChannelReadInterval<T> readInterval(const Time& timestamp, std::size_t nrSlots,
196  std::size_t olderSlots, std::size_t newerSlots,
197  IntervalFillMode fillMode = PREFER_NEWER);
198 
217  ChannelReadInterval<T> readInterval(const Time& from,
218  const Time& to = Time::eternity());
219 
231  ChannelWrite<T> write();
232 
233 public:
234  friend class Channel<T>;
235 };
236 
238 
239 
246 template<typename T>
247 struct ChannelCaster {
248  static ConcreteChannel<T>* cast(AbstractChannel* p)
249  {
250  // promote the channel if necessary (this will throw an exception, if
251  // the channel cannot be promoted to the desired type)
252  promote_channel<T>(p);
253 
254  assert(p->isTyped()); // at the point p will always be typed
255 
256  // check the type of our buffer's slot manually
257  if(typeId<T>()!=p->getTypeId())
258  MIRA_THROW(XBadCast, "Cannot cast channel '" << p->getID()
259  << "' (type '" << p->getTypename() << "') "
260  << " to typed channel of type '" << typeName<T>() << "'");
261 
262  // cast us "hard" using a static_cast.
263  // This is safe, since we have checked the types above
264  return static_cast<ConcreteChannel<T>*>(p);
265  }
266 };
267 
269 
270 // specialization to cast to untyped ConcreteChannel (void)
271 template<>
272 struct ChannelCaster<void> {
273  static ConcreteChannel<void>* cast(AbstractChannel* p)
274  {
275  // cast us "hard" using a static_cast.
276  // This is safe, since all channels can be casted to untyped channel
277  return static_cast<ConcreteChannel<void>* >(p);
278  }
279 };
280 
282 
283 // specialization to cast polymorphic channels
284 template<typename T>
285 struct ChannelCaster<T*> {
286  static ConcreteChannel<T*>* cast(AbstractChannel* p)
287  {
288  static_assert(std::is_base_of<mira::Object,T>::value,
289  "Pointers that are used in channels must be derived from "
290  "mira::Object. Pointers to other classes cannot be used.");
291 
292  // promote the channel if necessary (this will throw an exception, if the
293  // the channel cannot be promoted to the desired type)
294  promote_channel<T*>(p);
295 
296  // channel must be typed after promotion
297  assert(p->getBuffer()->isPolymorphic());
298 
299  // cast us "hard" using a static_cast.
300  // This is safe, since we have checked the types above
301  return static_cast<ConcreteChannel<T*>* >(p);
302  }
303 };
304 
306 
307 template<typename T>
308 inline ConcreteChannel<T>* channel_cast(AbstractChannel* p)
309 {
310  return ChannelCaster<T>::cast(p);
311 }
312 
314 
316 
318 template <typename T>
319 class Channel;
320 
322 template<typename T>
323 inline Channel<T> channel_cast(Channel<void> channel);
325 
326 
335 };
337 
338 
339 namespace {
340 
341 template <typename T>
342 struct ParamHelper {
343  typedef T type;
344 };
345 
346 template<>
347 struct ParamHelper<void> {
348  typedef int type; // arbitrary, it will not be used for T=void actually,
349  // but needs to name a valid argument type
350 };
351 
352 }
353 
355 
401 template <typename T>
402 class Channel
403 {
404 public:
405 
409  Channel() : mChannel(), mAccessFlags(CHANNEL_ACCESS_NONE) {}
410 
415  mChannel(channel), mAccessFlags(accessFlags) {
416  assert(mChannel!=NULL);
417  }
418 
422  void reset() {
423  mChannel=NULL;
424  mAccessFlags = CHANNEL_ACCESS_NONE;
425  }
426 
431  bool isValid() const {
432  return mChannel!=NULL;
433  }
434 
440  void validate() const {
441  if(mChannel==NULL)
442  MIRA_THROW(XAccessViolation,
443  "No channel assigned to the channel proxy (of type " <<
444  typeName<T>() << "). "
445  "You can obtain a channel using Authority::getChannel()!");
446  }
447 
453 
457  const std::string& getID() const {
458  validate();
459  return mChannel->getID();
460  }
461 
467  int getTypeId() const {
468  validate();
469  return mChannel->getTypeId();
470  }
471 
475  bool isTyped() const { return getTypeId()>=0; }
476 
482  validate();
483  return mChannel->getTypename();
484  }
485 
490  void setTypename(const Typename& type) {
491  validate();
492  mChannel->setTypename(type);
493  }
494 
499  validate();
500  return mChannel->getTypeMeta();
501  }
502 
507  validate();
508  mChannel->setTypeMeta(meta);
509  }
510 
512 
513 public:
514 
520 
524  bool isEmpty() const {
525  validate();
526  return mChannel->getNrOfSlots() == 0;
527  }
528 
532  bool hasSubscriber() const {
533  validate();
534  return mChannel->hasSubscriber();
535  }
536 
540  bool hasPublisher() const {
541  validate();
542  return mChannel->hasPublisher();
543  }
544 
548  bool hasSoloSlot() const {
549  validate();
550  return mChannel->getBuffer()->getMaxSlots() == 1;
551  }
552 
556  std::size_t getMaxSlots() const {
557  validate();
558  return mChannel->getBuffer()->getMaxSlots();
559  }
560 
564  std::size_t getMinSlots() const {
565  validate();
566  return mChannel->getBuffer()->getMinSlots();
567  }
568 
574  validate();
575  return mChannel->getBuffer()->getStorageDuration();
576  }
577 
582  validate();
583  return mChannel->getBuffer()->isAutoIncreasingStorageDuration();
584  }
585 
589  std::size_t getNrOfSlots() const {
590  validate();
591  return mChannel->getBuffer()->getSize();
592  }
593 
595 
596 public:
597 
604 
616  {
617  validateReadAccess();
618 
619  Time end;
620  if(!timeout.isValid() || timeout.isInfinity())
621  end = Time::eternity();
622  else
623  end = Time::now() + timeout;
624 
625  while(!boost::this_thread::interruption_requested())
626  {
627  try {
628  return mChannel->read();
629  } catch(XInvalidRead& ex) {}
630  if(Time::now()>end) // handle timeout
631  break;
632  MIRA_SLEEP(50)
633  }
634  return ChannelRead<T>();
635  }
636 
637 
647  bool waitForPublisher(const Duration& timeout = Duration::infinity()) const
648  {
649  validateReadAccess();
650 
651  Time end;
652  if(!timeout.isValid() || timeout.isInfinity())
653  end = Time::eternity();
654  else
655  end = Time::now() + timeout;
656 
657  while(!boost::this_thread::interruption_requested())
658  {
659  if(hasPublisher())
660  return true;
661  if(Time::now()>end) // handle timeout
662  break;
663  MIRA_SLEEP(50)
664  }
665  return false; // timeout
666  }
667 
668 
678  validateReadAccess();
679  return mChannel->read();
680  }
681 
703  const Duration& tolerance = Duration::infinity()) {
704  validateReadAccess();
705  return mChannel->read(timestamp, mode, tolerance);
706  }
707 
725  ChannelRead<T> read(uint32 sequenceID,
726  const Duration& searchInterval = Duration::seconds(1)) {
727  validateReadAccess();
728  Time newestSlotTime = mChannel->read()->timestamp;
729  ChannelReadInterval<T> interval = readInterval(newestSlotTime - searchInterval, newestSlotTime);
730  typename ChannelReadInterval<T>::const_iterator iter = interval.begin();
731  for(; iter != interval.end(); ++iter){
732  if(iter->sequenceID == sequenceID)
733  return (ChannelRead<T>)iter;
734  }
735  MIRA_THROW(XInvalidRead, "No slot with sequenceID "<<sequenceID<<
736  " found within searchInterval of channel");
737  }
738 
744  ChannelRead<T> read(const Time& timestamp, const Duration& tolerance) {
745  validateReadAccess();
746  return mChannel->read(timestamp, NEAREST_SLOT, tolerance);
747  }
748 
778  std::size_t nrSlots,
779  std::size_t olderSlots,
780  std::size_t newerSlots,
781  IntervalFillMode fillMode = PREFER_NEWER) {
782  validateReadAccess();
783  return mChannel->readInterval(timestamp, nrSlots, olderSlots,
784  newerSlots, fillMode);
785  }
786 
803  const Time& to=Time::eternity()) {
804  validateReadAccess();
805  return mChannel->readInterval(from, to);
806  }
807 
824  validateWriteAccess();
825  return mChannel->write();
826  }
827 
853  ChannelWrite<T> write(bool copyLatestData) {
854  validateWriteAccess();
855 
856  // check if we should and need to copy data into the write slot
857  if(copyLatestData
858  && (mChannel->getBuffer()->getMaxSlots()>1) // only necessary if we may have more than one slot
859  && (mChannel->getBuffer()->getSize()>0)) // and only if we have at least one slot yet
860  {
861  ChannelRead<T> latest = mChannel->read();
862  Stamped<T> tmp(*latest);
863  latest.finish();
864  ChannelWrite<T> writeSlot = mChannel->write();
865  *writeSlot = tmp;
866  return writeSlot;
867 
868  } else
869  return mChannel->write();
870  }
871 
885  Stamped<T> get() {
886  validateReadAccess();
887  ChannelRead<T> value = mChannel->read();
888  return *value;
889  }
890 
904  Stamped<T> get(const Time& timestamp, SlotQueryMode mode=NEAREST_SLOT,
905  const Duration& tolerance = Duration::infinity()) {
906  validateReadAccess();
907  ChannelRead<T> value = mChannel->read(timestamp, mode, tolerance);
908  return *value;
909  }
910 
916  Stamped<T> get(const Time& timestamp, Duration tolerance) {
917  validateReadAccess();
918  ChannelRead<T> value = mChannel->read(timestamp, NEAREST_SLOT, tolerance);
919  return *value;
920  }
921 
922 private:
923 
925 
927  struct GetTime
928  {
929  GetTime(const Time& iT0) : t0(iT0) {}
930 
931  //typedef const Time& result_type;
932  typedef float result_type;
933  result_type operator()(const Stamped<T>& p) const {
934  //return p.timestamp;
935  return (p.timestamp-t0).totalMilliseconds();
936  }
937 
938  Time t0;
939  };
940 
942  struct GetValue
943  {
944  typedef const T& result_type;
945  result_type operator()(const Stamped<T>& p) const {
946  return p;
947  }
948  };
949 
951 
952 public:
953 
972  template <typename Filter>
973  Stamped<T> get(const Time& timestamp, Filter&& filter) {
974  validateReadAccess();
975 
977  try
978  {
979  data = readInterval(timestamp, filter.samples(),
980  filter.samplesBefore(),
981  filter.samplesAfter());
982  // check filter requirements
983  if (!filter.canExtrapolate())
984  {
985  int samplesBefore = filter.samplesBefore();
986  int samplesAfter = filter.samplesAfter();
987  // a rbegin in ChannelReadInterval could speed this up
988  for (auto it = data.begin(); it != data.end(); ++it)
989  {
990  if (it->timestamp <= timestamp)
991  --samplesBefore;
992  else if (it->timestamp >= timestamp)
993  --samplesAfter;
994  }
995 
996  if (samplesBefore > 0)
997  MIRA_THROW(XRuntime, "Filter::samplesBefore: Requirements not met. Missing " << samplesBefore << " items.");
998  if (samplesAfter > 0)
999  MIRA_THROW(XRuntime, "Filter::samplesAfter: Requirements not met. Missing " << samplesAfter << " items.");
1000  }
1001  }
1002  catch(Exception&)
1003  {
1004  // read interval failed so test if the channel only contains a single data element
1005  // if so return it as a special case for interpolation of channels that will only
1006  // receive a single update during their lifetime
1007  if (mChannel->getNrOfSlots() == 1)
1008  return get();
1009  // more than one data element in the channel but still not sufficient for interpolation
1010  // rethrow is our only option
1011  throw;
1012  }
1013 
1014  const Time t0 = data.begin()->timestamp;
1015 
1016  typedef typename ChannelReadInterval<T>::const_iterator const_iterator;
1017  typedef boost::transform_iterator<GetTime, const_iterator> GetTimeIterator;
1018  GetTimeIterator begin1 = GetTimeIterator(data.begin(), GetTime(t0));
1019  GetTimeIterator end1 = GetTimeIterator(data.end() , GetTime(t0));
1020 
1021  typedef boost::transform_iterator<GetValue, const_iterator> GetValueIterator;
1022 
1023  GetValueIterator begin2=GetValueIterator(data.begin(), GetValue());
1024  GetValueIterator end2 =GetValueIterator(data.end() , GetValue());
1025 
1026  typedef mira::IteratorRangeContainer<GetTimeIterator> TimeContainer;
1027  typedef mira::IteratorRangeContainer<GetValueIterator> ValueContainer;
1028  TimeContainer timeContainer(begin1, end1);
1029  ValueContainer valueContainer(begin2, end2);
1030 
1031  return makeStamped(filter.template apply<float, T>(timeContainer,
1032  valueContainer,
1033  (timestamp-t0).totalMilliseconds()),
1034  timestamp);
1035  }
1036 
1046  template <typename U = void>
1047  void post(const Stamped<T>& value) {
1048  validateWriteAccess();
1049  ChannelWrite<T> writeSlot = mChannel->write();
1050  *writeSlot = value;
1051  writeSlot.finish(); // explicit finish to avoid throwing in destructor
1052  }
1053 
1055  template <typename U = void>
1056  void post(Stamped<T>&& value) {
1057  validateWriteAccess();
1058  ChannelWrite<T> writeSlot = mChannel->write();
1059  *writeSlot = std::move(value);
1060  writeSlot.finish(); // explicit finish to avoid throwing in destructor
1061  }
1062 
1072  template <typename U>
1073  typename std::enable_if<!std::is_base_of_v<StampedHeader, std::decay_t<U>>>::type
1074  post(U&& value, const Time& timestamp = Time::now()) {
1075  validateWriteAccess();
1076  ChannelWrite<T> writeSlot = mChannel->write();
1077  *writeSlot = makeStamped(std::forward<U>(value), timestamp);
1078  writeSlot.finish(); // explicit finish to avoid throwing in destructor
1079  }
1080 
1090  template <typename U = T>
1091  typename std::enable_if<!std::is_void<U>::value>::type
1092  post(const typename ParamHelper<T>::type& value, const Time& timestamp = Time::now()) {
1093  validateWriteAccess();
1094  ChannelWrite<T> writeSlot = mChannel->write();
1095  *writeSlot = makeStamped(value, timestamp);
1096  writeSlot.finish(); // explicit finish to avoid throwing in destructor
1097  }
1098 
1100  template <typename U = T>
1101  typename std::enable_if<!std::is_void<U>::value>::type
1102  post(typename ParamHelper<T>::type&& value, const Time& timestamp = Time::now()) {
1103  validateWriteAccess();
1104  ChannelWrite<T> writeSlot = mChannel->write();
1105  *writeSlot = makeStamped(std::move(value), timestamp);
1106  writeSlot.finish(); // explicit finish to avoid throwing in destructor
1107  }
1108 
1110 
1111 public:
1112 
1114  template<typename U>
1115  friend Channel<U> channel_cast(Channel<void> channel);
1117 
1118 public:
1119 
1121  void dbgDump(bool brief=true) { mChannel->dbgDump(brief); }
1123 
1124 private:
1125 
1126  void validateReadAccess() const
1127  {
1128  validate();
1129  if((mAccessFlags & CHANNEL_ACCESS_READ)==0)
1130  MIRA_THROW(XAccessViolation, "You are not allowed to read from channel '"
1131  << mChannel->getID() << "'. Forgot to subscribe?");
1132  }
1133 
1134  void validateWriteAccess() const
1135  {
1136  validate();
1137  if((mAccessFlags & CHANNEL_ACCESS_WRITE)==0)
1138  MIRA_THROW(XAccessViolation, "You are not allowed to write to channel '"
1139  << mChannel->getID() << "'. Forgot to publish?");
1140  }
1141 
1142 private:
1143 
1144  ConcreteChannel<T>* mChannel;
1145  ChannelAccessFlags mAccessFlags;
1146 };
1147 
1149 
1151 template<typename U>
1152 inline Channel<U> channel_cast(Channel<void> channel)
1153 {
1154  channel.validate();
1155  return Channel<U>(channel_cast<U>(channel.mChannel), channel.mAccessFlags);
1156 }
1158 
1160 
1161 } // namespace
1162 
1163 #include "impl/ChannelReadWrite.hpp"
1164 #include "impl/ChannelReadInterval.hpp"
1165 
1166 #endif
TypeMetaPtr getTypeMeta() const
Return the type meta information for this channel.
Definition: Channel.h:498
std::enable_if<!std::is_base_of_v< StampedHeader, std::decay_t< U > > >::type post(U &&value, const Time &timestamp=Time::now())
Writes the specified data with the specified time stamp into the channel.
Definition: Channel.h:1074
An object that allows read access to a whole interval of channel data.
Definition: ChannelReadInterval.h:72
const std::string & getID() const
Return the channel ID, its name.
Definition: Channel.h:457
Read access (Authority is a subscriber)
Definition: Channel.h:333
bool hasPublisher() const
Returns true, if this channel has at least one publisher.
Definition: Channel.h:540
void finish()
Releases the lock explicitly.
Definition: ChannelReadWrite.h:601
std::size_t getMaxSlots() const
Returns the upper limit of slots that are allowed for this channel.
Definition: Channel.h:556
void post(const Stamped< T > &value)
Writes the specified data into the channel.
Definition: Channel.h:1047
An exception that occurs whenever a channel has no data.
Definition: Channel.h:88
void post(Stamped< T > &&value)
Same as above, for rvalue reference (move semantics)
Definition: Channel.h:1056
Write access (Authority is a publisher)
Definition: Channel.h:334
Macros for generating logical operators for using enum values as flags.
ChannelRead< T > read(uint32 sequenceID, const Duration &searchInterval=Duration::seconds(1))
Obtains read access to the element with the specified sequenceID within the given search interval If ...
Definition: Channel.h:725
void validate() const
Checks if the channel is valid otherwise throws an exception.
Definition: Channel.h:440
#define MIRA_ENUM_TO_FLAGS(EnumType)
Macro that can be used with enums that contain flags.
Definition: EnumToFlags.h:80
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
Subscriber classes used to subscribe on channels for automatic notification.
Channel(ConcreteChannel< T > *channel, ChannelAccessFlags accessFlags)
Is used by Framework to create a channel proxy object.
Definition: Channel.h:414
std::string Typename
Definition: Typename.h:60
void setTypeMeta(TypeMetaPtr meta)
Set the type meta information for this channel.
Definition: Channel.h:506
bool isTyped() const
Returns true, if the channel is typed and false, if it is untyped.
Definition: Channel.h:475
An object that allows exclusive write access to data of a channel.
Definition: ChannelReadWrite.h:652
#define MIRA_DEFINE_SERIALIZABLE_EXCEPTION(Ex, Base)
Macro for easily defining a new serializable exception class.
Definition: Exceptions.h:66
Definition: ChannelReadWrite.h:67
An object that allows read access to data of a channel.
Definition: ChannelReadWrite.h:494
ChannelReadInterval< T > readInterval(const Time &timestamp, std::size_t nrSlots, std::size_t olderSlots, std::size_t newerSlots, IntervalFillMode fillMode=PREFER_NEWER)
Obtains read access to an interval of elements before and after the requested timestamp.
Definition: Channel.h:777
#define MIRA_THROW(ex, msg)
Macro for throwing an exception.
Definition: Exception.h:82
Typename getTypename() const
Return the typename of the channel.
Definition: Channel.h:481
void finish()
Releases the lock explicitly and informs the Channel to signal all Subscribers that new data is avail...
Definition: ChannelReadWrite.h:765
Wrapper class for boost::posix_time::ptime for adding more functionality to it.
Definition: Time.h:418
ChannelRead< T > read(const Time &timestamp, SlotQueryMode mode=NEAREST_SLOT, const Duration &tolerance=Duration::infinity())
Obtains read access to the element at the specified timestamp.
Definition: Channel.h:702
const_iterator end() const
Definition: ChannelReadInterval.h:164
const_iterator begin() const
Definition: ChannelReadInterval.h:163
Classes for automatic locking/unlocking when reading and writing to channels.
MIRA_BASE_EXPORT void write(const Value &value, std::ostream &ioStream, bool formatted=false, int precision=-1)
Writes a json::Value into a given stream using the JSON format.
Commonly used exception classes.
std::size_t getNrOfSlots() const
Returns how many slots (i.e.
Definition: Channel.h:589
PropertyHint type(const std::string &t)
Sets the attribute "type" to the specified value.
Definition: PropertyHint.h:295
Definition: AbstractChannel.h:70
bool hasSoloSlot() const
Returns true, if this channel has one solo slot only.
Definition: Channel.h:548
sec_type seconds() const
Returns normalized number of seconds (0..59)
Definition: Time.h:280
Use this class to represent time durations.
Definition: Time.h:106
ChannelRead< T > read(const Time &timestamp, const Duration &tolerance)
Same as above, but always takes the nearest slot.
Definition: Channel.h:744
ChannelRead< T > read()
Obtains read access to the latest data element of this channel.
Definition: Channel.h:677
void reset()
Reset the proxy object so that it becomes invalid.
Definition: Channel.h:422
MIRA_BASE_EXPORT void read(const std::string &s, Value &oValue)
Read a json::Value from a string that contains JSON format.
Typed ChannelBuffer.
Definition: ChannelBuffer.h:892
The slot with smallest time difference to the requested will be chosen.
Definition: ChannelBuffer.h:104
Const iterator for iterating over the interval.
Definition: ChannelReadInterval.h:85
void setTypename(const Typename &type)
Set the typename of this channel.
Definition: Channel.h:490
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
std::enable_if<!std::is_void< U >::value >::type post(typename ParamHelper< T >::type &&value, const Time &timestamp=Time::now())
Same as above, for rvalue reference (move semantics)
Definition: Channel.h:1102
bool isAutoIncreasingStorageDuration() const
Returns whether the channel buffer is automatically increasing the storage duration.
Definition: Channel.h:581
std::enable_if<!std::is_void< U >::value >::type post(const typename ParamHelper< T >::type &value, const Time &timestamp=Time::now())
This allows post({}, Time()); to deduce we want to post an object of the channel&#39;s type...
Definition: Channel.h:1092
Duration getStorageDuration() const
Returns the timeframe that specifies how long a slot is guaranteed to be kept in the channel buffer...
Definition: Channel.h:573
Stamped< typename std::decay< T >::type > makeStamped(T &&value, const Time &timestamp=Time::now(), const std::string &frameID=std::string(), uint32 sequenceID=0)
Declare stamped classes for all standard data types including std::string.
Definition: Stamped.h:471
Base class for exceptions.
Definition: Exception.h:199
Generic buffer class that can be used as a replacement for std::vector whenever copying and reallocat...
Definition: Buffer.h:84
bool hasSubscriber() const
Returns true, if this channel has at least one subscriber.
Definition: Channel.h:532
static Duration infinity()
Returns a special duration time representing positive infinity.
Definition: Time.h:242
An iterator range class.
ChannelRead< T > waitForData(const Duration &timeout=Duration::infinity()) const
Waits until data in this channel becomes available.
Definition: Channel.h:615
Channel()
Create channel proxy that is not assigned to a channel.
Definition: Channel.h:409
ChannelWrite< T > write()
Obtains exclusive write access to the next free data slot of this channel.
Definition: Channel.h:823
No access at all (Authority is not a publisher nor a subscriber)
Definition: Channel.h:332
ChannelWrite< T > write(bool copyLatestData)
Same as write above with an additional parameter copyLatestData that allows you to specify whether th...
Definition: Channel.h:853
static Time now() static Time eternity()
Returns the current utc based time.
Definition: Time.h:481
std::size_t getMinSlots() const
Returns the number slots that are guaranteed to be kept in the channel buffer.
Definition: Channel.h:564
int getTypeId() const
Returns the type id of the channel.
Definition: Channel.h:467
Prefer filling the interval with slots with timestamp > requested.
Definition: ChannelBuffer.h:116
bool isValid() const
Returns true if the proxy object is valid.
Definition: Channel.h:431
IntervalFillMode
Mode that is used to determine what slots should be added to the interval when not enough slots are a...
Definition: ChannelBuffer.h:111
SlotQueryMode
Mode that is used to determine the slot obtained from a channel when no slot exists at the exact time...
Definition: ChannelBuffer.h:95
Base class for all framework channels.
Infrastructure for promotion of channels from void to typed based on runtime knowledge of the typenam...
#define MIRA_SLEEP(ms)
Sleeps for ms milliseconds This is a thread interruption point - if interruption of the current threa...
Definition: Thread.h:96
Implements AbstractChannelSubscriber for a concrete data type.
Definition: ChannelSubscriber.h:82
The framework that holds all manager classes and provides startup and shutdown of all framework relat...
Provides method for generating a unique id for any type.
bool isEmpty() const
Returns if the channel is empty (no data has been published)
Definition: Channel.h:524
bool waitForPublisher(const Duration &timeout=Duration::infinity()) const
Waits until this channel has at least one publisher.
Definition: Channel.h:647
Wraps an STL conform container around a range of values within another container. ...
Definition: IteratorRangeContainer.h:64
Classes for reading whole intervals of data from channels.
ChannelReadInterval< T > readInterval(const Time &from, const Time &to=Time::eternity())
Obtains read access to an interval of elements in a given time span.
Definition: Channel.h:802
ChannelAccessFlags
Flags specifying the access rights of an authority to a channel Can be combined.
Definition: Channel.h:331