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 
152  void removeSubscriber()
153  {
154  boost::mutex::scoped_lock lock(mSubscribersMutex);
155  if (mNrOfSubscribersWithoutChannelSubscriber>0)
156  --mNrOfSubscribersWithoutChannelSubscriber;
157  }
158 
163  void removeSubscriber(SubscriberPtr subscriber)
164  {
166  }
167 
168 public:
169 
177  ChannelRead<T> read();
178 
189  ChannelRead<T> read(const Time& timestamp, SlotQueryMode mode = NEAREST_SLOT,
190  const Duration& tolerance = Duration::infinity());
191 
215  ChannelReadInterval<T> readInterval(const Time& timestamp, std::size_t nrSlots,
216  std::size_t olderSlots, std::size_t newerSlots,
217  IntervalFillMode fillMode = PREFER_NEWER);
218 
237  ChannelReadInterval<T> readInterval(const Time& from,
238  const Time& to = Time::eternity());
239 
251  ChannelWrite<T> write();
252 
253 public:
254  friend class Channel<T>;
255 };
256 
258 
259 
266 template<typename T>
267 struct ChannelCaster {
268  static ConcreteChannel<T>* cast(AbstractChannel* p)
269  {
270  // promote the channel if necessary (this will throw an exception, if
271  // the channel cannot be promoted to the desired type)
272  promote_channel<T>(p);
273 
274  assert(p->isTyped()); // at the point p will always be typed
275 
276  // check the type of our buffer's slot manually
277  if(typeId<T>()!=p->getTypeId())
278  MIRA_THROW(XBadCast, "Cannot cast channel '" << p->getID()
279  << "' (type '" << p->getTypename() << "') "
280  << " to typed channel of type '" << typeName<T>() << "'");
281 
282  // cast us "hard" using a static_cast.
283  // This is safe, since we have checked the types above
284  return static_cast<ConcreteChannel<T>*>(p);
285  }
286 };
287 
289 
290 // specialization to cast to untyped ConcreteChannel (void)
291 template<>
292 struct ChannelCaster<void> {
293  static ConcreteChannel<void>* cast(AbstractChannel* p)
294  {
295  // cast us "hard" using a static_cast.
296  // This is safe, since all channels can be casted to untyped channel
297  return static_cast<ConcreteChannel<void>* >(p);
298  }
299 };
300 
302 
303 // specialization to cast polymorphic channels
304 template<typename T>
305 struct ChannelCaster<T*> {
306  static ConcreteChannel<T*>* cast(AbstractChannel* p)
307  {
308  static_assert(std::is_base_of<mira::Object,T>::value,
309  "Pointers that are used in channels must be derived from "
310  "mira::Object. Pointers to other classes cannot be used.");
311 
312  // promote the channel if necessary (this will throw an exception, if the
313  // the channel cannot be promoted to the desired type)
314  promote_channel<T*>(p);
315 
316  // channel must be typed after promotion
317  assert(p->getBuffer()->isPolymorphic());
318 
319  // cast us "hard" using a static_cast.
320  // This is safe, since we have checked the types above
321  return static_cast<ConcreteChannel<T*>* >(p);
322  }
323 };
324 
326 
327 template<typename T>
328 inline ConcreteChannel<T>* channel_cast(AbstractChannel* p)
329 {
330  return ChannelCaster<T>::cast(p);
331 }
332 
334 
336 
338 template <typename T>
339 class Channel;
340 
342 template<typename T>
343 inline Channel<T> channel_cast(Channel<void> channel);
345 
346 
355 };
357 
358 
359 namespace {
360 
361 template <typename T>
362 struct ParamHelper {
363  typedef T type;
364 };
365 
366 template<>
367 struct ParamHelper<void> {
368  typedef int type; // arbitrary, it will not be used for T=void actually,
369  // but needs to name a valid argument type
370 };
371 
372 }
373 
375 
421 template <typename T>
422 class Channel
423 {
424 public:
425 
429  Channel() : mChannel(), mAccessFlags(CHANNEL_ACCESS_NONE) {}
430 
435  mChannel(channel), mAccessFlags(accessFlags) {
436  assert(mChannel!=NULL);
437  }
438 
442  void reset() {
443  mChannel=NULL;
444  mAccessFlags = CHANNEL_ACCESS_NONE;
445  }
446 
451  bool isValid() const {
452  return mChannel!=NULL;
453  }
454 
460  void validate() const {
461  if(mChannel==NULL)
462  MIRA_THROW(XAccessViolation,
463  "No channel assigned to the channel proxy (of type " <<
464  typeName<T>() << "). "
465  "You can obtain a channel using Authority::getChannel()!");
466  }
467 
473 
477  const std::string& getID() const {
478  validate();
479  return mChannel->getID();
480  }
481 
487  int getTypeId() const {
488  validate();
489  return mChannel->getTypeId();
490  }
491 
495  bool isTyped() const { return getTypeId()>=0; }
496 
502  validate();
503  return mChannel->getTypename();
504  }
505 
510  void setTypename(const Typename& type) {
511  validate();
512  mChannel->setTypename(type);
513  }
514 
519  validate();
520  return mChannel->getTypeMeta();
521  }
522 
527  validate();
528  mChannel->setTypeMeta(meta);
529  }
530 
532 
533 public:
534 
540 
544  bool isEmpty() const {
545  validate();
546  return mChannel->getNrOfSlots() == 0;
547  }
548 
552  bool hasSubscriber() const {
553  validate();
554  return mChannel->hasSubscriber();
555  }
556 
560  bool hasPublisher() const {
561  validate();
562  return mChannel->hasPublisher();
563  }
564 
568  bool hasSoloSlot() const {
569  validate();
570  return mChannel->getBuffer()->getMaxSlots() == 1;
571  }
572 
576  std::size_t getMaxSlots() const {
577  validate();
578  return mChannel->getBuffer()->getMaxSlots();
579  }
580 
584  std::size_t getMinSlots() const {
585  validate();
586  return mChannel->getBuffer()->getMinSlots();
587  }
588 
594  validate();
595  return mChannel->getBuffer()->getStorageDuration();
596  }
597 
602  validate();
603  return mChannel->getBuffer()->isAutoIncreasingStorageDuration();
604  }
605 
609  std::size_t getNrOfSlots() const {
610  validate();
611  return mChannel->getBuffer()->getSize();
612  }
613 
615 
616 public:
617 
624 
636  {
637  validateReadAccess();
638 
639  Time end;
640  if(!timeout.isValid() || timeout.isInfinity())
641  end = Time::eternity();
642  else
643  end = Time::now() + timeout;
644 
645  while(!boost::this_thread::interruption_requested())
646  {
647  try {
648  return mChannel->read();
649  } catch(XInvalidRead& ex) {}
650  if(Time::now()>end) // handle timeout
651  break;
652  MIRA_SLEEP(50)
653  }
654  return ChannelRead<T>();
655  }
656 
657 
667  bool waitForPublisher(const Duration& timeout = Duration::infinity()) const
668  {
669  validateReadAccess();
670 
671  Time end;
672  if(!timeout.isValid() || timeout.isInfinity())
673  end = Time::eternity();
674  else
675  end = Time::now() + timeout;
676 
677  while(!boost::this_thread::interruption_requested())
678  {
679  if(hasPublisher())
680  return true;
681  if(Time::now()>end) // handle timeout
682  break;
683  MIRA_SLEEP(50)
684  }
685  return false; // timeout
686  }
687 
688 
698  validateReadAccess();
699  return mChannel->read();
700  }
701 
723  const Duration& tolerance = Duration::infinity()) {
724  validateReadAccess();
725  return mChannel->read(timestamp, mode, tolerance);
726  }
727 
745  ChannelRead<T> read(uint32 sequenceID,
746  const Duration& searchInterval = Duration::seconds(1)) {
747  validateReadAccess();
748  Time newestSlotTime = mChannel->read()->timestamp;
749  ChannelReadInterval<T> interval = readInterval(newestSlotTime - searchInterval, newestSlotTime);
750  typename ChannelReadInterval<T>::const_iterator iter = interval.begin();
751  for(; iter != interval.end(); ++iter){
752  if(iter->sequenceID == sequenceID)
753  return (ChannelRead<T>)iter;
754  }
755  MIRA_THROW(XInvalidRead, "No slot with sequenceID "<<sequenceID<<
756  " found within searchInterval of channel");
757  }
758 
764  ChannelRead<T> read(const Time& timestamp, const Duration& tolerance) {
765  validateReadAccess();
766  return mChannel->read(timestamp, NEAREST_SLOT, tolerance);
767  }
768 
798  std::size_t nrSlots,
799  std::size_t olderSlots,
800  std::size_t newerSlots,
801  IntervalFillMode fillMode = PREFER_NEWER) {
802  validateReadAccess();
803  return mChannel->readInterval(timestamp, nrSlots, olderSlots,
804  newerSlots, fillMode);
805  }
806 
823  const Time& to=Time::eternity()) {
824  validateReadAccess();
825  return mChannel->readInterval(from, to);
826  }
827 
844  validateWriteAccess();
845  return mChannel->write();
846  }
847 
873  ChannelWrite<T> write(bool copyLatestData) {
874  validateWriteAccess();
875 
876  // check if we should and need to copy data into the write slot
877  if(copyLatestData
878  && (mChannel->getBuffer()->getMaxSlots()>1) // only necessary if we may have more than one slot
879  && (mChannel->getBuffer()->getSize()>0)) // and only if we have at least one slot yet
880  {
881  ChannelRead<T> latest = mChannel->read();
882  Stamped<T> tmp(*latest);
883  latest.finish();
884  ChannelWrite<T> writeSlot = mChannel->write();
885  *writeSlot = tmp;
886  return writeSlot;
887 
888  } else
889  return mChannel->write();
890  }
891 
905  Stamped<T> get() {
906  validateReadAccess();
907  ChannelRead<T> value = mChannel->read();
908  return *value;
909  }
910 
924  Stamped<T> get(const Time& timestamp, SlotQueryMode mode=NEAREST_SLOT,
925  const Duration& tolerance = Duration::infinity()) {
926  validateReadAccess();
927  ChannelRead<T> value = mChannel->read(timestamp, mode, tolerance);
928  return *value;
929  }
930 
936  Stamped<T> get(const Time& timestamp, Duration tolerance) {
937  validateReadAccess();
938  ChannelRead<T> value = mChannel->read(timestamp, NEAREST_SLOT, tolerance);
939  return *value;
940  }
941 
942 private:
943 
945 
947  struct GetTime
948  {
949  GetTime(const Time& iT0) : t0(iT0) {}
950 
951  //typedef const Time& result_type;
952  typedef float result_type;
953  result_type operator()(const Stamped<T>& p) const {
954  //return p.timestamp;
955  return (p.timestamp-t0).totalMilliseconds();
956  }
957 
958  Time t0;
959  };
960 
962  struct GetValue
963  {
964  typedef const T& result_type;
965  result_type operator()(const Stamped<T>& p) const {
966  return p;
967  }
968  };
969 
971 
972 public:
973 
992  template <typename Filter>
993  Stamped<T> get(const Time& timestamp, Filter&& filter) {
994  validateReadAccess();
995 
997  try
998  {
999  data = readInterval(timestamp, filter.samples(),
1000  filter.samplesBefore(),
1001  filter.samplesAfter());
1002  // check filter requirements
1003  if (!filter.canExtrapolate())
1004  {
1005  int samplesBefore = filter.samplesBefore();
1006  int samplesAfter = filter.samplesAfter();
1007  // a rbegin in ChannelReadInterval could speed this up
1008  for (auto it = data.begin(); it != data.end(); ++it)
1009  {
1010  if (it->timestamp <= timestamp)
1011  --samplesBefore;
1012  else if (it->timestamp >= timestamp)
1013  --samplesAfter;
1014  }
1015 
1016  if (samplesBefore > 0)
1017  MIRA_THROW(XRuntime, "Filter::samplesBefore: Requirements not met. Missing " << samplesBefore << " items.");
1018  if (samplesAfter > 0)
1019  MIRA_THROW(XRuntime, "Filter::samplesAfter: Requirements not met. Missing " << samplesAfter << " items.");
1020  }
1021  }
1022  catch(Exception&)
1023  {
1024  // read interval failed so test if the channel only contains a single data element
1025  // if so return it as a special case for interpolation of channels that will only
1026  // receive a single update during their lifetime
1027  if (mChannel->getNrOfSlots() == 1)
1028  return get();
1029  // more than one data element in the channel but still not sufficient for interpolation
1030  // rethrow is our only option
1031  throw;
1032  }
1033 
1034  const Time t0 = data.begin()->timestamp;
1035 
1036  typedef typename ChannelReadInterval<T>::const_iterator const_iterator;
1037  typedef boost::transform_iterator<GetTime, const_iterator> GetTimeIterator;
1038  GetTimeIterator begin1 = GetTimeIterator(data.begin(), GetTime(t0));
1039  GetTimeIterator end1 = GetTimeIterator(data.end() , GetTime(t0));
1040 
1041  typedef boost::transform_iterator<GetValue, const_iterator> GetValueIterator;
1042 
1043  GetValueIterator begin2=GetValueIterator(data.begin(), GetValue());
1044  GetValueIterator end2 =GetValueIterator(data.end() , GetValue());
1045 
1046  typedef mira::IteratorRangeContainer<GetTimeIterator> TimeContainer;
1047  typedef mira::IteratorRangeContainer<GetValueIterator> ValueContainer;
1048  TimeContainer timeContainer(begin1, end1);
1049  ValueContainer valueContainer(begin2, end2);
1050 
1051  return makeStamped(filter.template apply<float, T>(timeContainer,
1052  valueContainer,
1053  (timestamp-t0).totalMilliseconds()),
1054  timestamp);
1055  }
1056 
1066  template <typename U = void>
1067  void post(const Stamped<T>& value) {
1068  validateWriteAccess();
1069  ChannelWrite<T> writeSlot = mChannel->write();
1070  *writeSlot = value;
1071  writeSlot.finish(); // explicit finish to avoid throwing in destructor
1072  }
1073 
1075  template <typename U = void>
1076  void post(Stamped<T>&& value) {
1077  validateWriteAccess();
1078  ChannelWrite<T> writeSlot = mChannel->write();
1079  *writeSlot = std::move(value);
1080  writeSlot.finish(); // explicit finish to avoid throwing in destructor
1081  }
1082 
1092  template <typename U>
1093  void post(U&& value, const Time& timestamp = Time::now()) {
1094  validateWriteAccess();
1095  ChannelWrite<T> writeSlot = mChannel->write();
1096  *writeSlot = makeStamped(std::forward<U>(value), timestamp);
1097  writeSlot.finish(); // explicit finish to avoid throwing in destructor
1098  }
1099 
1109  template <typename U = T>
1110  typename std::enable_if<!std::is_void<U>::value>::type
1111  post(const typename ParamHelper<T>::type& value, const Time& timestamp = Time::now()) {
1112  validateWriteAccess();
1113  ChannelWrite<T> writeSlot = mChannel->write();
1114  *writeSlot = makeStamped(value, timestamp);
1115  writeSlot.finish(); // explicit finish to avoid throwing in destructor
1116  }
1117 
1119  template <typename U = T>
1120  typename std::enable_if<!std::is_void<U>::value>::type
1121  post(typename ParamHelper<T>::type&& value, const Time& timestamp = Time::now()) {
1122  validateWriteAccess();
1123  ChannelWrite<T> writeSlot = mChannel->write();
1124  *writeSlot = makeStamped(std::move(value), timestamp);
1125  writeSlot.finish(); // explicit finish to avoid throwing in destructor
1126  }
1127 
1129 
1130 public:
1131 
1133  template<typename U>
1134  friend Channel<U> channel_cast(Channel<void> channel);
1136 
1137 public:
1138 
1140  void dbgDump(bool brief=true) { mChannel->dbgDump(brief); }
1142 
1143 private:
1144 
1145  void validateReadAccess() const
1146  {
1147  validate();
1148  if((mAccessFlags & CHANNEL_ACCESS_READ)==0)
1149  MIRA_THROW(XAccessViolation, "You are not allowed to read from channel '"
1150  << mChannel->getID() << "'. Forgot to subscribe?");
1151  }
1152 
1153  void validateWriteAccess() const
1154  {
1155  validate();
1156  if((mAccessFlags & CHANNEL_ACCESS_WRITE)==0)
1157  MIRA_THROW(XAccessViolation, "You are not allowed to write to channel '"
1158  << mChannel->getID() << "'. Forgot to publish?");
1159  }
1160 
1161 private:
1162 
1163  ConcreteChannel<T>* mChannel;
1164  ChannelAccessFlags mAccessFlags;
1165 };
1166 
1168 
1170 template<typename U>
1171 inline Channel<U> channel_cast(Channel<void> channel)
1172 {
1173  channel.validate();
1174  return Channel<U>(channel_cast<U>(channel.mChannel), channel.mAccessFlags);
1175 }
1177 
1179 
1180 } // namespace
1181 
1182 #include "impl/ChannelReadWrite.hpp"
1183 #include "impl/ChannelReadInterval.hpp"
1184 
1185 #endif
TypeMetaPtr getTypeMeta() const
Return the type meta information for this channel.
Definition: Channel.h:518
void post(U &&value, const Time &timestamp=Time::now())
Writes the specified data with the specified time stamp into the channel.
Definition: Channel.h:1093
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:477
Read access (Authority is a subscriber)
Definition: Channel.h:353
bool hasPublisher() const
Returns true, if this channel has at least one publisher.
Definition: Channel.h:560
void finish()
Releases the lock explicitly.
Definition: ChannelReadWrite.h:543
std::size_t getMaxSlots() const
Returns the upper limit of slots that are allowed for this channel.
Definition: Channel.h:576
void post(const Stamped< T > &value)
Writes the specified data into the channel.
Definition: Channel.h:1067
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:1076
Write access (Authority is a publisher)
Definition: Channel.h:354
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:745
void validate() const
Checks if the channel is valid otherwise throws an exception.
Definition: Channel.h:460
#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:434
std::string Typename
Definition: Typename.h:60
void setTypeMeta(TypeMetaPtr meta)
Set the type meta information for this channel.
Definition: Channel.h:526
bool isTyped() const
Returns true, if the channel is typed and false, if it is untyped.
Definition: Channel.h:495
An object that allows exclusive write access to data of a channel.
Definition: ChannelReadWrite.h:594
#define MIRA_DEFINE_SERIALIZABLE_EXCEPTION(Ex, Base)
Macro for easily defining a new serializable exception class.
Definition: Exceptions.h:66
Definition: ChannelReadWrite.h:65
An object that allows read access to data of a channel.
Definition: ChannelReadWrite.h:435
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:797
#define MIRA_THROW(ex, msg)
Macro for throwing an exception.
Definition: Exception.h:81
Typename getTypename() const
Return the typename of the channel.
Definition: Channel.h:501
void finish()
Releases the lock explicitly and informs the Channel to signal all Subscribers that new data is avail...
Definition: ChannelReadWrite.h:704
Wrapper class for boost::posix_time::ptime for adding more functionality to it.
Definition: Time.h:421
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:722
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:609
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:568
sec_type seconds() const
Returns normalized number of seconds (0..59)
Definition: Time.h:283
Use this class to represent time durations.
Definition: Time.h:104
ChannelRead< T > read(const Time &timestamp, const Duration &tolerance)
Same as above, but always takes the nearest slot.
Definition: Channel.h:764
ChannelRead< T > read()
Obtains read access to the latest data element of this channel.
Definition: Channel.h:697
void reset()
Reset the proxy object so that it becomes invalid.
Definition: Channel.h:442
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:860
The slot with smallest time difference to the requested will be chosen.
Definition: ChannelBuffer.h:103
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:510
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:1121
bool isAutoIncreasingStorageDuration() const
Returns whether the channel buffer is automatically increasing the storage duration.
Definition: Channel.h:601
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:1111
Duration getStorageDuration() const
Returns the timeframe that specifies how long a slot is guaranteed to be kept in the channel buffer...
Definition: Channel.h:593
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:194
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:552
static Duration infinity()
Returns a special duration time representing positive infinity.
Definition: Time.h:245
An iterator range class.
ChannelRead< T > waitForData(const Duration &timeout=Duration::infinity()) const
Waits until data in this channel becomes available.
Definition: Channel.h:635
Channel()
Create channel proxy that is not assigned to a channel.
Definition: Channel.h:429
ChannelWrite< T > write()
Obtains exclusive write access to the next free data slot of this channel.
Definition: Channel.h:843
No access at all (Authority is not a publisher nor a subscriber)
Definition: Channel.h:352
ChannelWrite< T > write(bool copyLatestData)
Same as write above with an additional parameter copyLatestData that allows you to specify whether th...
Definition: Channel.h:873
static Time now() static Time eternity()
Returns the current utc based time.
Definition: Time.h:484
std::size_t getMinSlots() const
Returns the number slots that are guaranteed to be kept in the channel buffer.
Definition: Channel.h:584
int getTypeId() const
Returns the type id of the channel.
Definition: Channel.h:487
Prefer filling the interval with slots with timestamp > requested.
Definition: ChannelBuffer.h:115
bool isValid() const
Returns true if the proxy object is valid.
Definition: Channel.h:451
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
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
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:95
Implements AbstractChannelSubscriber for a concrete data type.
Definition: ChannelSubscriber.h:82
void removeSubscriber(AbstractChannelSubscriberPtr subscriber)
Removes the specified subscriber from this channel and calls its detach() method. ...
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:544
bool waitForPublisher(const Duration &timeout=Duration::infinity()) const
Waits until this channel has at least one publisher.
Definition: Channel.h:667
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:822
ChannelAccessFlags
Flags specifying the access rights of an authority to a channel Can be combined.
Definition: Channel.h:351