- 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
signalspy.hpp
Go to the documentation of this file.
1 #pragma once
2
3 #ifndef _QI_SIGNALSPY_HPP_
4 #define _QI_SIGNALSPY_HPP_
5
6 #include <qi/actor.hpp>
7 #include <qi/anyobject.hpp>
8 #include <qi/api.hpp>
9 #include <qi/clock.hpp>
10 #include <qi/signal.hpp>
11 #include <ka/src.hpp>
12
13 namespace qi
14 {
23 class QI_API SignalSpy: public Actor
24 {
25 public:
28 template<typename... Args>
29 SignalSpy(SignalF<void(Args...)>& signal)
30 : _records()
31 {
32 SignalLink link = signal.connect(stranded([this](const Args&... args)
33 {
34 this->recordCallback(args...);
35 }));
36 _disconnect = [link, &signal]{ signal.disconnect(link); };
37 }
38
40 SignalSpy(AnyObject& object, const std::string& signalOrPropertyName);
41
42 // Non-copyable
43 SignalSpy(const SignalSpy&) = delete;
44 SignalSpy& operator=(const SignalSpy&) = delete;
45
46 ~SignalSpy();
47
49 struct Record
50 {
52 std::vector<qi::AnyValue> args;
53
55 template<typename T>
56 const T& arg(int index) const
57 {
58 return args[index].asReference().as<T>();
59 }
60 };
61
63 std::vector<Record> allRecords() const;
64
66 Record record(size_t index) const;
67
69 Record lastRecord() const;
70
72 size_t recordCount() const;
73
74 QI_API_DEPRECATED_MSG(Use 'recordCount' instead)
75 unsigned int getCounter() const;
76
78 FutureSync<bool> waitUntil(size_t nofRecords, const Duration& timeout) const;
79
80 private:
82 std::function<void()> _disconnect;
83
85 std::vector<Record> _records;
86
88 mutable Signal<void> recorded;
89
91 template <typename... Args>
92 void recordCallback(const Args&... args)
93 {
94 QI_ASSERT(strand()->isInThisContext());
95 _records.emplace_back(Record{{AnyValue::from<Args>(args)...}});
96 recorded();
97 }
98
100 AnyReference recordAnyCallback(const AnyReferenceVector& args);
101 };
102 }
103
104 #endif // _QI_SIGNALSPY_HPP_
QI_API
#define QI_API
Definition: api.hpp:33
qi::SignalSpy
A tool to track signal emissions, specialized for testing. A signal spy can acknowledge every signal ...
Definition: signalspy.hpp:23
QI_ASSERT
#define QI_ASSERT(expr__)
Definition: assert.hpp:27
api.hpp
dll import/export and compiler message
qi::Signal< void >
Definition: signal.hpp:251
qi::Duration
NanoSeconds Duration
Definition: clock.hpp:32
actor.hpp
qi::SignalF
Definition: signal.hpp:171
qi::AnyReferenceVector
std::vector< AnyReference > AnyReferenceVector
Definition: anyreference.hpp:26
QI_API_DEPRECATED_MSG
#define QI_API_DEPRECATED_MSG(msg__)
Compiler flags to mark a function as deprecated. It will generate a compiler warning.
Definition: macro.hpp:55
qi::SignalSpy::SignalSpy
SignalSpy(SignalF< void(Args...)> &signal)
Definition: signalspy.hpp:29
qi::SignalSpy::Record::args
std::vector< qi::AnyValue > args
Signal arguments are stored here, in a type-erased way for compatibility.
Definition: signalspy.hpp:52
signal.hpp
qi::Object
Definition: object.hxx:243
clock.hpp
qi::SignalSpy::Record
A record data, corresponding to one signal emission.
Definition: signalspy.hpp:49
qi::FutureSync
Definition: future_fwd.hpp:70
qi::Actor
Definition: actor.hpp:24
qi::SignalLink
qi::uint64_t SignalLink
Definition: signal.hpp:36
anyobject.hpp
qi::SignalSpy::Record::arg
const T & arg(int index) const
Use this to access an argument in the type you expect it.
Definition: signalspy.hpp:56