ajwillia-ms pushed a commit to branch master. http://git.enlightenment.org/tools/examples.git/commit/?id=981d59e32d5a243fdef3cba3775374f7ab67d53b
commit 981d59e32d5a243fdef3cba3775374f7ab67d53b Author: Andy Williams <[email protected]> Date: Tue Nov 21 18:45:33 2017 +0000 core: Add first efl_core reference, loop --- reference/c/core/meson.build | 12 ++++ reference/c/core/src/core_loop.c | 147 +++++++++++++++++++++++++++++++++++++++ reference/c/core/src/meson.build | 22 ++++++ 3 files changed, 181 insertions(+) diff --git a/reference/c/core/meson.build b/reference/c/core/meson.build new file mode 100644 index 0000000..453b9a3 --- /dev/null +++ b/reference/c/core/meson.build @@ -0,0 +1,12 @@ +project( + 'efl-reference-core', 'c', + version : '0.0.1', + default_options: [ 'c_std=gnu99', 'warning_level=2' ], + meson_version : '>= 0.38.0') + +eina = dependency('eina', version : '>=1.20.99') +efl = dependency('efl-core', version : '>=1.20.99') + +inc = include_directories('.') +subdir('src') + diff --git a/reference/c/core/src/core_loop.c b/reference/c/core/src/core_loop.c new file mode 100644 index 0000000..09414a4 --- /dev/null +++ b/reference/c/core/src/core_loop.c @@ -0,0 +1,147 @@ +#define EFL_EO_API_SUPPORT 1 +#define EFL_BETA_API_SUPPORT 1 + +#include <stdio.h> + +#include <Eina.h> +#include <Efl_Core.h> + +#define FILENAME "/tmp/core_loop_test.txt" + +/* + * Efl Core Loop examples. + * + * TODO + */ + +static int _count = 0; +static void _loop_fd_read(); + +static void +_print_loop(Efl_Loop *loop, const char *label) +{ + printf("%s loop found at %p \"%s\"\n", label, loop, efl_name_get(loop)); +} + +static void +_loop_current(Efl_Loop *current) +{ + Efl_Loop *loop; + + loop = current; + _print_loop(loop, "Current"); + loop = efl_loop_main_get(current); + _print_loop(loop, "Application Main"); + + loop = efl_add(EFL_LOOP_USER_CLASS, NULL, + efl_name_set(efl_added, "User Loop")); + _print_loop(loop, "Child"); + efl_del(loop); +} + +static void +_loop_fd_read_cb(void *data EINA_UNUSED, const Efl_Event *event) +{ + Efl_Loop_Fd *fd; + char buf[7]; + int len; + + fd = event->object; + + len = read(efl_loop_fd_file_get(fd), &buf, sizeof(buf)); + + // here we are exiting + if (len <= 0) + { + efl_del(fd); + unlink(FILENAME); + + efl_exit(0); + return; + } + + buf[len] = 0; + printf("READ %s", buf); +} + +static void +_loop_fd_write_cb(void *data EINA_UNUSED, const Efl_Event *event) +{ + Efl_Loop_Fd *fd; + + fd = event->object; + + // we have outputted all we want to, remove the write handler + // start checking for read availability instead + if (_count >= 5) + { + efl_del(fd); + + _loop_fd_read(); + return; + } + + _count++; + printf("WRITING %d\n", _count); + write(efl_loop_fd_file_get(fd), eina_slstr_printf("TEST %d\n", _count), 7); +} + +static void +_loop_fd_write() +{ + Efl_Loop_Fd *loop_fd; + FILE *file; + int fd; + + loop_fd = efl_add(EFL_LOOP_FD_CLASS, NULL, + efl_name_set(efl_added, "Write Loop")); + + efl_event_callback_add(loop_fd, EFL_LOOP_FD_EVENT_WRITE, _loop_fd_write_cb, NULL); + + file = fopen(FILENAME, "w+"); + fd = fileno(file); + + printf("Opened file with fd %d\n", fd); + efl_loop_fd_file_set(loop_fd, fd); + +} + +static void +_loop_fd_read() +{ + Efl_Loop_Fd *loop_fd; + FILE *file; + int fd; + + loop_fd = efl_add(EFL_LOOP_FD_CLASS, NULL, + efl_name_set(efl_added, "Read Loop")); + + efl_event_callback_add(loop_fd, EFL_LOOP_FD_EVENT_READ, _loop_fd_read_cb, NULL); + + file = fopen("/tmp/core_loop_test.txt", "r"); + fd = fileno(file); + + printf("Opened file with fd %d\n", fd); + efl_loop_fd_file_set(loop_fd, fd); +} + +EAPI_MAIN void +efl_main(void *data EINA_UNUSED, const Efl_Event *ev) +{ + const Efl_Version *version; + + version = efl_loop_efl_version_get(ev->object); + printf("Running on EFL version %d.%d.%d [%s]\n", version->major, version->minor, + version->micro, version->build_id); + printf("\n"); + + _loop_current(ev->object); + printf("\n"); + + _loop_fd_write(); + // we will call _loop_fd_read() once write is complete! + + // we will exit from the end of the read loop +} +EFL_MAIN() + diff --git a/reference/c/core/src/meson.build b/reference/c/core/src/meson.build new file mode 100644 index 0000000..dd362e1 --- /dev/null +++ b/reference/c/core/src/meson.build @@ -0,0 +1,22 @@ +deps = [eina, efl] + +executable('efl_reference_core_loop', + files(['core_loop.c']), + dependencies : deps, + include_directories : inc, + install : true +) + +executable('efl_reference_core_exe', + files(['core_exe.c']), + dependencies : deps, + include_directories : inc, + install : true +) + +executable('efl_reference_core_thread', + files(['core_thread.c']), + dependencies : deps, + include_directories : inc, + install : true +) --
