ecore: add clean thread safety mecanism.
[framework/uifw/ecore.git] / src / lib / ecore / Ecore.h
1 /** 
2 @brief Ecore Library Public API Calls
3  
4 These routines are used for Ecore Library interaction
5 */
6
7 /**
8
9 @mainpage Ecore
10
11 @version 1.1
12 @date 2000-2011
13
14 Please see the @ref authors page for contact details.
15
16 @section intro Introduction
17
18 Ecore is a library of convenience functions. A brief explanation of how to use
19 it can be found in @ref Ecore_Main_Loop_Page.
20
21 The Ecore library provides the following modules:
22 @li @ref Ecore_File_Group
23 @li @ref Ecore_Con_Group
24 @li @link Ecore_Evas.h   Ecore_Evas - Evas convenience functions. @endlink
25 @li @ref Ecore_FB_Group
26 @li @link Ecore_Ipc.h    Ecore_IPC - Inter Process Communication functions. @endlink
27 @li @link Ecore_X.h      Ecore_X - X Windows System wrapper. @endlink
28 @li @ref Ecore_Win32_Group
29 @li @ref Ecore_WinCE_Group
30
31 For more info on Ecore usage, there are these @ref Examples.
32
33 @section compiling How to compile using Ecore?
34 pkgconfig (.pc) files are installed for every ecore module.
35 Thus, to compile using any of them, you can use something like the following:
36
37 @verbatim
38 gcc *.c $(pkg-config ecore ecore-$x ecore-$y [...] --cflags --libs)
39 @endverbatim
40
41 @section install How is it installed?
42
43 Suggested configure options for evas for a Linux desktop X display:
44
45 @verbatim
46 ./configure \
47 make
48 su -
49 ...
50 make install
51 @endverbatim
52
53 */
54
55 /**
56 @page authors Authors
57 @author Carsten Haitzler <raster@rasterman.com>
58 @author Tom Gilbert <tom@linuxbrit.co.uk>
59 @author Burra <burra@colorado.edu>
60 @author Chris Ross <chris@darkrock.co.uk>
61 @author Term <term@twistedpath.org>
62 @author Tilman Sauerbeck <tilman@code-monkey.de>
63 @author Ibukun Olumuyiwa <ibukun@computer.org>
64 @author Yuri <da2001@hotmail.ru>
65 @author Nicholas Curran <quasar@bigblue.net.au>
66 @author Howell Tam <pigeon@pigeond.net>
67 @author Nathan Ingersoll <rbdpngn@users.sourceforge.net>
68 @author Andrew Elcock <andy@elcock.org>
69 @author Kim Woelders <kim@woelders.dk>
70 @author Sebastian Dransfeld <sebastid@tango.flipp.net>
71 @author Simon Poole <simon.armlinux@themalago.net>
72 @author Jorge Luis Zapata Muga <jorgeluis.zapata@gmail.com>
73 @author dan sinclair <zero@everburning.com>
74 @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
75 @author David 'onefang' Seikel <onefang@gmail.com>
76 @author Hisham 'CodeWarrior' Mardam Bey <hisham@hisham.cc>
77 @author Brian 'rephorm' Mattern <rephorm@rephorm.com>
78 @author Tim Horton <hortont424@gmail.com>
79 @author Arnaud de Turckheim 'quarium' <quarium@gmail.com>
80 @author Matt Barclay <mbarclay@gmail.com>
81 @author Peter Wehrfritz <peter.wehrfritz@web.de>
82 @author Albin "Lutin" Tonnerre <albin.tonnerre@gmail.com>
83 @author Vincent Torri <vincent.torri@gmail.com>
84 @author Lars Munch <lars@segv.dk>
85 @author Andre Dieb <andre.dieb@gmail.com>
86 @author Mathieu Taillefumier <mathieu.taillefumier@free.fr>
87 @author Rui Miguel Silva Seabra <rms@1407.org>
88 @author Samsung Electronics
89 @author Samsung SAIT
90 @author Nicolas Aguirre <aguirre.nicolas@gmail.com>
91 @author Brett Nash <nash@nash.id.au>
92 @author Mike Blumenkrantz <mike@zentific.com>
93 @author Leif Middelschulte <leif.middelschulte@gmail.com>
94 @author Mike McCormack <mj.mccormack@samsung.com>
95 @author Sangho Park <gouache95@gmail.com>
96 @author Jihoon Kim <jihoon48.kim@samsung.com> <imfine98@gmail.com>
97 @author Daniel Juyung Seo <seojuyung2@gmail.com> <juyung.seo@samsung.com>
98
99 Please contact <enlightenment-devel@lists.sourceforge.net> to get in
100 contact with the developers and maintainers.
101 */
102
103 /*
104 @page Ecore_Main_Loop_Page The Ecore Main Loop
105
106 @section intro What is Ecore?
107
108 Ecore is a clean and tiny event loop library with many modules to do lots of
109 convenient things for a programmer, to save time and effort.
110
111 It's small and lean, designed to work on embedded systems all the way to
112 large and powerful multi-cpu workstations. It serialises all system signals,
113 events etc. into a single event queue, that is easily processed without
114 needing to worry about concurrency. A properly written, event-driven program
115 using this kind of programming doesn't need threads, nor has to worry about
116 concurrency. It turns a program into a state machine, and makes it very
117 robust and easy to follow.
118
119 Ecore gives you other handy primitives, such as timers to tick over for you
120 and call specified functions at particular times so the programmer can use
121 this to do things, like animate, or time out on connections or tasks that take
122 too long etc.
123
124 Idle handlers are provided too, as well as calls on entering an idle state
125 (often a very good time to update the state of the program). All events that
126 enter the system are passed to specific callback functions that the program
127 sets up to handle those events. Handling them is simple and other Ecore
128 modules produce more events on the queue, coming from other sources such as
129 file descriptors etc.
130
131 Ecore also lets you have functions called when file descriptors become active
132 for reading or writing, allowing for streamlined, non-blocking IO.
133
134 Here is an example of a simple program and its basic event loop flow:
135
136 @image html  prog_flow.png
137 @image latex prog_flow.eps width=\textwidth
138
139
140
141 @section work How does Ecore work?
142
143 Ecore is very easy to learn and use. All the function calls are designed to
144 be easy to remember, explicit in describing what they do, and heavily
145 name-spaced. Ecore programs can start and be very simple.
146
147 For example:
148
149 @code
150 #include <Ecore.h>
151
152 int main(int argc, const char **argv)
153 {
154   ecore_init();
155   ecore_app_args_set(argc, argv);
156   ecore_main_loop_begin();
157   ecore_shutdown();
158   return 0;
159 }
160 @endcode
161
162 This program is very simple and does't check for errors, but it does start up
163 and begin a main loop waiting for events or timers to tick off. This program
164 doesn't set up any, but now we can expand on this simple program a little
165 more by adding some event handlers and timers.
166
167 @code
168 #include <Ecore.h>
169
170 Ecore_Timer         *timer1     = NULL;
171 Ecore_Event_Handler *handler1   = NULL;
172 double               start_time = 0.0;
173
174 int timer_func(void *data)
175 {
176   printf("Tick timer. Sec: %3.2f\n", ecore_time_get() - start_time);
177   return 1;
178 }
179
180 int exit_func(void *data, int ev_type, void *ev)
181 {
182   Ecore_Event_Signal_Exit *e;
183
184   e = (Ecore_Event_Signal_Exit *)ev;
185   if (e->interrupt)      printf("Exit: interrupt\n");
186   else if (e->quit)      printf("Exit: quit\n");
187   else if (e->terminate) printf("Exit: terminate\n");
188   ecore_main_loop_quit();
189   return 1;
190 }
191
192 int main(int argc, const char **argv)
193 {
194   ecore_init();
195   ecore_app_args_set(argc, argv);  
196   start_time = ecore_time_get();
197   handler1 = ecore_event_handler_add(ECORE_EVENT_SIGNAL_EXIT, exit_func, NULL);
198   timer1 = ecore_timer_add(0.5, timer_func, NULL);  
199   ecore_main_loop_begin();
200   ecore_shutdown();
201   return 0;
202 }
203 @endcode
204
205 In the previous example, we initialize our application and get the time at
206 which our program has started so we can calculate an offset. We set
207 up a timer to tick off in 0.5 seconds, and since it returns 1, will
208 keep ticking off every 0.5 seconds until it returns 0, or is deleted
209 by hand. An event handler is set up to call a function - exit_func(),
210 whenever an event of type ECORE_EVENT_SIGNAL_EXIT is received (CTRL-C
211 on the command line will cause such an event to happen). If this event
212 occurs it tells you what kind of exit signal was received, and asks
213 the main loop to quit when it is finished by calling
214 ecore_main_loop_quit().
215
216 The handles returned by ecore_timer_add() and ecore_event_handler_add() are 
217 only stored here as an example. If you don't need to address the timer or 
218 event handler again you don't need to store the result, so just call the 
219 function, and don't assign the result to any variable.
220
221 This program looks slightly more complex than needed to do these simple
222 things, but in principle, programs don't get any more complex. You add more
223 event handlers, for more events, will have more timers and such, BUT it all
224 follows the same principles as shown in this example.
225
226 */
227
228 /*
229 @page Ecore_Config_Page The Enlightened Property Library
230
231 The Enlightened Property Library (Ecore_Config) is an adbstraction
232 from the complexities of writing your own configuration. It provides
233 many features using the Enlightenment 17 development libraries.
234
235 To use the library, you:
236 @li Set the default values of your properties.
237 @li Load the configuration from a file.  You must set the default values
238     first, so that the library knows the correct type of each argument.
239
240 The following examples show how to use the Enlightened Property Library:
241 @li @link config_basic_example.c config_basic_example.c @endlink
242 @li @link config_listener_example.c config_listener_example.c @endlink
243
244 */
245
246 /**
247 @page X_Window_System_Page X Window System
248
249 The Ecore library includes a wrapper for handling the X window system.
250 This page briefly explains what the X window system is and various terms
251 that are used.
252 */
253
254 #ifndef _ECORE_H
255 #define _ECORE_H
256
257 #ifdef _MSC_VER
258 # include <Evil.h>
259 #endif
260
261 #include <Eina.h>
262
263 #ifdef EAPI
264 # undef EAPI
265 #endif
266
267 #ifdef _WIN32
268 # ifdef EFL_ECORE_BUILD
269 #  ifdef DLL_EXPORT
270 #   define EAPI __declspec(dllexport)
271 #  else
272 #   define EAPI
273 #  endif /* ! DLL_EXPORT */
274 # else
275 #  define EAPI __declspec(dllimport)
276 # endif /* ! EFL_ECORE_BUILD */
277 #else
278 # ifdef __GNUC__
279 #  if __GNUC__ >= 4
280 #   define EAPI __attribute__ ((visibility("default")))
281 #  else
282 #   define EAPI
283 #  endif
284 # else
285 #  define EAPI
286 # endif
287 #endif /* ! _WIN32 */
288
289 #ifdef _WIN32
290 # include <winsock2.h>
291 #elif (defined (__FreeBSD__) && (__FreeBSD_version >= 420001)) || defined (__OpenBSD__)
292 # include <sys/select.h>
293 # include <signal.h>
294 #else
295 # include <sys/time.h>
296 # include <signal.h>
297 #endif
298
299 #include <sys/types.h>
300
301 #ifdef __cplusplus
302 extern "C" {
303 #endif
304
305   /**
306    * @defgroup Ecore_Init_Group Ecore initialization and shutdown functions.
307    *
308    * @{
309    */
310
311    EAPI int  ecore_init(void);
312    EAPI int  ecore_shutdown(void);
313
314   /**
315    * @}
316    */
317
318   /**
319    *
320    * @defgroup Ecore_Main_Loop_Group Ecore main loop functions
321    *
322    * These are functions acting on Ecore's main loop itself or on
323    * events and infrastructure directly linked to it. This loop is
324    * designed to work on embedded systems all the way to large and
325    * powerful multi-cpu workstations.
326    *
327    * It serialises all system signals and events into a single event
328    * queue, that can be easily processed without needing to worry
329    * about concurrency. A properly written, event-driven program
330    * using this kind of programming does not need threads. It makes
331    * the program very robust and easy to follow.
332    *
333    * For example, for the main loop to be of any use, you need to be
334    * able to add @b events and event handlers on it. Events for file
335    * descriptor events are covered in @ref Ecore_FD_Handler_Group.
336    *
337    * Timer functions are covered in @ref Ecore_Time_Group.
338    *
339    * There is also provision for callbacks for when the loop enters or
340    * exits an @b idle state. See @ref Ecore_Idle_Group for more
341    * information on it.
342    *
343    * Functions are also provided for spawning child processes using
344    * @c fork(). See @ref Ecore_Exe_Group for more details on it.
345    *
346    * Here is an example of simple program and its basic event loop
347    * flow:
348    *
349    * @image html prog_flow.png
350    * @image latex prog_flow.eps width=\textwidth
351    *
352    * For examples of setting up and using a main loop, see
353    * @ref Ecore_Main_Loop_Page.
354    *
355    * @{
356    */
357
358 #define ECORE_VERSION_MAJOR 1
359 #define ECORE_VERSION_MINOR 0
360
361    typedef struct _Ecore_Version
362      {
363         int major;
364         int minor;
365         int micro;
366         int revision;
367      } Ecore_Version;
368
369    EAPI extern Ecore_Version *ecore_version;
370
371 #define ECORE_CALLBACK_CANCEL EINA_FALSE /**< Return value to remove a callback */
372 #define ECORE_CALLBACK_RENEW EINA_TRUE  /**< Return value to keep a callback */
373
374 #define ECORE_CALLBACK_PASS_ON EINA_TRUE /**< Return value to pass event to next handler */
375 #define ECORE_CALLBACK_DONE EINA_FALSE /**< Return value to stop event handling */
376
377    /**
378     * @typedef Ecore_Task_Cb Ecore_Task_Cb
379     * A callback run for a task (timer, idler, poller, animator, etc)
380     */
381    typedef Eina_Bool (*Ecore_Task_Cb) (void *data);
382
383    /**
384     * @typedef Ecore_Eselect_Function Ecore_Eselect_Function
385     * A function which can be used to replace select() in the main loop
386     */
387    typedef int (*Ecore_Select_Function)(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
388
389    EAPI void              ecore_main_loop_iterate(void);
390
391    EAPI void              ecore_main_loop_select_func_set(Ecore_Select_Function func);
392    EAPI Ecore_Select_Function ecore_main_loop_select_func_get(void);
393
394    EAPI Eina_Bool         ecore_main_loop_glib_integrate(void);
395    EAPI void              ecore_main_loop_glib_always_integrate_disable(void);
396
397    EAPI void              ecore_main_loop_begin(void);
398    EAPI void              ecore_main_loop_quit(void);
399
400    /**
401     * @typedef Ecore_Cb Ecore_Cb
402     * A generic callback called as a hook when a certain point in
403     * execution is reached.
404     */
405    typedef void (*Ecore_Cb) (void *data);
406
407    /**
408     * @typedef Ecore_Data_Cb Ecore_Data_Cb
409     * A callback which is used to return data to the main function
410     */
411    typedef void *(*Ecore_Data_Cb) (void *data);
412
413   /**
414    * @brief Call callback asynchronously in the main loop.
415    * @since 1.1.0
416    *
417    * @param callback The callback to call in the main loop
418    * @param data The data to give to that call back
419    *
420    * For all call that need to happen in the main loop (most EFL functions do),
421    * this helper function provide the infrastructure needed to do it safely
422    * by avoind dead lock, race condition and properly wake up the main loop.
423    *
424    * Remember after that function call, you should never touch again the @p data
425    * in the thread, it is owned by the main loop and you callback should take
426    * care of freeing it if necessary.
427    */
428    EAPI void                 ecore_main_loop_thread_safe_call_async(Ecore_Cb callback, void *data);
429
430   /**
431    * @brief Call callback synchronously in the main loop.
432    * @since 1.1.0
433    *
434    * @param callback The callback to call in the main loop
435    * @param data The data to give to that call back
436    * @return the value returned by the callback in the main loop
437    *
438    * For all call that need to happen in the main loop (most EFL functions do),
439    * this helper function provide the infrastructure needed to do it safely
440    * by avoind dead lock, race condition and properly wake up the main loop.
441    *
442    * Remember this function will block until the callback is executed in the
443    * main loop. It can take time and you have no guaranty about the timeline.
444    */
445   EAPI void                 *ecore_main_loop_thread_safe_call_sync(Ecore_Data_Cb callback, void *data);
446
447   /**
448    * @brief This function suspend the main loop in a know state
449    * @since 1.1.0
450    *
451    * @result EINA_TRUE if the main loop was suspended correcly.
452    *
453    * This function suspend the main loop in a know state, this let you
454    * use any EFL call you want after it return. Be carefull, the main loop
455    * is blocked until you call ecore_thread_main_loop_end(). This is
456    * the only sane way to achieve pseudo thread safety.
457    *
458    * Notice that until the main loop is blocked, the thread is blocked
459    * and their is noway around that.
460    *
461    * We still advise you, when possible, to use ecore_main_loop_thread_safe_call_async()
462    * as it will not block the thread nor the main loop.
463    */
464   EAPI Eina_Bool ecore_thread_main_loop_begin(void);
465
466   /**
467    * @brief Unlock the main loop.
468    * @since 1.1.0
469    *
470    * After a call to ecore_thread_main_loop_begin(), you need to absolutly
471    * call ecore_thread_main_loop_end(), or you application will stay frozen.
472    */
473   EAPI void ecore_thread_main_loop_end(void);
474
475    /**
476     * @}
477     */
478
479    /**
480     * @defgroup Ecore_Event_Group Ecore Event functions
481     *
482     * Ecore events are used to wake up the Ecore main loop to warn
483     * about state changes, tasks completed, data available for reading
484     * or writing, etc. They are the base of the event oriented
485     * programming.
486     *
487     * The idea is to write many functions (callbacks) that will be
488     * registered to specific events, and called when these events
489     * happen. This way, when the system state changes (a mouse click is
490     * detected, a key is pressed, or the content of a file changes, for
491     * example), the respective callbacks will be called with some
492     * information about that event. Usually the function/callback will
493     * have a data pointer to the event info (the position in the screen
494     * where the mouse was clicked, the name of the key that was
495     * pressed, or the name of the file that has changed).
496     *
497     * The basic usage, when one needs to watch for an existing event,
498     * is to register a callback to it using ecore_event_add(). Of
499     * course it's necessary to know beforehand what are the types of
500     * events that the system/library will emmit.  This should be
501     * available with the documentation from that system/library.
502     *
503     * When writing a library or group of functions that need to inform
504     * about something, and you already are running on top of a main
505     * loop, it is usually a good approach to use events. This way you
506     * allow others to register as many callbacks as necessary to this
507     * event, and don't have to care about who is registering to it. The
508     * functions ecore_event_type_new() and ecore_event_add() are
509     * available for this purpose.
510     *
511     * Example that deals with events:
512     *
513     * @li @ref ecore_event_example_c
514     *
515     * @ingroup Ecore_Main_Loop_Group
516     *
517     * @{
518     */
519
520 #define ECORE_EVENT_NONE            0
521 #define ECORE_EVENT_SIGNAL_USER     1 /**< User signal event */
522 #define ECORE_EVENT_SIGNAL_HUP      2 /**< Hup signal event */
523 #define ECORE_EVENT_SIGNAL_EXIT     3 /**< Exit signal event */
524 #define ECORE_EVENT_SIGNAL_POWER    4 /**< Power signal event */
525 #define ECORE_EVENT_SIGNAL_REALTIME 5 /**< Realtime signal event */
526 #define ECORE_EVENT_COUNT           6
527
528    typedef struct _Ecore_Win32_Handler         Ecore_Win32_Handler; /**< A handle for HANDLE handlers on Windows */
529    typedef struct _Ecore_Event_Handler         Ecore_Event_Handler; /**< A handle for an event handler */
530    typedef struct _Ecore_Event_Filter          Ecore_Event_Filter; /**< A handle for an event filter */
531    typedef struct _Ecore_Event                 Ecore_Event; /**< A handle for an event */
532    typedef struct _Ecore_Event_Signal_User     Ecore_Event_Signal_User; /**< User signal event */
533    typedef struct _Ecore_Event_Signal_Hup      Ecore_Event_Signal_Hup; /**< Hup signal event */
534    typedef struct _Ecore_Event_Signal_Exit     Ecore_Event_Signal_Exit; /**< Exit signal event */
535    typedef struct _Ecore_Event_Signal_Power    Ecore_Event_Signal_Power; /**< Power signal event */
536    typedef struct _Ecore_Event_Signal_Realtime Ecore_Event_Signal_Realtime; /**< Realtime signal event */
537
538    /**
539     * @typedef Ecore_Filter_Cb
540     * A callback used for filtering events from the main loop.
541     */
542    typedef Eina_Bool (*Ecore_Filter_Cb) (void *data, void *loop_data, int type, void *event);
543
544    /**
545     * @typedef Ecore_End_Cb Ecore_End_Cb
546     * This is the callback which is called at the end of a function,
547     * usually for cleanup purposes.
548     */
549    typedef void (*Ecore_End_Cb) (void *user_data, void *func_data);
550
551    /**
552     * @typedef Ecore_Event_Handler_Cb Ecore_Event_Handler_Cb
553     * A callback used by the main loop to handle events of a specified
554     * type.
555     */
556    typedef Eina_Bool (*Ecore_Event_Handler_Cb) (void *data, int type, void *event);
557
558    struct _Ecore_Event_Signal_User /** User signal event */
559      {
560         int   number; /**< The signal number. Either 1 or 2 */
561         void *ext_data; /**< Extension data - not used */
562
563 #ifndef _WIN32
564         siginfo_t data; /**< Signal info */
565 #endif
566      };
567
568    struct _Ecore_Event_Signal_Hup /** Hup signal event */
569      {
570         void *ext_data; /**< Extension data - not used */
571
572 #ifndef _WIN32
573         siginfo_t data; /**< Signal info */
574 #endif
575      };
576
577    struct _Ecore_Event_Signal_Exit /** Exit request event */
578      {
579         Eina_Bool   interrupt : 1; /**< Set if the exit request was an interrupt  signal*/
580         Eina_Bool   quit      : 1; /**< set if the exit request was a quit signal */
581         Eina_Bool   terminate : 1; /**< Set if the exit request was a terminate singal */
582         void          *ext_data; /**< Extension data - not used */
583
584 #ifndef _WIN32
585         siginfo_t data; /**< Signal info */
586 #endif
587      };
588
589    struct _Ecore_Event_Signal_Power /** Power event */
590      {
591         void *ext_data; /**< Extension data - not used */
592
593 #ifndef _WIN32
594         siginfo_t data; /**< Signal info */
595 #endif
596      };
597
598    struct _Ecore_Event_Signal_Realtime /** Realtime event */
599      {
600         int num; /**< The realtime signal's number */
601
602 #ifndef _WIN32
603         siginfo_t data; /**< Signal info */
604 #endif
605      };
606
607    EAPI Ecore_Event_Handler *ecore_event_handler_add(int type, Ecore_Event_Handler_Cb func, const void *data);
608    EAPI void                *ecore_event_handler_del(Ecore_Event_Handler *event_handler);
609    EAPI Ecore_Event         *ecore_event_add(int type, void *ev, Ecore_End_Cb func_free, void *data);
610    EAPI void                *ecore_event_del(Ecore_Event *event);
611    EAPI void                *ecore_event_handler_data_get(Ecore_Event_Handler *eh);
612    EAPI void                *ecore_event_handler_data_set(Ecore_Event_Handler *eh, const void *data);
613    EAPI int                  ecore_event_type_new(void);
614    EAPI Ecore_Event_Filter  *ecore_event_filter_add(Ecore_Data_Cb func_start, Ecore_Filter_Cb func_filter, Ecore_End_Cb func_end, const void *data);
615    EAPI void                *ecore_event_filter_del(Ecore_Event_Filter *ef);
616    EAPI int                  ecore_event_current_type_get(void);
617    EAPI void                *ecore_event_current_event_get(void);
618
619    /**
620     * @}
621     */
622
623     /**
624      * @defgroup Ecore_Exe_Group Process Spawning Functions
625      *
626      * Functions that deal with and send signals to spawned processes.
627      *
628      * @ingroup Ecore_Main_Loop_Group
629      *
630      * @{
631      */
632
633  #define ECORE_EXE_PRIORITY_INHERIT 9999
634
635     EAPI extern int ECORE_EXE_EVENT_ADD; /**< A child process has been added */
636     EAPI extern int ECORE_EXE_EVENT_DEL; /**< A child process has been deleted (it exited, naming consistent with the rest of ecore). */
637    EAPI extern int ECORE_EXE_EVENT_DATA; /**< Data from a child process. */
638    EAPI extern int ECORE_EXE_EVENT_ERROR; /**< Errors from a child process. */
639
640    enum _Ecore_Exe_Flags /* flags for executing a child with its stdin and/or stdout piped back */
641      {
642         ECORE_EXE_NONE = 0, /**< No exe flags at all */
643         ECORE_EXE_PIPE_READ = 1, /**< Exe Pipe Read mask */
644         ECORE_EXE_PIPE_WRITE = 2, /**< Exe Pipe Write mask */
645         ECORE_EXE_PIPE_ERROR = 4, /**< Exe Pipe error mask */
646         ECORE_EXE_PIPE_READ_LINE_BUFFERED = 8, /**< Reads are buffered until a newline and delivered 1 event per line */
647         ECORE_EXE_PIPE_ERROR_LINE_BUFFERED = 16, /**< Errors are buffered until a newline and delivered 1 event per line */
648         ECORE_EXE_PIPE_AUTO = 32, /**< stdout and stderr are buffered automatically */
649         ECORE_EXE_RESPAWN = 64, /**< FIXME: Exe is restarted if it dies */
650         ECORE_EXE_USE_SH = 128, /**< Use /bin/sh to run the command. */
651         ECORE_EXE_NOT_LEADER = 256 /**< Do not use setsid() to have the executed process be its own session leader */
652      };
653    typedef enum _Ecore_Exe_Flags Ecore_Exe_Flags;
654
655    enum _Ecore_Exe_Win32_Priority
656      {
657        ECORE_EXE_WIN32_PRIORITY_IDLE, /**< Idle priority, for monitoring the system */
658        ECORE_EXE_WIN32_PRIORITY_BELOW_NORMAL, /**< Below default priority */
659        ECORE_EXE_WIN32_PRIORITY_NORMAL, /**< Default priority */
660        ECORE_EXE_WIN32_PRIORITY_ABOVE_NORMAL, /**< Above default priority */
661        ECORE_EXE_WIN32_PRIORITY_HIGH, /**< High priority, use with care as other threads in the system will not get processor time */
662        ECORE_EXE_WIN32_PRIORITY_REALTIME /**< Realtime priority, should be almost never used as it can interrupt system threads that manage mouse input, keyboard input, and background disk flushing */
663      };
664    typedef enum _Ecore_Exe_Win32_Priority Ecore_Exe_Win32_Priority;
665
666    typedef struct _Ecore_Exe                   Ecore_Exe; /**< A handle for spawned processes */
667
668    /**
669     * @typedef Ecore_Exe_Cb Ecore_Exe_Cb
670     * A callback to run with the associated @ref Ecore_Exe, usually
671     * for cleanup purposes.
672     */
673    typedef void (*Ecore_Exe_Cb)(void *data, const Ecore_Exe *exe);
674
675    typedef struct _Ecore_Exe_Event_Add         Ecore_Exe_Event_Add; /**< Spawned Exe add event */
676    typedef struct _Ecore_Exe_Event_Del         Ecore_Exe_Event_Del; /**< Spawned Exe exit event */
677    typedef struct _Ecore_Exe_Event_Data_Line   Ecore_Exe_Event_Data_Line; /**< Lines from a child process */
678    typedef struct _Ecore_Exe_Event_Data        Ecore_Exe_Event_Data; /**< Data from a child process */
679
680    struct _Ecore_Exe_Event_Add /** Process add event */
681      {
682         Ecore_Exe *exe; /**< The handle to the added process */
683         void      *ext_data; /**< Extension data - not used */
684      };
685
686    struct _Ecore_Exe_Event_Del /** Process exit event */
687      {
688         pid_t         pid; /**< The process ID of the process that exited */
689         int           exit_code; /**< The exit code of the process */
690         Ecore_Exe    *exe; /**< The handle to the exited process, or NULL if not found */
691         int           exit_signal; /** < The signal that caused the process to exit */
692         Eina_Bool  exited    : 1; /** < set to 1 if the process exited of its own accord */
693         Eina_Bool  signalled : 1; /** < set to 1 id the process exited due to uncaught signal */
694         void         *ext_data; /**< Extension data - not used */
695 #ifndef _WIN32
696         siginfo_t     data; /**< Signal info */
697 #endif
698      };
699
700    struct _Ecore_Exe_Event_Data_Line /**< Lines from a child process */
701       {
702          char *line;
703          int   size;
704       };
705
706    struct _Ecore_Exe_Event_Data /** Data from a child process event */
707      {
708         Ecore_Exe *exe; /**< The handle to the process */
709         void *data; /**< the raw binary data from the child process that was received */
710         int   size; /**< the size of this data in bytes */
711         Ecore_Exe_Event_Data_Line *lines; /**< an array of line data if line buffered, the last one has it's line member set to NULL */
712      };
713
714    EAPI void        ecore_exe_run_priority_set(int pri);
715    EAPI int         ecore_exe_run_priority_get(void);
716    EAPI Ecore_Exe  *ecore_exe_run(const char *exe_cmd, const void *data);
717    EAPI Ecore_Exe  *ecore_exe_pipe_run(const char *exe_cmd, Ecore_Exe_Flags flags, const void *data);
718    EAPI void        ecore_exe_callback_pre_free_set(Ecore_Exe *exe, Ecore_Exe_Cb func);
719    EAPI Eina_Bool   ecore_exe_send(Ecore_Exe *exe, const void *data, int size);
720    EAPI void        ecore_exe_close_stdin(Ecore_Exe *exe);
721    EAPI void        ecore_exe_auto_limits_set(Ecore_Exe *exe, int start_bytes, int end_bytes, int start_lines, int end_lines);
722    EAPI Ecore_Exe_Event_Data *ecore_exe_event_data_get(Ecore_Exe *exe, Ecore_Exe_Flags flags);
723    EAPI void        ecore_exe_event_data_free(Ecore_Exe_Event_Data *data);
724    EAPI void       *ecore_exe_free(Ecore_Exe *exe);
725    EAPI pid_t       ecore_exe_pid_get(const Ecore_Exe *exe);
726    EAPI void        ecore_exe_tag_set(Ecore_Exe *exe, const char *tag);
727    EAPI const char *ecore_exe_tag_get(const Ecore_Exe *exe);
728    EAPI const char *ecore_exe_cmd_get(const Ecore_Exe *exe);
729    EAPI void       *ecore_exe_data_get(const Ecore_Exe *exe);
730    EAPI void       *ecore_exe_data_set(Ecore_Exe *exe, void *data);
731    EAPI Ecore_Exe_Flags ecore_exe_flags_get(const Ecore_Exe *exe);
732    EAPI void        ecore_exe_pause(Ecore_Exe *exe);
733    EAPI void        ecore_exe_continue(Ecore_Exe *exe);
734    EAPI void        ecore_exe_interrupt(Ecore_Exe *exe);
735    EAPI void        ecore_exe_quit(Ecore_Exe *exe);
736    EAPI void        ecore_exe_terminate(Ecore_Exe *exe);
737    EAPI void        ecore_exe_kill(Ecore_Exe *exe);
738    EAPI void        ecore_exe_signal(Ecore_Exe *exe, int num);
739    EAPI void        ecore_exe_hup(Ecore_Exe *exe);
740
741    /**
742     * @}
743     */
744
745    /**
746     * @defgroup Ecore_FD_Handler_Group File Event Handling Functions
747     *
748     * Functions that deal with file descriptor handlers.
749     *
750     * The @ref Ecore_Fd_Handler can be used to watch a file descriptor
751     * for data available for reading, for the availability to write
752     * without blocking, and for errors on the file descriptor.
753     *
754     * ecore_main_fd_handler_add() is used to setup a handler for a
755     * given file descriptor. This file descriptor can be the standard
756     * input, a network socket, a stream received through some driver
757     * of a hardware decoder, etc. Thus it can contain errors, like a
758     * disconnection, a broken pipe, and so, and that's why it's
759     * possible to check for these errors with the @ref ECORE_FD_ERROR
760     * flag.
761     *
762     * An @ref Ecore_Fd_Handler can be used to watch on a file
763     * descriptor without blocking, still being able to receive events,
764     * expire timers, and other watch for other things that happen in
765     * the Ecore main loop.
766     *
767     * Example of use of a file descriptor handler:
768     * @li @ref ecore_fd_handler_example_c
769     *
770     * @ingroup Ecore_Main_Loop_Group
771     *
772     * @{
773     */
774
775    typedef struct _Ecore_Fd_Handler            Ecore_Fd_Handler; /**< A handle for Fd handlers */
776
777    enum _Ecore_Fd_Handler_Flags
778      {
779         ECORE_FD_READ = 1, /**< Fd Read mask */
780         ECORE_FD_WRITE = 2, /**< Fd Write mask */
781         ECORE_FD_ERROR = 4 /**< Fd Error mask */
782      };
783    typedef enum _Ecore_Fd_Handler_Flags Ecore_Fd_Handler_Flags;
784
785    /**
786     * @typedef Ecore_Fd_Cb Ecore_Fd_Cb
787     * A callback used by an @ref Ecore_Fd_Handler.
788     */
789    typedef Eina_Bool (*Ecore_Fd_Cb) (void *data, Ecore_Fd_Handler *fd_handler);
790
791    /**
792     * @typedef Ecore_Fd_Prep_Cb Ecore_Fd_Prep_Cb
793     * A callback used by an @ref Ecore_Fd_Handler.
794     */
795    typedef void (*Ecore_Fd_Prep_Cb) (void *data, Ecore_Fd_Handler *fd_handler);
796
797    /**
798     * @typedef Ecore_Win32_Handle_Cb Ecore_Win32_Handle_Cb
799     * A callback used by an @ref Ecore_Win32_Handler.
800     */
801    typedef Eina_Bool (*Ecore_Win32_Handle_Cb) (void *data, Ecore_Win32_Handler *wh);
802
803    EAPI Ecore_Fd_Handler *ecore_main_fd_handler_add(int fd, Ecore_Fd_Handler_Flags flags, Ecore_Fd_Cb func, const void *data,
804                                                     Ecore_Fd_Cb buf_func, const void *buf_data);
805    EAPI void              ecore_main_fd_handler_prepare_callback_set(Ecore_Fd_Handler *fd_handler, Ecore_Fd_Prep_Cb func, const void *data);
806    EAPI void             *ecore_main_fd_handler_del(Ecore_Fd_Handler *fd_handler);
807    EAPI int               ecore_main_fd_handler_fd_get(Ecore_Fd_Handler *fd_handler);
808    EAPI Eina_Bool         ecore_main_fd_handler_active_get(Ecore_Fd_Handler *fd_handler, Ecore_Fd_Handler_Flags flags);
809    EAPI void              ecore_main_fd_handler_active_set(Ecore_Fd_Handler *fd_handler, Ecore_Fd_Handler_Flags flags);
810
811    EAPI Ecore_Win32_Handler *ecore_main_win32_handler_add(void *h, Ecore_Win32_Handle_Cb func, const void *data);
812    EAPI void                *ecore_main_win32_handler_del(Ecore_Win32_Handler *win32_handler);
813
814    /**
815     * @}
816     */
817
818   /**
819    * @defgroup Ecore_Poller_Group Ecore Poll functions
820    *
821    * These functions are for the need to poll information, but provide
822    * a shared abstracted API to pool such polling to minimise wakeup
823    * and ensure all the polling happens in as few spots as possible
824    * areound a core poll interval.  For now only 1 core poller type is
825    * supprted: ECORE_POLLER_CORE
826    *
827    * Example of @ref Ecore_Poller:
828    * @li @ref ecore_poller_example_c
829    *
830    * @ingroup Ecore_Main_Loop_Group
831    *
832    * @{
833    */
834
835    enum _Ecore_Poller_Type /* Poller types */
836      {
837         ECORE_POLLER_CORE = 0 /**< The core poller interval */
838      };
839    typedef enum _Ecore_Poller_Type Ecore_Poller_Type;
840
841    typedef struct _Ecore_Poller                Ecore_Poller; /**< A handle for pollers */
842
843    EAPI void          ecore_poller_poll_interval_set(Ecore_Poller_Type type, double poll_time);
844    EAPI double        ecore_poller_poll_interval_get(Ecore_Poller_Type type);
845    EAPI Eina_Bool     ecore_poller_poller_interval_set(Ecore_Poller *poller, int interval);
846    EAPI int           ecore_poller_poller_interval_get(Ecore_Poller *poller);
847    EAPI Ecore_Poller *ecore_poller_add(Ecore_Poller_Type type, int interval, Ecore_Task_Cb func, const void *data);
848    EAPI void         *ecore_poller_del(Ecore_Poller *poller);
849
850   /**
851    * @}
852    */
853
854   /**
855    * @defgroup Ecore_Animator_Group Ecore Animator functions
856    *
857    * @brief Ecore animators are a helper to simplify creating
858    * animations.
859    *
860    * Creating an animation is as simple as saying for how long it
861    * should be run and having a callback that does the animation,
862    * something like this:
863    * @code
864    * static Eina_Bool
865    * _do_animation(void *data, double pos)
866    * {
867    *    evas_object_move(data, 100 * pos, 100 * pos);
868    *    ... do some more animating ...
869    * }
870    * ...
871    * ecore_animator_timeline_add(2, _do_animation, my_evas_object);
872    * @endcode
873    * In the sample above we create an animation to move
874    * @c my_evas_object from position (0,0) to (100,100) in 2 seconds.
875    *
876    * If your animation will run for an unspecified amount of time you
877    * can use ecore_animator_add(), which is like using
878    * ecore_timer_add() with the interval being the
879    * @ref ecore_animator_frametime_set "framerate". Note that this has
880    * tangible benefits to creating a timer for each animation in terms
881    * of performance.
882    *
883    * For a more detailed example that show several animation see
884    * @ref tutorial_ecore_animator.
885    *
886    * @ingroup Ecore_Main_Loop_Group
887    *
888    * @{
889    */
890
891    typedef struct _Ecore_Animator              Ecore_Animator; /**< A handle for animators */
892
893    enum _Ecore_Pos_Map /* Position mappings */
894      {
895         ECORE_POS_MAP_LINEAR,     /**< Linear 0.0 -> 1.0 */
896         ECORE_POS_MAP_ACCELERATE, /**< Start slow then speed up */
897         ECORE_POS_MAP_DECELERATE, /**< Start fast then slow down */
898         ECORE_POS_MAP_SINUSOIDAL, /**< Start slow, speed up then slow down at end */
899         ECORE_POS_MAP_ACCELERATE_FACTOR, /**< Start slow then speed up, v1 being a power factor, 0.0 being linear, 1.0 being normal accelerate, 2.0 being much more pronounced accelerate (squared), 3.0 being cubed, etc. */
900         ECORE_POS_MAP_DECELERATE_FACTOR, /**< Start fast then slow down, v1 being a power factor, 0.0 being linear, 1.0 being normal decelerate, 2.0 being much more pronounced decelerate (squared), 3.0 being cubed, etc. */
901         ECORE_POS_MAP_SINUSOIDAL_FACTOR, /**< Start slow, speed up then slow down at end, v1 being a power factor, 0.0 being linear, 1.0 being normal sinusoidal, 2.0 being much more pronounced sinusoidal (squared), 3.0 being cubed, etc. */
902         ECORE_POS_MAP_DIVISOR_INTERP, /**< Start at gradient * v1, interpolated via power of v2 curve */
903         ECORE_POS_MAP_BOUNCE, /**< Start at 0.0 then "drop" like a ball bouncing to the ground at 1.0, and bounce v2 times, with decay factor of v1 */
904         ECORE_POS_MAP_SPRING  /**< Start at 0.0 then "wobble" like a spring rest position 1.0, and wobble v2 times, with decay factor of v1 */
905      };
906    typedef enum _Ecore_Pos_Map Ecore_Pos_Map;
907
908    enum _Ecore_Animator_Source /* Timing sources for animators */
909      {
910         ECORE_ANIMATOR_SOURCE_TIMER, /**< The default system clock/timer based animator that ticks every "frametime" seconds */
911         ECORE_ANIMATOR_SOURCE_CUSTOM /**< A custom animator trigger that you need to call ecore_animator_trigger() to make it tick */
912      };
913    typedef enum _Ecore_Animator_Source Ecore_Animator_Source;
914
915    /**
916     * @typedef Ecore_Timeline_Cb Ecore_Timeline_Cb
917     * A callback run for a task (animators with runtimes)
918     */
919    typedef Eina_Bool (*Ecore_Timeline_Cb) (void *data, double pos);
920
921   /**
922    * @brief Add an animator to call @p func at every animaton tick during main
923    * loop execution.
924    *
925    * @param func The function to call when it ticks off
926    * @param data The data to pass to the function
927    * @return A handle to the new animator
928    *
929    * This function adds a animator and returns its handle on success and NULL on
930    * failure. The function @p func will be called every N seconds where N is the
931    * @p frametime interval set by ecore_animator_frametime_set(). The function
932    * will be passed the @p data pointer as its parameter.
933    *
934    * When the animator @p func is called, it must return a value of either 1 or
935    * 0. If it returns 1 (or ECORE_CALLBACK_RENEW), it will be called again at
936    * the next tick, or if it returns 0 (or ECORE_CALLBACK_CANCEL) it will be
937    * deleted automatically making any references/handles for it invalid.
938    *
939    * @note The default @p frametime value is 1/30th of a second.
940    *
941    * @see ecore_animator_timeline_add()
942    * @see ecore_animator_frametime_set()
943    */
944    EAPI Ecore_Animator *ecore_animator_add(Ecore_Task_Cb func, const void *data);
945   /**
946    * @brief Add a animator that runs for a limited time
947    *
948    * @param runtime The time to run in seconds
949    * @param func The function to call when it ticks off
950    * @param data The data to pass to the function
951    * @return A handle to the new animator
952    *
953    * This function is just like ecore_animator_add() except the animator only
954    * runs for a limited time specified in seconds by @p runtime. Once the
955    * runtime the animator has elapsed (animator finished) it will automatically
956    * be deleted. The callback function @p func can return ECORE_CALLBACK_RENEW
957    * to keep the animator running or ECORE_CALLBACK_CANCEL ro stop it and have
958    * it be deleted automatically at any time.
959    *
960    * The @p func will ALSO be passed a position parameter that will be in value
961    * from 0.0 to 1.0 to indicate where along the timeline (0.0 start, 1.0 end)
962    * the animator run is at. If the callback wishes not to have a linear
963    * transition it can "map" this value to one of several curves and mappings
964    * via ecore_animator_pos_map().
965    *
966    * @note The default @p frametime value is 1/30th of a second.
967    *
968    * @see ecore_animator_add()
969    * @see ecore_animator_pos_map()
970    * @since 1.1.0
971    */
972    EAPI Ecore_Animator *ecore_animator_timeline_add(double runtime, Ecore_Timeline_Cb func, const void *data);
973   /**
974    * @brief Delete the specified animator from the animator list.
975    *
976    * @param animator The animator to delete
977    * @return The data pointer set for the animator on add
978    *
979    * Delete the specified @p animator from the set of animators that are
980    * executed during main loop execution. This function returns the data
981    * parameter that was being passed to the callback on success, or NULL on
982    * failure. After this call returns the specified animator object @p animator
983    * is invalid and should not be used again. It will not get called again after
984    * deletion.
985    */
986    EAPI void           *ecore_animator_del(Ecore_Animator *animator);
987   /**
988    * @brief Suspend the specified animator.
989    *
990    * @param animator The animator to delete
991    *
992    * The specified @p animator will be temporarly removed from the set of
993    * animators that are executed during main loop.
994    *
995    * @warning Freezing an animator doesn't freeze accounting of how long that
996    * animator has been running. Therefore if the animator was created with
997    * ecore_animator_timeline_add() the @p pos argument given to the callback
998    * will increase as if the animator hadn't been frozen and the animator may
999    * have it's execution halted if @p runtime elapsed.
1000    */
1001    EAPI void            ecore_animator_freeze(Ecore_Animator *animator);
1002   /**
1003    * @brief Restore execution of the specified animator.
1004    *
1005    * @param animator The animator to delete
1006    *
1007    * The specified @p animator will be put back in the set of animators that are
1008    * executed during main loop.
1009    */
1010    EAPI void            ecore_animator_thaw(Ecore_Animator *animator);
1011   /**
1012    * @brief Set the animator call interval in seconds.
1013    *
1014    * @param frametime The time in seconds in between animator ticks.
1015    *
1016    * This function sets the time interval (in seconds) between animator ticks.
1017    * At every tick the callback of every existing animator will be called.
1018    *
1019    * @warning Too small a value may cause performance issues and too high a
1020    * value may cause your animation to seem "jerky".
1021    *
1022    * @note The default @p frametime value is 1/30th of a second.
1023    */
1024    EAPI void            ecore_animator_frametime_set(double frametime);
1025   /**
1026    * @brief Get the animator call interval in seconds.
1027    *
1028    * @return The time in second in between animator ticks.
1029    *
1030    * This function retrieves the time in seconds between animator ticks.
1031    *
1032    * @see ecore_animator_frametime_set()
1033    */
1034    EAPI double          ecore_animator_frametime_get(void);
1035   /**
1036    * @brief Maps an input position from 0.0 to 1.0 along a timeline to a
1037    * position in a different curve.
1038    *
1039    * @param pos The input position to map
1040    * @param map The mapping to use
1041    * @param v1 A parameter use by the mapping (pass 0.0 if not used)
1042    * @param v2 A parameter use by the mapping (pass 0.0 if not used)
1043    * @return The mapped value
1044    *
1045    * Takes an input position (0.0 to 1.0) and maps to a new position (normally
1046    * between 0.0 and 1.0, but it may go above/below 0.0 or 1.0 to show that it
1047    * has "overshot" the mark) using some interpolation (mapping) algorithm.
1048    *
1049    * This function useful to create non-linear animations. It offers a variety
1050    * of possible animaton curves to be used:
1051    * @li ECORE_POS_MAP_LINEAR - Linear, returns @p pos
1052    * @li ECORE_POS_MAP_ACCELERATE - Start slow then speed up
1053    * @li ECORE_POS_MAP_DECELERATE - Start fast then slow down
1054    * @li ECORE_POS_MAP_SINUSOIDAL - Start slow, speed up then slow down at end
1055    * @li ECORE_POS_MAP_ACCELERATE_FACTOR - Start slow then speed up, v1 being a
1056    * power factor, 0.0 being linear, 1.0 being ECORE_POS_MAP_ACCELERATE, 2.0
1057    * being much more pronounced accelerate (squared), 3.0 being cubed, etc.
1058    * @li ECORE_POS_MAP_DECELERATE_FACTOR - Start fast then slow down, v1 being a
1059    * power factor, 0.0 being linear, 1.0 being ECORE_POS_MAP_DECELERATE, 2.0
1060    * being much more pronounced decelerate (squared), 3.0 being cubed, etc.
1061    * @li ECORE_POS_MAP_SINUSOIDAL_FACTOR - Start slow, speed up then slow down
1062    * at end, v1 being a power factor, 0.0 being linear, 1.0 being
1063    * ECORE_POS_MAP_SINUSOIDAL, 2.0 being much more pronounced sinusoidal
1064    * (squared), 3.0 being cubed, etc.
1065    * @li ECORE_POS_MAP_DIVISOR_INTERP - Start at gradient * v1, interpolated via
1066    * power of v2 curve
1067    * @li ECORE_POS_MAP_BOUNCE - Start at 0.0 then "drop" like a ball bouncing to
1068    * the ground at 1.0, and bounce v2 times, with decay factor of v1
1069    * @li ECORE_POS_MAP_SPRING - Start at 0.0 then "wobble" like a spring rest
1070    * position 1.0, and wobble v2 times, with decay factor of v1
1071    * @note When not listed v1 and v2 have no effect.
1072    *
1073    * @image html ecore-pos-map.png
1074    * @image latex ecore-pos-map.eps width=\textwidth
1075    *
1076    * One way to use this would be:
1077    * @code
1078    * double pos; // input position in a timeline from 0.0 to 1.0
1079    * double out; // output position after mapping
1080    * int x1, y1, x2, y2; // x1 & y1 are start position, x2 & y2 are end position
1081    * int x, y; // x & y are the calculated position
1082    *
1083    * out = ecore_animator_pos_map(pos, ECORE_POS_MAP_BOUNCE, 1.8, 7);
1084    * x = (x1 * out) + (x2 * (1.0 - out));
1085    * y = (y1 * out) + (y2 * (1.0 - out));
1086    * move_my_object_to(myobject, x, y);
1087    * @endcode
1088    * This will make an animaton that bounces 7 each times diminishing by a
1089    * factor of 1.8.
1090    *
1091    * @see _Ecore_Pos_Map
1092    *
1093    * @since 1.1.0
1094    */
1095    EAPI double          ecore_animator_pos_map(double pos, Ecore_Pos_Map map, double v1, double v2);
1096   /**
1097    * @brief Set the source of animator ticks for the mainloop
1098    *
1099    * @param source The source of animator ticks to use
1100    *
1101    * This sets the source of animator ticks. When an animator is active the
1102    * mainloop will "tick" over frame by frame calling all animators that are
1103    * registered until none are. The mainloop will tick at a given rate based
1104    * on the animator source. The default source is the system clock timer
1105    * source - ECORE_ANIMATOR_SOURCE_TIMER. This source uses the system clock
1106    * to tick over every N seconds (specified by ecore_animator_frametime_set(),
1107    * with the default being 1/30th of a second unless set otherwise). You can
1108    * set a custom tick source by setting the source to
1109    * ECORE_ANIMATOR_SOURCE_CUSTOM and then drive it yourself based on some input
1110    * tick source (like another application via ipc, some vertical blanking
1111    * interrupt interrupt etc.) using
1112    * ecore_animator_custom_source_tick_begin_callback_set() and
1113    * ecore_animator_custom_source_tick_end_callback_set() to set the functions
1114    * that will be called to start and stop the ticking source, which when it
1115    * gets a "tick" should call ecore_animator_custom_tick() to make the "tick" over 1
1116    * frame.
1117    */
1118    EAPI void            ecore_animator_source_set(Ecore_Animator_Source source);
1119   /**
1120    * @brief Get the animator source currently set.
1121    *
1122    * @return The current animator source
1123    *
1124    * This gets the current animator source.
1125    *
1126    * @see ecore_animator_source_set()
1127    */
1128    EAPI Ecore_Animator_Source ecore_animator_source_get(void);
1129   /**
1130    * @brief Set the function that begins a custom animator tick source
1131    *
1132    * @param func The function to call when ticking is to begin
1133    * @param data The data passed to the tick begin function as its parameter
1134    *
1135    * The Ecore Animator infrastructure handles tracking if animators are needed
1136    * or not and which ones need to be called and when, but when the tick source
1137    * is custom, you have to provide a tick source by calling
1138    * ecore_animator_custom_tick() to indicate a frame tick happened. In order
1139    * to allow the source of ticks to be dynamically enabled or disabled as
1140    * needed, the @p func when set is called to enable the tick source to
1141    * produce tick events that call ecore_animator_custom_tick(). If @p func
1142    * is NULL then no function is called to begin custom ticking.
1143    *
1144    * @see ecore_animator_source_set()
1145    * @see ecore_animator_custom_source_tick_end_callback_set()
1146    * @see ecore_animator_custom_tick()
1147    */
1148    EAPI void            ecore_animator_custom_source_tick_begin_callback_set(Ecore_Cb func, const void *data);
1149   /**
1150    * @brief Set the function that ends a custom animator tick source
1151    *
1152    * @param func The function to call when ticking is to end
1153    * @param data The data passed to the tick end function as its parameter
1154    *
1155    * This function is a matching pair to the function set by
1156    * ecore_animator_custom_source_tick_begin_callback_set() and is called
1157    * when ticking is to stop. If @p func is NULL then no function will be
1158    * called to stop ticking. For more information please see
1159    * ecore_animator_custom_source_tick_begin_callback_set().
1160    *
1161    * @see ecore_animator_source_set()
1162    * @see ecore_animator_custom_source_tick_begin_callback_set()
1163    * @see ecore_animator_custom_tick()
1164    */
1165    EAPI void            ecore_animator_custom_source_tick_end_callback_set(Ecore_Cb func, const void *data);
1166   /**
1167    * @brief Trigger a custom animator tick
1168    *
1169    * When animator source is set to ECORE_ANIMATOR_SOURCE_CUSTOM, then calling
1170    * this function triggers a run of all animators currently registered with
1171    * Ecore as this indicates a "frame tick" happened. This will do nothing if
1172    * the animator source(set by ecore_animator_source_set()) is not set to
1173    * ECORE_ANIMATOR_SOURCE_CUSTOM.
1174    *
1175    * @see ecore_animator_source_set()
1176    * @see ecore_animator_custom_source_tick_begin_callback_set
1177    * @see ecore_animator_custom_source_tick_end_callback_set()()
1178    */
1179    EAPI void            ecore_animator_custom_tick(void);
1180
1181   /**
1182    * @}
1183    */
1184
1185    /**
1186     * @defgroup Ecore_Time_Group Ecore Time functions
1187     *
1188     * Functions that deal with time. These functions include those
1189     * that simply retrieve it in a given format, and those that create
1190     * events based on it.
1191     *
1192     * The timer allows callbacks to be called at specific intervals.
1193     *
1194     * Examples with functions that deal with time:
1195     * @li @ref ecore_time_functions_example_c
1196     * @li @ref ecore_timer_example_c
1197     *
1198     * @ingroup Ecore_Main_Loop_Group
1199     *
1200     * @{
1201     */
1202
1203    typedef struct _Ecore_Timer                 Ecore_Timer; /**< A handle for timers */
1204
1205    EAPI double ecore_time_get(void);
1206    EAPI double ecore_time_unix_get(void);
1207    EAPI double ecore_loop_time_get(void);
1208
1209    EAPI Ecore_Timer *ecore_timer_add(double in, Ecore_Task_Cb func, const void *data);
1210    EAPI Ecore_Timer *ecore_timer_loop_add(double in, Ecore_Task_Cb func, const void *data);
1211    EAPI void        *ecore_timer_del(Ecore_Timer *timer);
1212    EAPI void         ecore_timer_interval_set(Ecore_Timer *timer, double in);
1213    EAPI double       ecore_timer_interval_get(Ecore_Timer *timer);
1214    EAPI void         ecore_timer_freeze(Ecore_Timer *timer);
1215    EAPI void         ecore_timer_thaw(Ecore_Timer *timer);
1216    EAPI void         ecore_timer_delay(Ecore_Timer *timer, double add);
1217    EAPI double       ecore_timer_pending_get(Ecore_Timer *timer);
1218    EAPI double       ecore_timer_precision_get(void);
1219    EAPI void         ecore_timer_precision_set(double precision);
1220    EAPI char        *ecore_timer_dump(void);
1221
1222   /**
1223    * @}
1224    */
1225
1226    /**
1227     * @defgroup Ecore_Idle_Group Ecore Idle functions
1228     *
1229     * Callbacks that are called when the program enters or exits an
1230     * idle state.
1231     *
1232     * The ecore main loop enters an idle state when it is waiting for
1233     * timers to time out, data to come in on a file descriptor or any
1234     * other event to occur.  You can set callbacks to be called when
1235     * the main loop enters an idle state, during an idle state or just
1236     * after the program wakes up.
1237     *
1238     * Enterer callbacks are good for updating your program's state, if
1239     * it has a state engine.  Once all of the enterer handlers are
1240     * called, the program will enter a "sleeping" state.
1241     *
1242     * Idler callbacks are called when the main loop has called all
1243     * enterer handlers.  They are useful for interfaces that require
1244     * polling and timers would be too slow to use.
1245     *
1246     * If no idler callbacks are specified, then the process literally
1247     * goes to sleep.  Otherwise, the idler callbacks are called
1248     * continuously while the loop is "idle", using as much CPU as is
1249     * available to the process.
1250     *
1251     * Exiter callbacks are called when the main loop wakes up from an
1252     * idle state.
1253     *
1254     * @note Idle state doesn't mean that the @b program is idle, but
1255     * that the <b>main loop</b> is idle. It doesn't have any timers,
1256     * events, fd handlers or anything else to process (which in most
1257     * <em>event driven</em> programs also means that the @b program is
1258     * idle too, but it's not a rule). The program itself may be doing
1259     * a lot of processing in the idler, or in another thread, for
1260     * example.
1261     *
1262     * Example with functions that deal with idle state:
1263     *
1264     * @li @ref ecore_idler_example_c
1265     *
1266     * @ingroup Ecore_Main_Loop_Group
1267     *
1268     * @{
1269     */
1270
1271    typedef struct _Ecore_Idler                 Ecore_Idler; /**< A handle for idlers */
1272    typedef struct _Ecore_Idle_Enterer          Ecore_Idle_Enterer; /**< A handle for idle enterers */
1273    typedef struct _Ecore_Idle_Exiter           Ecore_Idle_Exiter; /**< A handle for idle exiters */
1274
1275    /**
1276     * Add an idler handler.
1277     * @param  func The function to call when idling.
1278     * @param  data The data to be passed to this @p func call.
1279     * @return A idler handle if successfully added.  NULL otherwise.
1280     *
1281     * Add an idler handle to the event loop, returning a handle on
1282     * success and NULL otherwise.  The function @p func will be called
1283     * repeatedly while no other events are ready to be processed, as
1284     * long as it returns 1 (or ECORE_CALLBACK_RENEW). A return of 0
1285     * (or ECORE_CALLBACK_CANCEL) deletes the idler.
1286     *
1287     * Idlers are useful for progressively prossessing data without blocking.
1288     */
1289    EAPI Ecore_Idler *ecore_idler_add(Ecore_Task_Cb func, const void *data);
1290
1291    /**
1292     * Delete an idler callback from the list to be executed.
1293     * @param  idler The handle of the idler callback to delete
1294     * @return The data pointer passed to the idler callback on success.  NULL
1295     *         otherwise.
1296     */
1297    EAPI void        *ecore_idler_del(Ecore_Idler *idler);
1298
1299    EAPI Ecore_Idle_Enterer *ecore_idle_enterer_add(Ecore_Task_Cb func, const void *data);
1300    EAPI Ecore_Idle_Enterer *ecore_idle_enterer_before_add(Ecore_Task_Cb func, const void *data);
1301    EAPI void               *ecore_idle_enterer_del(Ecore_Idle_Enterer *idle_enterer);
1302
1303    EAPI Ecore_Idle_Exiter *ecore_idle_exiter_add(Ecore_Task_Cb func, const void *data);
1304    EAPI void              *ecore_idle_exiter_del(Ecore_Idle_Exiter *idle_exiter);
1305
1306   /**
1307    * @}
1308    */
1309
1310   /**
1311    * @defgroup Ecore_Thread_Group Ecore Thread functions
1312    *
1313    * Facilities to run heavy tasks in different threads to avoid blocking
1314    * the main loop.
1315    *
1316    * The EFL is, for the most part, not thread safe. This means that if you
1317    * have some task running in another thread and you have, for example, an
1318    * Evas object to show the status progress of this task, you cannot update
1319    * the object from within the thread. This can only be done from the main
1320    * thread, the one running the main loop. This problem can be solved
1321    * by running a thread that sends messages to the main one using an
1322    * @ref Ecore_Pipe_Group "Ecore_Pipe", but when you need to handle other
1323    * things like cancelling the thread, your code grows in coplexity and gets
1324    * much harder to maintain.
1325    *
1326    * Ecore Thread is here to solve that problem. It is @b not a simple wrapper
1327    * around standard POSIX threads (or the equivalent in other systems) and
1328    * it's not meant to be used to run parallel tasks throughout the entire
1329    * duration of the program, especially when these tasks are performance
1330    * critical, as Ecore manages these tasks using a pool of threads based on
1331    * system configuration.
1332    *
1333    * What Ecore Thread does, is make it a lot easier to dispatch a worker
1334    * function to perform some heavy task and then get the result once it
1335    * completes, without blocking the application's UI. In addition, cancelling
1336    * and rescheduling comes practically for free and the developer needs not
1337    * worry about how many threads are launched, since Ecore will schedule
1338    * them according to the number of processors the system has and maximum
1339    * amount of concurrent threads set for the application.
1340    *
1341    * At the system level, Ecore will start a new thread on an as-needed basis
1342    * until the maximum set is reached. When no more threads can be launched,
1343    * new worker functions will be queued in a waiting list until a thread
1344    * becomes available. This way, system threads will be shared throughout
1345    * different worker functions, but running only one at a time. At the same
1346    * time, a worker function that is rescheduled may be run on a different
1347    * thread the next time.
1348    *
1349    * The ::Ecore_Thread handler has two meanings, depending on what context
1350    * it is on. The one returned when starting a worker with any of the
1351    * functions ecore_thread_run() or ecore_thread_feedback_run() is an
1352    * identifier of that specific instance of the function and can be used from
1353    * the main loop with the ecore_thread_cancel() and ecore_thread_check()
1354    * functions. This handler must not be shared with the worker function
1355    * function running in the thread. This same handler will be the one received
1356    * on the @c end, @c cancel and @c feedback callbacks.
1357    *
1358    * The worker function, that's the one running in the thread, also receives
1359    * an ::Ecore_Thread handler that can be used with ecore_thread_cancel() and
1360    * ecore_thread_check(), sharing the flag with the main loop. But this
1361    * handler is also associated with the thread where the function is running.
1362    * This has strong implications when working with thread local data.
1363    *
1364    * There are two kinds of worker threads Ecore handles: simple, or short,
1365    * workers and feedback workers.
1366    *
1367    * The first kind is for simple functions that perform a
1368    * usually small but time consuming task. Ecore will run this function in
1369    * a thread as soon as one becomes available and notify the calling user of
1370    * its completion once the task is done.
1371    *
1372    * The following image shows the flow of a program running four tasks on
1373    * a pool of two threads.
1374    *
1375    * @image html ecore_thread.png
1376    * @image rtf ecore_thread.png
1377    * @image latex ecore_thread.eps width=\textwidth
1378    *
1379    * For larger tasks that may require continuous communication with the main
1380    * program, the feedback workers provide the same functionality plus a way
1381    * for the function running in the thread to send messages to the main
1382    * thread.
1383    *
1384    * The next diagram omits some details shown in the previous one regarding
1385    * how threads are spawned and tasks are queued, but illustrates how feedback
1386    * jobs communicate with the main loop and the special case of threads
1387    * running out of pool.
1388    *
1389    * @image html ecore_thread_feedback.png
1390    * @image rtf ecore_thread_feedback.png
1391    * @image latex ecore_thread_feedback.eps width=\textwidth
1392    *
1393    * See an overview example in @ref ecore_thread_example_c.
1394    *
1395    * @ingroup Ecore_Main_Loop_Group
1396    *
1397    * @{
1398    */
1399
1400    typedef struct _Ecore_Thread                Ecore_Thread; /**< A handle for threaded jobs */
1401
1402    /**
1403     * @typedef Ecore_Thread_Cb Ecore_Thread_Cb
1404     * A callback used by Ecore_Thread helper.
1405     */
1406   typedef void (*Ecore_Thread_Cb) (void *data, Ecore_Thread *thread);
1407    /**
1408     * @typedef Ecore_Thread_Notify_Cb Ecore_Thread_Notify_Cb
1409     * A callback used by the main loop to receive data sent by an
1410     * @ref Ecore_Thread_Group.
1411     */
1412   typedef void (*Ecore_Thread_Notify_Cb) (void *data, Ecore_Thread *thread, void *msg_data);
1413
1414   /**
1415    * Schedule a task to run in a parallel thread to avoid locking the main loop
1416    *
1417    * @param func_blocking The function that should run in another thread.
1418    * @param func_end Function to call from main loop when @p func_blocking
1419    * completes its task successfully (may be NULL)
1420    * @param func_cancel Function to call from main loop if the thread running
1421    * @p func_blocking is cancelled or fails to start (may be NULL)
1422    * @param data User context data to pass to all callbacks.
1423    * @return A new thread handler, or NULL on failure
1424    *
1425    * This function will try to create a new thread to run @p func_blocking in,
1426    * or if the maximum number of concurrent threads has been reached, will
1427    * add it to the pending list, where it will wait until a thread becomes
1428    * available. The return value will be an ::Ecore_Thread handle that can
1429    * be used to cancel the thread before its completion.
1430    *
1431    * @note This function should always return immediately, but in the rare
1432    * case that Ecore is built with no thread support, @p func_blocking will
1433    * be called here, actually blocking the main loop.
1434    *
1435    * Once a thread becomes available, @p func_blocking will be run in it until
1436    * it finishes, then @p func_end is called from the thread containing the
1437    * main loop to inform the user of its completion. While in @p func_blocking,
1438    * no functions from the EFL can be used, except for those from Eina that are
1439    * marked to be thread-safe. Even for the latter, caution needs to be taken
1440    * if the data is shared across several threads.
1441    *
1442    * @p func_end will be called from the main thread when @p func_blocking ends,
1443    * so here it's safe to use anything from the EFL freely.
1444    *
1445    * The thread can also be cancelled before its completion calling
1446    * ecore_thread_cancel(), either from the main thread or @p func_blocking.
1447    * In this case, @p func_cancel will be called, also from the main thread
1448    * to inform of this happening. If the thread could not be created, this
1449    * function will be called and it's @c thread parameter will be NULL. It's
1450    * also safe to call any EFL function here, as it will be running in the
1451    * main thread.
1452    *
1453    * Inside @p func_blocking, it's possible to call ecore_thread_reschedule()
1454    * to tell Ecore that this function should be called again.
1455    *
1456    * Be aware that no assumptions can be made about the order in which the
1457    * @p func_end callbacks for each task will be called. Once the function is
1458    * running in a different thread, it's the OS that will handle its running
1459    * schedule, and different functions may take longer to finish than others.
1460    * Also remember that just starting several tasks together doesn't mean they
1461    * will be running at the same time. Ecore will schedule them based on the
1462    * number of threads available for the particular system it's running in,
1463    * so some of the jobs started may be waiting until another one finishes
1464    * before it can execute its own @p func_blocking.
1465    *
1466    * @see ecore_thread_feedback_run()
1467    * @see ecore_thread_cancel()
1468    * @see ecore_thread_reschedule()
1469    * @see ecore_thread_max_set()
1470    */
1471    EAPI Ecore_Thread *ecore_thread_run(Ecore_Thread_Cb func_blocking,
1472                                        Ecore_Thread_Cb func_end,
1473                                        Ecore_Thread_Cb func_cancel,
1474                                        const void *data);
1475   /**
1476    * Launch a thread to run a task than can talk back to the main thread
1477    *
1478    * @param func_heavy The function that should run in another thread.
1479    * @param func_notify Function that receives the data sent from the thread
1480    * @param func_end Function to call from main loop when @p func_heavy
1481    * completes its task successfully
1482    * @param func_cancel Function to call from main loop if the thread running
1483    * @p func_heavy is cancelled or fails to start
1484    * @param data User context data to pass to all callback.
1485    * @param try_no_queue If you want to run outside of the thread pool.
1486    * @return A new thread handler, or NULL on failure
1487    *
1488    * See ecore_thread_run() for a general description of this function.
1489    *
1490    * The difference with the above is that ecore_thread_run() is meant for
1491    * tasks that don't need to communicate anything until they finish, while
1492    * this function is provided with a new callback, @p func_notify, that will
1493    * be called from the main thread for every message sent from @p func_heavy
1494    * with ecore_thread_feedback().
1495    *
1496    * Like with ecore_thread_run(), a new thread will be launched to run
1497    * @p func_heavy unless the maximum number of simultaneous threadas has been
1498    * reached, in which case the function will be scheduled to run whenever a
1499    * running task ends and a thread becomes free. But if @p try_no_queue is
1500    * set, Ecore will first try to launch a thread outside of the pool to run
1501    * the task. If it fails, it will revert to the normal behaviour of using a
1502    * thread from the pool as if @p try_no_queue had not been set.
1503    *
1504    * Keep in mind that Ecore handles the thread pool based on the number of
1505    * CPUs available, but running a thread outside of the pool doesn't count for
1506    * this, so having too many of them may have drastic effects over the
1507    * program's performance.
1508    *
1509    * @see ecore_thread_feedback()
1510    * @see ecore_thread_run()
1511    * @see ecore_thread_cancel()
1512    * @see ecore_thread_reschedule()
1513    * @see ecore_thread_max_set()
1514    */
1515    EAPI Ecore_Thread *ecore_thread_feedback_run(Ecore_Thread_Cb func_heavy,
1516                                                 Ecore_Thread_Notify_Cb func_notify,
1517                                                 Ecore_Thread_Cb func_end,
1518                                                 Ecore_Thread_Cb func_cancel,
1519                                                 const void *data,
1520                                                 Eina_Bool try_no_queue);
1521   /**
1522    * Cancel a running thread.
1523    *
1524    * @param thread The thread to cancel.
1525    * @return Will return EINA_TRUE if the thread has been cancelled,
1526    *         EINA_FALSE if it is pending.
1527    *
1528    * This function can be called both in the main loop or in the running thread.
1529    *
1530    * This function cancels a running thread. If @p thread can be immediately
1531    * cancelled (it's still pending execution after creation or rescheduling),
1532    * then the @c cancel callback will be called, @p thread will be freed and
1533    * the function will return EINA_TRUE.
1534    *
1535    * If the thread is already running, then this function returns EINA_FALSE
1536    * after marking the @p thread as pending cancellation. For the thread to
1537    * actually be terminated, it needs to return from the user function back
1538    * into Ecore control. This can happen in several ways:
1539    * @li The function ends and returns normally. If it hadn't been cancelled,
1540    * @c func_end would be called here, but instead @c func_cancel will happen.
1541    * @li The function returns after requesting to be rescheduled with
1542    * ecore_thread_reschedule().
1543    * @li The function is prepared to leave early by checking if
1544    * ecore_thread_check() returns EINA_TRUE.
1545    *
1546    * The user function can cancel itself by calling ecore_thread_cancel(), but
1547    * it should always use the ::Ecore_Thread handle passed to it and never
1548    * share it with the main loop thread by means of shared user data or any
1549    * other way.
1550    *
1551    * @p thread will be freed and should not be used again if this function
1552    * returns EINA_TRUE or after the @c func_cancel callback returns.
1553    *
1554    * @see ecore_thread_check()
1555    */
1556    EAPI Eina_Bool     ecore_thread_cancel(Ecore_Thread *thread);
1557   /**
1558    * Checks if a thread is pending cancellation
1559    *
1560    * @param thread The thread to test.
1561    * @return EINA_TRUE if the thread is pending cancellation,
1562    *         EINA_FALSE if it is not.
1563    *
1564    * This function can be called both in the main loop or in the running thread.
1565    *
1566    * When ecore_thread_cancel() is called on an already running task, the
1567    * thread is marked as pending cancellation. This function returns EINA_TRUE
1568    * if this mark is set for the given @p thread and can be used from the
1569    * main loop thread to check if a still active thread has been cancelled,
1570    * or from the user function running in the thread to check if it should
1571    * stop doing what it's doing and return early, effectively cancelling the
1572    * task.
1573    *
1574    * @see ecore_thread_cancel()
1575    */
1576    EAPI Eina_Bool     ecore_thread_check(Ecore_Thread *thread);
1577   /**
1578    * Sends data from the worker thread to the main loop
1579    *
1580    * @param thread The current ::Ecore_Thread context to send data from
1581    * @param msg_data Data to be transmitted to the main loop
1582    * @return EINA_TRUE if @p msg_data was successfully sent to main loop,
1583    *         EINA_FALSE if anything goes wrong.
1584    *
1585    * You should use this function only in the @c func_heavy call.
1586    *
1587    * Only the address to @p msg_data will be sent and once this function
1588    * returns EINA_TRUE, the job running in the thread should never touch the
1589    * contents of it again. The data sent should be malloc()'ed or something
1590    * similar, as long as it's not memory local to the thread that risks being
1591    * overwritten or deleted once it goes out of scope or the thread finishes.
1592    *
1593    * Care must be taken that @p msg_data is properly freed in the @c func_notify
1594    * callback set when creating the thread.
1595    *
1596    * @see ecore_thread_feedback_run()
1597    */
1598    EAPI Eina_Bool     ecore_thread_feedback(Ecore_Thread *thread, const void *msg_data);
1599   /**
1600    * Asks for the function in the thread to be called again at a later time
1601    *
1602    * @param thread The current ::Ecore_Thread context to rescheduled
1603    * @return EINA_TRUE if the task was successfully rescheduled,
1604    *         EINA_FALSE if anything goes wrong.
1605    *
1606    * This function should be called only from the same function represented
1607    * by @pthread.
1608    *
1609    * Calling this function will mark the thread for a reschedule, so as soon
1610    * as it returns, it will be added to the end of the list of pending tasks.
1611    * If no other tasks are waiting or there are sufficient threads available,
1612    * the rescheduled task will be launched again immediately.
1613    *
1614    * This should never return EINA_FALSE, unless it was called from the wrong
1615    * thread or with the wrong arguments.
1616    *
1617    * The @c func_end callback set when the thread is created will not be
1618    * called until the function in the thread returns without being rescheduled.
1619    * Similarly, if the @p thread is cancelled, the reschedule will not take
1620    * effect.
1621    */
1622    EAPI Eina_Bool     ecore_thread_reschedule(Ecore_Thread *thread);
1623   /**
1624    * Gets the number of active threads running jobs
1625    *
1626    * @return Number of active threads running jobs
1627    *
1628    * This returns the number of threads currently running jobs of any type
1629    * through the Ecore_Thread API.
1630    *
1631    * @note Jobs started through the ecore_thread_feedback_run() function with
1632    * the @c try_no_queue parameter set to EINA_TRUE will not be accounted for
1633    * in the return of this function unless the thread creation fails and it
1634    * falls back to using one from the pool.
1635    */
1636    EAPI int           ecore_thread_active_get(void);
1637   /**
1638    * Gets the number of short jobs waiting for a thread to run
1639    *
1640    * @return Number of pending threads running "short" jobs
1641    *
1642    * This returns the number of tasks started with ecore_thread_run() that are
1643    * pending, waiting for a thread to become available to run them.
1644    */
1645    EAPI int           ecore_thread_pending_get(void);
1646   /**
1647    * Gets the number of feedback jobs waiting for a thread to run
1648    *
1649    * @return Number of pending threads running "feedback" jobs
1650    *
1651    * This returns the number of tasks started with ecore_thread_feedback_run()
1652    * that are pending, waiting for a thread to become available to run them.
1653    */
1654    EAPI int           ecore_thread_pending_feedback_get(void);
1655   /**
1656    * Gets the total number of pending jobs
1657    *
1658    * @return Number of pending threads running jobs
1659    *
1660    * Same as the sum of ecore_thread_pending_get() and
1661    * ecore_thread_pending_feedback_get().
1662    */
1663    EAPI int           ecore_thread_pending_total_get(void);
1664   /**
1665    * Gets the maximum number of threads that can run simultaneously
1666    *
1667    * @return Max possible number of Ecore_Thread's running concurrently
1668    *
1669    * This returns the maximum number of Ecore_Thread's that may be running at
1670    * the same time. If this number is reached, new jobs started by either
1671    * ecore_thread_run() or ecore_thread_feedback_run() will be added to the
1672    * respective pending queue until one of the running threads finishes its
1673    * task and becomes available to run a new one.
1674    *
1675    * By default, this will be the number of available CPUs for the
1676    * running program (as returned by eina_cpu_count()), or 1 if this value
1677    * could not be fetched.
1678    *
1679    * @see ecore_thread_max_set()
1680    * @see ecore_thread_max_reset()
1681    */
1682    EAPI int           ecore_thread_max_get(void);
1683   /**
1684    * Sets the maximum number of threads allowed to run simultaneously
1685    *
1686    * @param num The new maximum
1687    *
1688    * This sets a new value for the maximum number of concurrently running
1689    * Ecore_Thread's. It @b must an integer between 1 and (2 * @c x), where @c x
1690    * is the number for CPUs available.
1691    *
1692    * @see ecore_thread_max_get()
1693    * @see ecore_thread_max_reset()
1694    */
1695    EAPI void          ecore_thread_max_set(int num);
1696   /**
1697    * Resets the maximum number of concurrently running threads to the default
1698    *
1699    * This resets the value returned by ecore_thread_max_get() back to its
1700    * default.
1701    *
1702    * @see ecore_thread_max_get()
1703    * @see ecore_thread_max_set()
1704    */
1705    EAPI void          ecore_thread_max_reset(void);
1706   /**
1707    * Gets the number of threads available for running tasks
1708    *
1709    * @return The number of available threads
1710    *
1711    * Same as doing ecore_thread_max_get() - ecore_thread_active_get().
1712    *
1713    * This function may return a negative number only in the case the user
1714    * changed the maximum number of running threads while other tasks are
1715    * running.
1716    */
1717    EAPI int           ecore_thread_available_get(void);
1718   /**
1719    * Adds some data to a hash local to the thread
1720    *
1721    * @param thread The thread context the data belongs to
1722    * @param key The name under which the data will be stored
1723    * @param value The data to add
1724    * @param cb Function to free the data when removed from the hash
1725    * @param direct If true, this will not copy the key string (like
1726    * eina_hash_direct_add())
1727    * @return EINA_TRUE on success, EINA_FALSE on failure
1728    *
1729    * Ecore Thread has a mechanism to share data across several worker functions
1730    * that run on the same system thread. That is, the data is stored per
1731    * thread and for a worker function to have access to it, it must be run
1732    * by the same thread that stored the data.
1733    *
1734    * When there are no more workers pending, the thread will be destroyed
1735    * along with the internal hash and any data left in it will be freed with
1736    * the @p cb function given.
1737    *
1738    * This set of functions is useful to share things around several instances
1739    * of a function when that thing is costly to create and can be reused, but
1740    * may only be used by one function at a time.
1741    *
1742    * For example, if you have a program doing requisitions to a database,
1743    * these requisitions can be done in threads so that waiting for the
1744    * database to respond doesn't block the UI. Each of these threads will
1745    * run a function, and each function will be dependent on a connection to
1746    * the database, which may not be able to handle more than one request at
1747    * a time so for each running function you will need one connection handle.
1748    * The options then are:
1749    * @li Each function opens a connection when it's called, does the work and
1750    * closes the connection when it finishes. This may be costly, wasting a lot
1751    * of time on resolving hostnames, negotiating permissions and allocating
1752    * memory.
1753    * @li Open the connections in the main loop and pass it to the threads
1754    * using the data pointer. Even worse, it's just as costly as before and now
1755    * it may even be kept with connections open doing nothing until a thread
1756    * becomes available to run the function.
1757    * @li Have a way to share connection handles, so that each instance of the
1758    * function can check if an available connection exists, and if it doesn't,
1759    * create one and add it to the pool. When no more connections are needed,
1760    * they are all closed.
1761    *
1762    * The last option is the most efficient, but it requires a lot of work to
1763    * implement properly. Using thread local data helps to achieve the same
1764    * result while avoiding doing all the tracking work on your code. The way
1765    * to use it would be, at the worker function, to ask for the connection
1766    * with ecore_thread_local_data_find() and if it doesn't exist, then open
1767    * a new one and save it with ecore_thread_local_data_add(). Do the work and
1768    * forget about the connection handle, when everything is done the function
1769    * just ends. The next worker to run on that thread will check if a
1770    * connection exists and find that it does, so the process of opening a
1771    * new one has been spared. When no more workers exist, the thread is
1772    * destroyed and the callback used when saving the connection will be called
1773    * to close it.
1774    *
1775    * This function adds the data @p value to the thread data under the given
1776    * @p key.
1777    * No other value in the hash may have the same @p key. If you need to
1778    * change the value under a @p key, or you don't know if one exists already,
1779    * you can use ecore_thread_local_data_set().
1780    *
1781    * Neither @p key nor @p value may be NULL and @p key will be copied in the
1782    * hash, unless @p direct is set, in which case the string used should not
1783    * be freed until the data is removed from the hash.
1784    *
1785    * The @p cb function will be called when the data in the hash needs to be
1786    * freed, be it because it got deleted with ecore_thread_local_data_del() or
1787    * because @p thread was terminated and the hash destroyed. This parameter
1788    * may be NULL, in which case @p value needs to be manually freed after
1789    * removing it from the hash with either ecore_thread_local_data_del() or
1790    * ecore_thread_local_data_set(), but it's very unlikely that this is what
1791    * you want.
1792    *
1793    * This function, and all of the others in the @c ecore_thread_local_data
1794    * family of functions, can only be called within the worker function running
1795    * in the thread. Do not call them from the main loop or from a thread
1796    * other than the one represented by @p thread.
1797    *
1798    * @see ecore_thread_local_data_set()
1799    * @see ecore_thread_local_data_find()
1800    * @see ecore_thread_local_data_del()
1801    */
1802    EAPI Eina_Bool     ecore_thread_local_data_add(Ecore_Thread *thread, const char *key, void *value, Eina_Free_Cb cb, Eina_Bool direct);
1803   /**
1804    * Sets some data in the hash local to the given thread
1805    *
1806    * @param thread The thread context the data belongs to
1807    * @param key The name under which the data will be stored
1808    * @param value The data to add
1809    * @param cb Function to free the data when removed from the hash
1810    *
1811    * If no data exists in the hash under the @p key, this function adds
1812    * @p value in the hash under the given @p key and returns NULL.
1813    * The key itself is copied.
1814    *
1815    * If the hash already contains something under @p key, the data will be
1816    * replaced by @p value and the old value will be returned.
1817    *
1818    * NULL will also be returned if either @p key or @p value are NULL, or if
1819    * an error occurred.
1820    *
1821    * This function, and all of the others in the @c ecore_thread_local_data
1822    * family of functions, can only be called within the worker function running
1823    * in the thread. Do not call them from the main loop or from a thread
1824    * other than the one represented by @p thread.
1825    *
1826    * @see ecore_thread_local_data_add()
1827    * @see ecore_thread_local_data_del()
1828    * @see ecore_thread_local_data_find()
1829    */
1830    EAPI void         *ecore_thread_local_data_set(Ecore_Thread *thread, const char *key, void *value, Eina_Free_Cb cb);
1831   /**
1832    * Gets data stored in the hash local to the given thread
1833    *
1834    * @param thread The thread context the data belongs to
1835    * @param key The name under which the data is stored
1836    * @return The value under the given key, or NULL on error
1837    *
1838    * Finds and return the data stored in the shared hash under the key @p key.
1839    *
1840    * This function, and all of the others in the @c ecore_thread_local_data
1841    * family of functions, can only be called within the worker function running
1842    * in the thread. Do not call them from the main loop or from a thread
1843    * other than the one represented by @p thread.
1844    *
1845    * @see ecore_thread_local_data_add()
1846    * @see ecore_thread_local_data_wait()
1847    */
1848    EAPI void         *ecore_thread_local_data_find(Ecore_Thread *thread, const char *key);
1849   /**
1850    * Deletes from the thread's hash the data corresponding to the given key
1851    *
1852    * @param thread The thread context the data belongs to
1853    * @param key The name under which the data is stored
1854    * @return EINA_TRUE on success, EINA_FALSE on failure
1855    *
1856    * If there's any data stored associated with @p key in the global hash,
1857    * this function will remove it from it and return EINA_TRUE. If no data
1858    * exists or an error occurs, it returns EINA_FALSE.
1859    *
1860    * If the data was added to the hash with a free function, then it will
1861    * also be freed after removing it from the hash, otherwise it requires
1862    * to be manually freed by the user, which means that if no other reference
1863    * to it exists before calling this function, it will result in a memory
1864    * leak.
1865    *
1866    * This function, and all of the others in the @c ecore_thread_local_data
1867    * family of functions, can only be called within the worker function running
1868    * in the thread. Do not call them from the main loop or from a thread
1869    * other than the one represented by @p thread.
1870    *
1871    * @see ecore_thread_local_data_add()
1872    */
1873    EAPI Eina_Bool     ecore_thread_local_data_del(Ecore_Thread *thread, const char *key);
1874
1875   /**
1876    * Adds some data to a hash shared by all threads
1877    *
1878    * @param key The name under which the data will be stored
1879    * @param value The data to add
1880    * @param cb Function to free the data when removed from the hash
1881    * @param direct If true, this will not copy the key string (like
1882    * eina_hash_direct_add())
1883    * @return EINA_TRUE on success, EINA_FALSE on failure
1884    *
1885    * Ecore Thread keeps a hash that can be used to share data across several
1886    * threads, including the main loop one, without having to manually handle
1887    * mutexes to do so safely.
1888    *
1889    * This function adds the data @p value to this hash under the given @p key.
1890    * No other value in the hash may have the same @p key. If you need to
1891    * change the value under a @p key, or you don't know if one exists already,
1892    * you can use ecore_thread_global_data_set().
1893    *
1894    * Neither @p key nor @p value may be NULL and @p key will be copied in the
1895    * hash, unless @p direct is set, in which case the string used should not
1896    * be freed until the data is removed from the hash.
1897    *
1898    * The @p cb function will be called when the data in the hash needs to be
1899    * freed, be it because it got deleted with ecore_thread_global_data_del() or
1900    * because Ecore Thread was shut down and the hash destroyed. This parameter
1901    * may be NULL, in which case @p value needs to be manually freed after
1902    * removing it from the hash with either ecore_thread_global_data_del() or
1903    * ecore_thread_global_data_set().
1904    *
1905    * Manually freeing any data that was added to the hash with a @p cb function
1906    * is likely to produce a segmentation fault, or any other strange
1907    * happenings, later on in the program.
1908    *
1909    * @see ecore_thread_global_data_del()
1910    * @see ecore_thread_global_data_set()
1911    * @see ecore_thread_global_data_find()
1912    */
1913    EAPI Eina_Bool     ecore_thread_global_data_add(const char *key, void *value, Eina_Free_Cb cb, Eina_Bool direct);
1914   /**
1915    * Sets some data in the hash shared by all threads
1916    *
1917    * @param key The name under which the data will be stored
1918    * @param value The data to add
1919    * @param cb Function to free the data when removed from the hash
1920    *
1921    * If no data exists in the hash under the @p key, this function adds
1922    * @p value in the hash under the given @p key and returns NULL.
1923    * The key itself is copied.
1924    *
1925    * If the hash already contains something under @p key, the data will be
1926    * replaced by @p value and the old value will be returned.
1927    *
1928    * NULL will also be returned if either @p key or @p value are NULL, or if
1929    * an error occurred.
1930    *
1931    * @see ecore_thread_global_data_add()
1932    * @see ecore_thread_global_data_del()
1933    * @see ecore_thread_global_data_find()
1934    */
1935    EAPI void         *ecore_thread_global_data_set(const char *key, void *value, Eina_Free_Cb cb);
1936   /**
1937    * Gets data stored in the hash shared by all threads
1938    *
1939    * @param key The name under which the data is stored
1940    * @return The value under the given key, or NULL on error
1941    *
1942    * Finds and return the data stored in the shared hash under the key @p key.
1943    *
1944    * Keep in mind that the data returned may be used by more than one thread
1945    * at the same time and no reference counting is done on it by Ecore.
1946    * Freeing the data or modifying its contents may require additional
1947    * precautions to be considered, depending on the application's design.
1948    *
1949    * @see ecore_thread_global_data_add()
1950    * @see ecore_thread_global_data_wait()
1951    */
1952    EAPI void         *ecore_thread_global_data_find(const char *key);
1953   /**
1954    * Deletes from the shared hash the data corresponding to the given key
1955    *
1956    * @param key The name under which the data is stored
1957    * @return EINA_TRUE on success, EINA_FALSE on failure
1958    *
1959    * If there's any data stored associated with @p key in the global hash,
1960    * this function will remove it from it and return EINA_TRUE. If no data
1961    * exists or an error occurs, it returns EINA_FALSE.
1962    *
1963    * If the data was added to the hash with a free function, then it will
1964    * also be freed after removing it from the hash, otherwise it requires
1965    * to be manually freed by the user, which means that if no other reference
1966    * to it exists before calling this function, it will result in a memory
1967    * leak.
1968    *
1969    * Note, also, that freeing data that other threads may be using will result
1970    * in a crash, so appropriate care must be taken by the application when
1971    * that possibility exists.
1972    *
1973    * @see ecore_thread_global_data_add()
1974    */
1975    EAPI Eina_Bool     ecore_thread_global_data_del(const char *key);
1976   /**
1977    * Gets data stored in the shared hash, or wait for it if it doesn't exist
1978    *
1979    * @param key The name under which the data is stored
1980    * @param seconds The amount of time in seconds to wait for the data.
1981    * @return The value under the given key, or NULL on error
1982    *
1983    * Finds and return the data stored in the shared hash under the key @p key.
1984    *
1985    * If there's nothing in the hash under the given @p key, the function
1986    * will block and wait up to @p seconds seconds for some other thread to
1987    * add it with either ecore_thread_global_data_add() or
1988    * ecore_thread_global_data_set(). If after waiting there's still no data
1989    * to get, NULL will be returned.
1990    *
1991    * If @p seconds is 0, then no waiting will happen and this function works
1992    * like ecore_thread_global_data_find(). If @p seconds is less than 0, then
1993    * the function will wait indefinitely.
1994    *
1995    * Keep in mind that the data returned may be used by more than one thread
1996    * at the same time and no reference counting is done on it by Ecore.
1997    * Freeing the data or modifying its contents may require additional
1998    * precautions to be considered, depending on the application's design.
1999    *
2000    * @see ecore_thread_global_data_add()
2001    * @see ecore_thread_global_data_find()
2002    */
2003    EAPI void         *ecore_thread_global_data_wait(const char *key, double seconds);
2004
2005   /**
2006    * @}
2007    */
2008
2009   /**
2010    * @defgroup Ecore_Pipe_Group Pipe wrapper
2011    *
2012    * These functions wrap the pipe / write / read functions to easily
2013    * integrate its use into ecore's main loop.
2014    *
2015    * The ecore_pipe_add() function creates file descriptors (sockets
2016    * on Windows) and attach a handle to the ecore main loop. That
2017    * handle is called when data is read in the pipe. To write data in
2018    * the pipe, just call ecore_pipe_write(). When you are done, just
2019    * call ecore_pipe_del().
2020    *
2021    * For examples see here:
2022    * @li @ref tutorial_ecore_pipe_gstreamer_example
2023    * @li @ref tutorial_ecore_pipe_simple_example
2024    *
2025    * @ingroup Ecore_Main_Loop_Group
2026    *
2027    * @{
2028    */
2029
2030    typedef struct _Ecore_Pipe                  Ecore_Pipe; /**< A handle for pipes */
2031
2032    /**
2033     * @typedef Ecore_Pipe_Cb Ecore_Pipe_Cb
2034     * The callback that data written to the pipe is sent to.
2035     */
2036    typedef void (*Ecore_Pipe_Cb) (void *data, void *buffer, unsigned int nbyte);
2037
2038    EAPI Ecore_Pipe  *ecore_pipe_add(Ecore_Pipe_Cb handler, const void *data);
2039    EAPI void        *ecore_pipe_del(Ecore_Pipe *p);
2040    EAPI Eina_Bool    ecore_pipe_write(Ecore_Pipe *p, const void *buffer, unsigned int nbytes);
2041    EAPI void         ecore_pipe_write_close(Ecore_Pipe *p);
2042    EAPI void         ecore_pipe_read_close(Ecore_Pipe *p);
2043    EAPI void         ecore_pipe_thaw(Ecore_Pipe *p);
2044    EAPI void         ecore_pipe_freeze(Ecore_Pipe *p);
2045    EAPI int          ecore_pipe_wait(Ecore_Pipe *p, int message_count, double wait);
2046
2047   /**
2048    * @}
2049    */
2050
2051    /**
2052     * @defgroup Ecore_Job_Group Ecore Job functions
2053     *
2054     * You can queue jobs that are to be done by the main loop when the
2055     * current event is dealt with.
2056     *
2057     * Jobs are processed by the main loop similarly to events. They
2058     * also will be executed in the order in which they were added.
2059     *
2060     * A good use for them is when you don't want to execute an action
2061     * immeditately, but want to give the control back to the main loop
2062     * so that it will call your job callback when jobs start being
2063     * processed (and if there are other jobs added before yours, they
2064     * will be processed first). This also gives the chance to other
2065     * actions in your program to cancel the job before it is started.
2066     *
2067     * Examples of using @ref Ecore_Job:
2068     * @li @ref ecore_job_example_c
2069     *
2070     * @ingroup Ecore_Main_Loop_Group
2071     *
2072     * @{
2073     */
2074
2075    typedef struct _Ecore_Job Ecore_Job; /**< A job handle */
2076
2077    EAPI Ecore_Job *ecore_job_add(Ecore_Cb func, const void *data);
2078    EAPI void      *ecore_job_del(Ecore_Job *job);
2079
2080   /**
2081    * @}
2082    */
2083
2084   /**
2085    * @defgroup Ecore_Application_Group Ecore Application functions
2086    *
2087    * @{
2088    */
2089
2090    EAPI void ecore_app_args_set(int argc, const char **argv);
2091    EAPI void ecore_app_args_get(int *argc, char ***argv);
2092    EAPI void ecore_app_restart(void);
2093
2094   /**
2095    * @}
2096    */
2097
2098   /**
2099    * @defgroup Ecore_Throttle_Group Ecore Throttle functions
2100    *
2101    * @ingroup Ecore_Main_Loop_Group
2102    *
2103    * @{
2104    */
2105
2106    EAPI void       ecore_throttle_adjust(double amount );
2107    EAPI double     ecore_throttle_get(void);
2108
2109   /**
2110    * @}
2111    */
2112
2113 #ifdef __cplusplus
2114 }
2115 #endif
2116 #endif