Changes between Initial Version and Version 1 of ExamplesEFL


Ignore:
Timestamp:
Dec 3, 2009, 10:39:32 AM (15 years ago)
Author:
Thanatermesis
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ExamplesEFL

    v1 v1  
     1[[TOC]]
     2= Examples of Codes for EFL =
     3
     4This page includes some Tips and Tricks for EFL, you can found here a lot of chunks of examples of nice and useful things
     5
     6You can consider this page as a kind of fast reference
     7
     8
     9== Chunks of codes ==
     10
     11=== Exe Handler ===
     12Run an external command and set a handler (listener) to run a function when it has finished (exited), it also can know the exit code value of the command launched
     13
     14{{{
     15#!C
     16#include <stdio.h>
     17#include <Ecore.h>
     18
     19typedef struct _Handy Handy;
     20struct _Handy
     21{
     22   Ecore_Exe *gen_exe;
     23   Ecore_Event_Handler *handler;
     24};
     25
     26static int
     27_run_cb(){
     28   // Run this just in order to demonstrate that we are not catching the events anymore (handlers deleted previously)
     29   ecore_exe_run("echo 'running something extra (_run_cb) for check handler' ; sleep 1 ; false", NULL);
     30}
     31
     32static int
     33_del_cb(void *data, int type, void *event)
     34{
     35   Ecore_Exe_Event_Del *ev;
     36   Handy *hand = NULL;
     37
     38   ev = event;
     39   hand = data;
     40
     41   if (hand)
     42   {
     43      ecore_event_handler_del(hand->handler);
     44      hand->handler = NULL;
     45      hand->gen_exe = NULL;
     46      printf("handlers deleted\n");
     47   }
     48
     49   if (ev->exit_code == 1) // this is the return exit code by the job run before
     50   {
     51      printf("exit code (1) returned from command\n");
     52      _run_cb(); // This is not needed, is just a checker of that the handler has really finished (deleted)
     53   }
     54
     55   if(hand)
     56   {
     57      printf("hand freed\n");
     58      free(hand);
     59   }
     60
     61   return ECORE_CALLBACK_CANCEL; // 0
     62}
     63
     64int main (int argc, char **argv) {
     65
     66   ecore_init();
     67
     68   Handy *hand = NULL;
     69   hand = calloc(1, sizeof(Handy));
     70
     71   // Add event handler to call _del_cb when the job is finished (deleted), also pass the structure hand
     72   hand->handler = ecore_event_handler_add(ECORE_EXE_EVENT_DEL, _del_cb, hand);
     73   // run something, and return false in order to catch the 'error' exit code (1)
     74   hand->gen_exe = ecore_exe_run("echo running command ; sleep 1 ; echo command finished ; false", hand);
     75
     76
     77   ecore_main_loop_begin();
     78
     79   ecore_shutdown();
     80
     81   return(0);
     82}
     83}}}
     84
     85
     86
     87
     88
     89
     90=== ===
     91
     92{{{
     93#!C
     94
     95}}}
     96
     97
     98=== ===
     99
     100{{{
     101#!C
     102
     103}}}
     104
     105
     106=== ===
     107
     108{{{
     109#!C
     110
     111}}}
     112
     113
     114=== ===
     115
     116{{{
     117#!C
     118
     119}}}
     120
     121
     122=== ===
     123
     124{{{
     125#!C
     126
     127}}}
     128
     129
     130=== ===
     131
     132{{{
     133#!C
     134
     135}}}
     136
     137
     138=== ===
     139
     140{{{
     141#!C
     142
     143}}}
     144
     145
     146=== ===
     147
     148{{{
     149#!C
     150
     151}}}
     152
     153
     154=== ===
     155
     156{{{
     157#!C
     158
     159}}}
     160
     161
     162=== ===
     163
     164{{{
     165#!C
     166
     167}}}
     168
     169
     170=== ===
     171
     172{{{
     173#!C
     174
     175}}}