MIRA
MicroUnit.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 
47 #ifndef _MIRA_MICROUNIT_H_
48 #define _MIRA_MICROUNIT_H_
49 
52 
53 #include <fw/Framework.h>
54 
55 namespace mira {
56 
58 
61 
70 {
72 public:
73 
74  friend class Unit;
75 
76  MicroUnit(Flags flags = NORMAL) :
77  Authority(flags),
78  mNeedRecover(false),
79  mRecoverInterval(Duration::seconds(1))
80  {}
81 
83  virtual ~MicroUnit();
84 
85  template<typename Reflector>
86  void reflect(Reflector& r)
87  {
89  r.property("RecoverInterval", mRecoverInterval,
90  "The interval for trying to recover", Duration::seconds(1));
91  }
92 
99  virtual void checkin(const std::string& ns, const std::string& name);
100 
109  virtual void checkin(Authority& parent, const std::string& ns,
110  const std::string& name);
111 
113  void setPropertyNode(boost::shared_ptr<PropertyNode> node);
114 
117  virtual boost::shared_ptr<PropertyNode> getProperties();
119 
130  virtual void start();
131 
142  virtual void stop();
143 
145 
151  virtual void destruct();
152 
153 protected:
154 
157 
177  virtual void initialize() {}
178 
186  virtual void resume() {}
187 
195  virtual void pause() {}
196 
203  virtual void finalize() {}
204 
212  virtual void needRecovery(const std::string& reason = "");
213 
218  virtual void operational();
219 
226  virtual void recover() {};
227 
229  bool inRecoveryMode() const { return mNeedRecover; }
230 
232 
233 protected:
234 
235  void initializeIntern();
236 
237  void recoverIntern(const Timer& timer);
238 
239 protected:
241 
242 private:
243 
244  void setup();
245 
246  boost::shared_ptr<PropertyNode> mProperties;
247 
248  bool mNeedRecover;
249  Duration mRecoverInterval;
250 };
251 
253 
254 typedef boost::shared_ptr<MicroUnit> MicroUnitPtr;
255 
257 
258 }
259 
260 #endif
boost::shared_ptr< MicroUnit > MicroUnitPtr
Definition: MicroUnit.h:254
virtual void recover()
Overload this method in derived class.
Definition: MicroUnit.h:226
Class representing timers and tasks that can be registered and executed by the dispatcher thread...
Definition: DispatcherThread.h:147
bool inRecoveryMode() const
Return true, if the unit is in recovery mode.
Definition: MicroUnit.h:229
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
virtual void pause()
Overload this method in derived class.
Definition: MicroUnit.h:195
#define MIRA_REFLECT_BASE(reflector, BaseClass)
Macro that can be used to reflect the base class easily.
Definition: ReflectorInterface.h:912
MicroUnit(Flags flags=NORMAL)
Definition: MicroUnit.h:76
RootPropertyNode mPropertiesRoot
Definition: MicroUnit.h:240
virtual void finalize()
Overload this method in derived class.
Definition: MicroUnit.h:203
Provides MIRA_CLASS_SERIALIZATION macro and includes the major headers of the serialization framework...
Flags
Flags for creating an authority.
Definition: Authority.h:101
A more complex unit that adds a default timer to the thread dispatcher of the authority that acts as ...
Definition: Unit.h:63
virtual void initialize()
Overwrite this method to publish own or subscribe to channels.
Definition: MicroUnit.h:177
void reflect(Reflector &r)
Definition: MicroUnit.h:86
#define MIRA_FRAMEWORK_EXPORT
Definition: FrameworkExports.h:61
sec_type seconds() const
Returns normalized number of seconds (0..59)
Definition: Time.h:278
Use this class to represent time durations.
Definition: Time.h:104
A special node that acts only as (empty) root node for a property tree.
Definition: PropertyNode.h:448
The object class acts as a generic base class for classes which should be used with the classFactory...
Definition: Object.h:144
Authorities act as a facade to the framework.
Definition: Authority.h:94
#define MIRA_OBJECT(classIdentifier)
Use this MACRO if you like the factory to automatically extract the class name from the given identif...
Definition: FactoryMacros.h:179
virtual void resume()
Overload this method in derived class.
Definition: MicroUnit.h:186
The framework that holds all manager classes and provides startup and shutdown of all framework relat...
Provides definition for getters and setters that are used with the serialization framework.
Units are basic modules of a complex application.
Definition: MicroUnit.h:69