On Tue, Nov 28, 2017 at 7:21 AM, Andy Williams <a...@andywilliams.me> wrote:
> ajwillia-ms pushed a commit to branch master.
>
> http://git.enlightenment.org/tools/examples.git/commit/?id=bc275959dd4124ba96e87e444a38614d1453be43
>
> commit bc275959dd4124ba96e87e444a38614d1453be43
> Author: Andy Williams <a...@andywilliams.me>
> Date:   Tue Nov 28 09:21:09 2017 +0000
>
>     core: Add Efl_Io_File example into efl-core reference
>
>     Refactor the copier code into a separate method for clarity.
> ---
>  reference/c/core/src/core_io.c | 98 
> ++++++++++++++++++++++++++++++++++++------
>  1 file changed, 86 insertions(+), 12 deletions(-)
>
> diff --git a/reference/c/core/src/core_io.c b/reference/c/core/src/core_io.c
> index e70ee7f..3808fb8 100644
> --- a/reference/c/core/src/core_io.c
> +++ b/reference/c/core/src/core_io.c
> @@ -2,6 +2,7 @@
>  #define EFL_BETA_API_SUPPORT 1
>
>  #include <stdio.h>
> +#include <fcntl.h>
>
>  #include <Eina.h>
>  #include <Efl_Core.h>
> @@ -9,13 +10,77 @@
>  /*
>   * Efl.IO examples.
>   *
> - * This IO example simply copies data from a source (stdin) to a
> - * destination (stdout) using an Efl.Io.Copier.
> + * This IO example shows the use of various IO APIs. First we use Efl.Io.File
> + * to read and write a standard file. Then we set up a copier to copy data 
> from
> + * a source (stdin) to a destination (stdout) using an Efl.Io.Copier.
>   */
>
>  Eo *_copier = NULL;
>
>  static void
> +_io_write(const char *filename)
> +{
> +   Eina_Slice content = EINA_SLICE_STR("1. Some dummy content\n2. \n3. With 
> more...\n");
> +   Efl_Io_File *file;
> +
> +   file = efl_add(EFL_IO_FILE_CLASS, NULL,
> +                  efl_file_set(efl_added, filename, NULL), // mandatory
> +                  efl_io_file_flags_set(efl_added, O_WRONLY | O_CREAT), // 
> write and create - default is read
> +                  efl_io_file_mode_set(efl_added, 0644), // neccessary if we 
> use O_CREAT
> +                  efl_io_closer_close_on_destructor_set(efl_added, 
> EINA_TRUE)); // recommended
> +
> +   if (!file)
> +     return;
> +
> +   printf("Loaded file %s for read on fd %d\n", filename, 
> efl_io_reader_fd_get(file));
> +
> +   if (efl_io_writer_write(file, &content, NULL) != EINA_ERROR_NO_ERROR)
> +     fprintf(stderr, "Failed to write test file\n");

although this works for file, it's not a good example/approach, since
you should check and monitor "can_write" events.

likewise, monitor "can_read" before you call "efl_io_reader_read()".
The best approach is to use efl_io_copier class, that does all of that
for you in a main loop friendly way.

if you want to show case the "efl_io_reader/writer" APIs directly,
then also use can_{read,write} events... otherwise people will misuse
that.



-- 
Gustavo Sverzut Barbieri
--------------------------------------
Mobile: +55 (16) 99354-9890

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to