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 "#" 244 template<
typename Reflector>
247 r.roproperty(
"Status", &
getStatusManager(),
"The status of this authority");
248 r.property(
"HeartbeatInterval",
253 "The interval of the watchdog",
312 const std::string& name);
353 MIRA_THROW(XInvalidConfig,
"Authority is not registered.");
366 mStartWithParent =
start;
399 template <
typename F>
416 template <
typename F>
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;
588 std::string
resolveName(
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);
706 bool independentThread =
false);
712 bool independentThread);
719 template<
typename T,
typename Class>
724 bool independentThread =
false);
731 template<
typename T,
typename Class>
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);
842 bool independentThread =
false);
848 bool independentThread);
855 template<
typename T,
typename Class>
860 bool independentThread =
false);
867 template<
typename T,
typename Class>
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);
964 bool independentThread =
false,
971 template<
typename T,
typename Class>
976 bool independentThread =
false,
983 template<
typename T,
typename Class>
987 bool independentThread =
false,
996 template<
typename T,
typename Class>
1001 bool independentThread =
false,
1008 template <
typename T>
1012 bool independentThread =
false,
1020 template<
typename T,
typename Class>
1024 bool independentThread =
false,
1038 template <
typename T>
1061 template <
typename T>
1081 template <
typename T>
1091 bool hasSubscribedOn(
const std::string& channelID)
const) {
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>
1205 const std::string& sourceID,
1206 boost::function<
void (Transform,
Time)> fn,
1214 template<
typename Transform,
typename Filter,
typename Class>
1216 const std::string& sourceID,
1225 template<
typename Transform,
typename Filter,
typename Class>
1227 const std::string& sourceID,
1253 template<
typename Transform>
1255 const std::string& sourceID,
1256 boost::function<
void (Transform,
Time)> fn);
1263 template<
typename Transform,
typename Class>
1265 const std::string& sourceID,
1273 template<
typename Transform,
typename Class>
1275 const std::string& sourceID,
1292 template<
typename Transform,
typename Filter>
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>
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;
1543 const std::string& parentID,
1569 template<
typename Service>
1580 template<
typename Service>
1631 template<
typename R,
typename... ARGS>
1633 ARGS&&... args)
const;
1682 const std::string& method,
1697 const std::string& method,
1698 const std::string& params)
const;
1722 bool waitTillExists =
true,
bool showBootupMsg =
true);
1734 const std::string& interface)
const;
1779 template<
typename Class>
1781 void (
Class::*f)(
const std::string&,
1782 const std::string&),
1816 template<
typename T>
1824 const std::string& local,
1825 const std::string& global);
1827 const std::string& local,
1828 const std::string& global);
1837 void setProperty(
const std::string& property,
const std::string& value);
1838 std::string
getProperty(
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: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)...
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 '...
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'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
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
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