aboutsummaryrefslogtreecommitdiffstats
path: root/reference
diff options
context:
space:
mode:
authorAndy Williams <andy@andywilliams.me>2017-11-21 19:07:45 +0000
committerAndy Williams <andy@andywilliams.me>2017-11-21 19:07:45 +0000
commitb6c382900c5d0579b6cc6323c37069a056061524 (patch)
tree1cc6db66dd00d8ba2c45a225c187062f22b7a7ab /reference
parentcore: Add first efl_core reference, loop (diff)
downloadexamples-b6c382900c5d0579b6cc6323c37069a056061524.tar.gz
core: Add an io example (copier)
Diffstat (limited to 'reference')
-rw-r--r--reference/c/core/src/core_io.c93
-rw-r--r--reference/c/core/src/meson.build10
2 files changed, 95 insertions, 8 deletions
diff --git a/reference/c/core/src/core_io.c b/reference/c/core/src/core_io.c
new file mode 100644
index 00000000..64add9cf
--- /dev/null
+++ b/reference/c/core/src/core_io.c
@@ -0,0 +1,93 @@
+#define EFL_EO_API_SUPPORT 1
+#define EFL_BETA_API_SUPPORT 1
+
+#include <stdio.h>
+
+#include <Eina.h>
+#include <Efl_Core.h>
+
+/*
+ * Efl.IO examples.
+ *
+ * This IO example simply copies data from a source (stdin) to a
+ * destination (stdout) using an Efl.Io.Copier.
+ */
+
+Eo *_copier = NULL;
+
+static void
+_copier_done(void *data EINA_UNUSED, const Efl_Event *event)
+{
+ fprintf(stderr, "INFO: %s done\n", efl_name_get(event->object));
+
+ efl_exit(EXIT_SUCCESS);
+}
+
+static void
+_copier_error(void *data EINA_UNUSED, const Efl_Event *event)
+{
+ const Eina_Error *perr = event->info;
+
+ fprintf(stderr, "INFO: %s error: #%d '%s'\n",
+ efl_name_get(event->object), *perr, eina_error_msg_get(*perr));
+
+ efl_exit(EXIT_FAILURE);
+}
+
+EFL_CALLBACKS_ARRAY_DEFINE(copier_cbs,
+ { EFL_IO_COPIER_EVENT_DONE, _copier_done },
+ { EFL_IO_COPIER_EVENT_ERROR, _copier_error });
+
+EAPI void
+efl_pause(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
+{
+}
+
+EAPI void
+efl_resume(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
+{
+}
+
+EAPI void
+efl_terminate(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
+{
+ if (!_copier)
+ return;
+
+ efl_del(efl_io_copier_source_get(_copier));
+ efl_del(efl_io_copier_destination_get(_copier));
+ efl_del(_copier);
+}
+
+EAPI_MAIN void
+efl_main(void *data EINA_UNUSED, const Efl_Event *ev)
+{
+ Eo *input, *output, *loop;
+
+ /*
+ * some objects such as the Efl.Io.Copier depend on main loop,
+ * thus their parent must be a loop provider. We use the loop itself.
+ */
+ loop = ev->object;
+
+ // set up our objects to copy, use stdin and stdout
+ input = efl_add(EFL_IO_STDIN_CLASS, loop);
+ output = efl_add(EFL_IO_STDOUT_CLASS, loop);
+
+ // copier: set up a copied from input to output
+ _copier = efl_add(EFL_IO_COPIER_CLASS, loop,
+ efl_name_set(efl_added, "Copier"),
+ efl_io_copier_source_set(efl_added, input),
+ efl_io_copier_destination_set(efl_added, output),
+ efl_event_callback_array_add(efl_added, copier_cbs(), NULL));
+ if (!_copier)
+ {
+ fprintf(stderr, "ERROR: could not create Efl_Io_Copier\n");
+ efl_exit(EXIT_FAILURE);
+ }
+
+ printf("Type something here and press enter, it will be copied to stdout...\n");
+ printf(" (press Ctrl-D to exit)\n");
+}
+EFL_MAIN_EX()
+
diff --git a/reference/c/core/src/meson.build b/reference/c/core/src/meson.build
index dd362e1d..fae0d692 100644
--- a/reference/c/core/src/meson.build
+++ b/reference/c/core/src/meson.build
@@ -7,16 +7,10 @@ executable('efl_reference_core_loop',
install : true
)
-executable('efl_reference_core_exe',
- files(['core_exe.c']),
+executable('efl_reference_core_io',
+ files(['core_io.c']),
dependencies : deps,
include_directories : inc,
install : true
)
-executable('efl_reference_core_thread',
- files(['core_thread.c']),
- dependencies : deps,
- include_directories : inc,
- install : true
-)