f283849c78cdc9b2fe43001c639d8a157910749f
[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.2
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 @ref Ecore_Evas_Group
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    @author Jérémy Zurcher <jeremy@asynk.ch>
120    @author Vikram Narayanan <vikram186@gmail.com>
121
122    Please contact <enlightenment-devel@lists.sourceforge.net> to get in
123    contact with the developers and maintainers.
124  */
125
126 /**
127  * @page Ecore_Main_Loop_Page The Ecore Main Loop
128  *
129  * @section intro What is Ecore?
130  *
131  * Ecore is a clean and tiny event loop library with many modules to do lots of
132  * convenient things for a programmer, to save time and effort. It's small and
133  * lean, designed to work from embedded systems all the way up to large and
134  * powerful multi-cpu workstations. The main loop has a number of primitives to
135  * be used with its main loop. It serializes all the primitives and allows for
136  * great responsiveness without the need for threads(or any other concurrency).
137  *
138  * @subsection timers Timers
139  *
140  * Timers serve two main purposes: doing something at a specified time and
141  * repeatedly doing something with a set interval.
142  * @see Ecore_Timer_Group
143  *
144  * @subsection poolers Poolers
145  *
146  * Poolers allow for pooling to be centralized into a single place therefore
147  * alleviating the need for different parts of the program to wake up at
148  * different times to do pooling, thereby making the code simpler and more
149  * efficient.
150  * @see Ecore_Poller_Group
151  *
152  * @subsection idler Idlers
153  *
154  * There are three types of idlers, enterers, idlers(proper) and exiters, they
155  * are called, respectively, when the program is about to enter an idle state,
156  * when the program is idle and when the program is leaving an idle state. Idler
157  * enterers are usually a good place to update the program state. Proper idlers
158  * are the appropriate place to do heavy computational tasks thereby using what
159  * would otherwise be wasted CPU cycles. Exiters are the perfect place to do
160  * anything your program should do just before processing events(also timers,
161  * poolers, file descriptor handlers and animators)
162  * @see Ecore_Idle_Group
163  *
164  * @subsection fd_handler File descriptor handlers
165  *
166  * File descriptor handlers allow you to monitor when there is data available to
167  * read on file descriptors, when writing will not block or if there was an
168  * error. Any valid file descriptor can be used with this API, regardless of if
169  * was gotten with an OS specific API or from ecore.
170  * @see Ecore_FD_Handler_Group
171  *
172  * @subsection animators Animators
173  *
174  * Ecore provides a facility called animators, so named since the intended use
175  * was in animations, that facilitates knowing what percentage of a given
176  * interval has elapsed. This is perfect for performing animations, but is not
177  * limited to that use, it can, for example, also be used to create a progress
178  * bar.
179  * @see Ecore_Animator_Group
180  *
181  * @subsection ev_handlers Event handlers
182  *
183  * Event handlers are, arguably, the most important feature of the ecore main
184  * loop, they are what allows the programmer to easily handle user interaction.
185  * Events however are not only things the user does, events can represent
186  * anything for which a type is created.
187  * @see Ecore_Event_Group
188  *
189  * All of these primitives are discussed in more detail in their respective
190  * pages linked above.
191  *
192  * Here is a diagram of the main loop flow of a simple program:
193  *
194  * @image html  prog_flow.png
195  * @image latex prog_flow.eps width=\textwidth
196  *
197  *
198  *
199  * @section work How does Ecore work?
200  *
201  * Ecore is very easy to learn and use. All the function calls are designed to
202  * be easy to remember, explicit in describing what they do, and heavily
203  * name-spaced. Ecore programs can start and be very simple.
204  *
205  * For example:
206  *
207  * @code
208  * #include <Ecore.h>
209  *
210  * int
211  * main(int argc, const char **argv)
212  * {
213  *    ecore_init();
214  *    ecore_app_args_set(argc, argv);
215  *    ecore_main_loop_begin();
216  *    ecore_shutdown();
217  *    return 0;
218  * }
219  * @endcode
220  *
221  * This program is very simple and doesn't check for errors, but it does start up
222  * and begin a main loop waiting for events or timers to tick off. This program
223  * doesn't set up any, but now we can expand on this simple program a little
224  * more by adding some event handlers and timers.
225  *
226  * @code
227  * #include <Ecore.h>
228  *
229  * Ecore_Timer         *timer1     = NULL;
230  * Ecore_Event_Handler *handler1   = NULL;
231  * double               start_time = 0.0;
232  *
233  * int
234  * timer_func(void *data)
235  * {
236  *    printf("Tick timer. Sec: %3.2f\n", ecore_time_get() - start_time);
237  *    return 1;
238  * }
239  *
240  * int
241  * exit_func(void *data, int ev_type, void *ev)
242  * {
243  *    Ecore_Event_Signal_Exit *e;
244  *
245  *    e = (Ecore_Event_Signal_Exit *)ev;
246  *    if (e->interrupt)      printf("Exit: interrupt\n");
247  *    else if (e->quit)      printf("Exit: quit\n");
248  *    else if (e->terminate) printf("Exit: terminate\n");
249  *    ecore_main_loop_quit();
250  *    return 1;
251  * }
252  *
253  * int
254  * main(int argc, const char **argv)
255  * {
256  *    ecore_init();
257  *    ecore_app_args_set(argc, argv);
258  *    start_time = ecore_time_get();
259  *    handler1 = ecore_event_handler_add(ECORE_EVENT_SIGNAL_EXIT, exit_func, NULL);
260  *    timer1 = ecore_timer_add(0.5, timer_func, NULL);
261  *    ecore_main_loop_begin();
262  *    ecore_shutdown();
263  *    return 0;
264  * }
265  * @endcode
266  *
267  * In the previous example, we initialize our application and get the time at
268  * which our program has started so we can calculate an offset. We set
269  * up a timer to tick off in 0.5 seconds, and since it returns 1, will
270  * keep ticking off every 0.5 seconds until it returns 0, or is deleted
271  * by hand. An event handler is set up to call a function -
272  * exit_func(),
273  * whenever an event of type ECORE_EVENT_SIGNAL_EXIT is received (CTRL-C
274  * on the command line will cause such an event to happen). If this event
275  * occurs it tells you what kind of exit signal was received, and asks
276  * the main loop to quit when it is finished by calling
277  * ecore_main_loop_quit().
278  *
279  * The handles returned by ecore_timer_add() and
280  * ecore_event_handler_add() are
281  * only stored here as an example. If you don't need to address the timer or
282  * event handler again you don't need to store the result, so just call the
283  * function, and don't assign the result to any variable.
284  *
285  * This program looks slightly more complex than needed to do these simple
286  * things, but in principle, programs don't get any more complex. You add more
287  * event handlers, for more events, will have more timers and such, BUT it all
288  * follows the same principles as shown in this example.
289  *
290  */
291
292 /*
293    @page Ecore_Config_Page The Enlightened Property Library
294
295    The Enlightened Property Library (Ecore_Config) is an abstraction
296    from the complexities of writing your own configuration. It provides
297    many features using the Enlightenment 17 development libraries.
298
299    To use the library, you:
300    @li Set the default values of your properties.
301    @li Load the configuration from a file.  You must set the default values
302     first, so that the library knows the correct type of each argument.
303
304    The following examples show how to use the Enlightened Property Library:
305    @li @link config_basic_example.c config_basic_example.c @endlink
306    @li @link config_listener_example.c config_listener_example.c @endlink
307
308  */
309
310 /**
311    @page X_Window_System_Page X Window System
312
313    The Ecore library includes a wrapper for handling the X window system.
314    This page briefly explains what the X window system is and various terms
315    that are used.
316  */
317
318 #ifndef _ECORE_H
319 #define _ECORE_H
320
321 #ifdef _MSC_VER
322 # include <Evil.h>
323 #endif
324
325 #include <Eina.h>
326
327 #ifdef EAPI
328 # undef EAPI
329 #endif
330
331 #ifdef _WIN32
332 # ifdef EFL_ECORE_BUILD
333 #  ifdef DLL_EXPORT
334 #   define EAPI __declspec(dllexport)
335 #  else
336 #   define EAPI
337 #  endif /* ! DLL_EXPORT */
338 # else
339 #  define EAPI __declspec(dllimport)
340 # endif /* ! EFL_ECORE_BUILD */
341 #else
342 # ifdef __GNUC__
343 #  if __GNUC__ >= 4
344 #   define EAPI __attribute__ ((visibility("default")))
345 #  else
346 #   define EAPI
347 #  endif
348 # else
349 #  define EAPI
350 # endif
351 #endif /* ! _WIN32 */
352
353 #ifdef _WIN32
354 # include <winsock2.h>
355 #elif defined (__FreeBSD__) || defined (__OpenBSD__)
356 # include <sys/select.h>
357 # include <signal.h>
358 #else
359 # include <sys/time.h>
360 # if !defined (EXOTIC_NO_SIGNAL)
361 #  include <signal.h>
362 # endif
363 #endif
364
365 #include <sys/types.h>
366
367 #ifdef __cplusplus
368 extern "C" {
369 #endif
370
371 /**
372  * @defgroup Ecore_Init_Group Ecore initialization and shutdown functions.
373  *
374  * @{
375  */
376
377 EAPI int ecore_init(void);
378 EAPI int ecore_shutdown(void);
379
380 /**
381  * @}
382  */
383
384 /**
385  * @defgroup Ecore_Main_Loop_Group Ecore main loop
386  *
387  * This group discusses functions that are acting on Ecore's main loop itself or
388  * on events and infrastructure directly linked to it. Most programs only need
389  * to start and end the main loop, the rest of the function discussed here are
390  * meant to be used in special situations, and with great care.
391  *
392  * For details on the usage of ecore's main loop and how it interacts with other
393  * ecore facilities see: @ref Ecore_Main_Loop_Page.
394  *
395  * @{
396  */
397
398 #define ECORE_VERSION_MAJOR 1
399 #define ECORE_VERSION_MINOR 2
400
401 typedef struct _Ecore_Version
402 {
403    int major;
404    int minor;
405    int micro;
406    int revision;
407 } Ecore_Version;
408
409 EAPI extern Ecore_Version *ecore_version;
410
411 #define ECORE_CALLBACK_CANCEL  EINA_FALSE /**< Return value to remove a callback */
412 #define ECORE_CALLBACK_RENEW   EINA_TRUE /**< Return value to keep a callback */
413
414 #define ECORE_CALLBACK_PASS_ON EINA_TRUE /**< Return value to pass event to next handler */
415 #define ECORE_CALLBACK_DONE    EINA_FALSE /**< Return value to stop event handling */
416
417 /**
418  * @typedef Ecore_Task_Cb Ecore_Task_Cb
419  * A callback run for a task (timer, idler, poller, animator, etc)
420  */
421 typedef Eina_Bool (*Ecore_Task_Cb)(void *data);
422
423 /**
424  * @typedef Ecore_Select_Function
425  * A function which can be used to replace select() in the main loop
426  */
427 typedef int (*Ecore_Select_Function)(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
428
429 EAPI void ecore_main_loop_iterate(void);
430
431 EAPI void ecore_main_loop_select_func_set(Ecore_Select_Function func);
432 EAPI Ecore_Select_Function ecore_main_loop_select_func_get(void);
433
434 EAPI Eina_Bool ecore_main_loop_glib_integrate(void);
435 EAPI void ecore_main_loop_glib_always_integrate_disable(void);
436
437 EAPI void ecore_main_loop_begin(void);
438 EAPI void ecore_main_loop_quit(void);
439
440 /**
441  * @typedef Ecore_Cb Ecore_Cb
442  * A generic callback called as a hook when a certain point in
443  * execution is reached.
444  */
445 typedef void (*Ecore_Cb)(void *data);
446
447 /**
448  * @typedef Ecore_Data_Cb Ecore_Data_Cb
449  * A callback which is used to return data to the main function
450  */
451 typedef void *(*Ecore_Data_Cb)(void *data);
452
453 /**
454  * @brief Call callback asynchronously in the main loop.
455  * @since 1.1.0
456  *
457  * @param callback The callback to call in the main loop
458  * @param data The data to give to that call back
459  *
460  * For all calls that need to happen in the main loop (most EFL functions do),
461  * this helper function provides the infrastructure needed to do it safely
462  * by avoiding dead lock, race condition and properly wake up the main loop.
463  *
464  * Remember after that function call, you should never touch again the @p data
465  * in the thread, it is owned by the main loop and your callback should take
466  * care of freeing it if necessary.
467  */
468 EAPI void ecore_main_loop_thread_safe_call_async(Ecore_Cb callback, void *data);
469
470 /**
471  * @brief Call callback synchronously in the main loop.
472  * @since 1.1.0
473  *
474  * @param callback The callback to call in the main loop
475  * @param data The data to give to that call back
476  * @return the value returned by the callback in the main loop
477  *
478  * For all calls that need to happen in the main loop (most EFL functions do),
479  * this helper function provides the infrastructure needed to do it safely
480  * by avoiding dead lock, race condition and properly wake up the main loop.
481  *
482  * Remember this function will block until the callback is executed in the
483  * main loop. It can take time and you have no guaranty about the timeline.
484  */
485 EAPI void *ecore_main_loop_thread_safe_call_sync(Ecore_Data_Cb callback, void *data);
486
487 /**
488  * @brief This function suspend the main loop in a know state
489  * @since 1.1.0
490  *
491  * @result the number of time ecore_thread_main_loop_begin() has been called
492  * in this thread, if the main loop was suspended correctly. If not, it return @c -1.
493  *
494  * This function suspend the main loop in a know state, this let you
495  * use any EFL call you want after it return. Be carefully, the main loop
496  * is blocked until you call ecore_thread_main_loop_end(). This is
497  * the only sane way to achieve pseudo thread safety.
498  *
499  * Notice that until the main loop is blocked, the thread is blocked
500  * and their is noway around that.
501  *
502  * We still advise you, when possible, to use ecore_main_loop_thread_safe_call_async()
503  * as it will not block the thread nor the main loop.
504  */
505 EAPI int ecore_thread_main_loop_begin(void);
506
507 /**
508  * @brief Unlock the main loop.
509  * @since 1.1.0
510  *
511  * @result the number of time ecore_thread_main_loop_end() need to be called before
512  * the main loop is unlocked again. @c -1 will be returned if you are trying to unlock
513  * when there wasn't enough call to ecore_thread_main_loop_begin().
514  *
515  * After a call to ecore_thread_main_loop_begin(), you need to absolutely
516  * call ecore_thread_main_loop_end(), or you application will stay frozen.
517  */
518 EAPI int ecore_thread_main_loop_end(void);
519
520 /**
521  * @}
522  */
523
524 /**
525  * @defgroup Ecore_Event_Group Ecore Event functions
526  *
527  * Ecore events provide two main features that are of use to those using ecore:
528  * creating events and being notified of events. Those two will usually be used
529  * in different contexts, creating events is mainly done by libraries wrapping
530  * some system functionality while being notified of events is mainly a
531  * necessity of applications.
532  *
533  * For a program to be notified of events it's interested in it needs to have a
534  * function to process the event and to register that function as the callback
535  * to the event, that's all:
536  * @code
537  * ecore_event_handler_add(EVENT_TYPE, _my_event_handler, some_data);
538  * ...
539  * static Eina_Bool
540  * _my_event_handler(void *data, int type, void *event)
541  * {
542  *    //data is some_data
543  *    //event is provided by whoever created the event
544  *    //Do really cool stuff with event
545  * }
546  * @endcode
547  *
548  * One very important thing to note here is the @c EVENT_TYPE, to register a
549  * handler for an event you must know its type before hand. Ecore provides
550  * the following events which are emitted in response to POSIX
551  * signals(https://en.wikipedia.org/wiki/Signal_%28computing%29):
552  * @li @b ECORE_EVENT_SIGNAL_USER
553  * @li @b ECORE_EVENT_SIGNAL_HUP
554  * @li @b ECORE_EVENT_SIGNAL_POWER
555  * @li @b ECORE_EVENT_SIGNAL_EXIT
556  *
557  * @warning Don't override these using the @c signal or @c sigaction calls.
558  * These, however, aren't the only signals one can handle. Many
559  * libraries(including ecore modules) have their own signals that can be
560  * listened for and handled, to do that one only needs to know the type of the
561  * event. This information can be found on the documentation of the library
562  * emitting the signal, so, for example, for events related to windowing one
563  * would look in @ref Ecore_Evas_Group.
564  *
565  * Examples of libraries that integrate into ecore's main loop by providing
566  * events are @ref Ecore_Con_Group, @ref Ecore_Evas_Group and @ref
567  * Ecore_Exe_Group, amongst others. This usage can be divided into two parts,
568  * setup and adding events. The setup is very simple, all that needs doing is
569  * getting a type id for the event:
570  * @code
571  * int MY_EV_TYPE = ecore_event_type_new();
572  * @endcode
573  * @note This variable should be declared in the header since it'll be needed by
574  * anyone wishing to register a handler to your event.
575  *
576  * The complexity of adding of an event to the queue depends on whether that
577  * event sends uses @c event, if it doesn't it a one-liner:
578  * @code
579  * ecore_event_add(MY_EV_TYPE, NULL, NULL, NULL);
580  * @endcode
581  * The usage when an @c event is needed is not that much more complex and can be
582  * seen in @ref ecore_event_add.
583  *
584  * Examples that deals with events:
585  * @li @ref ecore_event_example_01_c
586  * @li @ref ecore_event_example_02_c
587  *
588  * @ingroup Ecore_Main_Loop_Group
589  *
590  * @{
591  */
592
593 #define ECORE_EVENT_NONE            0
594 #define ECORE_EVENT_SIGNAL_USER     1 /**< User signal event */
595 #define ECORE_EVENT_SIGNAL_HUP      2 /**< Hup signal event */
596 #define ECORE_EVENT_SIGNAL_EXIT     3 /**< Exit signal event */
597 #define ECORE_EVENT_SIGNAL_POWER    4 /**< Power signal event */
598 #define ECORE_EVENT_SIGNAL_REALTIME 5 /**< Realtime signal event */
599 #define ECORE_EVENT_COUNT           6
600
601 typedef struct _Ecore_Win32_Handler         Ecore_Win32_Handler;    /**< A handle for HANDLE handlers on Windows */
602 typedef struct _Ecore_Event_Handler         Ecore_Event_Handler;    /**< A handle for an event handler */
603 typedef struct _Ecore_Event_Filter          Ecore_Event_Filter;    /**< A handle for an event filter */
604 typedef struct _Ecore_Event                 Ecore_Event;    /**< A handle for an event */
605 typedef struct _Ecore_Event_Signal_User     Ecore_Event_Signal_User;    /**< User signal event */
606 typedef struct _Ecore_Event_Signal_Hup      Ecore_Event_Signal_Hup;    /**< Hup signal event */
607 typedef struct _Ecore_Event_Signal_Exit     Ecore_Event_Signal_Exit;    /**< Exit signal event */
608 typedef struct _Ecore_Event_Signal_Power    Ecore_Event_Signal_Power;    /**< Power signal event */
609 typedef struct _Ecore_Event_Signal_Realtime Ecore_Event_Signal_Realtime;    /**< Realtime signal event */
610
611 /**
612  * @typedef Ecore_Filter_Cb
613  * A callback used for filtering events from the main loop.
614  */
615 typedef Eina_Bool (*Ecore_Filter_Cb)(void *data, void *loop_data, int type, void *event);
616
617 /**
618  * @typedef Ecore_End_Cb Ecore_End_Cb
619  * This is the callback which is called at the end of a function,
620  * usually for cleanup purposes.
621  */
622 typedef void (*Ecore_End_Cb)(void *user_data, void *func_data);
623
624 /**
625  * @typedef Ecore_Event_Handler_Cb Ecore_Event_Handler_Cb
626  * A callback used by the main loop to handle events of a specified
627  * type.
628  */
629 typedef Eina_Bool (*Ecore_Event_Handler_Cb)(void *data, int type, void *event);
630
631 struct _Ecore_Event_Signal_User    /** User signal event */
632 {
633    int       number;  /**< The signal number. Either 1 or 2 */
634    void     *ext_data;  /**< Extension data - not used */
635
636 #if !defined (_WIN32) && !defined (__lv2ppu__) && !defined (EXOTIC_NO_SIGNAL)
637    siginfo_t data; /**< Signal info */
638 #endif
639 };
640
641 struct _Ecore_Event_Signal_Hup    /** Hup signal event */
642 {
643    void     *ext_data;  /**< Extension data - not used */
644
645 #if !defined (_WIN32) && !defined (__lv2ppu__) && !defined (EXOTIC_NO_SIGNAL)
646    siginfo_t data; /**< Signal info */
647 #endif
648 };
649
650 struct _Ecore_Event_Signal_Exit    /** Exit request event */
651 {
652    Eina_Bool interrupt : 1; /**< Set if the exit request was an interrupt  signal*/
653    Eina_Bool quit      : 1; /**< set if the exit request was a quit signal */
654    Eina_Bool terminate : 1; /**< Set if the exit request was a terminate signal */
655    void     *ext_data; /**< Extension data - not used */
656
657 #if !defined (_WIN32) && !defined (__lv2ppu__) && !defined (EXOTIC_NO_SIGNAL)
658    siginfo_t data; /**< Signal info */
659 #endif
660 };
661
662 struct _Ecore_Event_Signal_Power    /** Power event */
663 {
664    void     *ext_data;  /**< Extension data - not used */
665
666 #if !defined (_WIN32) && !defined (__lv2ppu__) && !defined (EXOTIC_NO_SIGNAL)
667    siginfo_t data; /**< Signal info */
668 #endif
669 };
670
671 struct _Ecore_Event_Signal_Realtime    /** Realtime event */
672 {
673    int       num; /**< The realtime signal's number */
674
675 #if !defined (_WIN32) && !defined (__lv2ppu__) && !defined (EXOTIC_NO_SIGNAL)
676    siginfo_t data; /**< Signal info */
677 #endif
678 };
679
680 /**
681  * @brief Add an event handler.
682  * @param type The type of the event this handler will get called for
683  * @param func The function to call when the event is found in the queue
684  * @param data A data pointer to pass to the called function @p func
685  * @return A new Event handler, or @c NULL on failure.
686  *
687  * Add an event handler to the list of handlers. This will, on success, return
688  * a handle to the event handler object that was created, that can be used
689  * later to remove the handler using ecore_event_handler_del(). The @p type
690  * parameter is the integer of the event type that will trigger this callback
691  * to be called. The callback @p func is called when this event is processed
692  * and will be passed the event type, a pointer to the private event
693  * structure that is specific to that event type, and a data pointer that is
694  * provided in this call as the @p data parameter.
695  *
696  * When the callback @p func is called, it must return 1 or 0. If it returns
697  * 1 (or ECORE_CALLBACK_PASS_ON), It will keep being called as per normal, for
698  * each handler set up for that event type. If it returns 0 (or
699  * ECORE_CALLBACK_DONE), it will cease processing handlers for that particular
700  * event, so all handler set to handle that event type that have not already
701  * been called, will not be.
702  */
703 EAPI Ecore_Event_Handler *ecore_event_handler_add(int type, Ecore_Event_Handler_Cb func, const void *data);
704 /**
705  * @brief Delete an event handler.
706  * @param event_handler Event handler handle to delete
707  * @return Data passed to handler
708  *
709  * Delete a specified event handler from the handler list. On success this will
710  * delete the event handler and return the pointer passed as @p data when the
711  * handler was added by ecore_event_handler_add(). On failure @c NULL will be
712  * returned. Once a handler is deleted it will no longer be called.
713  */
714 EAPI void *ecore_event_handler_del(Ecore_Event_Handler *event_handler);
715 /**
716  * @brief Add an event to the event queue.
717  * @param type The event type to add to the end of the event queue
718  * @param ev The data structure passed as @c event to event handlers
719  * @param func_free The function to be called to free @a ev
720  * @param data The data pointer to be passed to the free function
721  * @return A Handle for that event on success, otherwise NULL
722  *
723  * If it succeeds, an event of type @a type will be added to the queue for
724  * processing by event handlers added by ecore_event_handler_add(). The @a ev
725  * parameter will be passed as the @c event parameter of the handler. When the
726  * event is no longer needed, @a func_free will be called and passed @a ev for
727  * cleaning up. If @p func_free is NULL, free() will be called with the private
728  * structure pointer.
729  */
730 EAPI Ecore_Event *ecore_event_add(int type, void *ev, Ecore_End_Cb func_free, void *data);
731 /**
732  * @brief Delete an event from the queue.
733  * @param event The event handle to delete
734  * @return The data pointer originally set for the event free function
735  *
736  * This deletes the event @p event from the event queue, and returns the
737  * @p data parameter originally set when adding it with ecore_event_add(). This
738  * does not immediately call the free function, and it may be called later on
739  * cleanup, and so if the free function depends on the data pointer to work,
740  * you should defer cleaning of this till the free function is called later.
741  */
742 EAPI void *ecore_event_del(Ecore_Event *event);
743 /**
744  * @brief Get the data associated with an #Ecore_Event_Handler
745  * @param eh The event handler
746  * @return The data
747  *
748  * This function returns the data previously associated with @p eh by
749  * ecore_event_handler_add().
750  */
751 EAPI void *ecore_event_handler_data_get(Ecore_Event_Handler *eh);
752 /**
753  * @brief Set the data associated with an #Ecore_Event_Handler
754  * @param eh The event handler
755  * @param data The data to associate
756  * @return The previous data
757  *
758  * This function sets @p data to @p eh and returns the old data pointer
759  * which was previously associated with @p eh by ecore_event_handler_add().
760  */
761 EAPI void *ecore_event_handler_data_set(Ecore_Event_Handler *eh, const void *data);
762 /**
763  * @brief Allocate a new event type id sensibly and return the new id.
764  * @return A new event type id.
765  *
766  * This function allocates a new event type id and returns it. Once an event
767  * type has been allocated it can never be de-allocated during the life of
768  * the program. There is no guarantee of the contents of this event ID, or how
769  * it is calculated, except that the ID will be unique to the current instance
770  * of the process.
771  */
772 EAPI int ecore_event_type_new(void);
773 /**
774  * @brief Add a filter the current event queue.
775  *
776  * @param func_start Function to call just before filtering and return data
777  * @param func_filter Function to call on each event
778  * @param func_end Function to call after the queue has been filtered
779  * @param data Data to pass to the filter functions
780  * @return A filter handle on success, @c NULL otherwise.
781  *
782  * Adds a callback to filter events from the event queue. Filters are called on
783  * the queue just before Event handler processing to try and remove redundant
784  * events. Just as processing is about to start @a func_start is called and
785  * passed the @a data pointer, the return value of this functions is passed to
786  * @a func_filter as loop_data. @a func_filter is also passed @a data and the
787  * event type and event structure. If this @a func_filter returns
788  * @c EINA_FALSE, the event is removed from the queue, if it returns
789  * @c EINA_TRUE, the event is kept. When processing is finished @p func_end is
790  * called and is passed the loop_data(returned by @c func_start) and @p data
791  * pointer to clean up.
792  */
793 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);
794 /**
795  * @brief Delete an event filter.
796  * @param ef The event filter handle
797  * @return The data set for the filter on success, @c NULL otherwise.
798  *
799  * Delete a filter that has been added by its @p ef handle.
800  */
801 EAPI void *ecore_event_filter_del(Ecore_Event_Filter *ef);
802 /**
803  * @brief Return the current event type being handled.
804  * @return The current event type being handled if inside a handler callback,
805  * ECORE_EVENT_NONE otherwise
806  *
807  * If the program is currently inside an Ecore event handler callback this
808  * will return the type of the current event being processed.
809  *
810  * This is useful when certain Ecore modules such as Ecore_Evas "swallow"
811  * events and not all the original information is passed on. In special cases
812  * this extra information may be useful or needed and using this call can let
813  * the program know if the event type being handled is one it wants to get more
814  * information about.
815  */
816 EAPI int ecore_event_current_type_get(void);
817 /**
818  * @brief Return the current event type pointer handled.
819  * @return The current event pointer being handled if inside a handler callback,
820  * @c NULL otherwise.
821  *
822  * If the program is currently inside an Ecore event handler callback this
823  * will return the pointer of the current event being processed.
824  *
825  * This is useful when certain Ecore modules such as Ecore_Evas "swallow"
826  * events and not all the original information is passed on. In special cases
827  * this extra information may be useful or needed and using this call can let
828  * the program access the event data if the type of the event is handled by
829  * the program.
830  */
831 EAPI void *ecore_event_current_event_get(void);
832
833 /**
834  * @}
835  */
836
837 /**
838  * @defgroup Ecore_Exe_Group Process Spawning Functions
839  *
840  * This module is responsible for managing portable processes using Ecore.
841  * With this module you're able to spawn processes and you also can pause,
842  * quit your spawned processes.
843  * An interaction between your process and those spawned is possible
844  * using pipes or signals.
845  *
846  * Example
847  * @li @ref Ecore_exe_simple_example_c
848  *
849  * @ingroup Ecore_Main_Loop_Group
850  *
851  * @{
852  */
853
854 /** Inherit priority from parent process */
855 #define ECORE_EXE_PRIORITY_INHERIT 9999
856
857 EAPI extern int ECORE_EXE_EVENT_ADD;     /**< A child process has been added */
858 EAPI extern int ECORE_EXE_EVENT_DEL;     /**< A child process has been deleted (it exited, naming consistent with the rest of ecore). */
859 EAPI extern int ECORE_EXE_EVENT_DATA;    /**< Data from a child process. */
860 EAPI extern int ECORE_EXE_EVENT_ERROR;    /**< Errors from a child process. */
861
862 /**
863  * @enum _Ecore_Exe_Flags
864  * Flags for executing a child with its stdin and/or stdout piped back.
865  */
866 enum _Ecore_Exe_Flags    /* flags for executing a child with its stdin and/or stdout piped back */
867 {
868    ECORE_EXE_NONE = 0, /**< No exe flags at all */
869    ECORE_EXE_PIPE_READ = 1, /**< Exe Pipe Read mask */
870    ECORE_EXE_PIPE_WRITE = 2, /**< Exe Pipe Write mask */
871    ECORE_EXE_PIPE_ERROR = 4, /**< Exe Pipe error mask */
872    ECORE_EXE_PIPE_READ_LINE_BUFFERED = 8, /**< Reads are buffered until a newline and split 1 line per Ecore_Exe_Event_Data_Line */
873    ECORE_EXE_PIPE_ERROR_LINE_BUFFERED = 16, /**< Errors are buffered until a newline and split 1 line per Ecore_Exe_Event_Data_Line */
874    ECORE_EXE_PIPE_AUTO = 32, /**< stdout and stderr are buffered automatically */
875    ECORE_EXE_RESPAWN = 64, /**< FIXME: Exe is restarted if it dies */
876    ECORE_EXE_USE_SH = 128, /**< Use /bin/sh to run the command. */
877    ECORE_EXE_NOT_LEADER = 256, /**< Do not use setsid() to have the executed process be its own session leader */
878    ECORE_EXE_TERM_WITH_PARENT = 512 /**< Makes child receive SIGTERM when parent dies. */
879 };
880 typedef enum _Ecore_Exe_Flags Ecore_Exe_Flags;
881
882 /**
883  * @enum _Ecore_Exe_Win32_Priority
884  * Defines the priority of the proccess.
885  */
886 enum _Ecore_Exe_Win32_Priority
887 {
888    ECORE_EXE_WIN32_PRIORITY_IDLE, /**< Idle priority, for monitoring the system */
889    ECORE_EXE_WIN32_PRIORITY_BELOW_NORMAL, /**< Below default priority */
890    ECORE_EXE_WIN32_PRIORITY_NORMAL, /**< Default priority */
891    ECORE_EXE_WIN32_PRIORITY_ABOVE_NORMAL, /**< Above default priority */
892    ECORE_EXE_WIN32_PRIORITY_HIGH, /**< High priority, use with care as other threads in the system will not get processor time */
893    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 */
894 };
895 typedef enum _Ecore_Exe_Win32_Priority Ecore_Exe_Win32_Priority;
896
897 typedef struct _Ecore_Exe              Ecore_Exe; /**< A handle for spawned processes */
898
899 /**
900  * @typedef Ecore_Exe_Cb Ecore_Exe_Cb
901  * A callback to run with the associated @ref Ecore_Exe, usually
902  * for cleanup purposes.
903  */
904 typedef void                            (*Ecore_Exe_Cb)(void *data, const Ecore_Exe *exe);
905
906 typedef struct _Ecore_Exe_Event_Add       Ecore_Exe_Event_Add; /**< Spawned Exe add event */
907 typedef struct _Ecore_Exe_Event_Del       Ecore_Exe_Event_Del; /**< Spawned Exe exit event */
908 typedef struct _Ecore_Exe_Event_Data_Line Ecore_Exe_Event_Data_Line; /**< Lines from a child process */
909 typedef struct _Ecore_Exe_Event_Data      Ecore_Exe_Event_Data; /**< Data from a child process */
910
911 struct _Ecore_Exe_Event_Add    /** Process add event */
912 {
913    Ecore_Exe *exe; /**< The handle to the added process */
914    void      *ext_data; /**< Extension data - not used */
915 };
916
917 struct _Ecore_Exe_Event_Del    /** Process exit event */
918 {
919    pid_t      pid; /**< The process ID of the process that exited */
920    int        exit_code; /**< The exit code of the process */
921    Ecore_Exe *exe; /**< The handle to the exited process, or @c NULL if not found */
922    int        exit_signal; /** < The signal that caused the process to exit */
923    Eina_Bool  exited    : 1; /** < set to 1 if the process exited of its own accord */
924    Eina_Bool  signalled : 1; /** < set to 1 id the process exited due to uncaught signal */
925    void      *ext_data; /**< Extension data - not used */
926 #if !defined (_WIN32) && !defined (__lv2ppu__) && !defined (EXOTIC_NO_SIGNAL)
927    siginfo_t  data; /**< Signal info */
928 #endif
929 };
930
931 struct _Ecore_Exe_Event_Data_Line    /**< Lines from a child process */
932 {
933    char *line;
934    int   size;
935 };
936
937 struct _Ecore_Exe_Event_Data    /** Data from a child process event */
938 {
939    Ecore_Exe                 *exe; /**< The handle to the process */
940    void                      *data; /**< the raw binary data from the child process that was received */
941    int                        size; /**< the size of this data in bytes */
942    Ecore_Exe_Event_Data_Line *lines; /**< an array of line data if line buffered, the last one has it's line member set to @c NULL */
943 };
944
945 EAPI void ecore_exe_run_priority_set(int pri);
946 EAPI int ecore_exe_run_priority_get(void);
947 EAPI Ecore_Exe *ecore_exe_run(const char *exe_cmd, const void *data);
948 EAPI Ecore_Exe *ecore_exe_pipe_run(const char *exe_cmd, Ecore_Exe_Flags flags, const void *data);
949 EAPI void ecore_exe_callback_pre_free_set(Ecore_Exe *exe, Ecore_Exe_Cb func);
950 EAPI Eina_Bool ecore_exe_send(Ecore_Exe *exe, const void *data, int size);
951 EAPI void ecore_exe_close_stdin(Ecore_Exe *exe);
952 EAPI void ecore_exe_auto_limits_set(Ecore_Exe *exe, int start_bytes, int end_bytes, int start_lines, int end_lines);
953 EAPI Ecore_Exe_Event_Data *ecore_exe_event_data_get(Ecore_Exe *exe, Ecore_Exe_Flags flags);
954 EAPI void ecore_exe_event_data_free(Ecore_Exe_Event_Data *data);
955 EAPI void *ecore_exe_free(Ecore_Exe *exe);
956 EAPI pid_t ecore_exe_pid_get(const Ecore_Exe *exe);
957 EAPI void ecore_exe_tag_set(Ecore_Exe *exe, const char *tag);
958 EAPI const char *ecore_exe_tag_get(const Ecore_Exe *exe);
959 EAPI const char *ecore_exe_cmd_get(const Ecore_Exe *exe);
960 EAPI void *ecore_exe_data_get(const Ecore_Exe *exe);
961 EAPI void *ecore_exe_data_set(Ecore_Exe *exe, void *data);
962 EAPI Ecore_Exe_Flags ecore_exe_flags_get(const Ecore_Exe *exe);
963 EAPI void ecore_exe_pause(Ecore_Exe *exe);
964 EAPI void ecore_exe_continue(Ecore_Exe *exe);
965 EAPI void ecore_exe_interrupt(Ecore_Exe *exe);
966 EAPI void ecore_exe_quit(Ecore_Exe *exe);
967 EAPI void ecore_exe_terminate(Ecore_Exe *exe);
968 EAPI void ecore_exe_kill(Ecore_Exe *exe);
969 EAPI void ecore_exe_signal(Ecore_Exe *exe, int num);
970 EAPI void ecore_exe_hup(Ecore_Exe *exe);
971
972 /**
973  * @}
974  */
975
976 /**
977  * @defgroup Ecore_FD_Handler_Group File Descriptor Handling Functions
978  *
979  * @brief Functions that deal with file descriptor handlers.
980  *
981  * File descriptor handlers facilitate reading, writing and checking for errors
982  * without blocking the program or doing expensive pooling. This can be used to
983  * monitor a socket, pipe, or other stream for which an FD can be had.
984  *
985  * @warning File descriptor handlers can't be used to monitor for file creation,
986  * modification or deletion, see @ref Ecore_File_Group for this.
987  *
988  * One common FD to be monitored is the standard input(stdin), monitoring it for
989  * reading requires a single call:
990  * @code
991  * static Eina_Bool
992  * _my_cb_func(void *data, Ecore_Fd_Handler *handler)
993  * {
994  *    char c;
995  *    scanf("%c", &c); //Guaranteed not to block
996  *    ... do stuff with c ...
997  * }
998  * ecore_main_fd_handler_add(STDIN_FILENO, ECORE_FD_READ, _my_cb_func, NULL, NULL, NULL);
999  * @endcode
1000  *
1001  * When using a socket, pipe or other stream it's important to remember that
1002  * errors may occur and as such to monitor not only for reading/writing but also
1003  * for errors using the @ref ECORE_FD_ERROR flag.
1004  *
1005  * Example of use of a file descriptor handler:
1006  * @li @ref ecore_fd_handler_example_c
1007  *
1008  * @ingroup Ecore_Main_Loop_Group
1009  *
1010  * @{
1011  */
1012
1013 typedef struct _Ecore_Fd_Handler Ecore_Fd_Handler; /**< A handle for Fd handlers */
1014
1015 /**
1016  * @enum _Ecore_Fd_Handler_Flags
1017  * What to monitor the file descriptor for: reading, writing or error.
1018  */
1019 enum _Ecore_Fd_Handler_Flags
1020 {
1021    ECORE_FD_READ = 1, /**< Fd Read mask */
1022    ECORE_FD_WRITE = 2, /**< Fd Write mask */
1023    ECORE_FD_ERROR = 4 /**< Fd Error mask */
1024 };
1025 typedef enum _Ecore_Fd_Handler_Flags Ecore_Fd_Handler_Flags;
1026
1027 /**
1028  * @typedef Ecore_Fd_Cb Ecore_Fd_Cb
1029  * A callback used by an @ref Ecore_Fd_Handler.
1030  */
1031 typedef Eina_Bool (*Ecore_Fd_Cb)(void *data, Ecore_Fd_Handler *fd_handler);
1032
1033 /**
1034  * @typedef Ecore_Fd_Prep_Cb Ecore_Fd_Prep_Cb
1035  * A callback used by an @ref Ecore_Fd_Handler.
1036  */
1037 typedef void (*Ecore_Fd_Prep_Cb)(void *data, Ecore_Fd_Handler *fd_handler);
1038
1039 /**
1040  * @typedef Ecore_Win32_Handle_Cb Ecore_Win32_Handle_Cb
1041  * A callback used by an @ref Ecore_Win32_Handler.
1042  */
1043 typedef Eina_Bool (*Ecore_Win32_Handle_Cb)(void *data, Ecore_Win32_Handler *wh);
1044
1045 /**
1046  * @brief Adds a callback for activity on the given file descriptor.
1047  *
1048  * @param fd The file descriptor to watch.
1049  * @param flags To monitor it for reading use @c ECORE_FD_READ, for writing @c
1050  * ECORE_FD_WRITE, and for error @c ECORE_FD_ERROR. Values bay |(ored).
1051  * @param func The callback function.
1052  * @param data The data to pass to the callback.
1053  * @param buf_func The function to call to check if any data has been buffered
1054  * and already read from the fd. May be @c NULL.
1055  * @param buf_data The data to pass to the @p buf_func function.
1056  * @return A fd handler handle on success, @c NULL otherwise.
1057  *
1058  * @a func will be called during the execution of @ref Ecore_Main_Loop_Page
1059  * when the file descriptor is available for reading, writing, or there has been
1060  * an error(depending on the given @a flags).
1061  *
1062  * When @a func returns ECORE_CALLBACK_CANCEL, it indicates that the
1063  * handler should be marked for deletion (identical to calling @ref
1064  * ecore_main_fd_handler_del).
1065  *
1066  * @warning @a buf_func is meant for @b internal use only and should be @b
1067  * avoided.
1068  *
1069  * The return value of @a buf_func has a different meaning, when it returns
1070  * ECORE_CALLBACK_CANCEL, it indicates that @a func @b shouldn't be called, and
1071  * when it returns ECORE_CALLBACK_RENEW it indicates @a func should be called.
1072  * The return value of @a buf_func will not cause the FD handler to be deleted.
1073  *
1074  * @a buf_func is called during event loop handling to check if data that has
1075  * been read from the file descriptor is in a buffer and is available to read.
1076  * Some systems, notably xlib, handle their own buffering, and would otherwise
1077  * not work with select(). These systems should use a @a buf_func. This is a
1078  * most annoying hack, only ecore_x uses it, so refer to that for an example.
1079  *
1080  * @warning This function should @b not be used for monitoring "normal" files, like text files.
1081  *
1082  */
1083 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);
1084 /**
1085  * @brief Set the prepare callback with data for a given #Ecore_Fd_Handler
1086  *
1087  * @param fd_handler The fd handler
1088  * @param func The prep function
1089  * @param data The data to pass to the prep function
1090  *
1091  * This function will be called prior to any fd handler's callback function
1092  * (even the other fd handlers), before entering the main loop select function.
1093  *
1094  * @note Once a prepare callback is set for a fd handler, it cannot be changed.
1095  * You need to delete the fd handler and create a new one, to set another
1096  * callback.
1097  * @note You probably don't need this function. It is only necessary for very
1098  * uncommon cases that need special behavior.
1099  */
1100 EAPI void ecore_main_fd_handler_prepare_callback_set(Ecore_Fd_Handler *fd_handler, Ecore_Fd_Prep_Cb func, const void *data);
1101 /**
1102  * @brief Marks an FD handler for deletion.
1103  * @param fd_handler The FD handler.
1104  * @return The data pointer set using @ref ecore_main_fd_handler_add, for
1105  * @a fd_handler on success, @c NULL otherwise.
1106  * This function marks an fd handler to be deleted during an iteration of the
1107  * main loop. It does NOT close the associated fd!
1108  *
1109  * @warning If the underlying fd is already closed ecore may complain if the
1110  * main loop is using epoll internally, and also in some rare cases this may
1111  * cause crashes and instability. Remember to delete your fd handlers before the
1112  * fds they listen to are closed.
1113  */
1114 EAPI void *ecore_main_fd_handler_del(Ecore_Fd_Handler *fd_handler);
1115 /**
1116  * @brief Retrieves the file descriptor that the given handler is handling.
1117  * @param fd_handler The given FD handler.
1118  * @return The file descriptor the handler is watching.
1119  */
1120 EAPI int ecore_main_fd_handler_fd_get(Ecore_Fd_Handler *fd_handler);
1121 /**
1122  * @brief Gets which flags are active on an FD handler.
1123  * @param fd_handler The given FD handler.
1124  * @param flags The flags, @c ECORE_FD_READ, @c ECORE_FD_WRITE or
1125  * @c ECORE_FD_ERROR to query.
1126  * @return @c EINA_TRUE if any of the given flags are active, @c EINA_FALSE
1127  * otherwise.
1128  */
1129 EAPI Eina_Bool ecore_main_fd_handler_active_get(Ecore_Fd_Handler *fd_handler, Ecore_Fd_Handler_Flags flags);
1130 /**
1131  * @brief Set what active streams the given FD handler should be monitoring.
1132  * @param fd_handler The given FD handler.
1133  * @param flags The flags to be watching.
1134  */
1135 EAPI void ecore_main_fd_handler_active_set(Ecore_Fd_Handler *fd_handler, Ecore_Fd_Handler_Flags flags);
1136
1137 EAPI Ecore_Win32_Handler *ecore_main_win32_handler_add(void *h, Ecore_Win32_Handle_Cb func, const void *data);
1138 EAPI void *ecore_main_win32_handler_del(Ecore_Win32_Handler *win32_handler);
1139
1140 /**
1141  * @}
1142  */
1143
1144 /**
1145  * @defgroup Ecore_Poller_Group Ecore Poll functions
1146  *
1147  * Ecore poller provides infrastructure for the creation of pollers. Pollers
1148  * are, in essence, callbacks that share a single timer per type. Because not
1149  * all pollers need to be called at the same frequency the user may specify the
1150  * frequency in ticks(each expiration of the shared timer is called a tick, in
1151  * ecore poller parlance) for each added poller. Ecore pollers should only be
1152  * used when the poller doesn't have specific requirements on the exact times
1153  * to poll.
1154  *
1155  * This architecture means that the main loop is only woken up once to handle
1156  * all pollers of that type, this will save power as the CPU has more of a
1157  * chance to go into a low power state the longer it is asleep for, so this
1158  * should be used in situations where power usage is a concern.
1159  *
1160  * For now only 1 core poller type is supported: ECORE_POLLER_CORE, the default
1161  * interval for ECORE_POLLER_CORE is 0.125(or 1/8th) second.
1162  *
1163  * The creation of a poller is extremely simple and only requires one line:
1164  * @code
1165  * ecore_poller_add(ECORE_POLLER_CORE, 1, my_poller_function, NULL);
1166  * @endcode
1167  * This sample creates a poller to call @c my_poller_function at every tick with
1168  * @c NULL as data.
1169  *
1170  * Example:
1171  * @li @ref ecore_poller_example_c
1172  *
1173  * @ingroup Ecore_Main_Loop_Group
1174  *
1175  * @{
1176  */
1177
1178 /**
1179  * @enum _Ecore_Poller_Type
1180  * Defines the frequency of ticks for the poller.
1181  */
1182 enum _Ecore_Poller_Type    /* Poller types */
1183 {
1184    ECORE_POLLER_CORE = 0 /**< The core poller interval */
1185 };
1186 typedef enum _Ecore_Poller_Type Ecore_Poller_Type;
1187
1188 typedef struct _Ecore_Poller    Ecore_Poller; /**< A handle for pollers */
1189
1190 /**
1191  * @brief Sets the time(in seconds) between ticks for the given poller type.
1192  * @param type The poller type to adjust.
1193  * @param poll_time The time(in seconds) between ticks of the timer.
1194  *
1195  * This will adjust the time between ticks of the given timer type defined by
1196  * @p type to the time period defined by @p poll_time.
1197  */
1198 EAPI void ecore_poller_poll_interval_set(Ecore_Poller_Type type, double poll_time);
1199 /**
1200  * @brief Gets the time(in seconds) between ticks for the given poller type.
1201  * @param type The poller type to query.
1202  * @return The time in seconds between ticks of the poller timer.
1203  *
1204  * This will get the time between ticks of the specified poller timer.
1205  */
1206 EAPI double ecore_poller_poll_interval_get(Ecore_Poller_Type type);
1207 /**
1208  * @brief Changes the polling interval rate of @p poller.
1209  * @param poller The Ecore_Poller to change the interval of.
1210  * @param interval The tick interval to set; must be a power of 2 and <= 32768.
1211  * @return Returns true on success, false on failure.
1212  *
1213  * This allows the changing of a poller's polling interval. It is useful when
1214  * you want to alter a poll rate without deleting and re-creating a poller.
1215  */
1216 EAPI Eina_Bool ecore_poller_poller_interval_set(Ecore_Poller *poller, int interval);
1217 /**
1218  * @brief Gets the polling interval rate of @p poller.
1219  * @param poller The Ecore_Poller to change the interval of.
1220  * @return Returns the interval, in ticks, that @p poller polls at.
1221  *
1222  * This returns a poller's polling interval, or 0 on error.
1223  */
1224 EAPI int ecore_poller_poller_interval_get(Ecore_Poller *poller);
1225 /**
1226  * @brief Creates a poller to call the given function at a particular tick interval.
1227  * @param type The ticker type to attach the poller to. Must be ECORE_POLLER_CORE.
1228  * @param interval The poll interval.
1229  * @param func The poller function.
1230  * @param data Data to pass to @a func when it is called.
1231  * @return A poller object on success, @c NULL otherwise.
1232  *
1233  * This function adds @a func as a poller callback that will be called every @a
1234  * interval ticks together with other pollers of type @a type. @a func will be
1235  * passed the @p data pointer as a parameter.
1236  *
1237  * The @p interval must be between 1 and 32768 inclusive, and must be a power of
1238  * 2 (i.e. 1, 2, 4, 8, 16, ... 16384, 32768). The exact tick in which @a func
1239  * will be called is undefined, as only the interval between calls can be
1240  * defined. Ecore will endeavor to keep pollers synchronized and to call as
1241  * many in 1 wakeup event as possible. If @a interval is not a power of two, the
1242  * closest power of 2 greater than @a interval will be used.
1243  *
1244  * When the poller @p func is called, it must return a value of either
1245  * ECORE_CALLBACK_RENEW(or 1) or ECORE_CALLBACK_CANCEL(or 0). If it
1246  * returns 1, it will be called again at the next tick, or if it returns
1247  * 0 it will be deleted automatically making any references/handles for it
1248  * invalid.
1249  */
1250 EAPI Ecore_Poller *ecore_poller_add(Ecore_Poller_Type type, int interval, Ecore_Task_Cb func, const void *data);
1251 /**
1252  * @brief Delete the specified poller from the timer list.
1253  * @param poller The poller to delete.
1254  * @return The data pointer set for the timer when @ref ecore_poller_add was
1255  * called on success, @c NULL otherwise.
1256  *
1257  * @note @a poller must be a valid handle. If the poller function has already
1258  * returned 0, the handle is no longer valid (and does not need to be deleted).
1259  */
1260 EAPI void *ecore_poller_del(Ecore_Poller *poller);
1261
1262 /**
1263  * @}
1264  */
1265
1266 /**
1267  * @defgroup Ecore_Animator_Group Ecore Animator functions
1268  *
1269  * @brief Ecore animators are a helper to simplify creating
1270  * animations.
1271  *
1272  * Creating an animation is as simple as saying for how long it
1273  * should be run and having a callback that does the animation,
1274  * something like this:
1275  * @code
1276  * static Eina_Bool
1277  * _do_animation(void *data, double pos)
1278  * {
1279  *    evas_object_move(data, 100 * pos, 100 * pos);
1280  *    ... do some more animating ...
1281  * }
1282  * ...
1283  *ecore_animator_timeline_add(2, _do_animation, my_evas_object);
1284  * @endcode
1285  * In the sample above we create an animation to move
1286  * @c my_evas_object from position (0,0) to (100,100) in 2 seconds.
1287  *
1288  * If your animation will run for an unspecified amount of time you
1289  * can use ecore_animator_add(), which is like using
1290  *ecore_timer_add() with the interval being the
1291  * @ref ecore_animator_frametime_set "framerate". Note that this has
1292  * tangible benefits to creating a timer for each animation in terms
1293  * of performance.
1294  *
1295  * For a more detailed example that show several animation see
1296  * @ref tutorial_ecore_animator.
1297  *
1298  * @ingroup Ecore_Main_Loop_Group
1299  *
1300  * @{
1301  */
1302
1303 typedef struct _Ecore_Animator Ecore_Animator; /**< A handle for animators */
1304
1305 /**
1306  * @enum _Ecore_Pos_Map
1307  * Defines the position mappings for the animation.
1308  */
1309 enum _Ecore_Pos_Map    /* Position mappings */
1310 {
1311    ECORE_POS_MAP_LINEAR, /**< Linear 0.0 -> 1.0 */
1312    ECORE_POS_MAP_ACCELERATE, /**< Start slow then speed up */
1313    ECORE_POS_MAP_DECELERATE, /**< Start fast then slow down */
1314    ECORE_POS_MAP_SINUSOIDAL, /**< Start slow, speed up then slow down at end */
1315    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. */
1316    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. */
1317    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. */
1318    ECORE_POS_MAP_DIVISOR_INTERP, /**< Start at gradient * v1, interpolated via power of v2 curve */
1319    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 */
1320    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 */
1321 };
1322 typedef enum _Ecore_Pos_Map Ecore_Pos_Map;
1323
1324 /**
1325  * @enum _Ecore_Animator_Source
1326  * Defines the timing sources for animators.
1327  */
1328 enum _Ecore_Animator_Source    /* Timing sources for animators */
1329 {
1330    ECORE_ANIMATOR_SOURCE_TIMER, /**< The default system clock/timer based animator that ticks every "frametime" seconds */
1331    ECORE_ANIMATOR_SOURCE_CUSTOM /**< A custom animator trigger that you need to call ecore_animator_trigger() to make it tick */
1332 };
1333 typedef enum _Ecore_Animator_Source Ecore_Animator_Source;
1334
1335 /**
1336  * @typedef Ecore_Timeline_Cb Ecore_Timeline_Cb
1337  * A callback run for a task (animators with runtimes)
1338  */
1339 typedef Eina_Bool (*Ecore_Timeline_Cb)(void *data, double pos);
1340
1341 /**
1342  * @brief Add an animator to call @p func at every animation tick during main
1343  * loop execution.
1344  *
1345  * @param func The function to call when it ticks off
1346  * @param data The data to pass to the function
1347  * @return A handle to the new animator
1348  *
1349  * This function adds a animator and returns its handle on success and @c NULL
1350  * on failure. The function @p func will be called every N seconds where N is
1351  * the @p frametime interval set by ecore_animator_frametime_set(). The
1352  * function will be passed the @p data pointer as its parameter.
1353  *
1354  * When the animator @p func is called, it must return a value of either 1 or
1355  * 0. If it returns 1 (or ECORE_CALLBACK_RENEW), it will be called again at
1356  * the next tick, or if it returns 0 (or ECORE_CALLBACK_CANCEL) it will be
1357  * deleted automatically making any references/handles for it invalid.
1358  *
1359  * @note The default @p frametime value is 1/30th of a second.
1360  *
1361  * @see ecore_animator_timeline_add()
1362  * @see ecore_animator_frametime_set()
1363  */
1364 EAPI Ecore_Animator *ecore_animator_add(Ecore_Task_Cb func, const void *data);
1365 /**
1366  * @brief Add a animator that runs for a limited time
1367  *
1368  * @param runtime The time to run in seconds
1369  * @param func The function to call when it ticks off
1370  * @param data The data to pass to the function
1371  * @return A handle to the new animator
1372  *
1373  * This function is just like ecore_animator_add() except the animator only
1374  * runs for a limited time specified in seconds by @p runtime. Once the
1375  * runtime the animator has elapsed (animator finished) it will automatically
1376  * be deleted. The callback function @p func can return ECORE_CALLBACK_RENEW
1377  * to keep the animator running or ECORE_CALLBACK_CANCEL ro stop it and have
1378  * it be deleted automatically at any time.
1379  *
1380  * The @p func will ALSO be passed a position parameter that will be in value
1381  * from 0.0 to 1.0 to indicate where along the timeline (0.0 start, 1.0 end)
1382  * the animator run is at. If the callback wishes not to have a linear
1383  * transition it can "map" this value to one of several curves and mappings
1384  * via ecore_animator_pos_map().
1385  *
1386  * @note The default @p frametime value is 1/30th of a second.
1387  *
1388  * @see ecore_animator_add()
1389  * @see ecore_animator_pos_map()
1390  * @since 1.1.0
1391  */
1392 EAPI Ecore_Animator *ecore_animator_timeline_add(double runtime, Ecore_Timeline_Cb func, const void *data);
1393 /**
1394  * @brief Delete the specified animator from the animator list.
1395  *
1396  * @param animator The animator to delete
1397  * @return The data pointer set for the animator on add
1398  *
1399  * Delete the specified @p animator from the set of animators that are
1400  * executed during main loop execution. This function returns the data
1401  * parameter that was being passed to the callback on success, or @c NULL on
1402  * failure. After this call returns the specified animator object @p animator
1403  * is invalid and should not be used again. It will not get called again after
1404  * deletion.
1405  */
1406 EAPI void *ecore_animator_del(Ecore_Animator *animator);
1407 /**
1408  * @brief Suspend the specified animator.
1409  *
1410  * @param animator The animator to delete
1411  *
1412  * The specified @p animator will be temporarily removed from the set of
1413  * animators that are executed during main loop.
1414  *
1415  * @warning Freezing an animator doesn't freeze accounting of how long that
1416  * animator has been running. Therefore if the animator was created with
1417  *ecore_animator_timeline_add() the @p pos argument given to the callback
1418  * will increase as if the animator hadn't been frozen and the animator may
1419  * have it's execution halted if @p runtime elapsed.
1420  */
1421 EAPI void ecore_animator_freeze(Ecore_Animator *animator);
1422 /**
1423  * @brief Restore execution of the specified animator.
1424  *
1425  * @param animator The animator to delete
1426  *
1427  * The specified @p animator will be put back in the set of animators that are
1428  * executed during main loop.
1429  */
1430 EAPI void ecore_animator_thaw(Ecore_Animator *animator);
1431 /**
1432  * @brief Set the animator call interval in seconds.
1433  *
1434  * @param frametime The time in seconds in between animator ticks.
1435  *
1436  * This function sets the time interval (in seconds) between animator ticks.
1437  * At every tick the callback of every existing animator will be called.
1438  *
1439  * @warning Too small a value may cause performance issues and too high a
1440  * value may cause your animation to seem "jerky".
1441  *
1442  * @note The default @p frametime value is 1/30th of a second.
1443  */
1444 EAPI void ecore_animator_frametime_set(double frametime);
1445 /**
1446  * @brief Get the animator call interval in seconds.
1447  *
1448  * @return The time in second in between animator ticks.
1449  *
1450  * This function retrieves the time in seconds between animator ticks.
1451  *
1452  * @see ecore_animator_frametime_set()
1453  */
1454 EAPI double ecore_animator_frametime_get(void);
1455 /**
1456  * @brief Maps an input position from 0.0 to 1.0 along a timeline to a
1457  * position in a different curve.
1458  *
1459  * @param pos The input position to map
1460  * @param map The mapping to use
1461  * @param v1 A parameter use by the mapping (pass 0.0 if not used)
1462  * @param v2 A parameter use by the mapping (pass 0.0 if not used)
1463  * @return The mapped value
1464  *
1465  * Takes an input position (0.0 to 1.0) and maps to a new position (normally
1466  * between 0.0 and 1.0, but it may go above/below 0.0 or 1.0 to show that it
1467  * has "overshot" the mark) using some interpolation (mapping) algorithm.
1468  *
1469  * This function useful to create non-linear animations. It offers a variety
1470  * of possible animation curves to be used:
1471  * @li ECORE_POS_MAP_LINEAR - Linear, returns @p pos
1472  * @li ECORE_POS_MAP_ACCELERATE - Start slow then speed up
1473  * @li ECORE_POS_MAP_DECELERATE - Start fast then slow down
1474  * @li ECORE_POS_MAP_SINUSOIDAL - Start slow, speed up then slow down at end
1475  * @li ECORE_POS_MAP_ACCELERATE_FACTOR - Start slow then speed up, v1 being a
1476  * power factor, 0.0 being linear, 1.0 being ECORE_POS_MAP_ACCELERATE, 2.0
1477  * being much more pronounced accelerate (squared), 3.0 being cubed, etc.
1478  * @li ECORE_POS_MAP_DECELERATE_FACTOR - Start fast then slow down, v1 being a
1479  * power factor, 0.0 being linear, 1.0 being ECORE_POS_MAP_DECELERATE, 2.0
1480  * being much more pronounced decelerate (squared), 3.0 being cubed, etc.
1481  * @li ECORE_POS_MAP_SINUSOIDAL_FACTOR - Start slow, speed up then slow down
1482  * at end, v1 being a power factor, 0.0 being linear, 1.0 being
1483  * ECORE_POS_MAP_SINUSOIDAL, 2.0 being much more pronounced sinusoidal
1484  * (squared), 3.0 being cubed, etc.
1485  * @li ECORE_POS_MAP_DIVISOR_INTERP - Start at gradient * v1, interpolated via
1486  * power of v2 curve
1487  * @li ECORE_POS_MAP_BOUNCE - Start at 0.0 then "drop" like a ball bouncing to
1488  * the ground at 1.0, and bounce v2 times, with decay factor of v1
1489  * @li ECORE_POS_MAP_SPRING - Start at 0.0 then "wobble" like a spring rest
1490  * position 1.0, and wobble v2 times, with decay factor of v1
1491  * @note When not listed v1 and v2 have no effect.
1492  *
1493  * @image html ecore-pos-map.png
1494  * @image latex ecore-pos-map.eps width=\textwidth
1495  *
1496  * One way to use this would be:
1497  * @code
1498  * double pos; // input position in a timeline from 0.0 to 1.0
1499  * double out; // output position after mapping
1500  * int x1, y1, x2, y2; // x1 & y1 are start position, x2 & y2 are end position
1501  * int x, y; // x & y are the calculated position
1502  *
1503  * out = ecore_animator_pos_map(pos, ECORE_POS_MAP_BOUNCE, 1.8, 7);
1504  * x = (x1 * out) + (x2 * (1.0 - out));
1505  * y = (y1 * out) + (y2 * (1.0 - out));
1506  * move_my_object_to(myobject, x, y);
1507  * @endcode
1508  * This will make an animation that bounces 7 each times diminishing by a
1509  * factor of 1.8.
1510  *
1511  * @see _Ecore_Pos_Map
1512  *
1513  * @since 1.1.0
1514  */
1515 EAPI double ecore_animator_pos_map(double pos, Ecore_Pos_Map map, double v1, double v2);
1516 /**
1517  * @brief Set the source of animator ticks for the mainloop
1518  *
1519  * @param source The source of animator ticks to use
1520  *
1521  * This sets the source of animator ticks. When an animator is active the
1522  * mainloop will "tick" over frame by frame calling all animators that are
1523  * registered until none are. The mainloop will tick at a given rate based
1524  * on the animator source. The default source is the system clock timer
1525  * source - ECORE_ANIMATOR_SOURCE_TIMER. This source uses the system clock
1526  * to tick over every N seconds (specified by ecore_animator_frametime_set(),
1527  * with the default being 1/30th of a second unless set otherwise). You can
1528  * set a custom tick source by setting the source to
1529  * ECORE_ANIMATOR_SOURCE_CUSTOM and then drive it yourself based on some input
1530  * tick source (like another application via ipc, some vertical blanking
1531  * interrupt interrupt etc.) using
1532  *ecore_animator_custom_source_tick_begin_callback_set() and
1533  *ecore_animator_custom_source_tick_end_callback_set() to set the functions
1534  * that will be called to start and stop the ticking source, which when it
1535  * gets a "tick" should call ecore_animator_custom_tick() to make the "tick" over 1
1536  * frame.
1537  */
1538 EAPI void ecore_animator_source_set(Ecore_Animator_Source source);
1539 /**
1540  * @brief Get the animator source currently set.
1541  *
1542  * @return The current animator source
1543  *
1544  * This gets the current animator source.
1545  *
1546  * @see ecore_animator_source_set()
1547  */
1548 EAPI Ecore_Animator_Source ecore_animator_source_get(void);
1549 /**
1550  * @brief Set the function that begins a custom animator tick source
1551  *
1552  * @param func The function to call when ticking is to begin
1553  * @param data The data passed to the tick begin function as its parameter
1554  *
1555  * The Ecore Animator infrastructure handles tracking if animators are needed
1556  * or not and which ones need to be called and when, but when the tick source
1557  * is custom, you have to provide a tick source by calling
1558  *ecore_animator_custom_tick() to indicate a frame tick happened. In order
1559  * to allow the source of ticks to be dynamically enabled or disabled as
1560  * needed, the @p func when set is called to enable the tick source to
1561  * produce tick events that call ecore_animator_custom_tick(). If @p func
1562  * is @c NULL then no function is called to begin custom ticking.
1563  *
1564  * @see ecore_animator_source_set()
1565  * @see ecore_animator_custom_source_tick_end_callback_set()
1566  * @see ecore_animator_custom_tick()
1567  */
1568 EAPI void ecore_animator_custom_source_tick_begin_callback_set(Ecore_Cb func, const void *data);
1569 /**
1570  * @brief Set the function that ends a custom animator tick source
1571  *
1572  * @param func The function to call when ticking is to end
1573  * @param data The data passed to the tick end function as its parameter
1574  *
1575  * This function is a matching pair to the function set by
1576  * ecore_animator_custom_source_tick_begin_callback_set() and is called
1577  * when ticking is to stop. If @p func is @c NULL then no function will be
1578  * called to stop ticking. For more information please see
1579  * ecore_animator_custom_source_tick_begin_callback_set().
1580  *
1581  * @see ecore_animator_source_set()
1582  * @see ecore_animator_custom_source_tick_begin_callback_set()
1583  * @see ecore_animator_custom_tick()
1584  */
1585 EAPI void ecore_animator_custom_source_tick_end_callback_set(Ecore_Cb func, const void *data);
1586 /**
1587  * @brief Trigger a custom animator tick
1588  *
1589  * When animator source is set to ECORE_ANIMATOR_SOURCE_CUSTOM, then calling
1590  * this function triggers a run of all animators currently registered with
1591  * Ecore as this indicates a "frame tick" happened. This will do nothing if
1592  * the animator source(set by ecore_animator_source_set()) is not set to
1593  * ECORE_ANIMATOR_SOURCE_CUSTOM.
1594  *
1595  * @see ecore_animator_source_set()
1596  * @see ecore_animator_custom_source_tick_begin_callback_set
1597  * @see ecore_animator_custom_source_tick_end_callback_set()()
1598  */
1599 EAPI void ecore_animator_custom_tick(void);
1600
1601 /**
1602  * @}
1603  */
1604
1605 /**
1606  * @defgroup Ecore_Time_Group Ecore time functions
1607  *
1608  * These are function to retrieve time in a given format.
1609  *
1610  * Examples:
1611  * @li @ref ecore_time_functions_example_c
1612  * @{
1613  */
1614 EAPI double ecore_time_get(void);
1615 EAPI double ecore_time_unix_get(void);
1616 EAPI double ecore_loop_time_get(void);
1617
1618 /**
1619  * @}
1620  */
1621
1622 /**
1623  * @defgroup Ecore_Timer_Group Ecore Timer functions
1624  *
1625  * Ecore provides very flexible timer functionality. The basic usage of timers,
1626  * to call a certain function at a certain interval can be achieved with a
1627  * single line:
1628  * @code
1629  * Eina_Bool my_func(void *data) {
1630  *    do_funky_stuff_with_data(data);
1631  *    return EINA_TRUE;
1632  * }
1633  * ecore_timer_add(interval_in_seconds, my_func, data_given_to_function);
1634  * @endcode
1635  * @note If the function was to be executed only once simply return
1636  * @c EINA_FALSE instead.
1637  *
1638  * An example that shows the usage of a lot of these:
1639  * @li @ref ecore_timer_example_c
1640  *
1641  * @ingroup Ecore_Main_Loop_Group
1642  *
1643  * @{
1644  */
1645
1646 typedef struct _Ecore_Timer Ecore_Timer; /**< A handle for timers */
1647
1648 EAPI Ecore_Timer *ecore_timer_add(double in, Ecore_Task_Cb func, const void *data);
1649 EAPI Ecore_Timer *ecore_timer_loop_add(double in, Ecore_Task_Cb func, const void *data);
1650 EAPI void *ecore_timer_del(Ecore_Timer *timer);
1651 EAPI void ecore_timer_interval_set(Ecore_Timer *timer, double in);
1652 EAPI double ecore_timer_interval_get(Ecore_Timer *timer);
1653 EAPI void ecore_timer_freeze(Ecore_Timer *timer);
1654 EAPI void ecore_timer_thaw(Ecore_Timer *timer);
1655 EAPI void ecore_timer_delay(Ecore_Timer *timer, double add);
1656 EAPI void ecore_timer_reset(Ecore_Timer *timer);
1657 EAPI double ecore_timer_pending_get(Ecore_Timer *timer);
1658 EAPI double ecore_timer_precision_get(void);
1659 EAPI void ecore_timer_precision_set(double precision);
1660 EAPI char *ecore_timer_dump(void);
1661
1662 /**
1663  * @}
1664  */
1665
1666 /**
1667  * @defgroup Ecore_Idle_Group Ecore Idle functions
1668  *
1669  * The idler functionality in Ecore allows for callbacks to be called when the
1670  * program isn't handling @ref Ecore_Event_Group "events", @ref Ecore_Timer_Group
1671  * "timers" or @ref Ecore_FD_Handler_Group "fd handlers".
1672  *
1673  * There are three types of idlers: Enterers, Idlers(proper) and Exiters. They
1674  * are called, respectively, when the program is about to enter an idle state,
1675  * when the program is in an idle state and when the program has just left an
1676  * idle state and will begin processing @ref Ecore_Event_Group "events", @ref
1677  * Ecore_Timer_Group "timers" or @ref Ecore_FD_Handler_Group "fd handlers".
1678  *
1679  * Enterer callbacks are good for updating your program's state, if
1680  * it has a state engine.  Once all of the enterer handlers are
1681  * called, the program will enter a "sleeping" state.
1682  *
1683  * Idler callbacks are called when the main loop has called all
1684  * enterer handlers.  They are useful for interfaces that require
1685  * polling and timers would be too slow to use.
1686  *
1687  * Exiter callbacks are called when the main loop wakes up from an idle state.
1688  *
1689  * If no idler callbacks are specified, then the process literally
1690  * goes to sleep.  Otherwise, the idler callbacks are called
1691  * continuously while the loop is "idle", using as much CPU as is
1692  * available to the process.
1693  *
1694  * @note Idle state doesn't mean that the @b program is idle, but
1695  * that the <b>main loop</b> is idle. It doesn't have any timers,
1696  * events, fd handlers or anything else to process (which in most
1697  * <em>event driven</em> programs also means that the @b program is
1698  * idle too, but it's not a rule). The program itself may be doing
1699  * a lot of processing in the idler, or in another thread, for
1700  * example.
1701  *
1702  * Example with functions that deal with idle state:
1703  *
1704  * @li @ref ecore_idler_example_c
1705  *
1706  * @ingroup Ecore_Main_Loop_Group
1707  *
1708  * @{
1709  */
1710
1711 typedef struct _Ecore_Idler        Ecore_Idler; /**< A handle for idlers */
1712 typedef struct _Ecore_Idle_Enterer Ecore_Idle_Enterer; /**< A handle for idle enterers */
1713 typedef struct _Ecore_Idle_Exiter  Ecore_Idle_Exiter; /**< A handle for idle exiters */
1714
1715 /**
1716  * Add an idler handler.
1717  * @param  func The function to call when idling.
1718  * @param  data The data to be passed to this @p func call.
1719  * @return A idler handle if successfully added, @c NULL otherwise.
1720  *
1721  * Add an idler handle to the event loop, returning a handle on
1722  * success and @c NULL otherwise. The function @p func will be called
1723  * repeatedly while no other events are ready to be processed, as
1724  * long as it returns @c 1 (or ECORE_CALLBACK_RENEW). A return of @c 0
1725  * (or ECORE_CALLBACK_CANCEL) deletes the idler.
1726  *
1727  * Idlers are useful for progressively prossessing data without blocking.
1728  */
1729 EAPI Ecore_Idler *ecore_idler_add(Ecore_Task_Cb func, const void *data);
1730
1731 /**
1732  * Delete an idler callback from the list to be executed.
1733  * @param  idler The handle of the idler callback to delete
1734  * @return The data pointer passed to the idler callback on success, @c NULL
1735  *         otherwise.
1736  */
1737 EAPI void *ecore_idler_del(Ecore_Idler *idler);
1738
1739 EAPI Ecore_Idle_Enterer *ecore_idle_enterer_add(Ecore_Task_Cb func, const void *data);
1740 EAPI Ecore_Idle_Enterer *ecore_idle_enterer_before_add(Ecore_Task_Cb func, const void *data);
1741 EAPI void *ecore_idle_enterer_del(Ecore_Idle_Enterer *idle_enterer);
1742
1743 EAPI Ecore_Idle_Exiter *ecore_idle_exiter_add(Ecore_Task_Cb func, const void *data);
1744 EAPI void *ecore_idle_exiter_del(Ecore_Idle_Exiter *idle_exiter);
1745
1746 /**
1747  * @}
1748  */
1749
1750 /**
1751  * @defgroup Ecore_Thread_Group Ecore Thread functions
1752  *
1753  * Facilities to run heavy tasks in different threads to avoid blocking
1754  * the main loop.
1755  *
1756  * The EFL is, for the most part, not thread safe. This means that if you
1757  * have some task running in another thread and you have, for example, an
1758  * Evas object to show the status progress of this task, you cannot update
1759  * the object from within the thread. This can only be done from the main
1760  * thread, the one running the main loop. This problem can be solved
1761  * by running a thread that sends messages to the main one using an
1762  * @ref Ecore_Pipe_Group "Ecore_Pipe", but when you need to handle other
1763  * things like cancelling the thread, your code grows in complexity and gets
1764  * much harder to maintain.
1765  *
1766  * Ecore Thread is here to solve that problem. It is @b not a simple wrapper
1767  * around standard POSIX threads (or the equivalent in other systems) and
1768  * it's not meant to be used to run parallel tasks throughout the entire
1769  * duration of the program, especially when these tasks are performance
1770  * critical, as Ecore manages these tasks using a pool of threads based on
1771  * system configuration.
1772  *
1773  * What Ecore Thread does, is make it a lot easier to dispatch a worker
1774  * function to perform some heavy task and then get the result once it
1775  * completes, without blocking the application's UI. In addition, cancelling
1776  * and rescheduling comes practically for free and the developer needs not
1777  * worry about how many threads are launched, since Ecore will schedule
1778  * them according to the number of processors the system has and maximum
1779  * amount of concurrent threads set for the application.
1780  *
1781  * At the system level, Ecore will start a new thread on an as-needed basis
1782  * until the maximum set is reached. When no more threads can be launched,
1783  * new worker functions will be queued in a waiting list until a thread
1784  * becomes available. This way, system threads will be shared throughout
1785  * different worker functions, but running only one at a time. At the same
1786  * time, a worker function that is rescheduled may be run on a different
1787  * thread the next time.
1788  *
1789  * The ::Ecore_Thread handler has two meanings, depending on what context
1790  * it is on. The one returned when starting a worker with any of the
1791  * functions ecore_thread_run() or ecore_thread_feedback_run() is an
1792  * identifier of that specific instance of the function and can be used from
1793  * the main loop with the ecore_thread_cancel() and ecore_thread_check()
1794  * functions. This handler must not be shared with the worker function
1795  * function running in the thread. This same handler will be the one received
1796  * on the @c end, @c cancel and @c feedback callbacks.
1797  *
1798  * The worker function, that's the one running in the thread, also receives
1799  * an ::Ecore_Thread handler that can be used with ecore_thread_cancel() and
1800  *ecore_thread_check(), sharing the flag with the main loop. But this
1801  * handler is also associated with the thread where the function is running.
1802  * This has strong implications when working with thread local data.
1803  *
1804  * There are two kinds of worker threads Ecore handles: simple, or short,
1805  * workers and feedback workers.
1806  *
1807  * The first kind is for simple functions that perform a
1808  * usually small but time consuming task. Ecore will run this function in
1809  * a thread as soon as one becomes available and notify the calling user of
1810  * its completion once the task is done.
1811  *
1812  * The following image shows the flow of a program running four tasks on
1813  * a pool of two threads.
1814  *
1815  * @image html ecore_thread.png
1816  * @image rtf ecore_thread.png
1817  * @image latex ecore_thread.eps width=\textwidth
1818  *
1819  * For larger tasks that may require continuous communication with the main
1820  * program, the feedback workers provide the same functionality plus a way
1821  * for the function running in the thread to send messages to the main
1822  * thread.
1823  *
1824  * The next diagram omits some details shown in the previous one regarding
1825  * how threads are spawned and tasks are queued, but illustrates how feedback
1826  * jobs communicate with the main loop and the special case of threads
1827  * running out of pool.
1828  *
1829  * @image html ecore_thread_feedback.png
1830  * @image rtf ecore_thread_feedback.png
1831  * @image latex ecore_thread_feedback.eps width=\textwidth
1832  *
1833  * See an overview example in @ref ecore_thread_example_c.
1834  *
1835  * @ingroup Ecore_Main_Loop_Group
1836  *
1837  * @{
1838  */
1839
1840 typedef struct _Ecore_Thread Ecore_Thread; /**< A handle for threaded jobs */
1841
1842 /**
1843  * @typedef Ecore_Thread_Cb Ecore_Thread_Cb
1844  * A callback used by Ecore_Thread helper.
1845  */
1846 typedef void (*Ecore_Thread_Cb)(void *data, Ecore_Thread *thread);
1847 /**
1848  * @typedef Ecore_Thread_Notify_Cb Ecore_Thread_Notify_Cb
1849  * A callback used by the main loop to receive data sent by an
1850  * @ref Ecore_Thread_Group.
1851  */
1852 typedef void (*Ecore_Thread_Notify_Cb)(void *data, Ecore_Thread *thread, void *msg_data);
1853
1854 /**
1855  * Schedule a task to run in a parallel thread to avoid locking the main loop
1856  *
1857  * @param func_blocking The function that should run in another thread.
1858  * @param func_end Function to call from main loop when @p func_blocking
1859  * completes its task successfully (may be NULL)
1860  * @param func_cancel Function to call from main loop if the thread running
1861  * @p func_blocking is cancelled or fails to start (may be NULL)
1862  * @param data User context data to pass to all callbacks.
1863  * @return A new thread handler, or @c NULL on failure.
1864  *
1865  * This function will try to create a new thread to run @p func_blocking in,
1866  * or if the maximum number of concurrent threads has been reached, will
1867  * add it to the pending list, where it will wait until a thread becomes
1868  * available. The return value will be an ::Ecore_Thread handle that can
1869  * be used to cancel the thread before its completion.
1870  *
1871  * @note This function should always return immediately, but in the rare
1872  * case that Ecore is built with no thread support, @p func_blocking will
1873  * be called here, actually blocking the main loop.
1874  *
1875  * Once a thread becomes available, @p func_blocking will be run in it until
1876  * it finishes, then @p func_end is called from the thread containing the
1877  * main loop to inform the user of its completion. While in @p func_blocking,
1878  * no functions from the EFL can be used, except for those from Eina that are
1879  * marked to be thread-safe. Even for the latter, caution needs to be taken
1880  * if the data is shared across several threads.
1881  *
1882  * @p func_end will be called from the main thread when @p func_blocking ends,
1883  * so here it's safe to use anything from the EFL freely.
1884  *
1885  * The thread can also be cancelled before its completion calling
1886  *ecore_thread_cancel(), either from the main thread or @p func_blocking.
1887  * In this case, @p func_cancel will be called, also from the main thread
1888  * to inform of this happening. If the thread could not be created, this
1889  * function will be called and it's @c thread parameter will be NULL. It's
1890  * also safe to call any EFL function here, as it will be running in the
1891  * main thread.
1892  *
1893  * Inside @p func_blocking, it's possible to call ecore_thread_reschedule()
1894  * to tell Ecore that this function should be called again.
1895  *
1896  * Be aware that no assumptions can be made about the order in which the
1897  * @p func_end callbacks for each task will be called. Once the function is
1898  * running in a different thread, it's the OS that will handle its running
1899  * schedule, and different functions may take longer to finish than others.
1900  * Also remember that just starting several tasks together doesn't mean they
1901  * will be running at the same time. Ecore will schedule them based on the
1902  * number of threads available for the particular system it's running in,
1903  * so some of the jobs started may be waiting until another one finishes
1904  * before it can execute its own @p func_blocking.
1905  *
1906  * @see ecore_thread_feedback_run()
1907  * @see ecore_thread_cancel()
1908  * @see ecore_thread_reschedule()
1909  * @see ecore_thread_max_set()
1910  */
1911 EAPI Ecore_Thread *ecore_thread_run(Ecore_Thread_Cb func_blocking, Ecore_Thread_Cb func_end, Ecore_Thread_Cb func_cancel, const void *data);
1912 /**
1913  * Launch a thread to run a task that can talk back to the main thread
1914  *
1915  * @param func_heavy The function that should run in another thread.
1916  * @param func_notify Function that receives the data sent from the thread
1917  * @param func_end Function to call from main loop when @p func_heavy
1918  * completes its task successfully
1919  * @param func_cancel Function to call from main loop if the thread running
1920  * @p func_heavy is cancelled or fails to start
1921  * @param data User context data to pass to all callback.
1922  * @param try_no_queue If you want to run outside of the thread pool.
1923  * @return A new thread handler, or @c NULL on failure.
1924  *
1925  * See ecore_thread_run() for a general description of this function.
1926  *
1927  * The difference with the above is that ecore_thread_run() is meant for
1928  * tasks that don't need to communicate anything until they finish, while
1929  * this function is provided with a new callback, @p func_notify, that will
1930  * be called from the main thread for every message sent from @p func_heavy
1931  * with ecore_thread_feedback().
1932  *
1933  * Like with ecore_thread_run(), a new thread will be launched to run
1934  * @p func_heavy unless the maximum number of simultaneous threads has been
1935  * reached, in which case the function will be scheduled to run whenever a
1936  * running task ends and a thread becomes free. But if @p try_no_queue is
1937  * set, Ecore will first try to launch a thread outside of the pool to run
1938  * the task. If it fails, it will revert to the normal behaviour of using a
1939  * thread from the pool as if @p try_no_queue had not been set.
1940  *
1941  * Keep in mind that Ecore handles the thread pool based on the number of
1942  * CPUs available, but running a thread outside of the pool doesn't count for
1943  * this, so having too many of them may have drastic effects over the
1944  * program's performance.
1945  *
1946  * @see ecore_thread_feedback()
1947  * @see ecore_thread_run()
1948  * @see ecore_thread_cancel()
1949  * @see ecore_thread_reschedule()
1950  * @see ecore_thread_max_set()
1951  */
1952 EAPI Ecore_Thread *ecore_thread_feedback_run(Ecore_Thread_Cb func_heavy, Ecore_Thread_Notify_Cb func_notify,
1953                                              Ecore_Thread_Cb func_end, Ecore_Thread_Cb func_cancel,
1954                                              const void *data, Eina_Bool try_no_queue);
1955 /**
1956  * Cancel a running thread.
1957  *
1958  * @param thread The thread to cancel.
1959  * @return Will return @c EINA_TRUE if the thread has been cancelled,
1960  *         @c EINA_FALSE if it is pending.
1961  *
1962  * This function can be called both in the main loop or in the running thread.
1963  *
1964  * This function cancels a running thread. If @p thread can be immediately
1965  * cancelled (it's still pending execution after creation or rescheduling),
1966  * then the @c cancel callback will be called, @p thread will be freed and
1967  * the function will return @c EINA_TRUE.
1968  *
1969  * If the thread is already running, then this function returns @c EINA_FALSE
1970  * after marking the @p thread as pending cancellation. For the thread to
1971  * actually be terminated, it needs to return from the user function back
1972  * into Ecore control. This can happen in several ways:
1973  * @li The function ends and returns normally. If it hadn't been cancelled,
1974  * @c func_end would be called here, but instead @c func_cancel will happen.
1975  * @li The function returns after requesting to be rescheduled with
1976  * ecore_thread_reschedule().
1977  * @li The function is prepared to leave early by checking if
1978  * ecore_thread_check() returns @c EINA_TRUE.
1979  *
1980  * The user function can cancel itself by calling ecore_thread_cancel(), but
1981  * it should always use the ::Ecore_Thread handle passed to it and never
1982  * share it with the main loop thread by means of shared user data or any
1983  * other way.
1984  *
1985  * @p thread will be freed and should not be used again if this function
1986  * returns @c EINA_TRUE or after the @c func_cancel callback returns.
1987  *
1988  * @see ecore_thread_check()
1989  */
1990 EAPI Eina_Bool ecore_thread_cancel(Ecore_Thread *thread);
1991 /**
1992  * Checks if a thread is pending cancellation
1993  *
1994  * @param thread The thread to test.
1995  * @return @c EINA_TRUE if the thread is pending cancellation,
1996  *         @c EINA_FALSE if it is not.
1997  *
1998  * This function can be called both in the main loop or in the running thread.
1999  *
2000  * When ecore_thread_cancel() is called on an already running task, the
2001  * thread is marked as pending cancellation. This function returns @c EINA_TRUE
2002  * if this mark is set for the given @p thread and can be used from the
2003  * main loop thread to check if a still active thread has been cancelled,
2004  * or from the user function running in the thread to check if it should
2005  * stop doing what it's doing and return early, effectively cancelling the
2006  * task.
2007  *
2008  * @see ecore_thread_cancel()
2009  */
2010 EAPI Eina_Bool ecore_thread_check(Ecore_Thread *thread);
2011 /**
2012  * Sends data from the worker thread to the main loop
2013  *
2014  * @param thread The current ::Ecore_Thread context to send data from
2015  * @param msg_data Data to be transmitted to the main loop
2016  * @return @c EINA_TRUE if @p msg_data was successfully sent to main loop,
2017  *         @c EINA_FALSE if anything goes wrong.
2018  *
2019  * You should use this function only in the @c func_heavy call.
2020  *
2021  * Only the address to @p msg_data will be sent and once this function
2022  * returns @c EINA_TRUE, the job running in the thread should never touch the
2023  * contents of it again. The data sent should be malloc()'ed or something
2024  * similar, as long as it's not memory local to the thread that risks being
2025  * overwritten or deleted once it goes out of scope or the thread finishes.
2026  *
2027  * Care must be taken that @p msg_data is properly freed in the @c func_notify
2028  * callback set when creating the thread.
2029  *
2030  * @see ecore_thread_feedback_run()
2031  */
2032 EAPI Eina_Bool ecore_thread_feedback(Ecore_Thread *thread, const void *msg_data);
2033 /**
2034  * Asks for the function in the thread to be called again at a later time
2035  *
2036  * @param thread The current ::Ecore_Thread context to rescheduled
2037  * @return @c EINA_TRUE if the task was successfully rescheduled,
2038  *         @c EINA_FALSE if anything goes wrong.
2039  *
2040  * This function should be called only from the same function represented
2041  * by @p thread.
2042  *
2043  * Calling this function will mark the thread for a reschedule, so as soon
2044  * as it returns, it will be added to the end of the list of pending tasks.
2045  * If no other tasks are waiting or there are sufficient threads available,
2046  * the rescheduled task will be launched again immediately.
2047  *
2048  * This should never return @c EINA_FALSE, unless it was called from the wrong
2049  * thread or with the wrong arguments.
2050  *
2051  * The @c func_end callback set when the thread is created will not be
2052  * called until the function in the thread returns without being rescheduled.
2053  * Similarly, if the @p thread is cancelled, the reschedule will not take
2054  * effect.
2055  */
2056 EAPI Eina_Bool ecore_thread_reschedule(Ecore_Thread *thread);
2057 /**
2058  * Gets the number of active threads running jobs
2059  *
2060  * @return Number of active threads running jobs
2061  *
2062  * This returns the number of threads currently running jobs of any type
2063  * through the Ecore_Thread API.
2064  *
2065  * @note Jobs started through the ecore_thread_feedback_run() function with
2066  * the @c try_no_queue parameter set to @c EINA_TRUE will not be accounted for
2067  * in the return of this function unless the thread creation fails and it
2068  * falls back to using one from the pool.
2069  */
2070 EAPI int ecore_thread_active_get(void);
2071 /**
2072  * Gets the number of short jobs waiting for a thread to run
2073  *
2074  * @return Number of pending threads running "short" jobs
2075  *
2076  * This returns the number of tasks started with ecore_thread_run() that are
2077  * pending, waiting for a thread to become available to run them.
2078  */
2079 EAPI int ecore_thread_pending_get(void);
2080 /**
2081  * Gets the number of feedback jobs waiting for a thread to run
2082  *
2083  * @return Number of pending threads running "feedback" jobs
2084  *
2085  * This returns the number of tasks started with ecore_thread_feedback_run()
2086  * that are pending, waiting for a thread to become available to run them.
2087  */
2088 EAPI int ecore_thread_pending_feedback_get(void);
2089 /**
2090  * Gets the total number of pending jobs
2091  *
2092  * @return Number of pending threads running jobs
2093  *
2094  * Same as the sum of ecore_thread_pending_get() and
2095  *ecore_thread_pending_feedback_get().
2096  */
2097 EAPI int ecore_thread_pending_total_get(void);
2098 /**
2099  * Gets the maximum number of threads that can run simultaneously
2100  *
2101  * @return Max possible number of Ecore_Thread's running concurrently
2102  *
2103  * This returns the maximum number of Ecore_Thread's that may be running at
2104  * the same time. If this number is reached, new jobs started by either
2105  *ecore_thread_run() or ecore_thread_feedback_run() will be added to the
2106  * respective pending queue until one of the running threads finishes its
2107  * task and becomes available to run a new one.
2108  *
2109  * By default, this will be the number of available CPUs for the
2110  * running program (as returned by eina_cpu_count()), or 1 if this value
2111  * could not be fetched.
2112  *
2113  * @see ecore_thread_max_set()
2114  * @see ecore_thread_max_reset()
2115  */
2116 EAPI int ecore_thread_max_get(void);
2117 /**
2118  * Sets the maximum number of threads allowed to run simultaneously
2119  *
2120  * @param num The new maximum
2121  *
2122  * This sets a new value for the maximum number of concurrently running
2123  * Ecore_Thread's. It @b must an integer between 1 and (16 * @c x), where @c x
2124  * is the number for CPUs available.
2125  *
2126  * @see ecore_thread_max_get()
2127  * @see ecore_thread_max_reset()
2128  */
2129 EAPI void ecore_thread_max_set(int num);
2130 /**
2131  * Resets the maximum number of concurrently running threads to the default
2132  *
2133  * This resets the value returned by ecore_thread_max_get() back to its
2134  * default.
2135  *
2136  * @see ecore_thread_max_get()
2137  * @see ecore_thread_max_set()
2138  */
2139 EAPI void ecore_thread_max_reset(void);
2140 /**
2141  * Gets the number of threads available for running tasks
2142  *
2143  * @return The number of available threads
2144  *
2145  * Same as doing ecore_thread_max_get() - ecore_thread_active_get().
2146  *
2147  * This function may return a negative number only in the case the user
2148  * changed the maximum number of running threads while other tasks are
2149  * running.
2150  */
2151 EAPI int ecore_thread_available_get(void);
2152 /**
2153  * Adds some data to a hash local to the thread
2154  *
2155  * @param thread The thread context the data belongs to
2156  * @param key The name under which the data will be stored
2157  * @param value The data to add
2158  * @param cb Function to free the data when removed from the hash
2159  * @param direct If true, this will not copy the key string (like
2160  * eina_hash_direct_add())
2161  * @return @c EINA_TRUE on success, @c EINA_FALSE on failure.
2162  *
2163  * Ecore Thread has a mechanism to share data across several worker functions
2164  * that run on the same system thread. That is, the data is stored per
2165  * thread and for a worker function to have access to it, it must be run
2166  * by the same thread that stored the data.
2167  *
2168  * When there are no more workers pending, the thread will be destroyed
2169  * along with the internal hash and any data left in it will be freed with
2170  * the @p cb function given.
2171  *
2172  * This set of functions is useful to share things around several instances
2173  * of a function when that thing is costly to create and can be reused, but
2174  * may only be used by one function at a time.
2175  *
2176  * For example, if you have a program doing requisitions to a database,
2177  * these requisitions can be done in threads so that waiting for the
2178  * database to respond doesn't block the UI. Each of these threads will
2179  * run a function, and each function will be dependent on a connection to
2180  * the database, which may not be able to handle more than one request at
2181  * a time so for each running function you will need one connection handle.
2182  * The options then are:
2183  * @li Each function opens a connection when it's called, does the work and
2184  * closes the connection when it finishes. This may be costly, wasting a lot
2185  * of time on resolving hostnames, negotiating permissions and allocating
2186  * memory.
2187  * @li Open the connections in the main loop and pass it to the threads
2188  * using the data pointer. Even worse, it's just as costly as before and now
2189  * it may even be kept with connections open doing nothing until a thread
2190  * becomes available to run the function.
2191  * @li Have a way to share connection handles, so that each instance of the
2192  * function can check if an available connection exists, and if it doesn't,
2193  * create one and add it to the pool. When no more connections are needed,
2194  * they are all closed.
2195  *
2196  * The last option is the most efficient, but it requires a lot of work to
2197  * implement properly. Using thread local data helps to achieve the same
2198  * result while avoiding doing all the tracking work on your code. The way
2199  * to use it would be, at the worker function, to ask for the connection
2200  * with ecore_thread_local_data_find() and if it doesn't exist, then open
2201  * a new one and save it with ecore_thread_local_data_add(). Do the work and
2202  * forget about the connection handle, when everything is done the function
2203  * just ends. The next worker to run on that thread will check if a
2204  * connection exists and find that it does, so the process of opening a
2205  * new one has been spared. When no more workers exist, the thread is
2206  * destroyed and the callback used when saving the connection will be called
2207  * to close it.
2208  *
2209  * This function adds the data @p value to the thread data under the given
2210  * @p key.
2211  * No other value in the hash may have the same @p key. If you need to
2212  * change the value under a @p key, or you don't know if one exists already,
2213  * you can use ecore_thread_local_data_set().
2214  *
2215  * Neither @p key nor @p value may be @c NULL and @p key will be copied in the
2216  * hash, unless @p direct is set, in which case the string used should not
2217  * be freed until the data is removed from the hash.
2218  *
2219  * The @p cb function will be called when the data in the hash needs to be
2220  * freed, be it because it got deleted with ecore_thread_local_data_del() or
2221  * because @p thread was terminated and the hash destroyed. This parameter
2222  * may be NULL, in which case @p value needs to be manually freed after
2223  * removing it from the hash with either ecore_thread_local_data_del() or
2224  * ecore_thread_local_data_set(), but it's very unlikely that this is what
2225  * you want.
2226  *
2227  * This function, and all of the others in the @c ecore_thread_local_data
2228  * family of functions, can only be called within the worker function running
2229  * in the thread. Do not call them from the main loop or from a thread
2230  * other than the one represented by @p thread.
2231  *
2232  * @see ecore_thread_local_data_set()
2233  * @see ecore_thread_local_data_find()
2234  * @see ecore_thread_local_data_del()
2235  */
2236 EAPI Eina_Bool ecore_thread_local_data_add(Ecore_Thread *thread, const char *key, void *value,
2237                                            Eina_Free_Cb cb, Eina_Bool direct);
2238 /**
2239  * Sets some data in the hash local to the given thread
2240  *
2241  * @param thread The thread context the data belongs to
2242  * @param key The name under which the data will be stored
2243  * @param value The data to add
2244  * @param cb Function to free the data when removed from the hash
2245  *
2246  * If no data exists in the hash under the @p key, this function adds
2247  * @p value in the hash under the given @p key and returns NULL.
2248  * The key itself is copied.
2249  *
2250  * If the hash already contains something under @p key, the data will be
2251  * replaced by @p value and the old value will be returned.
2252  *
2253  * @c NULL will also be returned if either @p key or @p value are @c NULL, or
2254  * if an error occurred.
2255  *
2256  * This function, and all of the others in the @c ecore_thread_local_data
2257  * family of functions, can only be called within the worker function running
2258  * in the thread. Do not call them from the main loop or from a thread
2259  * other than the one represented by @p thread.
2260  *
2261  * @see ecore_thread_local_data_add()
2262  * @see ecore_thread_local_data_del()
2263  * @see ecore_thread_local_data_find()
2264  */
2265 EAPI void *ecore_thread_local_data_set(Ecore_Thread *thread, const char *key, void *value, Eina_Free_Cb cb);
2266 /**
2267  * Gets data stored in the hash local to the given thread
2268  *
2269  * @param thread The thread context the data belongs to
2270  * @param key The name under which the data is stored
2271  * @return The value under the given key, or @c NULL on error.
2272  *
2273  * Finds and return the data stored in the shared hash under the key @p key.
2274  *
2275  * This function, and all of the others in the @c ecore_thread_local_data
2276  * family of functions, can only be called within the worker function running
2277  * in the thread. Do not call them from the main loop or from a thread
2278  * other than the one represented by @p thread.
2279  *
2280  * @see ecore_thread_local_data_add()
2281  * @see ecore_thread_local_data_wait()
2282  */
2283 EAPI void *ecore_thread_local_data_find(Ecore_Thread *thread, const char *key);
2284 /**
2285  * Deletes from the thread's hash the data corresponding to the given key
2286  *
2287  * @param thread The thread context the data belongs to
2288  * @param key The name under which the data is stored
2289  * @return @c EINA_TRUE on success, @c EINA_FALSE on failure.
2290  *
2291  * If there's any data stored associated with @p key in the global hash,
2292  * this function will remove it from it and return @c EINA_TRUE. If no data
2293  * exists or an error occurs, it returns @c EINA_FALSE.
2294  *
2295  * If the data was added to the hash with a free function, then it will
2296  * also be freed after removing it from the hash, otherwise it requires
2297  * to be manually freed by the user, which means that if no other reference
2298  * to it exists before calling this function, it will result in a memory
2299  * leak.
2300  *
2301  * This function, and all of the others in the @c ecore_thread_local_data
2302  * family of functions, can only be called within the worker function running
2303  * in the thread. Do not call them from the main loop or from a thread
2304  * other than the one represented by @p thread.
2305  *
2306  * @see ecore_thread_local_data_add()
2307  */
2308 EAPI Eina_Bool ecore_thread_local_data_del(Ecore_Thread *thread, const char *key);
2309
2310 /**
2311  * Adds some data to a hash shared by all threads
2312  *
2313  * @param key The name under which the data will be stored
2314  * @param value The data to add
2315  * @param cb Function to free the data when removed from the hash
2316  * @param direct If true, this will not copy the key string (like
2317  * eina_hash_direct_add())
2318  * @return @c EINA_TRUE on success, @c EINA_FALSE on failure.
2319  *
2320  * Ecore Thread keeps a hash that can be used to share data across several
2321  * threads, including the main loop one, without having to manually handle
2322  * mutexes to do so safely.
2323  *
2324  * This function adds the data @p value to this hash under the given @p key.
2325  * No other value in the hash may have the same @p key. If you need to
2326  * change the value under a @p key, or you don't know if one exists already,
2327  * you can use ecore_thread_global_data_set().
2328  *
2329  * Neither @p key nor @p value may be @c NULL and @p key will be copied in the
2330  * hash, unless @p direct is set, in which case the string used should not
2331  * be freed until the data is removed from the hash.
2332  *
2333  * The @p cb function will be called when the data in the hash needs to be
2334  * freed, be it because it got deleted with ecore_thread_global_data_del() or
2335  * because Ecore Thread was shut down and the hash destroyed. This parameter
2336  * may be NULL, in which case @p value needs to be manually freed after
2337  * removing it from the hash with either ecore_thread_global_data_del() or
2338  *ecore_thread_global_data_set().
2339  *
2340  * Manually freeing any data that was added to the hash with a @p cb function
2341  * is likely to produce a segmentation fault, or any other strange
2342  * happenings, later on in the program.
2343  *
2344  * @see ecore_thread_global_data_del()
2345  * @see ecore_thread_global_data_set()
2346  * @see ecore_thread_global_data_find()
2347  */
2348 EAPI Eina_Bool ecore_thread_global_data_add(const char *key, void *value, Eina_Free_Cb cb, Eina_Bool direct);
2349 /**
2350  * Sets some data in the hash shared by all threads
2351  *
2352  * @param key The name under which the data will be stored
2353  * @param value The data to add
2354  * @param cb Function to free the data when removed from the hash
2355  *
2356  * If no data exists in the hash under the @p key, this function adds
2357  * @p value in the hash under the given @p key and returns NULL.
2358  * The key itself is copied.
2359  *
2360  * If the hash already contains something under @p key, the data will be
2361  * replaced by @p value and the old value will be returned.
2362  *
2363  * @c NULL will also be returned if either @p key or @p value are @c NULL, or
2364  * if an error occurred.
2365  *
2366  * @see ecore_thread_global_data_add()
2367  * @see ecore_thread_global_data_del()
2368  * @see ecore_thread_global_data_find()
2369  */
2370 EAPI void *ecore_thread_global_data_set(const char *key, void *value, Eina_Free_Cb cb);
2371 /**
2372  * Gets data stored in the hash shared by all threads
2373  *
2374  * @param key The name under which the data is stored
2375  * @return The value under the given key, or @c NULL on error.
2376  *
2377  * Finds and return the data stored in the shared hash under the key @p key.
2378  *
2379  * Keep in mind that the data returned may be used by more than one thread
2380  * at the same time and no reference counting is done on it by Ecore.
2381  * Freeing the data or modifying its contents may require additional
2382  * precautions to be considered, depending on the application's design.
2383  *
2384  * @see ecore_thread_global_data_add()
2385  * @see ecore_thread_global_data_wait()
2386  */
2387 EAPI void *ecore_thread_global_data_find(const char *key);
2388 /**
2389  * Deletes from the shared hash the data corresponding to the given key
2390  *
2391  * @param key The name under which the data is stored
2392  * @return @c EINA_TRUE on success, @c EINA_FALSE on failure.
2393  *
2394  * If there's any data stored associated with @p key in the global hash,
2395  * this function will remove it from it and return @c EINA_TRUE. If no data
2396  * exists or an error occurs, it returns @c EINA_FALSE.
2397  *
2398  * If the data was added to the hash with a free function, then it will
2399  * also be freed after removing it from the hash, otherwise it requires
2400  * to be manually freed by the user, which means that if no other reference
2401  * to it exists before calling this function, it will result in a memory
2402  * leak.
2403  *
2404  * Note, also, that freeing data that other threads may be using will result
2405  * in a crash, so appropriate care must be taken by the application when
2406  * that possibility exists.
2407  *
2408  * @see ecore_thread_global_data_add()
2409  */
2410 EAPI Eina_Bool ecore_thread_global_data_del(const char *key);
2411 /**
2412  * Gets data stored in the shared hash, or wait for it if it doesn't exist
2413  *
2414  * @param key The name under which the data is stored
2415  * @param seconds The amount of time in seconds to wait for the data.
2416  * @return The value under the given key, or @c NULL on error.
2417  *
2418  * Finds and return the data stored in the shared hash under the key @p key.
2419  *
2420  * If there's nothing in the hash under the given @p key, the function
2421  * will block and wait up to @p seconds seconds for some other thread to
2422  * add it with either ecore_thread_global_data_add() or
2423  * ecore_thread_global_data_set(). If after waiting there's still no data
2424  * to get, @c NULL will be returned.
2425  *
2426  * If @p seconds is 0, then no waiting will happen and this function works
2427  * like ecore_thread_global_data_find(). If @p seconds is less than 0, then
2428  * the function will wait indefinitely.
2429  *
2430  * Keep in mind that the data returned may be used by more than one thread
2431  * at the same time and no reference counting is done on it by Ecore.
2432  * Freeing the data or modifying its contents may require additional
2433  * precautions to be considered, depending on the application's design.
2434  *
2435  * @see ecore_thread_global_data_add()
2436  * @see ecore_thread_global_data_find()
2437  */
2438 EAPI void *ecore_thread_global_data_wait(const char *key, double seconds);
2439
2440 /**
2441  * @}
2442  */
2443
2444 /**
2445  * @defgroup Ecore_Pipe_Group Pipe wrapper
2446  *
2447  * These functions wrap the pipe / write / read functions to easily
2448  * integrate its use into ecore's main loop.
2449  *
2450  * The ecore_pipe_add() function creates file descriptors (sockets
2451  * on Windows) and attach a handle to the ecore main loop. That
2452  * handle is called when data is read in the pipe. To write data in
2453  * the pipe, just call ecore_pipe_write(). When you are done, just
2454  * call ecore_pipe_del().
2455  *
2456  * For examples see here:
2457  * @li @ref tutorial_ecore_pipe_gstreamer_example
2458  * @li @ref tutorial_ecore_pipe_simple_example
2459  *
2460  * @ingroup Ecore_Main_Loop_Group
2461  *
2462  * @{
2463  */
2464
2465 typedef struct _Ecore_Pipe Ecore_Pipe; /**< A handle for pipes */
2466
2467 /**
2468  * @typedef Ecore_Pipe_Cb Ecore_Pipe_Cb
2469  * The callback that data written to the pipe is sent to.
2470  */
2471 typedef void (*Ecore_Pipe_Cb)(void *data, void *buffer, unsigned int nbyte);
2472
2473 EAPI Ecore_Pipe *ecore_pipe_add(Ecore_Pipe_Cb handler, const void *data);
2474 EAPI void *ecore_pipe_del(Ecore_Pipe *p);
2475 EAPI Eina_Bool ecore_pipe_write(Ecore_Pipe *p, const void *buffer, unsigned int nbytes);
2476 EAPI void ecore_pipe_write_close(Ecore_Pipe *p);
2477 EAPI void ecore_pipe_read_close(Ecore_Pipe *p);
2478 EAPI void ecore_pipe_thaw(Ecore_Pipe *p);
2479 EAPI void ecore_pipe_freeze(Ecore_Pipe *p);
2480 EAPI int ecore_pipe_wait(Ecore_Pipe *p, int message_count, double wait);
2481
2482 /**
2483  * @}
2484  */
2485
2486 /**
2487  * @defgroup Ecore_Job_Group Ecore Job functions
2488  *
2489  * You can queue jobs that are to be done by the main loop when the
2490  * current event is dealt with.
2491  *
2492  * Jobs are processed by the main loop similarly to events. They
2493  * also will be executed in the order in which they were added.
2494  *
2495  * A good use for them is when you don't want to execute an action
2496  * immediately, but want to give the control back to the main loop
2497  * so that it will call your job callback when jobs start being
2498  * processed (and if there are other jobs added before yours, they
2499  * will be processed first). This also gives the chance to other
2500  * actions in your program to cancel the job before it is started.
2501  *
2502  * Examples of using @ref Ecore_Job :
2503  * @li @ref ecore_job_example_c
2504  *
2505  * @ingroup Ecore_Main_Loop_Group
2506  *
2507  * @{
2508  */
2509
2510 typedef struct _Ecore_Job Ecore_Job;    /**< A job handle */
2511
2512 EAPI Ecore_Job *ecore_job_add(Ecore_Cb func, const void *data);
2513 EAPI void *ecore_job_del(Ecore_Job *job);
2514
2515 /**
2516  * @}
2517  */
2518
2519 /**
2520  * @defgroup Ecore_Application_Group Ecore Application functions
2521  *
2522  * @{
2523  */
2524
2525 EAPI void ecore_app_args_set(int argc, const char **argv);
2526 EAPI void ecore_app_args_get(int *argc, char ***argv);
2527 EAPI void ecore_app_restart(void);
2528
2529 /**
2530  * @}
2531  */
2532
2533 /**
2534  * @defgroup Ecore_Throttle_Group Ecore Throttle functions
2535  *
2536  * @ingroup Ecore_Main_Loop_Group
2537  *
2538  * @{
2539  */
2540
2541 EAPI void ecore_throttle_adjust(double amount);
2542 EAPI double ecore_throttle_get(void);
2543
2544 /**
2545  * @}
2546  */
2547
2548 #ifdef __cplusplus
2549 }
2550 #endif
2551 #endif