MIRA
RemoteAuthority.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 
48 #ifndef _MIRA_REMOTEAUTHORITY_H_
49 #define _MIRA_REMOTEAUTHORITY_H_
50 
51 #include <fw/AbstractAuthority.h>
52 #include <fw/FrameworkDefines.h>
53 
54 namespace mira {
55 
57 
58 class RemoteAuthority;
59 class RemoteAuthorityPropertyNode;
60 
61 class RemoteAuthorityPropertyUpdater : public LazySingleton<RemoteAuthorityPropertyUpdater>
62 {
63 public:
64 
67 
68  // destroy instance to stop all updates and prevent further access to RPCs
70 
74  void scheduleUpdate(const std::string& authorityID, RemoteAuthorityPropertyNode* property);
75 
76  void removeScheduledUpdates(RemoteAuthorityPropertyNode* property);
77 
78 private:
79  void process();
80 
81 private:
82  boost::thread mThread;
83  boost::mutex mMutex;
84  boost::condition_variable mSignal;
85  // queue with pairs of (Authority ID,PropertyNode)
86  std::deque<std::pair<std::string,RemoteAuthorityPropertyNode*>> mPendingProperties;
87 };
88 
90 {
91 public:
92 
95  : authority(iAuthority), updater(iUpdater)
96  {}
97 
98 public:
99 
101  {
102  if (children().empty())
103  return NULL;
104 
105  return children().front();
106  }
107 
109  {
110  const RemoteAuthorityRootPropertyNode* This = this;
111  return const_cast<PropertyNode*>(This->getRootProperty());
112  }
113 
114  const RemoteAuthority* getAuthority() const { return authority; }
116 
118 
119 protected:
122 };
123 
125 
142 {
143 public:
144 
146 
147  virtual ~RemoteAuthority();
148 
149 public:
150 
153 
155 
156  virtual boost::shared_ptr<PropertyNode> getProperties();
157 
158  virtual std::set<std::string> getPublishedChannels();
159 
160  virtual std::set<std::string> getSubscribedChannels();
161 
162  virtual std::set<std::string> getServiceInterfaces();
163 
165 
167 
169 
170  virtual void start();
171 
172  virtual void stop();
173 
174  virtual bool hasUnrecoverableFailure() const;
175 
176  virtual bool isStarted() const;
177 
178  virtual bool isRunning() const;
179 
181 
183  void synchronizeProperties();
184 
185 private:
186 
187  PropertyTree fetchProperties();
188 
189 private:
190 
192 
193  boost::shared_ptr<RemoteAuthorityPropertyNode> mRemoteProperties;
194  RemoteAuthorityRootPropertyNode mRemotePropertiesRoot;
195  Time mRemotePropertiesTimestamp;
196  bool mRemotePropertyValuesQueried;
197 
198  bool mHasServiceInterfaceQueryMethod;
199  bool mHasExtendedPropertyJSONBatchQueryMethod;
200 
201  boost::mutex mMutex;
202 };
203 
205 
206 } // namespace
207 
208 #endif
Abstract base class for all derived property node classes.
Definition: PropertyNode.h:202
virtual std::set< std::string > getPublishedChannels()
Returns all published channels by this authority (and its sub-authorities)
virtual boost::shared_ptr< PropertyNode > getProperties()
Returns the main property node of this Authority.
RemoteAuthority * authority
Definition: RemoteAuthority.h:120
void scheduleUpdate(const std::string &authorityID, RemoteAuthorityPropertyNode *property)
Schedule an update of a remote property.
virtual ChannelNameMapping getSubscribedChannelNames()
Returns all subscribed channels (pair of global and local names) by this authority (and its sub-autho...
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
RemoteAuthority(const AuthorityDescription &desc)
virtual NodeList & children()
Returns a vector with all child property nodes.
Definition: PropertyNode.h:230
virtual ChannelNameMapping getPublishedChannelNames()
Returns all published channels (pair of global and local names) by this authority (and its sub-author...
std::multimap< std::string, Status > StatusMap
Definition: Status.h:295
Provided for convenience.
Definition: Singleton.h:564
RemoteAuthorityRootPropertyNode(RemoteAuthority *iAuthority, RemoteAuthorityPropertyUpdater &iUpdater)
Definition: RemoteAuthority.h:93
std::map< std::string, Status > ChannelStatusMap
Definition: AbstractAuthority.h:141
Abstract base class of authorities.
virtual std::set< std::string > getServiceInterfaces()
Returns all service interfaces provided by this authority.
virtual bool hasUnrecoverableFailure() const
Returns true, if there was a failure while processing the immediate handlers.
Wrapper class for boost::posix_time::ptime for adding more functionality to it.
Definition: Time.h:421
This is the descriptive part of an authority.
Definition: AuthorityDescription.h:61
virtual bool isStarted() const
Returns true, if the authority was started (by calling start()).
Definition: RemoteAuthority.h:89
A special node that acts only as (empty) root node for a property tree.
Definition: PropertyNode.h:448
virtual std::set< std::string > getSubscribedChannels()
Returns all subscribed channels by this authority (and its sub-authorities)
virtual StatusManager::StatusMap getStatusMap()
Return a status map that contains the status of the authority as well as all registered submodules...
Definition: RemoteAuthority.h:61
const PropertyNode * getRootProperty() const
Definition: RemoteAuthority.h:100
virtual ChannelStatusMap getSubscribedChannelStatus()
Returns status for all subscribed channels (ok, no publisher, no data, ...) by this authority (and it...
RemoteAuthorityPropertyUpdater & getUpdater() const
Definition: RemoteAuthority.h:117
virtual void stop()
Stops/Pauses the authority. To continue call start().
virtual void start()
Starts/Resumes the authority.
bool needSynchronizeProperties()
virtual bool isRunning() const
Return if the authority is running.
RemoteAuthorityPropertyUpdater & updater
Definition: RemoteAuthority.h:121
This is the abstract base class of local and remote authority classes.
Definition: AbstractAuthority.h:76
A remote authority is located in another framework.
Definition: RemoteAuthority.h:141
virtual ~RemoteAuthority()
const RemoteAuthority * getAuthority() const
Definition: RemoteAuthority.h:114
Defines and constants for the framework.
RemoteAuthority * getAuthority()
Definition: RemoteAuthority.h:115
std::multimap< std::string, std::string > ChannelNameMapping
Definition: AbstractAuthority.h:139
Helper class that is able to hold a complete property tree structure.
Definition: PropertyTree.h:86
void removeScheduledUpdates(RemoteAuthorityPropertyNode *property)
PropertyNode * getRootProperty()
Definition: RemoteAuthority.h:108