Using the Teonet QUEUE callback
Module: cque.cThis is example application to register callback and receive timeout or success call of callback function or(and) in teonet event callback when event type equal to EV_K_CQUE_CALLBACK.
In this example we:
- Initialize teonet event manager and Read configuration
- Set custom timer with 2 second interval. To generate continously timer events
- Start teonet
- Check timer event in teonet event callback
- At first timer event we: Add callback to queue and start waiting timeout call after 5 sec ...
- At fifth timer event we: Add next callback to queue and start waiting for success result ...
- At seventh timer event we: Execute callback queue function to make success result and got it at the same time.
- At tenth timer event we: Stop the teonet to finish this Example
Created on October 19, 2017, 6:07 PM
#define TCQUE_VERSION "0.0.2"
void kq_cb(uint32_t
id,
int type,
void *
data) {
std::cout << "Got Callback Queue callback with id: " << id << ", type: "
<< type << " => " << (type ? "success" : "timeout")
<< ", data: " << (const char*)data << "\n";
}
size_t data_len, void *user_data) {
switch(event) {
} break;
} break;
static int num = 0,
success_id = -1;
std::cout << "\nTimer event " << ++num << "...\n";
switch(num) {
case 1: {
[&](uint32_t id, int type, void *data) {
std::cout
<< "Got lambda Callback Queue callback with"
<< " id: " << id
<< ", type: " << type
<< " => " << (type ? "success" : "timeout")
<< ", data: " << (const char*)data
<< ",
teonet class version: " << cque.getTeonet()->getClassVersion()
<< "\n";
}, 5.000, (void*)(const char*)"Hello");
std::cout << "Register callback
id " << cque.getId(
cq) << "\n";
} break;
case 5: {
auto cq = cque.add(
kq_cb, 5.000, (
void*)(
const char*)
"Hello2");
std::cout <<
"Register callback id " << cque.getId(
cq) <<
" \n";
success_id = cque.getId(
cq);
} break;
case 7: {
cque.exec(success_id);
} break;
case 10: {
std::cout << "\nExample stopped...\n\n";
} break;
default: break;
}
} break;
int type = *(int*) user_data;
std::cout << "Got Callback Queue event with id: " << cque.getId(cq)
<< ", type: " << type
<< " => " << (type ? "success" : "timeout")
<< "\n";
} break;
default: break;
}
}
int main(
int argc,
char** argv) {
"based on teonet ver. " VERSION "\n";
std::cout << "Example started...\n\n";
delete(teo);
return (EXIT_SUCCESS);
}