47 #ifndef _MIRA_AUTHORITY_H_ 48 #define _MIRA_AUTHORITY_H_ 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" 59 #include <serialization/adapters/std/set> 75 class AuthorityManager;
76 class FrameworkTransformerNode;
83 #define MIRA_HIDDEN_AUTHORITY_PREFIX "#" 126 INVISIBLE_PUBLISHER_SUBSCRIBER = 0x0004,
147 INDEPENDENT_SUBSCRIBER_THREAD = 0x0010,
161 INDEPENDENT_RPC_THREAD = 0x0020,
167 NO_MAIN_THREAD = 0x0040
244 template<
typename Reflector>
247 r.roproperty(
"Status", &getStatusManager(),
"The status of this authority");
248 r.property(
"HeartbeatInterval",
253 "The interval of the watchdog",
296 void checkin(
const ResourceName& ns,
const std::string& name,
312 const std::string& name);
326 void checkin(
Authority& iParent,
const std::string& name);
353 MIRA_THROW(XInvalidConfig,
"Authority is not registered.");
366 mStartWithParent = start;
399 template <
typename F>
400 void addImmediateHandlerFunction(F&& fn);
416 template <
typename F>
417 void addFinalizeHandlerFunction(F&& fn);
447 template<
typename Class>
453 template<
typename Class>
458 template<
typename Class>
464 template<
typename Class>
466 void (
Class::*f)(
const Timer&),
bool oneshot=
false);
478 template<
typename Class>
482 template<
typename Class>
503 void start()
override;
514 void stop()
override;
537 [[nodiscard]]
bool hasWork(
Time horizon =
Time::now())
const;
546 bool hasUnrecoverableFailure()
const override;
552 bool isStarted()
const override;
558 bool isRunning()
const override;
569 void enableSubscriberCallbacks(
bool enable);
588 std::string resolveName(
const std::string& name)
const;
598 std::string resolveServiceName(
const std::string& name)
const;
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>());
639 void unpublish(
const std::string& channelID);
667 Channel<T> subscribe(
const std::string& channelID,
703 Channel<T> subscribe(
const std::string& channelID,
706 bool independentThread =
false);
710 Channel<T> subscribe(
const std::string& channelID,
712 bool independentThread);
719 template<
typename T,
typename Class>
720 Channel<T> subscribe(
const std::string& channelID,
724 bool independentThread =
false);
731 template<
typename T,
typename Class>
732 Channel<T> subscribe(
const std::string& channelID,
734 Class* obj,
bool independentThread);
757 template<
typename T,
typename Class>
761 bool independentThread =
false)
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);
774 template<
typename T,
typename Class>
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);
807 Channel<T> publishAndSubscribe(
const std::string& channelID,
839 Channel<T> publishAndSubscribe(
const std::string& channelID,
842 bool independentThread =
false);
846 Channel<T> publishAndSubscribe(
const std::string& channelID,
848 bool independentThread);
855 template<
typename T,
typename Class>
856 Channel<T> publishAndSubscribe(
const std::string& channelID,
860 bool independentThread =
false);
867 template<
typename T,
typename Class>
868 Channel<T> publishAndSubscribe(
const std::string& channelID,
870 Class* obj,
bool independentThread);
893 template<
typename T,
typename Class>
897 bool independentThread =
false)
901 return publishAndSubscribe<T>(channelID, f, obj, storageDuration, independentThread);
908 template<
typename T,
typename Class>
911 bool independentThread)
915 return publishAndSubscribe<T>(channelID, f, obj, independentThread);
961 Channel<T> subscribeInterval(
const std::string& channelID,
964 bool independentThread =
false,
971 template<
typename T,
typename Class>
972 Channel<T> subscribeInterval(
const std::string& channelID,
976 bool independentThread =
false,
983 template<
typename T,
typename Class>
984 Channel<T> subscribeInterval(
const std::string& channelID,
987 bool independentThread =
false,
996 template<
typename T,
typename Class>
997 Channel<T> subscribeIntervalByElements(
const std::string& channelID,
1001 bool independentThread =
false,
1008 template <
typename T>
1009 Channel<T> subscribeIntervalByElements(
const std::string& channelID,
1012 bool independentThread =
false,
1020 template<
typename T,
typename Class>
1021 Channel<T> subscribeIntervalByElements(
const std::string& channelID,
1024 bool independentThread =
false,
1038 template <
typename T>
1054 void unsubscribe(
const std::string& channelID);
1061 template <
typename T>
1062 void unsubscribe(
const std::string& channelID);
1081 template <
typename T>
1082 Channel<T> getChannel(
const std::string& channelID);
1087 bool isSubscribedOn(
const std::string& channelID)
const;
1091 bool hasSubscribedOn(
const std::string& channelID)
const) {
1092 return isSubscribedOn(channelID);
1098 bool hasPublished(
const std::string& channelID)
const;
1103 bool doesChannelExist(
const std::string& channelID)
const;
1108 bool waitForChannel(
const std::string& channelID,
1134 bool isTransformAvailable(
const std::string& targetID,
const std::string& sourceID)
const;
1147 bool isTransformAvailable(
const std::string& targetID,
const std::string& sourceID,
1148 const std::string& fixedID)
const;
1161 bool waitForTransform(
const std::string& targetID,
const std::string& sourceID,
1176 bool waitForTransform(
const std::string& targetID,
const std::string& sourceID,
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,
1214 template<
typename Transform,
typename Filter,
typename Class>
1215 void subscribeTransform(
const std::string& targetID,
1216 const std::string& sourceID,
1225 template<
typename Transform,
typename Filter,
typename Class>
1226 void subscribeTransform(
const std::string& targetID,
1227 const std::string& sourceID,
1253 template<
typename Transform>
1254 void subscribeTransform(
const std::string& targetID,
1255 const std::string& sourceID,
1256 boost::function<
void (Transform,
Time)> fn);
1263 template<
typename Transform,
typename Class>
1264 void subscribeTransform(
const std::string& targetID,
1265 const std::string& sourceID,
1273 template<
typename Transform,
typename Class>
1274 void subscribeTransform(
const std::string& targetID,
1275 const std::string& sourceID,
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;
1305 template<
typename Transform>
1307 const std::string& sourceID,
1310 return getTransform<Transform>(targetID, sourceID, time,
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;
1357 template<
typename Transform>
1359 const std::string& sourceID,
const Time& sourceTime,
1360 const std::string& fixedID)
const 1362 return getTransform<Transform>(targetID, targetTime, sourceID,
1363 sourceTime, fixedID,
1394 const std::string& sourceID)
const;
1415 const std::string& sourceID,
1416 const std::string& fixedID)
const;
1428 template<
typename Transform,
typename Filter>
1430 Filter&& filter)
const;
1439 template<
typename Transform>
1459 template<
typename Transform,
typename Filter>
1461 const Time& sourceTime, Filter&& filter)
const;
1469 template<
typename Transform>
1471 const Time& sourceTime)
const 1473 return getTransform<Transform>(desc, targetTime, sourceTime,
1484 template<
typename Transform>
1485 void publishTransform(
const std::string& frameID,
const Transform& transform,
1486 const Time& time)
const;
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,
1531 void addTransformLink(
const std::string& childID,
const std::string& parentID)
const;
1542 void addTransformLink(
const std::string& childID,
1543 const std::string& parentID,
1569 template<
typename Service>
1570 void publishService(
const std::string& name, Service& iService,
1580 template<
typename Service>
1581 void publishService(Service& iService,
1588 void unpublishService();
1594 void unpublishService(
const std::string& name);
1631 template<
typename R,
typename... ARGS>
1632 inline RPCFuture<R> callService(
const std::string& iService,
const std::string& method,
1633 ARGS&&... args)
const;
1682 const std::string& method,
1697 const std::string& method,
1698 const std::string& params)
const;
1721 [[nodiscard]]
ServiceCall<F> createServiceCall(
const std::string& service, std::string method,
1722 bool waitTillExists =
true,
bool showBootupMsg =
true);
1727 bool existsService(
const std::string& name)
const;
1733 bool implementsInterface(
const std::string& name,
1734 const std::string& interface)
const;
1743 bool waitForService(
const std::string& name,
1754 std::string waitForServiceInterface(
const std::string& interface,
1761 std::list<std::string> queryServicesForInterface(
const std::string& interface)
const;
1772 void registerCallbackForInterface(
const std::string& interface,
1779 template<
typename Class>
1780 void registerCallbackForInterface(
const std::string& interface,
1781 void (
Class::*f)(
const std::string&,
1782 const std::string&),
1798 boost::shared_ptr<PropertyNode> getProperties()
override;
1800 std::set<std::string> getPublishedChannels()
override;
1802 std::set<std::string> getSubscribedChannels()
override;
1804 std::set<std::string> getServiceInterfaces()
override;
1806 ChannelNameMapping getPublishedChannelNames()
override;
1808 ChannelNameMapping getSubscribedChannelNames()
override;
1810 ChannelStatusMap getSubscribedChannelStatus()
override;
1816 template<
typename T>
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);
1830 void remotePublishService(
const std::string& service)
const;
1832 friend struct AuthorityService;
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;
1870 bool mIsInvisiblePublisherSubscriber;
1878 bool mStartWithParent;
1880 std::set<Authority*> mChildren;
1883 bool mSubscriberEnabled;
1885 typedef boost::shared_ptr<DispatcherThread> DispatcherThreadPtr;
1892 typedef std::list<DispatcherThreadPtr> IndependentSubscribers;
1895 IndependentSubscribers mIndependentSubscriberDispatchers;
1898 DispatcherThreadPtr mSubscriberDispatcher;
1900 DispatcherThreadPtr mRPCDispatcher;
1909 std::set<std::string> mPublishedServices;
1911 boost::mutex mNameMutex;
boost::shared_ptr< RPCHandler > RPCHandlerPtr
Definition: RPCHandler.h:102
RWAccessFlags()
Definition: Authority.h:1846
An object that allows read access to a whole interval of channel data.
Definition: ChannelReadInterval.h:72
Manages the status of one or multiple modules inheriting from DiagnosticsModule.
Definition: Status.h:291
static Duration invalid()
Returns an invalid duration.
Definition: Time.h:249
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
PropertyHint spin(const T &min, const T &max, const T &s)
Sets the attribute "type" to the value "spinbox" and sets the "minimum", "maximum" and "step" attribu...
Definition: PropertyHint.h:328
DispatcherThread::TimerPtr TimerPtr
Definition: DispatcherThread.h:525
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:73
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
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
Class representing timers and tasks that can be registered and executed by the dispatcher thread...
Definition: DispatcherThread.h:147
void setHeartbeatInterval(const Duration &interval)
Set the watchdog interval.
Definition: Status.h:153
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
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
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
MIRA_DEPRECATED("Please use isSubscribedOn() instead", bool hasSubscribedOn(const std::string &channelID) const)
Definition: Authority.h:1089
Class object which supports some kind of class reflection.
Definition: Class.h:97
std::list< AbstractChannelSubscriberPtr > SubscribePtrList
Definition: Authority.h:1851
constexpr std::enable_if<!FunctionTraits< F >::isFunction, bool >::type isValid()
Definition: RPCPatternCheck.h:193
std::multimap< std::string, Status > StatusMap
Definition: Status.h:295
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:511
Definition: ChannelReadWrite.h:67
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
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:82
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
Duration getHeartbeatInterval() const
Return the watchdog interval.
Definition: Status.h:166
Wrapper class for boost::posix_time::ptime for adding more functionality to it.
Definition: Time.h:418
class MIRA_FRAMEWORK_EXPORT Authority
forward declaration
Definition: RemoteConnection.h:74
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.
Filter that returns the nearest neighbor.
DispatcherThread::TimerCallback TimerCallback
Definition: DispatcherThread.h:526
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
Class for storing/combining/managing resource names consisting of namespaces and names separated by '...
Definition: ResourceName.h:68
#define MIRA_FRAMEWORK_EXPORT
Definition: FrameworkExports.h:61
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
Use this class to represent time durations.
Definition: Time.h:106
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:95
boost::shared_ptr< DiagnosticRunnable > DiagnosticRunnablePtr
Definition: Runnable.h:107
std::set< Authority * > getChildren()
Returns a set with all children / sub-authorities.
Definition: Authority.h:382
Framework channel classes.
Signal handler class for signaling when service interfaces get available.
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:176
Central instance that stores all created Authorities.
Definition: AuthorityManager.h:130
Signal handler class for RPC calls.
No access at all (Authority is not a publisher nor a subscriber)
Definition: Channel.h:332
void validate() const
Check if authority is checked in and therefore valid.
Definition: Authority.h:351
static Time now() static Time eternity()
Returns the current utc based time.
Definition: Time.h:481
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
This is the abstract base class of local and remote authority classes.
Definition: AbstractAuthority.h:76
std::map< std::string, RWAccessFlags > RWAccessMap
Definition: Authority.h:1850
Stores info required to call an RPC method - service name, method name, arguments.
Definition: RPCCallDefinition.h:62
Transform getTransform(const TransformDesc &desc, const Time &time=Time()) const
Definition: Authority.h:1440
Definition: Authority.h:78
std::multimap< std::string, std::string > ChannelNameMapping
Definition: AbstractAuthority.h:139
ChannelAccessFlags flags
Definition: Authority.h:1847
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:138
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
ChannelAccessFlags
Flags specifying the access rights of an authority to a channel Can be combined.
Definition: Channel.h:331