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