libqi-api  2.4.3.28
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
manageable.hpp
Go to the documentation of this file.
1 #pragma once
2 /*
3 ** Copyright (C) 2013 Aldebaran Robotics
4 ** See COPYING for the license
5 */
6 
7 #ifndef _QITYPE_MANAGEABLE_HPP_
8 #define _QITYPE_MANAGEABLE_HPP_
9 
10 #include <qi/stats.hpp>
11 
12 #include <qi/api.hpp>
13 #include <qi/anyfunction.hpp>
14 #include <qi/type/typeobject.hpp>
15 #include <qi/signal.hpp>
16 #include <boost/function.hpp>
17 #include <algorithm>
18 
19 #ifdef _MSC_VER
20 # pragma warning( push )
21 # pragma warning( disable: 4251 ) // dll interface
22 #endif
23 
24 namespace qi {
25 
26  class ManageablePrivate;
27  class ExecutionContext;
28 
31  {
36 
38  };
39 
40 
41  class EventTrace
42  {
43  public:
44  enum EventKind
45  {
50  };
52  EventTrace(unsigned int id, EventKind kind, unsigned int slotId,
55  unsigned int callerContext=0, unsigned int calleeContext=0,
57  : _id(id), _kind(kind), _slotId(slotId), _arguments(arguments),
58  _timestamp(timestamp), _postTimestamp(postTimestamp), _userUsTime(userUsTime), _systemUsTime(systemUsTime),
59  _callerContext(callerContext), _calleeContext(calleeContext)
60  {}
61 
62  // trace id, used to match call and call result
63  const unsigned int& id() const { return _id;}
64  const EventKind& kind() const { return _kind;}
65  // method or signal id
66  const unsigned int& slotId() const { return _slotId;}
67  // call or signal arguments
68  const AnyValue& arguments() const { return _arguments;}
69  const qi::os::timeval& timestamp() const { return _timestamp;}
70  const qi::os::timeval& postTimestamp() const { return _postTimestamp;}
71  const qi::int64_t& userUsTime() const { return _userUsTime;}
72  const qi::int64_t& systemUsTime() const { return _systemUsTime;}
73  const unsigned int& callerContext() const { return _callerContext;}
74  const unsigned int& calleeContext() const { return _calleeContext;}
75 
76  private:
77  unsigned int _id; // trace id, used to match call and call result
78  EventKind _kind;
79  unsigned int _slotId; // method or signal id
80  AnyValue _arguments; // call or signal arguments
81  qi::os::timeval _timestamp;
82  qi::os::timeval _postTimestamp; // timestamp of eventual post call
83  qi::int64_t _userUsTime;
84  qi::int64_t _systemUsTime;
85  unsigned int _callerContext; // context of caller function
86  unsigned int _calleeContext; // context where method runs
87  };
88 
89 }
90 
92  ("minValue", minValue),
93  ("maxValue", maxValue),
94  ("cumulatedValue", cumulatedValue));
95 
97  ("count", count),
98  ("wall", wall),
99  ("user", user),
100  ("system", system));
101 
103  ("id", id),
104  ("kind", kind),
105  ("slotId", slotId),
106  ("arguments", arguments),
107  ("timestamp", timestamp),
108  ("userUsTime", userUsTime),
109  ("systemUsTime", systemUsTime),
110  ("callerContext", callerContext),
111  ("calleeContext", calleeContext));
112 
113 QI_TYPE_STRUCT(qi::os::timeval, tv_sec, tv_usec);
114 
115 namespace qi {
116 
117  typedef std::map<unsigned int, MethodStatistics> ObjectStatistics;
121  {
122  public:
123  Manageable();
124  ~Manageable();
125  Manageable(const Manageable& b);
126  void operator = (const Manageable& b);
127 
128  boost::mutex& initMutex();
129 
131  void forceExecutionContext(boost::shared_ptr<ExecutionContext> eventLoop);
133  boost::shared_ptr<ExecutionContext> executionContext() const;
134 
136 
139  bool isStatsEnabled() const;
142  void enableStats(bool enable);
144  void pushStats(int slotId, float wallTime, float userTime, float systemTime);
145  ObjectStatistics stats() const;
147  void clearStats();
148 
151 
153  bool isTraceEnabled() const;
164  void enableTrace(bool enable);
166 
168  static const uint32_t startId = 80;
170  static const uint32_t endId = 99;
171  typedef std::map<unsigned int,
172  std::pair<AnyFunction, MetaCallType>
174  typedef boost::function<SignalBase* (void*)> SignalGetter;
175  typedef std::map<unsigned int, SignalGetter> SignalMap;
177  /* Return the methods and signals defined at GenericObject level.
178  * The 'this' argument must be the Manageable*.
179  */
180  static MethodMap& manageableMmethodMap();
181  static SignalMap& manageableSignalMap();
182  static MetaObject& manageableMetaObject();
183  static void _build();
184  int _nextTraceId();
185  boost::scoped_ptr<ManageablePrivate> _p;
186  };
187 }
188 
189 #ifdef _MSC_VER
190 # pragma warning( pop )
191 #endif
192 
194 #endif // _QITYPE_MANAGEABLE_HPP_
Stores min, max and sum of values fed to it.
Definition: stats.hpp:17
Store statistics about method calls.
Definition: stats.hpp:78
const unsigned int & calleeContext() const
Definition: manageable.hpp:74
const unsigned int & id() const
Definition: manageable.hpp:63
#define QI_API
Definition: api.hpp:34
const qi::int64_t & userUsTime() const
Definition: manageable.hpp:71
QI_TYPE_STRUCT_AGREGATE_CONSTRUCTOR(qi::MinMaxSum,("minValue", minValue),("maxValue", maxValue),("cumulatedValue", cumulatedValue))
const qi::os::timeval & timestamp() const
Definition: manageable.hpp:69
EventTrace(unsigned int id, EventKind kind, unsigned int slotId, const AnyValue &arguments, const qi::os::timeval timestamp, qi::int64_t userUsTime=0, qi::int64_t systemUsTime=0, unsigned int callerContext=0, unsigned int calleeContext=0, qi::os::timeval postTimestamp=qi::os::timeval())
Definition: manageable.hpp:52
const AnyValue & arguments() const
Definition: manageable.hpp:68
const EventKind & kind() const
Definition: manageable.hpp:64
Signal< EventTrace > traceObject
Emitted each time a call starts and finishes, and for each signal trigger.
Definition: manageable.hpp:150
const qi::int64_t & systemUsTime() const
Definition: manageable.hpp:72
SignalMap signalMap
Definition: manageable.hpp:176
QI_TYPE_ENUM_REGISTER(qi::EventTrace::EventKind)
dll import/export and compiler message
QI_TYPE_STRUCT(qi::os::timeval, tv_sec, tv_usec)
Object is thread safe, multiple calls can occur in different threads in parallel. ...
Definition: manageable.hpp:35
boost::function< SignalBase *(void *)> SignalGetter
Definition: manageable.hpp:174
std::map< unsigned int, std::pair< AnyFunction, MetaCallType > > MethodMap
Definition: manageable.hpp:173
boost::scoped_ptr< ManageablePrivate > _p
Definition: manageable.hpp:185
const qi::os::timeval & postTimestamp() const
Definition: manageable.hpp:70
struct similar to POSIX timeval
Definition: os.hpp:240
const unsigned int & callerContext() const
Definition: manageable.hpp:73
std::map< unsigned int, MethodStatistics > ObjectStatistics
Definition: manageable.hpp:117
const unsigned int & slotId() const
Definition: manageable.hpp:66
Object is not thread safe, all method calls must occur in the same thread.
Definition: manageable.hpp:33
int system(const char *command)
Execute a shell command.
ObjectThreadingModel
Possible thread models for an object.
Definition: manageable.hpp:30
std::map< unsigned int, SignalGetter > SignalMap
Definition: manageable.hpp:175
int64_t int64_t
Cross-platform signed integer of length 64 bits (8 bytes).
Definition: types.hpp:76
uint32_t uint32_t
Cross-platform unsigned integer of length 32 bits (4 bytes).
Definition: types.hpp:80
Description of the signals and methods accessible on an ObjectTypeInterface.
Definition: metaobject.hpp:25