aboutsummaryrefslogtreecommitdiffstats
path: root/reference
diff options
context:
space:
mode:
authorAndy Williams <andy@andywilliams.me>2017-11-22 13:11:38 +0000
committerAndy Williams <andy@andywilliams.me>2017-11-22 13:11:38 +0000
commit07c0c68cc74e08fe22ff9dd253a00ed8ac790c17 (patch)
treedc5fb22f95abbd305bb6e4408ee25668dec82e71 /reference
parentnet: Add a simple net_io example simulating an HTTP client (diff)
downloadexamples-07c0c68cc74e08fe22ff9dd253a00ed8ac790c17.tar.gz
core: Add idler reference
Diffstat (limited to 'reference')
-rw-r--r--reference/c/core/src/core_idler.c65
-rw-r--r--reference/c/core/src/meson.build7
2 files changed, 72 insertions, 0 deletions
diff --git a/reference/c/core/src/core_idler.c b/reference/c/core/src/core_idler.c
new file mode 100644
index 00000000..3256baca
--- /dev/null
+++ b/reference/c/core/src/core_idler.c
@@ -0,0 +1,65 @@
+#define EFL_EO_API_SUPPORT 1
+#define EFL_BETA_API_SUPPORT 1
+
+#include <stdio.h>
+
+#include <Eina.h>
+#include <Efl_Core.h>
+
+/*
+ * Efl Core Idler examples.
+ *
+ * Here we register callbacks to execute code when the loop is idle.
+ * We also record when we enter or exit the idle state.
+ *
+ * We initiate a timer to exit the idle state and then exit the application
+ */
+
+Efl_Loop_Timer *_timer;
+
+// the idler enter callback
+static void
+_enter_cb(void *data EINA_UNUSED, const Efl_Event *event EINA_UNUSED)
+{
+ printf("IDLE ENTER: Entering idle state.\n");
+}
+
+// the idler exit callback
+static void
+_exit_cb(void *data EINA_UNUSED, const Efl_Event *event EINA_UNUSED)
+{
+ printf("IDLE EXIT: Exiting idle state.\n");
+}
+
+// the idler callback - ran while the loop is idle
+static void
+_idler_cb(void *data EINA_UNUSED, const Efl_Event *event EINA_UNUSED)
+{
+ printf("IDLER: executing idler callback while in idle state.\n");
+}
+
+// Our timer callback ticks at the specified interval to interrupt the idle state
+static void
+_timer_cb(void *data, const Efl_Event *event)
+{
+ printf("TIMER: 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;
+
+ efl_event_callback_add(loop, EFL_LOOP_EVENT_IDLE, _idler_cb, NULL);
+ efl_event_callback_add(loop, EFL_LOOP_EVENT_IDLE_ENTER, _enter_cb, NULL);
+ efl_event_callback_add(loop, EFL_LOOP_EVENT_IDLE_EXIT, _exit_cb, NULL);
+
+ _timer = efl_add(EFL_LOOP_TIMER_CLASS, loop,
+ efl_loop_timer_interval_set(efl_added, 0.0005));
+ 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 fae0d692..5d2cfe2f 100644
--- a/reference/c/core/src/meson.build
+++ b/reference/c/core/src/meson.build
@@ -14,3 +14,10 @@ executable('efl_reference_core_io',
install : true
)
+executable('efl_reference_core_idler',
+ files(['core_idler.c']),
+ dependencies : deps,
+ include_directories : inc,
+ install : true
+)
+