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