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