Using the Teonet QUEUE callback
Module: cque.c This 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 September 2, 2015, 6:04 PM
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define TCQUE_VERSION "0.0.1"
void kq_cb(uint32_t
id,
int type,
void *
data) {
printf("Got Callback Queue callback with id: %d, type: %d => %s\n",
id, type, type ? "success" : "timeout");
}
size_t data_len, void *user_data) {
switch(event) {
{
static int num = 0,
success_id = -1;
printf("\nTimer event %d...\n", ++num);
switch(num) {
case 1: {
printf(
"Register callback id %d\n", cq->
id);
}
break;
case 5: {
printf(
"Register callback id %d\n", cq->
id);
}
break;
case 7: {
}
break;
case 10:
printf("\nExample stopped...\n\n");
break;
default: break;
}
}
break;
{
int type = *(int*)user_data;
printf("Got Callback Queue event with id: %d, type: %d => %s\n",
cq->
id, type, type ?
"success" :
"timeout");
}
break;
default: break;
}
}
int main(
int argc,
char** argv) {
"based on teonet ver. " VERSION "\n");
return (EXIT_SUCCESS);
}