3 #ifndef _QI_SIGNALHELPER_HPP_
4 #define _QI_SIGNALHELPER_HPP_
25 template<
typename... Args>
29 signal.connect(
stranded([
this](
const Args&... args)
31 this->recordCallback(args...);
44 return this->recordAnyCallback(anything);
61 std::vector<qi::AnyValue>
args;
65 const T&
arg(
int index)
const
67 return args[index].asReference().as<T>();
82 qiLogDebug(
"qi.signalspy") <<
"Getting record #" << index <<
" "
85 return async([
this, index]
87 qiLogDebug(
"qi.signalspy") <<
"Getting record #" << index;
88 return _records[index];
97 assert(!_records.empty());
return _records.back();
104 qiLogDebug(
"qi.signalspy") <<
"Getting record count "
108 qiLogDebug(
"qi.signalspy") <<
"Getting record count";
109 return _records.size();
116 return async([&]{
return static_cast<unsigned int>(_records.size()); }).value();
123 async([
this, waiting, nofRecords, timeout]()
mutable
125 if(nofRecords <= _records.size())
134 auto timingOut =
asyncDelay([
this, waiting, &recordedSubscription]()
mutable
142 [
this, waiting, &recordedSubscription, timingOut, nofRecords]()
mutable
144 if (nofRecords <= _records.size())
157 std::vector<Record> _records;
163 template <
typename... Args>
164 void recordCallback(
const Args&... args)
166 assert(
strand()->isInThisContext());
167 _records.emplace_back(Record{{qi::AnyValue::from<Args>(args)...}});
174 assert(
strand()->isInThisContext());
176 for (
const auto& arg: args)
178 _records.emplace_back(std::move(record));
180 return AnyReference();
SignalSubscriber & setCallType(MetaCallType ct)
bool isInThisContext() override
unsigned int getCounter() const
auto stranded(Args &&...args) const -> decltype(_strand.schedulerFor(std::forward< Args >(args)...))
A tool to track signal emissions, specialized for testing. A signal spy can acknowledge every signal ...
qi::Strand * strand() const
Future< T > future() const
Get a future linked to this promise. Can be called multiple times.
Record lastRecord() const
Direct access to last record.
auto async(Args &&...args) const -> decltype(_strand.async(std::forward< Args >(args)...))
SignalSubscriber & connect(...)
bool disconnect(const SignalLink &link)
std::vector< AnyReference > AnyReferenceVector
Force a synchronous call.
#define QI_API_DEPRECATED_MSG(msg__)
Compiler flags to mark a function as deprecated. It will generate a compiler warning.
SignalSpy(SignalF< void(Args...)> &signal)
Constructor taking a signal instance.
std::vector< qi::AnyValue > args
Signal arguments are stored here, in a type-erased way for compatibility.
SignalSpy & operator=(const SignalSpy &)=delete
Record record(size_t index) const
Direct access to a record, by order of arrival.
static AnyFunction fromDynamicFunction(DynamicFunction f)
SignalSpy(qi::AnyObject &object, const std::string &signalOrPropertyName)
Constructor taking a type-erased signal.
A record data, corresponding to one signal emission.
size_t recordCount() const
The number of records.
void setValue(const ValueType &value)
qi::FutureSync< bool > waitUntil(unsigned int nofRecords, const qi::Duration &timeout) const
Waits for the given number of records to be reached, before the given timeout.
std::vector< Record > allRecords() const
Retrieve all the records in one shot.
const T & arg(int index) const
Use this to access an argument in the type you expect it.
auto asyncDelay(Args &&...args) const -> decltype(_strand.asyncDelay(std::forward< Args >(args)...))