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