aboutsummaryrefslogtreecommitdiffstats
path: root/reference
diff options
context:
space:
mode:
authorAndy Williams <andy@andywilliams.me>2017-11-22 14:32:32 +0000
committerAndy Williams <andy@andywilliams.me>2017-11-22 14:32:32 +0000
commite58ac7d5c86e102f892dfedc9b279ede4fb9e4b8 (patch)
tree3fbbc15af8e157a4ffa70a07781da2f84fa57793 /reference
parentcore: Add idler reference (diff)
downloadexamples-e58ac7d5c86e102f892dfedc9b279ede4fb9e4b8.tar.gz
core: Add a polling example
Diffstat (limited to 'reference')
-rw-r--r--reference/c/core/src/core_poll.c66
-rw-r--r--reference/c/core/src/meson.build7
2 files changed, 73 insertions, 0 deletions
diff --git a/reference/c/core/src/core_poll.c b/reference/c/core/src/core_poll.c
new file mode 100644
index 00000000..84f095cd
--- /dev/null
+++ b/reference/c/core/src/core_poll.c
@@ -0,0 +1,66 @@
+#define EFL_EO_API_SUPPORT 1
+#define EFL_BETA_API_SUPPORT 1
+
+#include <stdio.h>
+
+#include <Eina.h>
+#include <Efl_Core.h>
+
+/*
+ * Efl Core Poll examples.
+ *
+ * This example sets up poll callbacks for LOW, MEDIUM and HIGH frequency events.
+ * We run for 30 seconds and print to stdout to show when each is called.
+ * Depending on your system this may not include any LOW frequency polls.
+ */
+
+Efl_Loop_Timer *_timer;
+
+// the poll callback for low frequency events
+static void
+_poll_low_cb(void *data EINA_UNUSED, const Efl_Event *event EINA_UNUSED)
+{
+ printf("L");
+}
+
+// the poll callback for medium frequency events
+static void
+_poll_med_cb(void *data EINA_UNUSED, const Efl_Event *event EINA_UNUSED)
+{
+ printf("M");
+}
+
+// the poll callback for high frequency events
+static void
+_poll_high_cb(void *data EINA_UNUSED, const Efl_Event *event EINA_UNUSED)
+{
+ printf(".");
+
+}
+
+// Our timer callback ticks at the specified interval to interrupt the polling
+static void
+_timer_cb(void *data EINA_UNUSED, const Efl_Event *event EINA_UNUSED)
+{
+ printf("\nTIMER: timer callback called, exiting.\n");
+
+ efl_del(_timer);
+ efl_exit(0);
+}
+
+EAPI_MAIN void
+efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
+{
+ Eo *loop = ev->object;
+
+ setbuf(stdout, NULL);
+ efl_event_callback_add(loop, EFL_LOOP_EVENT_POLL_LOW, _poll_low_cb, NULL);
+ efl_event_callback_add(loop, EFL_LOOP_EVENT_POLL_MEDIUM, _poll_med_cb, NULL);
+ efl_event_callback_add(loop, EFL_LOOP_EVENT_POLL_HIGH, _poll_high_cb, NULL);
+
+ _timer = efl_add(EFL_LOOP_TIMER_CLASS, loop,
+ efl_loop_timer_interval_set(efl_added, 30));
+ efl_event_callback_add(_timer, EFL_LOOP_TIMER_EVENT_TICK, _timer_cb, NULL);
+}
+EFL_MAIN()
+
diff --git a/reference/c/core/src/meson.build b/reference/c/core/src/meson.build
index 5d2cfe2f..6906e537 100644
--- a/reference/c/core/src/meson.build
+++ b/reference/c/core/src/meson.build
@@ -21,3 +21,10 @@ executable('efl_reference_core_idler',
install : true
)
+executable('efl_reference_core_poll',
+ files(['core_poll.c']),
+ dependencies : deps,
+ include_directories : inc,
+ install : true
+)
+