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 PropertyTree;
62 
63 class RemoteAuthorityPropertyUpdater : public LazySingleton<RemoteAuthorityPropertyUpdater>
64 {
65 public:
66 
69 
70  // destroy instance to stop all updates and prevent further access to RPCs
72 
76  void scheduleUpdate(const std::string& authorityID, RemoteAuthorityPropertyNode* property);
77 
78  void removeScheduledUpdates(RemoteAuthorityPropertyNode* property);
79 
80 private:
81  void process();
82 
83 private:
84  boost::thread mThread;
85  boost::mutex mMutex;
86  boost::condition_variable mSignal;
87  // queue with pairs of (Authority ID,PropertyNode)
88  std::deque<std::pair<std::string,RemoteAuthorityPropertyNode*>> mPendingProperties;
89 };
90 
92 {
93 public:
94 
97  : authority(iAuthority), updater(iUpdater)
98  {}
99 
100 public:
101 
103  {
104  if (children().empty())
105  return NULL;
106 
107  return children().front();
108  }
109 
111  {
112  const RemoteAuthorityRootPropertyNode* This = this;
113  return const_cast<PropertyNode*>(This->getRootProperty());
114  }
115 
116  const RemoteAuthority* getAuthority() const { return authority; }
118 
120 
121 protected:
124 };
125 
127 
144 {
145 public:
146 
148 
149  virtual ~RemoteAuthority();
150 
151 public:
152 
155 
157 
158  virtual boost::shared_ptr<PropertyNode> getProperties();
159 
160  virtual std::set<std::string> getPublishedChannels();
161 
162  virtual std::set<std::string> getSubscribedChannels();
163 
164  virtual std::set<std::string> getServiceInterfaces();
165 
167 
169 
171 
172  virtual void start();
173 
174  virtual void stop();
175 
176  virtual bool hasUnrecoverableFailure() const;
177 
178  virtual bool isStarted() const;
179 
180  virtual bool isRunning() const;
181 
183 
185  void synchronizeProperties();
186 
187 private:
188 
189  PropertyTree fetchProperties();
190 
191 private:
192 
194 
195  boost::shared_ptr<RemoteAuthorityPropertyNode> mRemoteProperties;
196  RemoteAuthorityRootPropertyNode mRemotePropertiesRoot;
197  Time mRemotePropertiesTimestamp;
198  bool mRemotePropertyValuesQueried;
199 
200  bool mHasServiceInterfaceQueryMethod;
201  bool mHasExtendedPropertyJSONBatchQueryMethod;
202 
203  boost::mutex mMutex;
204 };
205 
207 
208 } // namespace
209 
210 #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:122
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:95
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:418
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:91
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:63
const PropertyNode * getRootProperty() const
Definition: RemoteAuthority.h:102
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:119
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:123
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:143
virtual ~RemoteAuthority()
const RemoteAuthority * getAuthority() const
Definition: RemoteAuthority.h:116
Defines and constants for the framework.
RemoteAuthority * getAuthority()
Definition: RemoteAuthority.h:117
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:110