Single thread and multi thread callbacks
This program displays basic information about CIC events generated by a grabber, this
time using the CallbackSingleThread
model.
#include <iostream>
#include <EGrabber.h>
using namespace Euresys;
class MyGrabber : public EGrabber<CallbackSingleThread> { // 1
public:
MyGrabber(EGenTL &gentl) : EGrabber<CallbackSingleThread>(gentl) { // 2
runScript("config.js");
enableEvent<CicData>();
reallocBuffers(3);
start();
}
private:
virtual void onCicEvent(const CicData &data) {
std::cout << "timestamp: " << std::dec << data.timestamp << " us, "
<< "numid: 0x" << std::hex << data.numid
<< " (" << getEventDescription(data.numid) << ")"
<< std::endl;
}
};
int main() {
try {
EGenTL gentl;
MyGrabber grabber(gentl);
while (true) { // 3
}
} catch (const std::exception &e) {
std::cout << "error: " << e.what() << std::endl;
}
}
There are very few differences between this program and the CallbackOnDemand
version:
MyGrabber
is derived fromEGrabber<CallbackSingleThread>
instead ofEGrabber<CallbackOnDemand>
.- Consequently,
MyGrabber
's constructor initializes its base class by callingEGrabber<CallbackSingleThread>
's constructor. EGrabber
creates a callback thread in which it callsprocessEvent
, so we don't have to. Here, we simply enter an infinite loop.
As you can see, moving from CallbackOnDemand
to
CallbackSingleThread
is very simple. If instead you want the
CallbackMultiThread
variant, simply change the base class of
MyGrabber
to EGrabber<CallbackMultiThread>
(and
call the appropriate constructor).