- Aldebaran documentation |
- C++ Libraries |
- index

libqi-api 2.8.7.4

- Main Page
- Related Pages
- Namespaces
- Classes
- Files
- Examples

- File List
- File Members

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 <memory>
11 #include <algorithm>
12 #include <boost/function.hpp>
13
14
15 #include <qi/stats.hpp>
16
17 #include <qi/api.hpp>
18 #include <qi/anyfunction.hpp>
19 #include <qi/type/typeobject.hpp>
20 #include <qi/signal.hpp>
21
22 #ifdef _MSC_VER
23 # pragma warning( push )
24 # pragma warning( disable: 4251 ) // dll interface
25 #endif
26
27 namespace qi {
28
29 class ManageablePrivate;
30 class ExecutionContext;
31
33 enum ObjectThreadingModel
34 {
36 ObjectThreadingModel_SingleThread = 0,
38 ObjectThreadingModel_MultiThread = 1,
39
40 ObjectThreadingModel_Default = ObjectThreadingModel_SingleThread
41 };
42
43
44 class EventTrace
45 {
46 public:
47 enum EventKind
48 {
49 Event_Call = 1,
50 Event_Result = 2,
51 Event_Error = 3,
52 Event_Signal = 4
53 };
54 EventTrace() {}
55 EventTrace(unsigned int id, EventKind kind, unsigned int slotId,
56 const AnyValue& arguments, const qi::os::timeval timestamp,
57 qi::int64_t userUsTime=0, qi::int64_t systemUsTime=0,
58 unsigned int callerContext=0, unsigned int calleeContext=0,
59 qi::os::timeval postTimestamp = qi::os::timeval())
60 : _id(id), _kind(kind), _slotId(slotId), _arguments(arguments),
61 _timestamp(timestamp), _postTimestamp(postTimestamp), _userUsTime(userUsTime), _systemUsTime(systemUsTime),
62 _callerContext(callerContext), _calleeContext(calleeContext)
63 {}
64
65 // trace id, used to match call and call result
66 const unsigned int& id() const { return _id;}
67 const EventKind& kind() const { return _kind;}
68 // method or signal id
69 const unsigned int& slotId() const { return _slotId;}
70 // call or signal arguments
71 const AnyValue& arguments() const { return _arguments;}
72 const qi::os::timeval& timestamp() const { return _timestamp;}
73 const qi::os::timeval& postTimestamp() const { return _postTimestamp;}
74 const qi::int64_t& userUsTime() const { return _userUsTime;}
75 const qi::int64_t& systemUsTime() const { return _systemUsTime;}
76 const unsigned int& callerContext() const { return _callerContext;}
77 const unsigned int& calleeContext() const { return _calleeContext;}
78
79 private:
80 unsigned int _id; // trace id, used to match call and call result
81 EventKind _kind;
82 unsigned int _slotId; // method or signal id
83 AnyValue _arguments; // call or signal arguments
84 qi::os::timeval _timestamp;
85 qi::os::timeval _postTimestamp; // timestamp of eventual post call
86 qi::int64_t _userUsTime;
87 qi::int64_t _systemUsTime;
88 unsigned int _callerContext; // context of caller function
89 unsigned int _calleeContext; // context where method runs
90 };
91
92 }
93
94 QI_TYPE_STRUCT_AGREGATE_CONSTRUCTOR(qi::MinMaxSum,
95 ("minValue", minValue),
96 ("maxValue", maxValue),
97 ("cumulatedValue", cumulatedValue));
98
99 QI_TYPE_STRUCT_AGREGATE_CONSTRUCTOR(qi::MethodStatistics,
100 ("count", count),
101 ("wall", wall),
102 ("user", user),
103 ("system", system));
104
105 QI_TYPE_STRUCT_AGREGATE_CONSTRUCTOR(qi::EventTrace,
106 ("id", id),
107 ("kind", kind),
108 ("slotId", slotId),
109 ("arguments", arguments),
110 ("timestamp", timestamp),
111 ("userUsTime", userUsTime),
112 ("systemUsTime", systemUsTime),
113 ("callerContext", callerContext),
114 ("calleeContext", calleeContext));
115
116 QI_TYPE_STRUCT(qi::os::timeval, tv_sec, tv_usec);
117
118 namespace qi {
119
120 using ObjectStatistics = std::map<unsigned int, MethodStatistics>;
123 class QI_API Manageable
124 {
125 protected:
126 Manageable();
127 Manageable(const Manageable& b);
128 Manageable& operator=(const Manageable& b);
129
130 public:
131 virtual ~Manageable();
132
133 boost::mutex& initMutex();
134
136 void forceExecutionContext(boost::shared_ptr<ExecutionContext> eventLoop);
138 boost::shared_ptr<ExecutionContext> executionContext() const;
139
141
144 bool isStatsEnabled() const;
147 void enableStats(bool enable);
149 void pushStats(int slotId, float wallTime, float userTime, float systemTime);
150 ObjectStatistics stats() const;
152 void clearStats();
153
155 Signal<EventTrace> traceObject;
156
158 bool isTraceEnabled() const;
169 void enableTrace(bool enable);
171
173 static const uint32_t startId = 80;
175 static const uint32_t endId = 99;
176 using MethodMap = std::map<unsigned int, std::pair<AnyFunction, MetaCallType>>;
177 using SignalGetter = boost::function<SignalBase* (void*)>;
178 using SignalMap = std::map<unsigned int, SignalGetter>;
179
180 /* Return the methods and signals defined at GenericObject level.
181 * The 'this' argument must be the Manageable*.
182 */
183 static MethodMap& manageableMmethodMap();
184 static SignalMap& manageableSignalMap();
185 static MetaObject& manageableMetaObject();
186 static void _build();
187 int _nextTraceId();
188
189 private:
190 std::unique_ptr<ManageablePrivate> _p;
191 SignalMap signalMap;
192 };
193 }
194
195 #ifdef _MSC_VER
196 # pragma warning( pop )
197 #endif
198
199 QI_TYPE_ENUM(qi::EventTrace::EventKind);
200 #endif // _QITYPE_MANAGEABLE_HPP_
qi::MinMaxSum
Stores min, max and sum of values fed to it.
Definition: stats.hpp:17
qi::AnyValue
Definition: anyvalue.hpp:19
stats.hpp
qi::MethodStatistics
Store statistics about method calls.
Definition: stats.hpp:78
qi::int64_t
int64_t int64_t
Definition: types.hpp:61
qi::EventTrace::calleeContext
const unsigned int & calleeContext() const
Definition: manageable.hpp:77
qi::EventTrace::EventTrace
EventTrace()
Definition: manageable.hpp:54
qi::EventTrace::id
const unsigned int & id() const
Definition: manageable.hpp:66
QI_API
#define QI_API
Definition: api.hpp:33
qi::EventTrace::userUsTime
const qi::int64_t & userUsTime() const
Definition: manageable.hpp:74
qi::uint32_t
uint32_t uint32_t
Definition: types.hpp:65
QI_TYPE_STRUCT_AGREGATE_CONSTRUCTOR
QI_TYPE_STRUCT_AGREGATE_CONSTRUCTOR(qi::MinMaxSum,("minValue", minValue),("maxValue", maxValue),("cumulatedValue", cumulatedValue))
qi::EventTrace::timestamp
const qi::os::timeval & timestamp() const
Definition: manageable.hpp:72
qi::EventTrace::EventTrace
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:55
qi::EventTrace::Event_Signal
Definition: manageable.hpp:52
qi::ObjectStatistics
std::map< unsigned int, MethodStatistics > ObjectStatistics
Definition: manageable.hpp:120
qi::EventTrace::arguments
const AnyValue & arguments() const
Definition: manageable.hpp:71
qi::EventTrace::kind
const EventKind & kind() const
Definition: manageable.hpp:67
qi::Manageable::SignalMap
std::map< unsigned int, SignalGetter > SignalMap
Definition: manageable.hpp:178
qi::Manageable
Definition: manageable.hpp:123
qi::Manageable::traceObject
Signal< EventTrace > traceObject
Emitted each time a call starts and finishes, and for each signal trigger.
Definition: manageable.hpp:155
qi::EventTrace::systemUsTime
const qi::int64_t & systemUsTime() const
Definition: manageable.hpp:75
api.hpp
dll import/export and compiler message
qi::Signal
Definition: signal.hpp:168
QI_TYPE_STRUCT
QI_TYPE_STRUCT(qi::os::timeval, tv_sec, tv_usec)
qi::ObjectThreadingModel_MultiThread
Object is thread safe, multiple calls can occur in different threads in parallel. ...
Definition: manageable.hpp:38
qi::ObjectThreadingModel_Default
Definition: manageable.hpp:40
QI_TYPE_ENUM
QI_TYPE_ENUM(qi::EventTrace::EventKind)
qi::Manageable::SignalGetter
boost::function< SignalBase *(void *)> SignalGetter
Definition: manageable.hpp:177
qi::EventTrace::postTimestamp
const qi::os::timeval & postTimestamp() const
Definition: manageable.hpp:73
qi::os::timeval
struct similar to POSIX timeval
Definition: os.hpp:293
qi::EventTrace
Definition: manageable.hpp:44
qi::EventTrace::callerContext
const unsigned int & callerContext() const
Definition: manageable.hpp:76
signal.hpp
qi::EventTrace::Event_Result
Definition: manageable.hpp:50
typeobject.hpp
qi::EventTrace::Event_Call
Definition: manageable.hpp:49
qi::EventTrace::EventKind
EventKind
Definition: manageable.hpp:47
qi::EventTrace::slotId
const unsigned int & slotId() const
Definition: manageable.hpp:69
qi::ObjectThreadingModel_SingleThread
Object is not thread safe, all method calls must occur in the same thread.
Definition: manageable.hpp:36
qi::os::system
int system(const char *command)
Execute a shell command.
anyfunction.hpp
qi::ObjectThreadingModel
ObjectThreadingModel
Possible thread models for an object.
Definition: manageable.hpp:33
qi::EventTrace::Event_Error
Definition: manageable.hpp:51
qi::MetaObject
Description of the signals and methods accessible on an ObjectTypeInterface.
Definition: metaobject.hpp:25
qi::Manageable::MethodMap
std::map< unsigned int, std::pair< AnyFunction, MetaCallType >> MethodMap
Definition: manageable.hpp:176