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 virtual void start();
539 virtual bool hasUnrecoverableFailure()
const;
545 virtual bool isStarted()
const;
551 virtual bool isRunning()
const;
562 void enableSubscriberCallbacks(
bool enable);
581 std::string resolveName(
const std::string& name)
const;
591 std::string resolveServiceName(
const std::string& name)
const;
614 static_assert(std::is_void<T>::value!=
true,
615 "You must specify a typename for untyped channels");
616 return publish<T>(channelID, typeName<T>());
632 void unpublish(
const std::string& channelID);
660 Channel<T> subscribe(
const std::string& channelID,
696 Channel<T> subscribe(
const std::string& channelID,
699 bool independentThread =
false);
703 Channel<T> subscribe(
const std::string& channelID,
705 bool independentThread);
712 template<
typename T,
typename Class>
713 Channel<T> subscribe(
const std::string& channelID,
717 bool independentThread =
false);
724 template<
typename T,
typename Class>
725 Channel<T> subscribe(
const std::string& channelID,
727 Class* obj,
bool independentThread);
750 template<
typename T,
typename Class>
754 bool independentThread =
false)
758 "Called 'Authority::subscribe(..., Class::member, ...)' on an object that is not " 759 "of type Class (you may need to provide a pointer to the correct object)!");
760 return subscribe<T>(channelID, f, obj, storageDuration, independentThread);
767 template<
typename T,
typename Class>
773 "Called 'Authority::subscribe(..., Class::member, ...)' on an object that is not " 774 "of type Class (you may need to provide a pointer to the correct object)!");
775 return subscribe<T>(channelID, f, obj, independentThread);
800 Channel<T> publishAndSubscribe(
const std::string& channelID,
832 Channel<T> publishAndSubscribe(
const std::string& channelID,
835 bool independentThread =
false);
839 Channel<T> publishAndSubscribe(
const std::string& channelID,
841 bool independentThread);
848 template<
typename T,
typename Class>
849 Channel<T> publishAndSubscribe(
const std::string& channelID,
853 bool independentThread =
false);
860 template<
typename T,
typename Class>
861 Channel<T> publishAndSubscribe(
const std::string& channelID,
863 Class* obj,
bool independentThread);
886 template<
typename T,
typename Class>
890 bool independentThread =
false)
894 return publishAndSubscribe<T>(channelID, f, obj, storageDuration, independentThread);
901 template<
typename T,
typename Class>
904 bool independentThread)
908 return publishAndSubscribe<T>(channelID, f, obj, independentThread);
954 Channel<T> subscribeInterval(
const std::string& channelID,
957 bool independentThread =
false,
964 template<
typename T,
typename Class>
965 Channel<T> subscribeInterval(
const std::string& channelID,
969 bool independentThread =
false,
976 template<
typename T,
typename Class>
977 Channel<T> subscribeInterval(
const std::string& channelID,
980 bool independentThread =
false,
989 template<
typename T,
typename Class>
990 Channel<T> subscribeIntervalByElements(
const std::string& channelID,
994 bool independentThread =
false,
1001 template <
typename T>
1002 Channel<T> subscribeIntervalByElements(
const std::string& channelID,
1005 bool independentThread =
false,
1013 template<
typename T,
typename Class>
1014 Channel<T> subscribeIntervalByElements(
const std::string& channelID,
1017 bool independentThread =
false,
1031 template <
typename T>
1047 void unsubscribe(
const std::string& channelID);
1054 template <
typename T>
1055 void unsubscribe(
const std::string& channelID);
1074 template <
typename T>
1075 Channel<T> getChannel(
const std::string& channelID);
1080 bool isSubscribedOn(
const std::string& channelID)
const;
1084 bool hasSubscribedOn(
const std::string& channelID)
const) {
1085 return isSubscribedOn(channelID);
1091 bool hasPublished(
const std::string& channelID)
const;
1096 bool doesChannelExist(
const std::string& channelID)
const;
1101 bool waitForChannel(
const std::string& channelID,
1127 bool isTransformAvailable(
const std::string& targetID,
const std::string& sourceID)
const;
1140 bool isTransformAvailable(
const std::string& targetID,
const std::string& sourceID,
1141 const std::string& fixedID)
const;
1154 bool waitForTransform(
const std::string& targetID,
const std::string& sourceID,
1169 bool waitForTransform(
const std::string& targetID,
const std::string& sourceID,
1196 template<
typename Transform,
typename Filter>
1197 void subscribeTransform(
const std::string& targetID,
1198 const std::string& sourceID,
1199 boost::function<
void (Transform,
Time)> fn,
1207 template<
typename Transform,
typename Filter,
typename Class>
1208 void subscribeTransform(
const std::string& targetID,
1209 const std::string& sourceID,
1218 template<
typename Transform,
typename Filter,
typename Class>
1219 void subscribeTransform(
const std::string& targetID,
1220 const std::string& sourceID,
1246 template<
typename Transform>
1247 void subscribeTransform(
const std::string& targetID,
1248 const std::string& sourceID,
1249 boost::function<
void (Transform,
Time)> fn);
1256 template<
typename Transform,
typename Class>
1257 void subscribeTransform(
const std::string& targetID,
1258 const std::string& sourceID,
1266 template<
typename Transform,
typename Class>
1267 void subscribeTransform(
const std::string& targetID,
1268 const std::string& sourceID,
1285 template<
typename Transform,
typename Filter>
1286 Transform getTransform(
const std::string& targetID,
1287 const std::string& sourceID,
1288 const Time& time, Filter&& filter)
const;
1298 template<
typename Transform>
1300 const std::string& sourceID,
1303 return getTransform<Transform>(targetID, sourceID, time,
1336 template<
typename Transform,
typename Filter>
1337 Transform getTransform(
const std::string& targetID,
const Time& targetTime,
1338 const std::string& sourceID,
const Time& sourceTime,
1339 const std::string& fixedID,
1340 Filter&& filter)
const;
1350 template<
typename Transform>
1352 const std::string& sourceID,
const Time& sourceTime,
1353 const std::string& fixedID)
const 1355 return getTransform<Transform>(targetID, targetTime, sourceID,
1356 sourceTime, fixedID,
1387 const std::string& sourceID)
const;
1408 const std::string& sourceID,
1409 const std::string& fixedID)
const;
1421 template<
typename Transform,
typename Filter>
1423 Filter&& filter)
const;
1432 template<
typename Transform>
1452 template<
typename Transform,
typename Filter>
1454 const Time& sourceTime, Filter&& filter)
const;
1462 template<
typename Transform>
1464 const Time& sourceTime)
const 1466 return getTransform<Transform>(desc, targetTime, sourceTime,
1477 template<
typename Transform>
1478 void publishTransform(
const std::string& frameID,
const Transform& transform,
1479 const Time& time)
const;
1510 template<
typename Transform,
typename Filter>
1511 void publishTransformIndirect(
const std::string& frameID,
1512 const std::string& targetID,
1513 const std::string& sourceID,
1514 const Transform& transform,
const Time& time,
1515 Filter&& filter)
const;
1526 template<
typename Transform>
1528 const std::string& targetID,
1529 const std::string& sourceID,
1530 const Transform& transform,
const Time& time)
1532 publishTransformIndirect(frameID, targetID, sourceID,
1543 void addTransformLink(
const std::string& childID,
const std::string& parentID)
const;
1554 void addTransformLink(
const std::string& childID,
1555 const std::string& parentID,
1581 template<
typename Service>
1582 void publishService(
const std::string& name, Service& iService,
1592 template<
typename Service>
1593 void publishService(Service& iService,
1600 void unpublishService();
1606 void unpublishService(
const std::string& name);
1643 template<
typename R,
typename... ARGS>
1644 inline RPCFuture<R> callService(
const std::string& iService,
const std::string& method,
1645 ARGS&&... args)
const;
1694 const std::string& method,
1709 const std::string& method,
1710 const std::string& params)
const;
1733 [[nodiscard]]
ServiceCall<F> createServiceCall(
const std::string& service, std::string method,
1734 bool waitTillExists =
true,
bool showBootupMsg =
true);
1739 bool existsService(
const std::string& name)
const;
1745 bool implementsInterface(
const std::string& name,
1746 const std::string& interface)
const;
1755 bool waitForService(
const std::string& name,
1766 std::string waitForServiceInterface(
const std::string& interface,
1773 std::list<std::string> queryServicesForInterface(
const std::string& interface)
const;
1784 void registerCallbackForInterface(
const std::string& interface,
1791 template<
typename Class>
1792 void registerCallbackForInterface(
const std::string& interface,
1793 void (
Class::*f)(
const std::string&,
1794 const std::string&),
1810 virtual boost::shared_ptr<PropertyNode> getProperties();
1812 virtual std::set<std::string> getPublishedChannels();
1814 virtual std::set<std::string> getSubscribedChannels();
1816 virtual std::set<std::string> getServiceInterfaces();
1818 virtual ChannelNameMapping getPublishedChannelNames();
1820 virtual ChannelNameMapping getSubscribedChannelNames();
1822 virtual ChannelStatusMap getSubscribedChannelStatus();
1828 template<
typename T>
1831 void setChannelReadAccess(
const std::string& channelID);
1832 void setChannelWriteAccess(
const std::string& channelID);
1833 void removeChannelReadAccess(
const std::string& channelID);
1834 void removeChannelWriteAccess(
const std::string& channelID);
1836 const std::string& local,
1837 const std::string& global);
1839 const std::string& local,
1840 const std::string& global);
1842 void remotePublishService(
const std::string& service)
const;
1844 friend struct AuthorityService;
1849 void setProperty(
const std::string& property,
const std::string& value);
1850 std::string getProperty(
const std::string& property)
const;
1851 void setPropertyJSON(
const std::string& property,
const json::Value& value);
1852 json::Value getPropertyJSON(
const std::string& property)
const;
1882 bool mIsInvisiblePublisherSubscriber;
1890 bool mStartWithParent;
1892 std::set<Authority*> mChildren;
1895 bool mSubscriberEnabled;
1897 typedef boost::shared_ptr<DispatcherThread> DispatcherThreadPtr;
1904 typedef std::list<DispatcherThreadPtr> IndependentSubscribers;
1907 IndependentSubscribers mIndependentSubscriberDispatchers;
1910 DispatcherThreadPtr mSubscriberDispatcher;
1912 DispatcherThreadPtr mRPCDispatcher;
1921 std::set<std::string> mPublishedServices;
1923 boost::mutex mNameMutex;
boost::shared_ptr< RPCHandler > RPCHandlerPtr
Definition: RPCHandler.h:102
RWAccessFlags()
Definition: Authority.h:1858
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:252
Channel access flags.
Definition: Authority.h:1857
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:513
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:1351
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:1933
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:1463
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:751
MIRA_DEPRECATED("Please use isSubscribedOn() instead", bool hasSubscribedOn(const std::string &channelID) const)
Definition: Authority.h:1082
Class object which supports some kind of class reflection.
Definition: Class.h:97
std::list< AbstractChannelSubscriberPtr > SubscribePtrList
Definition: Authority.h:1863
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:1299
static Time unixEpoch()
Returns the unix epoch 1.1.1970 0:0:0.000.
Definition: Time.h:514
Definition: ChannelReadWrite.h:65
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:440
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:81
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:612
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:421
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.
void publishTransformIndirect(const std::string &frameID, const std::string &targetID, const std::string &sourceID, const Transform &transform, const Time &time)
Definition: Authority.h:1527
Filter that returns the nearest neighbor.
DispatcherThread::TimerCallback TimerCallback
Definition: DispatcherThread.h:514
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:768
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:283
Use this class to represent time durations.
Definition: Time.h:104
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:887
static Duration infinity()
Returns a special duration time representing positive infinity.
Definition: Time.h:245
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
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:1862
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:1433
Definition: Authority.h:78
std::multimap< std::string, std::string > ChannelNameMapping
Definition: AbstractAuthority.h:139
ChannelAccessFlags flags
Definition: Authority.h:1859
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:902
ChannelAccessFlags
Flags specifying the access rights of an authority to a channel Can be combined.
Definition: Channel.h:331