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" 60 #include <serialization/adapters/std/set> 76 class AuthorityManager;
77 class FrameworkTransformerNode;
82 #define MIRA_HIDDEN_AUTHORITY_PREFIX "#" 125 INVISIBLE_PUBLISHER_SUBSCRIBER = 0x0004,
146 INDEPENDENT_SUBSCRIBER_THREAD = 0x0010,
160 INDEPENDENT_RPC_THREAD = 0x0020,
166 NO_MAIN_THREAD = 0x0040
235 template<
typename Reflector>
238 r.roproperty(
"Status", &getStatusManager(),
"The status of this authority");
239 r.property(
"HeartbeatInterval",
244 "The interval of the watchdog",
287 void checkin(
const ResourceName& ns,
const std::string& name,
303 const std::string& name);
317 void checkin(
Authority& iParent,
const std::string& name);
341 MIRA_THROW(XInvalidConfig,
"Authority is not registered.");
374 template <
typename F>
375 void addImmediateHandlerFunction(F&& fn);
391 template <
typename F>
392 void addFinalizeHandlerFunction(F&& fn);
422 template<
typename Class>
428 template<
typename Class>
433 template<
typename Class>
439 template<
typename Class>
441 void (
Class::*f)(
const Timer&),
bool oneshot=
false);
453 template<
typename Class>
457 template<
typename Class>
473 virtual void start();
504 virtual bool hasUnrecoverableFailure()
const;
510 virtual bool isStarted()
const;
516 virtual bool isRunning()
const;
527 void enableSubscriberCallbacks(
bool enable);
546 std::string resolveName(
const std::string& name)
const;
556 std::string resolveServiceName(
const std::string& name)
const;
579 static_assert(std::is_void<T>::value!=
true,
580 "You must specify a typename for untyped channels");
581 return publish<T>(channelID, typeName<T>());
597 void unpublish(
const std::string& channelID);
625 Channel<T> subscribe(
const std::string& channelID,
661 Channel<T> subscribe(
const std::string& channelID,
664 bool independentThread =
false);
668 Channel<T> subscribe(
const std::string& channelID,
670 bool independentThread);
677 template<
typename T,
typename Class>
678 Channel<T> subscribe(
const std::string& channelID,
682 bool independentThread =
false);
689 template<
typename T,
typename Class>
690 Channel<T> subscribe(
const std::string& channelID,
692 Class* obj,
bool independentThread);
715 template<
typename T,
typename Class>
719 bool independentThread =
false)
723 "Called 'Authority::subscribe(..., Class::member, ...)' on an object that is not " 724 "of type Class (you may need to provide a pointer to the correct object)!");
725 return subscribe<T>(channelID, f, obj, storageDuration, independentThread);
732 template<
typename T,
typename Class>
738 "Called 'Authority::subscribe(..., Class::member, ...)' on an object that is not " 739 "of type Class (you may need to provide a pointer to the correct object)!");
740 return subscribe<T>(channelID, f, obj, independentThread);
765 Channel<T> publishAndSubscribe(
const std::string& channelID,
797 Channel<T> publishAndSubscribe(
const std::string& channelID,
800 bool independentThread =
false);
804 Channel<T> publishAndSubscribe(
const std::string& channelID,
806 bool independentThread);
813 template<
typename T,
typename Class>
814 Channel<T> publishAndSubscribe(
const std::string& channelID,
818 bool independentThread =
false);
825 template<
typename T,
typename Class>
826 Channel<T> publishAndSubscribe(
const std::string& channelID,
828 Class* obj,
bool independentThread);
851 template<
typename T,
typename Class>
855 bool independentThread =
false)
859 return publishAndSubscribe<T>(channelID, f, obj, storageDuration, independentThread);
866 template<
typename T,
typename Class>
869 bool independentThread)
873 return publishAndSubscribe<T>(channelID, f, obj, independentThread);
919 Channel<T> subscribeInterval(
const std::string& channelID,
922 bool independentThread =
false,
929 template<
typename T,
typename Class>
930 Channel<T> subscribeInterval(
const std::string& channelID,
934 bool independentThread =
false,
941 template<
typename T,
typename Class>
942 Channel<T> subscribeInterval(
const std::string& channelID,
945 bool independentThread =
false,
954 template<
typename T,
typename Class>
955 Channel<T> subscribeIntervalByElements(
const std::string& channelID,
959 bool independentThread =
false,
966 template <
typename T>
967 Channel<T> subscribeIntervalByElements(
const std::string& channelID,
970 bool independentThread =
false,
978 template<
typename T,
typename Class>
979 Channel<T> subscribeIntervalByElements(
const std::string& channelID,
982 bool independentThread =
false,
996 template <
typename T>
1012 template <
typename T>
1013 void unsubscribe(
const std::string& channelID);
1032 template <
typename T>
1033 Channel<T> getChannel(
const std::string& channelID);
1038 bool isSubscribedOn(
const std::string& channelID)
const;
1042 bool hasSubscribedOn(
const std::string& channelID)
const) {
1043 return isSubscribedOn(channelID);
1049 bool hasPublished(
const std::string& channelID)
const;
1054 bool doesChannelExist(
const std::string& channelID)
const;
1059 bool waitForChannel(
const std::string& channelID,
1085 bool isTransformAvailable(
const std::string& targetID,
const std::string& sourceID)
const;
1098 bool isTransformAvailable(
const std::string& targetID,
const std::string& sourceID,
1099 const std::string& fixedID)
const;
1112 bool waitForTransform(
const std::string& targetID,
const std::string& sourceID,
1127 bool waitForTransform(
const std::string& targetID,
const std::string& sourceID,
1154 template<
typename Transform,
typename Filter>
1155 void subscribeTransform(
const std::string& targetID,
1156 const std::string& sourceID,
1157 boost::function<
void (Transform,
Time)> fn,
1165 template<
typename Transform,
typename Filter,
typename Class>
1166 void subscribeTransform(
const std::string& targetID,
1167 const std::string& sourceID,
1176 template<
typename Transform,
typename Filter,
typename Class>
1177 void subscribeTransform(
const std::string& targetID,
1178 const std::string& sourceID,
1204 template<
typename Transform>
1205 void subscribeTransform(
const std::string& targetID,
1206 const std::string& sourceID,
1207 boost::function<
void (Transform,
Time)> fn);
1214 template<
typename Transform,
typename Class>
1215 void subscribeTransform(
const std::string& targetID,
1216 const std::string& sourceID,
1224 template<
typename Transform,
typename Class>
1225 void subscribeTransform(
const std::string& targetID,
1226 const std::string& sourceID,
1243 template<
typename Transform,
typename Filter>
1244 Transform getTransform(
const std::string& targetID,
1245 const std::string& sourceID,
1246 const Time& time, Filter&& filter)
const;
1256 template<
typename Transform>
1258 const std::string& sourceID,
1261 return getTransform<Transform>(targetID, sourceID, time,
1294 template<
typename Transform,
typename Filter>
1295 Transform getTransform(
const std::string& targetID,
const Time& targetTime,
1296 const std::string& sourceID,
const Time& sourceTime,
1297 const std::string& fixedID,
1298 Filter&& filter)
const;
1308 template<
typename Transform>
1310 const std::string& sourceID,
const Time& sourceTime,
1311 const std::string& fixedID)
const 1313 return getTransform<Transform>(targetID, targetTime, sourceID,
1314 sourceTime, fixedID,
1345 const std::string& sourceID)
const;
1366 const std::string& sourceID,
1367 const std::string& fixedID)
const;
1379 template<
typename Transform,
typename Filter>
1381 Filter&& filter)
const;
1390 template<
typename Transform>
1410 template<
typename Transform,
typename Filter>
1412 const Time& sourceTime, Filter&& filter)
const;
1420 template<
typename Transform>
1422 const Time& sourceTime)
const 1424 return getTransform<Transform>(desc, targetTime, sourceTime,
1435 template<
typename Transform>
1436 void publishTransform(
const std::string& frameID,
const Transform& transform,
1437 const Time& time)
const;
1468 template<
typename Transform,
typename Filter>
1469 void publishTransformIndirect(
const std::string& frameID,
1470 const std::string& targetID,
1471 const std::string& sourceID,
1472 const Transform& transform,
const Time& time,
1473 Filter&& filter)
const;
1484 template<
typename Transform>
1486 const std::string& targetID,
1487 const std::string& sourceID,
1488 const Transform& transform,
const Time& time)
1490 publishTransformIndirect(frameID, targetID, sourceID,
1501 void addTransformLink(
const std::string& childID,
const std::string& parentID)
const;
1512 void addTransformLink(
const std::string& childID,
1513 const std::string& parentID,
1539 template<
typename Service>
1540 void publishService(
const std::string& name, Service& iService,
1550 template<
typename Service>
1551 void publishService(Service& iService,
1558 void unpublishService();
1564 void unpublishService(
const std::string& name);
1601 template<
typename R,
typename... ARGS>
1602 inline RPCFuture<R> callService(
const std::string& iService,
const std::string& method,
1603 ARGS&&... args)
const;
1652 const std::string& method,
1667 const std::string& method,
1668 const std::string& params)
const;
1682 bool existsService(
const std::string& name)
const;
1688 bool implementsInterface(
const std::string& name,
1689 const std::string& interface)
const;
1698 bool waitForService(
const std::string& name,
1709 std::string waitForServiceInterface(
const std::string& interface,
1716 std::list<std::string> queryServicesForInterface(
const std::string& interface)
const;
1727 void registerCallbackForInterface(
const std::string& interface,
1734 template<
typename Class>
1735 void registerCallbackForInterface(
const std::string& interface,
1736 void (
Class::*f)(
const std::string&,
1737 const std::string&),
1753 virtual boost::shared_ptr<PropertyNode> getProperties();
1755 virtual std::set<std::string> getPublishedChannels();
1757 virtual std::set<std::string> getSubscribedChannels();
1759 virtual std::set<std::string> getServiceInterfaces();
1761 virtual ChannelNameMapping getPublishedChannelNames();
1763 virtual ChannelNameMapping getSubscribedChannelNames();
1765 virtual ChannelStatusMap getSubscribedChannelStatus();
1771 template<
typename T>
1774 void setChannelReadAccess(
const std::string& channelID);
1775 void setChannelWriteAccess(
const std::string& channelID);
1776 void removeChannelReadAccess(
const std::string& channelID);
1777 void removeChannelWriteAccess(
const std::string& channelID);
1779 const std::string& local,
1780 const std::string& global);
1782 const std::string& local,
1783 const std::string& global);
1785 void remotePublishService(
const std::string& service)
const;
1787 friend struct AuthorityService;
1792 void setProperty(
const std::string& property,
const std::string& value);
1793 std::string getProperty(
const std::string& property)
const;
1794 void setPropertyJSON(
const std::string& property,
const json::Value& value);
1795 json::Value getPropertyJSON(
const std::string& property)
const;
1825 bool mIsInvisiblePublisherSubscriber;
1833 std::set<Authority*> mChildren;
1836 bool mSubscriberEnabled;
1838 typedef boost::shared_ptr<DispatcherThread> DispatcherThreadPtr;
1845 typedef std::list<DispatcherThreadPtr> IndependentSubscribers;
1848 IndependentSubscribers mIndependentSubscriberDispatchers;
1851 DispatcherThreadPtr mSubscriberDispatcher;
1853 DispatcherThreadPtr mRPCDispatcher;
1862 std::set<std::string> mPublishedServices;
1864 boost::mutex mNameMutex;
boost::shared_ptr< RPCHandler > RPCHandlerPtr
Definition: RPCHandler.h:102
RWAccessFlags()
Definition: Authority.h:1801
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:1800
bool isValid() const
Returns true, if this Authority was initialized and is checked in, otherwise false.
Definition: Authority.h:331
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:515
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:1309
AuthorityRuntimePtr getRuntime()
Returns a shared_ptr to the runtime that this authority uses.
Definition: Authority.h:350
boost::shared_ptr< Authority > AuthorityPtr
Typedef for Authority pointers.
Definition: Authority.h:1874
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:1421
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:716
MIRA_DEPRECATED("Please use isSubscribedOn() instead", bool hasSubscribedOn(const std::string &channelID) const)
Definition: Authority.h:1040
Class object which supports some kind of class reflection.
Definition: Class.h:97
std::list< AbstractChannelSubscriberPtr > SubscribePtrList
Definition: Authority.h:1806
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:1257
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:435
Flags
Flags for creating an authority.
Definition: Authority.h:100
#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:577
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
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:1485
Filter that returns the nearest neighbor.
DispatcherThread::TimerCallback TimerCallback
Definition: DispatcherThread.h:516
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:733
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:93
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:357
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:852
Utility macros used in generating RPC method definitions with BOOST_PP.
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:352
void validate() const
Check if authority is checked in and therefore valid.
Definition: Authority.h:339
void reflect(Reflector &r)
reflect method
Definition: Authority.h:236
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:1805
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:1391
std::multimap< std::string, std::string > ChannelNameMapping
Definition: AbstractAuthority.h:139
ChannelAccessFlags flags
Definition: Authority.h:1802
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:867
ChannelAccessFlags
Flags specifying the access rights of an authority to a channel Can be combined.
Definition: Channel.h:351