MIRA
Authority.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_AUTHORITY_H_
48 #define _MIRA_AUTHORITY_H_
49 
50 #ifndef _MIRA_FRAMEWORK_H_
51 # error "Authority.h must be included via the Framework.h. You must not include it directly. Use #include <fw/Framework.h> instead"
52 #endif
53 
54 #include <utils/EnumToFlags.h>
55 #include <rpc/RPCFuture.h>
56 
58 
59 #include <serialization/adapters/std/set>
61 
62 #include <fw/AbstractAuthority.h>
63 #include <fw/AuthorityRuntime.h>
64 #include <fw/Channel.h>
66 #include <fw/RPCHandler.h>
68 
69 namespace mira {
70 
72 
73 // forward declarations
74 struct TransformDesc;
75 class AuthorityManager;
76 class FrameworkTransformerNode;
77 template<typename>
79 
81 
83 #define MIRA_HIDDEN_AUTHORITY_PREFIX "#"
84 
95 {
96 public:
97 
101  enum Flags
102  {
104  NORMAL = 0x0000,
105 
111  ANONYMOUS = 0x0001,
112 
117  HIDDEN = 0x0002,
118 
127 
132  INTERNAL = 0x000A,
133 
148 
162 
167  NO_MAIN_THREAD = 0x0040
168 
169  };
171 
172 public:
173 
179  Authority(Flags flags = NORMAL);
180 
196  Authority(const ResourceName& fullname, Flags flags = NORMAL);
197 
215  Authority(const ResourceName& ns, const std::string& name, Flags flags = NORMAL);
216 
232  Authority(Authority& iParent, const std::string& name, Flags flags = ANONYMOUS);
233 
241  ~Authority() override;
242 
244  template<typename Reflector>
245  void reflect(Reflector& r)
246  {
247  r.roproperty("Status", &getStatusManager(), "The status of this authority");
248  r.property("HeartbeatInterval",
249  getter<Duration>(&DiagnosticsModule::getHeartbeatInterval,
250  (DiagnosticsModule*)this),
251  setter<Duration>(&DiagnosticsModule::setHeartbeatInterval,
252  (DiagnosticsModule*)this),
253  "The interval of the watchdog",
255  }
256 
257 public:
265 
279  void checkin(const ResourceName& fullname,
281 
296  void checkin(const ResourceName& ns, const std::string& name,
298 
311  void checkin(Authority& iParent, const ResourceName& ns,
312  const std::string& name);
313 
326  void checkin(Authority& iParent, const std::string& name);
327 
337  void checkout();
338 
343  bool isValid() const {
344  return mValid;
345  }
346 
351  void validate() const {
352  if ( !isValid() )
353  MIRA_THROW(XInvalidConfig, "Authority is not registered.");
354  }
355 
365  void startWithParent(bool start) {
366  mStartWithParent = start;
367  }
368 
376  return mRuntime;
377  }
378 
382  std::set<Authority*> getChildren() {
383  return mChildren;
384  }
385 
392 
399  template <typename F>
400  void addImmediateHandlerFunction(F&& fn);
401 
409 
416  template <typename F>
417  void addFinalizeHandlerFunction(F&& fn);
418 
428  TimerPtr createTimer(Duration period, TimerCallback callback,
429  bool oneshot=false);
430 
443  TimerPtr createTimer(Duration period, Duration tolerance,
444  TimerCallback callback, bool oneshot=false);
445 
447  template<typename Class>
449  void (Class::*f)(const Timer&), Class* obj,
450  bool oneshot=false);
451 
453  template<typename Class>
454  TimerPtr createTimer(Duration period, void (Class::*f)(const Timer&),
455  bool oneshot=false);
456 
458  template<typename Class>
459  TimerPtr createTimer(Duration period, Duration tolerance,
460  void (Class::*f)(const Timer&), Class* obj,
461  bool oneshot=false);
462 
464  template<typename Class>
465  TimerPtr createTimer(Duration period, Duration tolerance,
466  void (Class::*f)(const Timer&), bool oneshot=false);
467 
475  TimerPtr createTimer(Time time, TimerCallback callback);
476 
478  template<typename Class>
479  TimerPtr createTimer(Time time, void (Class::*f)(const Timer&), Class* obj);
480 
482  template<typename Class>
483  TimerPtr createTimer(Time time, void (Class::*f)(const Timer&));
484 
490  void removeTimer(TimerPtr timer);
491 
503  void start() override;
504 
514  void stop() override;
515 
530  bool spin(const Duration& maxWait = Duration::infinity());
531 
537  [[nodiscard]] bool hasWork(Time horizon = Time::now()) const;
538 
546  bool hasUnrecoverableFailure() const override;
547 
552  bool isStarted() const override;
553 
558  bool isRunning() const override;
559 
561 
562 public:
563 
569  void enableSubscriberCallbacks(bool enable);
570 
571 public:
572 
574  // Channel framework
581 
588  std::string resolveName(const std::string& name) const;
589 
598  std::string resolveServiceName(const std::string& name) const;
599 
618  template<typename T>
619  Channel<T> publish(const std::string& channelID)
620  {
621  static_assert(std::is_void<T>::value!=true,
622  "You must specify a typename for untyped channels");
623  return publish<T>(channelID, typeName<T>());
624  }
625 
630  template<typename T>
631  Channel<T> publish(const std::string& channelID, const Typename& type);
632 
639  void unpublish(const std::string& channelID);
640 
666  template<typename T>
667  Channel<T> subscribe(const std::string& channelID,
668  const Duration& storageDuration = Duration::seconds(0));
669 
702  template<typename T>
703  Channel<T> subscribe(const std::string& channelID,
704  boost::function<void (ChannelRead<T>)> fn,
705  const Duration& storageDuration = Duration::seconds(0),
706  bool independentThread = false);
707 
709  template<typename T>
710  Channel<T> subscribe(const std::string& channelID,
711  boost::function<void (ChannelRead<T>)> fn,
712  bool independentThread);
713 
719  template<typename T, typename Class>
720  Channel<T> subscribe(const std::string& channelID,
721  void (Class::*f)(ChannelRead<T>),
722  Class* obj,
723  const Duration& storageDuration = Duration::seconds(0),
724  bool independentThread = false);
725 
731  template<typename T, typename Class>
732  Channel<T> subscribe(const std::string& channelID,
733  void (Class::*f)(ChannelRead<T>),
734  Class* obj, bool independentThread);
735 
757  template<typename T, typename Class>
758  Channel<T> subscribe(const std::string& channelID,
759  void (Class::*f)(ChannelRead<T>),
760  const Duration& storageDuration = Duration::seconds(0),
761  bool independentThread = false)
762  {
763  Class* obj = dynamic_cast<Class*>(this);
764  assert(obj!=NULL &&
765  "Called 'Authority::subscribe(..., Class::member, ...)' on an object that is not "
766  "of type Class (you may need to provide a pointer to the correct object)!");
767  return subscribe<T>(channelID, f, obj, storageDuration, independentThread);
768  }
769 
774  template<typename T, typename Class>
775  Channel<T> subscribe(const std::string& channelID,
776  void (Class::*f)(ChannelRead<T>), bool independentThread)
777  {
778  Class* obj = dynamic_cast<Class*>(this);
779  assert(obj!=NULL &&
780  "Called 'Authority::subscribe(..., Class::member, ...)' on an object that is not "
781  "of type Class (you may need to provide a pointer to the correct object)!");
782  return subscribe<T>(channelID, f, obj, independentThread);
783  }
784 
806  template<typename T>
807  Channel<T> publishAndSubscribe(const std::string& channelID,
808  const Duration& storageDuration = Duration::seconds(0));
809 
838  template<typename T>
839  Channel<T> publishAndSubscribe(const std::string& channelID,
840  boost::function<void (ChannelRead<T>)> fn,
841  const Duration& storageDuration = Duration::seconds(0),
842  bool independentThread = false);
843 
845  template<typename T>
846  Channel<T> publishAndSubscribe(const std::string& channelID,
847  boost::function<void (ChannelRead<T>)> fn,
848  bool independentThread);
849 
855  template<typename T, typename Class>
856  Channel<T> publishAndSubscribe(const std::string& channelID,
857  void (Class::*f)(ChannelRead<T>),
858  Class* obj,
859  const Duration& storageDuration = Duration::seconds(0),
860  bool independentThread = false);
861 
867  template<typename T, typename Class>
868  Channel<T> publishAndSubscribe(const std::string& channelID,
869  void (Class::*f)(ChannelRead<T>),
870  Class* obj, bool independentThread);
871 
893  template<typename T, typename Class>
894  Channel<T> publishAndSubscribe(const std::string& channelID,
895  void (Class::*f)(ChannelRead<T>),
896  const Duration& storageDuration = Duration::seconds(0),
897  bool independentThread = false)
898  {
899  Class* obj = dynamic_cast<Class*>(this);
900  assert(obj!=NULL);
901  return publishAndSubscribe<T>(channelID, f, obj, storageDuration, independentThread);
902  }
903 
908  template<typename T, typename Class>
909  Channel<T> publishAndSubscribe(const std::string& channelID,
910  void (Class::*f)(ChannelRead<T>),
911  bool independentThread)
912  {
913  Class* obj = dynamic_cast<Class*>(this);
914  assert(obj!=NULL);
915  return publishAndSubscribe<T>(channelID, f, obj, independentThread);
916  }
917 
960  template<typename T>
961  Channel<T> subscribeInterval(const std::string& channelID,
962  boost::function<void (ChannelReadInterval<T>)> fn,
963  const Duration& storageDuration,
964  bool independentThread = false,
965  const Time& startAfter = Time::unixEpoch());
966 
967  /*
968  * Provided for simplified registration of a member function as callback
969  * function. See the above subscribe methods for more details.
970  */
971  template<typename T, typename Class>
972  Channel<T> subscribeInterval(const std::string& channelID,
973  void (Class::*f)(ChannelReadInterval<T>),
974  Class* obj,
975  const Duration& storageDuration,
976  bool independentThread = false,
977  const Time& startAfter = Time::unixEpoch());
978 
983  template<typename T, typename Class>
984  Channel<T> subscribeInterval(const std::string& channelID,
985  void (Class::*f)(ChannelReadInterval<T>),
986  const Duration& storageDuration,
987  bool independentThread = false,
988  const Time& startAfter = Time::unixEpoch());
989 
996  template<typename T, typename Class>
997  Channel<T> subscribeIntervalByElements(const std::string& channelID,
998  void (Class::*f)(ChannelRead<T>),
999  Class* obj,
1000  const Duration& storageDuration = Duration::seconds(0),
1001  bool independentThread = false,
1002  const Time& startAfter = Time::unixEpoch());
1003 
1008  template <typename T>
1009  Channel<T> subscribeIntervalByElements(const std::string& channelID,
1010  boost::function<void(ChannelRead<T>)>,
1011  const Duration& storageDuration = Duration::seconds(0),
1012  bool independentThread = false,
1013  const Time& startAfter = Time::unixEpoch());
1014 
1020  template<typename T, typename Class>
1021  Channel<T> subscribeIntervalByElements(const std::string& channelID,
1022  void (Class::*f)(ChannelRead<T>),
1023  const Duration& storageDuration = Duration::seconds(0),
1024  bool independentThread = false,
1025  const Time& startAfter = Time::unixEpoch());
1026 
1038  template <typename T>
1040  Duration timeout = Duration::infinity()) const;
1041 
1054  void unsubscribe(const std::string& channelID);
1055 
1061  template <typename T>
1062  void unsubscribe(const std::string& channelID);
1063 
1081  template <typename T>
1082  Channel<T> getChannel(const std::string& channelID);
1083 
1087  bool isSubscribedOn(const std::string& channelID) const;
1088 
1089  MIRA_DEPRECATED("Please use isSubscribedOn() instead",
1091  bool hasSubscribedOn(const std::string& channelID) const) {
1092  return isSubscribedOn(channelID);
1093  }
1094 
1098  bool hasPublished(const std::string& channelID) const;
1099 
1103  bool doesChannelExist(const std::string& channelID) const;
1104 
1108  bool waitForChannel(const std::string& channelID,
1109  const Duration& timeout = Duration::infinity()) const;
1110 
1112 
1113 public:
1114 
1116  // Transform framework
1117 
1123 
1134  bool isTransformAvailable(const std::string& targetID, const std::string& sourceID) const;
1135 
1147  bool isTransformAvailable(const std::string& targetID, const std::string& sourceID,
1148  const std::string& fixedID) const;
1149 
1161  bool waitForTransform(const std::string& targetID, const std::string& sourceID,
1162  Duration timeout = Duration::invalid()) const;
1163 
1176  bool waitForTransform(const std::string& targetID, const std::string& sourceID,
1177  const std::string& fixedID, Duration timeout = Duration::invalid()) const;
1178 
1179 
1203  template<typename Transform, typename Filter>
1204  void subscribeTransform(const std::string& targetID,
1205  const std::string& sourceID,
1206  boost::function<void (Transform, Time)> fn,
1207  Filter&& filter);
1208 
1214  template<typename Transform, typename Filter, typename Class>
1215  void subscribeTransform(const std::string& targetID,
1216  const std::string& sourceID,
1217  void (Class::*f)(Transform, Time), Class* obj,
1218  Filter&& filter);
1219 
1225  template<typename Transform, typename Filter, typename Class>
1226  void subscribeTransform(const std::string& targetID,
1227  const std::string& sourceID,
1228  void (Class::*f)(Transform, Time),
1229  Filter&& filter);
1230 
1253  template<typename Transform>
1254  void subscribeTransform(const std::string& targetID,
1255  const std::string& sourceID,
1256  boost::function<void (Transform, Time)> fn);
1257 
1263  template<typename Transform, typename Class>
1264  void subscribeTransform(const std::string& targetID,
1265  const std::string& sourceID,
1266  void (Class::*f)(Transform, Time), Class* obj);
1267 
1273  template<typename Transform, typename Class>
1274  void subscribeTransform(const std::string& targetID,
1275  const std::string& sourceID,
1276  void (Class::*f)(Transform, Time));
1277 
1278 
1279 
1292  template<typename Transform, typename Filter>
1293  Transform getTransform(const std::string& targetID,
1294  const std::string& sourceID,
1295  const Time& time, Filter&& filter) const;
1296 
1305  template<typename Transform>
1306  Transform getTransform(const std::string& targetID,
1307  const std::string& sourceID,
1308  const Time& time = Time()) const
1309  {
1310  return getTransform<Transform>(targetID, sourceID, time,
1312  }
1313 
1343  template<typename Transform, typename Filter>
1344  Transform getTransform(const std::string& targetID, const Time& targetTime,
1345  const std::string& sourceID, const Time& sourceTime,
1346  const std::string& fixedID,
1347  Filter&& filter) const;
1348 
1357  template<typename Transform>
1358  Transform getTransform(const std::string& targetID, const Time& targetTime,
1359  const std::string& sourceID, const Time& sourceTime,
1360  const std::string& fixedID) const
1361  {
1362  return getTransform<Transform>(targetID, targetTime, sourceID,
1363  sourceTime, fixedID,
1365  }
1366 
1367 
1368 
1369 
1377  FrameworkTransformerNode* getTransformNode(const std::string& frameID) const;
1378 
1393  TransformDesc prepareTransform(const std::string& targetID,
1394  const std::string& sourceID) const;
1395 
1414  TransformDesc prepareTransform(const std::string& targetID,
1415  const std::string& sourceID,
1416  const std::string& fixedID) const;
1417 
1428  template<typename Transform, typename Filter>
1429  Transform getTransform(const TransformDesc& desc, const Time& time,
1430  Filter&& filter) const;
1431 
1439  template<typename Transform>
1440  Transform getTransform(const TransformDesc& desc, const Time& time = Time()) const
1441  {
1442  return getTransform<Transform>(desc, time, NearestNeighborInterpolator());
1443  }
1444 
1459  template<typename Transform, typename Filter>
1460  Transform getTransform(const TransformDesc& desc, const Time& targetTime,
1461  const Time& sourceTime, Filter&& filter) const;
1462 
1469  template<typename Transform>
1470  Transform getTransform(const TransformDesc& desc, const Time& targetTime,
1471  const Time& sourceTime) const
1472  {
1473  return getTransform<Transform>(desc, targetTime, sourceTime,
1475  }
1476 
1484  template<typename Transform>
1485  void publishTransform(const std::string& frameID, const Transform& transform,
1486  const Time& time) const;
1487 
1517  template<typename Transform, typename Filter = NearestNeighborInterpolator>
1518  void publishTransformIndirect(const std::string& frameID,
1519  const std::string& targetID,
1520  const std::string& sourceID,
1521  const Transform& transform, const Time& time,
1522  Filter&& filter = NearestNeighborInterpolator()) const;
1523 
1531  void addTransformLink(const std::string& childID, const std::string& parentID) const;
1532 
1542  void addTransformLink(const std::string& childID,
1543  const std::string& parentID,
1545 
1547 
1548 public:
1549 
1551  // RPC Framework
1552 
1558 
1569  template<typename Service>
1570  void publishService(const std::string& name, Service& iService,
1571  RPCHandlerPtr handler = RPCHandlerPtr());
1572 
1580  template<typename Service>
1581  void publishService(Service& iService,
1582  RPCHandlerPtr handler = RPCHandlerPtr());
1583 
1588  void unpublishService();
1589 
1594  void unpublishService(const std::string& name);
1595 
1631  template<typename R, typename... ARGS>
1632  inline RPCFuture<R> callService(const std::string& iService, const std::string& method,
1633  ARGS&&... args) const;
1634 
1658  RPCFuture<JSONRPCResponse> callServiceJSON(const json::Value& jsonRequest) const;
1659 
1666  RPCFuture<JSONRPCResponse> callServiceJSON(const std::string& jsonString) const;
1667 
1681  RPCFuture<JSONRPCResponse> callServiceJSON(const std::string& service,
1682  const std::string& method,
1683  const json::Value& params = json::Value()) const;
1684 
1696  RPCFuture<JSONRPCResponse> callServiceJSON(const std::string& service,
1697  const std::string& method,
1698  const std::string& params) const;
1699 
1708 
1720  template<class F>
1721  [[nodiscard]] ServiceCall<F> createServiceCall(const std::string& service, std::string method,
1722  bool waitTillExists = true, bool showBootupMsg = true);
1723 
1727  bool existsService(const std::string& name) const;
1728 
1733  bool implementsInterface(const std::string& name,
1734  const std::string& interface) const;
1735 
1743  bool waitForService(const std::string& name,
1744  Duration timeout = Duration::invalid()) const;
1745 
1754  std::string waitForServiceInterface(const std::string& interface,
1755  Duration timeout = Duration::invalid()) const;
1756 
1761  std::list<std::string> queryServicesForInterface(const std::string& interface) const;
1762 
1772  void registerCallbackForInterface(const std::string& interface,
1774 
1779  template<typename Class>
1780  void registerCallbackForInterface(const std::string& interface,
1781  void (Class::*f)(const std::string&,
1782  const std::string&),
1783  Class* obj);
1784 
1786 
1787 public:
1788 
1790 
1794  //{@
1795 
1797 
1798  boost::shared_ptr<PropertyNode> getProperties() override;
1799 
1800  std::set<std::string> getPublishedChannels() override;
1801 
1802  std::set<std::string> getSubscribedChannels() override;
1803 
1804  std::set<std::string> getServiceInterfaces() override;
1805 
1807 
1809 
1811 
1813 
1814 protected:
1815 
1816  template<typename T>
1818 
1819  void setChannelReadAccess(const std::string& channelID);
1820  void setChannelWriteAccess(const std::string& channelID);
1821  void removeChannelReadAccess(const std::string& channelID);
1822  void removeChannelWriteAccess(const std::string& channelID);
1824  const std::string& local,
1825  const std::string& global);
1827  const std::string& local,
1828  const std::string& global);
1829 
1830  void remotePublishService(const std::string& service) const;
1831 
1832  friend struct AuthorityService;
1833  friend class AuthorityManager;
1834 
1836 
1837  void setProperty(const std::string& property, const std::string& value);
1838  std::string getProperty(const std::string& property) const;
1839  void setPropertyJSON(const std::string& property, const json::Value& value);
1840  json::Value getPropertyJSON(const std::string& property) const;
1841 
1842 protected:
1843 
1845  struct RWAccessFlags {
1848  };
1849 
1850  typedef std::map<std::string, RWAccessFlags> RWAccessMap;
1851  typedef std::list<AbstractChannelSubscriberPtr> SubscribePtrList;
1852 
1853 private:
1854 
1855  void init();
1856 
1857 private:
1858 
1860  AuthorityRuntimePtr mRuntime;
1862  bool mOwnsRuntime;
1864  bool mValid;
1866  bool mStarted;
1868  bool mIsInternal;
1870  bool mIsInvisiblePublisherSubscriber;
1871 
1872  Flags mFlags;
1874  RWAccessMap mAccessMap;
1876  Authority* mParent;
1878  bool mStartWithParent;
1880  std::set<Authority*> mChildren;
1881 
1883  bool mSubscriberEnabled;
1884 
1885  typedef boost::shared_ptr<DispatcherThread> DispatcherThreadPtr;
1886 
1892  typedef std::list<DispatcherThreadPtr> IndependentSubscribers;
1893 
1895  IndependentSubscribers mIndependentSubscriberDispatchers;
1896 
1898  DispatcherThreadPtr mSubscriberDispatcher;
1900  DispatcherThreadPtr mRPCDispatcher;
1901 
1903  RPCHandlerPtr mRPCHandler;
1905  ServiceInterfaceHandlerPtr mServiceInterfaceHandler;
1907  SubscribePtrList mSubscriberList;
1909  std::set<std::string> mPublishedServices;
1911  boost::mutex mNameMutex;
1913  ChannelNameMapping mPublishedChannelNames;
1915  ChannelNameMapping mSubscribedChannelNames;
1917  StatusManager mStatusManager;
1918 };
1919 
1921 typedef boost::shared_ptr<Authority> AuthorityPtr;
1922 
1924 
1925 } // namespace
1926 
1927 #endif
Definition: FrameworkTransformer.h:74
boost::shared_ptr< RPCHandler > RPCHandlerPtr
Definition: RPCHandler.h:101
RWAccessFlags()
Definition: Authority.h:1846
An object that allows read access to a whole interval of channel data.
Definition: ChannelReadInterval.h:72
bool doesChannelExist(const std::string &channelID) const
Returns if a channel with the given channel id exists.
Transform getTransform(const std::string &targetID, const std::string &sourceID, const Time &time, Filter &&filter) const
Get a transformation from source to target frame at a given time stamp.
Manages the status of one or multiple modules inheriting from DiagnosticsModule.
Definition: Status.h:289
static Duration invalid()
Returns an invalid duration.
Definition: Time.h:249
Instructs the authority to use a separate and independent thread for handling RPC requests...
Definition: Authority.h:161
Channel< T > getChannel(const std::string &channelID)
Returns channel object that can be used to obtain read and write access on the channel.
void removeChannelWriteAccess(const std::string &channelID)
Channel access flags.
Definition: Authority.h:1845
bool isValid() const
Returns true, if this Authority was initialized and is checked in, otherwise false.
Definition: Authority.h:343
std::string resolveServiceName(const std::string &name) const
Resolves the given name of the service by taking the namespace of the authority into account...
DispatcherThread::TimerPtr TimerPtr
Definition: DispatcherThread.h:524
An exception that occurs whenever a channel has no data.
Definition: Channel.h:88
boost::function< void(const std::string &, const std::string &)> Callback
Definition: ServiceInterfaceHandler.h:72
Normally authorities must have a unique name.
Definition: Authority.h:104
Transform getTransform(const std::string &targetID, const Time &targetTime, const std::string &sourceID, const Time &sourceTime, const std::string &fixedID) const
Definition: Authority.h:1358
ChannelNameMapping getPublishedChannelNames() override
Returns all published channels (pair of global and local names) by this authority (and its sub-author...
AuthorityRuntimePtr getRuntime()
Returns a shared_ptr to the runtime that this authority uses.
Definition: Authority.h:375
boost::shared_ptr< Authority > AuthorityPtr
Typedef for Authority pointers.
Definition: Authority.h:1921
void addImmediateHandler(DiagnosticRunnablePtr runnable)
Adds a runnable that is invoked immediately.
Class representing timers and tasks that can be registered and executed by the dispatcher thread...
Definition: DispatcherThread.h:146
void setHeartbeatInterval(const Duration &interval)
Set the watchdog interval.
Definition: Status.h:151
void publishTransformIndirect(const std::string &frameID, const std::string &targetID, const std::string &sourceID, const Transform &transform, const Time &time, Filter &&filter=NearestNeighborInterpolator()) const
Publish a transformation (frameID) indirect by specifying a direct transform between two nodes (sourc...
Macros for generating logical operators for using enum values as flags.
Transform getTransform(const TransformDesc &desc, const Time &targetTime, const Time &sourceTime) const
Definition: Authority.h:1470
1D nearest neighbor interpolator.
Definition: NearestNeighborInterpolator.h:68
std::set< std::string > getSubscribedChannels() override
Returns all subscribed channels by this authority (and its sub-authorities)
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
void removeChannelReadAccess(const std::string &channelID)
std::string Typename
Definition: Typename.h:60
Channel< T > subscribe(const std::string &channelID, void(Class::*f)(ChannelRead< T >), const Duration &storageDuration=Duration::seconds(0), bool independentThread=false)
Provided for simplified registration of a member function of a class as callback. ...
Definition: Authority.h:758
std::set< std::string > getPublishedChannels() override
Returns all published channels by this authority (and its sub-authorities)
void unpublish(const std::string &channelID)
Unpublish a channel with the given channel id.
void setPropertyJSON(const std::string &property, const json::Value &value)
MIRA_DEPRECATED("Please use isSubscribedOn() instead", bool hasSubscribedOn(const std::string &channelID) const)
Definition: Authority.h:1089
void publishTransform(const std::string &frameID, const Transform &transform, const Time &time) const
Publish a transformation for a given frame.
void unpublishService()
Unpublish this service by unregistering the service with the id of the authority from the RPC manager...
Class object which supports some kind of class reflection.
Definition: Class.h:97
std::list< AbstractChannelSubscriberPtr > SubscribePtrList
Definition: Authority.h:1851
void addFinalizeHandlerFunction(F &&fn)
Adds a function that is executed ONCE just before the thread terminates.
void addTransformLink(const std::string &childID, const std::string &parentID) const
Add a transformation link between the given child and parent.
void addFinalizeHandler(DiagnosticRunnablePtr runnable)
Adds a runnable that is executed ONCE just before the thread terminates.
For Authorities that are not shown by default to the user.
Definition: Authority.h:117
TimerPtr createTimer(Duration period, TimerCallback callback, bool oneshot=false)
Creates and adds a timer that gets called cyclic in a given period (if oneshot is false) and calls th...
However sometimes more than one instance is created of an authority where the name does not matter an...
Definition: Authority.h:111
bool isStarted() const override
Returns true, if the authority was started (by calling start()).
std::multimap< std::string, Status > StatusMap
Definition: Status.h:293
bool waitForTransform(const std::string &targetID, const std::string &sourceID, Duration timeout=Duration::invalid()) const
Waits until a transform from source frame to target frame is available.
Implementation of RPCFuture.
Transform getTransform(const std::string &targetID, const std::string &sourceID, const Time &time=Time()) const
Definition: Authority.h:1306
static Time unixEpoch()
Returns the unix epoch 1.1.1970 0:0:0.000.
Definition: Time.h:506
Definition: ChannelReadWrite.h:67
FrameworkTransformerNode * getTransformNode(const std::string &frameID) const
Get a transformation node for the given frame.
std::map< std::string, Status > ChannelStatusMap
Definition: AbstractAuthority.h:141
Abstract base class of authorities.
An RPCFuture is a proxy for the result of an asynchronous RPC call.
Definition: RPCFuture.h:173
An object that allows read access to data of a channel.
Definition: ChannelReadWrite.h:494
bool waitForChannel(const std::string &channelID, const Duration &timeout=Duration::infinity()) const
Waits until a channel with the given channel id becomes available.
void unsubscribe(const std::string &channelID)
Unsubscribe from a given channel.
Flags
Flags for creating an authority.
Definition: Authority.h:101
#define MIRA_ENUM_TO_FLAGS_INCLASS(EnumType)
Macro that can be used with enums that contain flags.
Definition: EnumToFlags.h:143
#define MIRA_THROW(ex, msg)
Macro for throwing an exception.
Definition: Exception.h:78
Channel< T > publish(const std::string &channelID)
Publishes a channel with the given id and marks the authority as a publisher of this channel...
Definition: Authority.h:619
std::string getProperty(const std::string &property) const
Duration getHeartbeatInterval() const
Return the watchdog interval.
Definition: Status.h:164
void enableSubscriberCallbacks(bool enable)
Enables/disables subscriptions.
Wrapper class for boost::posix_time::ptime for adding more functionality to it.
Definition: Time.h:418
void removeTimer(TimerPtr timer)
Removes the given timer (timer callback will not be called again and timer will not be rescheduled)...
Transformer manages and provides access to the transformation tree of the framework.
ChannelStatusMap getSubscribedChannelStatus() override
Returns status for all subscribed channels (ok, no publisher, no data, ...) by this authority (and it...
void registerCallbackForInterface(const std::string &interface, ServiceInterfaceHandler::Callback cb)
Registers a callback that is called whenever a service registers the given interface, which is specified as first parameter.
Instructs the authority to use a separate and independent thread for handling subscriber callbacks...
Definition: Authority.h:147
ChannelNameMapping getSubscribedChannelNames() override
Returns all subscribed channels (pair of global and local names) by this authority (and its sub-autho...
bool waitForService(const std::string &name, Duration timeout=Duration::invalid()) const
Waits until a service with the specified name becomes available.
bool isTransformAvailable(const std::string &targetID, const std::string &sourceID) const
Checks if a transform from source frame to target frame is available.
Marker for indicating parameters that should be ignored if they are missing in the config file...
Definition: IgnoreMissing.h:73
Helper class for representing the tree structure of properties.
void setProperty(const std::string &property, const std::string &value)
StatusManager & getStatusManager()
void publishService(const std::string &name, Service &iService, RPCHandlerPtr handler=RPCHandlerPtr())
Publish a service to register RPC functions at the RPC manager.
Filter that returns the nearest neighbor.
bool spin(const Duration &maxWait=Duration::infinity())
Executes a single step of the main dispatcher of this authority.
void insertChannelNameMapping(AbstractAuthority::ChannelNameMapping &map, const std::string &local, const std::string &global)
Channel< T > subscribeIntervalByElements(const std::string &channelID, void(Class::*f)(ChannelRead< T >), Class *obj, const Duration &storageDuration=Duration::seconds(0), bool independentThread=false, const Time &startAfter=Time::unixEpoch())
Provided for simplified registration of a member function taking a simple ChannelRead as parameter...
DispatcherThread::TimerCallback TimerCallback
Definition: DispatcherThread.h:525
Channel< T > subscribe(const std::string &channelID, void(Class::*f)(ChannelRead< T >), bool independentThread)
Provided for simplified registration of a member function as callback.
Definition: Authority.h:775
TransformDesc prepareTransform(const std::string &targetID, const std::string &sourceID) const
Prepares a transformation chain from a source node to a target node.
std::list< std::string > queryServicesForInterface(const std::string &interface) const
Returns a string list with the names of all registered services, that implement the specified interfa...
std::string waitForServiceInterface(const std::string &interface, Duration timeout=Duration::invalid()) const
Waits until a service with the specified interface becomes available.
Class for storing/combining/managing resource names consisting of namespaces and names separated by &#39;...
Definition: ResourceName.h:67
Authority(Flags flags=NORMAL)
Creates an invalid (not yet checked in) authority by optionally providing a combination of flags...
PropertyHint type(const std::string &t)
Sets the attribute "type" to the specified value.
Definition: PropertyHint.h:295
This is a specialization for JSON RPC calls.
Definition: RPCFuture.h:315
sec_type seconds() const
Returns normalized number of seconds (0..59)
Definition: Time.h:280
std::set< std::string > getServiceInterfaces() override
Returns all service interfaces provided by this authority.
Use this class to represent time durations.
Definition: Time.h:106
bool isRunning() const override
Return if the authority&#39;s main dispatcher is running.
bool hasWork(Time horizon=Time::now()) const
Checks if the main dispatcher thread of this authority has work that must be executed till horizon...
void eraseChannelNameMapping(AbstractAuthority::ChannelNameMapping &map, const std::string &local, const std::string &global)
boost::shared_ptr< AuthorityRuntime > AuthorityRuntimePtr
Pointer of AuthorityRuntime.
Definition: AuthorityRuntime.h:98
Authorities act as a facade to the framework.
Definition: Authority.h:94
boost::shared_ptr< ServiceInterfaceHandler > ServiceInterfaceHandlerPtr
Definition: ServiceInterfaceHandler.h:94
boost::shared_ptr< DiagnosticRunnable > DiagnosticRunnablePtr
Definition: Runnable.h:107
Authorities with this flag set are invisible subscribers and publishers for channels e...
Definition: Authority.h:126
PropertyTree getPropertiesRPC()
ChannelRead< T > waitForData(Channel< T > channel, Duration timeout=Duration::infinity()) const
Waits until data in the specified channel becomes available.
void setChannelReadAccess(const std::string &channelID)
static Time now()
Returns the current utc based time.
Definition: Time.h:481
Describes a path of transformations through the transformation tree.
Definition: Transformer.h:229
void addImmediateHandlerFunction(F &&fn)
Adds a handler function that is invoked immediately.
std::set< Authority * > getChildren()
Returns a set with all children / sub-authorities.
Definition: Authority.h:382
Type
Definition: FrameworkTransformer.h:79
bool hasPublished(const std::string &channelID) const
Returns if this authority has published a channel with the given channel id.
Framework channel classes.
void stop() override
Stops/Pauses the main dispatcher thread as well as channel subscriber and RPC threads, if exist, and disables channel callbacks subscribed by this authority.
Signal handler class for signaling when service interfaces get available.
void checkout()
Checks out and therefore invalidates the authority.
Channel< T > publishAndSubscribe(const std::string &channelID, void(Class::*f)(ChannelRead< T >), const Duration &storageDuration=Duration::seconds(0), bool independentThread=false)
Provided for simplified registration of a member function of a class as callback. ...
Definition: Authority.h:894
static Duration infinity()
Returns a special duration time representing positive infinity.
Definition: Time.h:242
json_spirit::mValue Value
A value is an abstract description of data in JSON (underlying data can either be one of the JSON bas...
Definition: JSON.h:174
Central instance that stores all created Authorities.
Definition: AuthorityManager.h:130
Channel< T > publishAndSubscribe(const std::string &channelID, const Duration &storageDuration=Duration::seconds(0))
Publishes a channel with the given id and marks the authority as a publisher of this channel...
Signal handler class for RPC calls.
RPCFuture< R > callService(const std::string &iService, const std::string &method, ARGS &&... args) const
Performs an RPC call.
bool hasUnrecoverableFailure() const override
Returns true, if there was a failure while processing the immediate handlers.
No access at all (Authority is not a publisher nor a subscriber)
Definition: Channel.h:333
bool isSubscribedOn(const std::string &channelID) const
Returns if this authority is subscribed to a channel with the given channel id.
~Authority() override
The destructor.
std::string resolveName(const std::string &name) const
Resolve a given name by taking the namespace of the authority into account.
void subscribeTransform(const std::string &targetID, const std::string &sourceID, boost::function< void(Transform, Time)> fn, Filter &&filter)
Subscribes to a transformation between the given target and source frame.
void validate() const
Check if authority is checked in and therefore valid.
Definition: Authority.h:351
boost::shared_ptr< PropertyNode > getProperties() override
Returns the main property node of this Authority.
Channel< T > subscribeInterval(const std::string &channelID, boost::function< void(ChannelReadInterval< T >)> fn, const Duration &storageDuration, bool independentThread=false, const Time &startAfter=Time::unixEpoch())
Subscribes authority to a given channel.
void startWithParent(bool start)
Select whether the authority should be started when its parent authority starts (only meaningful if i...
Definition: Authority.h:365
void reflect(Reflector &r)
reflect method
Definition: Authority.h:245
Authorities with this flag set are automatically HIDDEN and are invisible to remote frameworks (inter...
Definition: Authority.h:132
This is the abstract base class of local and remote authority classes.
Definition: AbstractAuthority.h:76
bool existsService(const std::string &name) const
Returns true, if a service with the given name exists, otherwise false.
std::map< std::string, RWAccessFlags > RWAccessMap
Definition: Authority.h:1850
void remotePublishService(const std::string &service) const
void setChannelWriteAccess(const std::string &channelID)
bool implementsInterface(const std::string &name, const std::string &interface) const
Returns true, if a service with the given name implements the given interface, otherwise false...
ServiceCall< F > createServiceCall(const std::string &service, std::string method, bool waitTillExists=true, bool showBootupMsg=true)
Create a ServiceCall object.
Stores info required to call an RPC method - service name, method name, arguments.
Definition: RPCCallDefinition.h:62
json::Value getPropertyJSON(const std::string &property) const
RPCFuture< JSONRPCResponse > callServiceJSON(const json::Value &jsonRequest) const
Invokes a JSON RPC call.
void checkin(const ResourceName &fullname, AuthorityRuntimePtr runtime=AuthorityRuntimePtr())
Checks in and therefore makes the authority valid by providing a namespace and a name that are given ...
Transform getTransform(const TransformDesc &desc, const Time &time=Time()) const
Definition: Authority.h:1440
Definition: Authority.h:78
Does not start a thread for processing the main dispatcher, instead the user needs to call the spin()...
Definition: Authority.h:167
std::multimap< std::string, std::string > ChannelNameMapping
Definition: AbstractAuthority.h:139
ChannelAccessFlags flags
Definition: Authority.h:1847
Channel< T > subscribe(const std::string &channelID, const Duration &storageDuration=Duration::seconds(0))
Subscribes authority to a given channel.
Runtime class containing the threading related parts of authorities.
Base class for modules that want to use diagnostics and set the current status.
Definition: Status.h:136
Helper class that is able to hold a complete property tree structure.
Definition: PropertyTree.h:86
Channel< T > publishAndSubscribe(const std::string &channelID, void(Class::*f)(ChannelRead< T >), bool independentThread)
Provided for simplified registration of a member function as callback.
Definition: Authority.h:909
friend struct AuthorityService
Definition: Authority.h:1832
void start() override
Starts/Resumes the main dispatcher thread, e.g.
Channel< T > toProxy(ConcreteChannel< T > *channel)
StatusManager::StatusMap getStatusMap() override
Return a status map that contains the status of the authority as well as all registered submodules...
ChannelAccessFlags
Flags specifying the access rights of an authority to a channel Can be combined.
Definition: Channel.h:332