6 Ecore_Fd_Handler *handler;
11 _fd_prepare_cb(void *data, Ecore_Fd_Handler *handler)
13 printf("prepare_cb called.\n");
17 _fd_handler_cb(void *data, Ecore_Fd_Handler *handler)
19 struct context *ctxt = data;
24 if (ecore_main_fd_handler_active_get(handler, ECORE_FD_ERROR))
26 printf("An error has occurred. Stop watching this fd and quit.\n");
27 ecore_main_loop_quit();
29 return ECORE_CALLBACK_CANCEL;
32 fd = ecore_main_fd_handler_fd_get(handler);
33 nbytes = read(fd, buf, sizeof(buf));
36 printf("Nothing to read, exiting...\n");
37 ecore_main_loop_quit();
39 return ECORE_CALLBACK_CANCEL;
41 buf[nbytes - 1] = '\0';
43 printf("Read %zd bytes from input: \"%s\"\n", nbytes - 1, buf);
45 return ECORE_CALLBACK_RENEW;
51 printf("Timer expired after 5 seconds...\n");
53 return ECORE_CALLBACK_RENEW;
57 main(int argc, char **argv)
59 struct context ctxt = {0};
63 printf("ERROR: Cannot init Ecore!\n");
67 ctxt.handler = ecore_main_fd_handler_add(STDIN_FILENO,
68 ECORE_FD_READ | ECORE_FD_ERROR,
71 ecore_main_fd_handler_prepare_callback_set(ctxt.handler, _fd_prepare_cb, &ctxt);
72 ctxt.timer = ecore_timer_add(5, _timer_cb, &ctxt);
74 printf("Starting the main loop. Type anything and hit <enter> to "
75 "activate the fd_handler callback, or CTRL+d to shutdown.\n");
77 ecore_main_loop_begin();
80 ecore_main_fd_handler_del(ctxt.handler);
83 ecore_timer_del(ctxt.timer);