svn update: 48958 (latest:48959)
[framework/uifw/ecore.git] / src / lib / ecore / Ecore.h
1 #ifndef _ECORE_H
2 #define _ECORE_H
3
4 #ifdef _MSC_VER
5 # include <Evil.h>
6 #endif
7
8 #include <Eina.h>
9
10 #ifdef EAPI
11 # undef EAPI
12 #endif
13
14 #ifdef _WIN32
15 # ifdef EFL_ECORE_BUILD
16 #  ifdef DLL_EXPORT
17 #   define EAPI __declspec(dllexport)
18 #  else
19 #   define EAPI
20 #  endif /* ! DLL_EXPORT */
21 # else
22 #  define EAPI __declspec(dllimport)
23 # endif /* ! EFL_ECORE_BUILD */
24 #else
25 # ifdef __GNUC__
26 #  if __GNUC__ >= 4
27 #   define EAPI __attribute__ ((visibility("default")))
28 #  else
29 #   define EAPI
30 #  endif
31 # else
32 #  define EAPI
33 # endif
34 #endif /* ! _WIN32 */
35
36 /**
37  * @file Ecore.h
38  * @brief The file that provides the program utility, main loop and timer
39  *        functions.
40  *
41  * This header provides the Ecore event handling loop.  For more
42  * details, see @ref Ecore_Main_Loop_Group.
43  *
44  * For the main loop to be of any use, you need to be able to add events
45  * and event handlers.  Events for file descriptor events are covered in
46  * @ref Ecore_FD_Handler_Group.
47  *
48  * Time functions are covered in @ref Ecore_Time_Group.
49  *
50  * There is also provision for callbacks for when the loop enters or
51  * exits an idle state. See @ref Idle_Group for more information.
52  *
53  * Functions are also provided for spawning child processes using fork.
54  * See @ref Ecore_Exe_Basic_Group and @ref Ecore_Exe_Signal_Group for
55  * more details.
56  */
57
58 #ifdef _WIN32
59 # include <winsock2.h>
60 #elif (defined (__FreeBSD__) && (__FreeBSD_version >= 420001)) || defined (__OpenBSD__)
61 # include <sys/select.h>
62 # include <signal.h>
63 #else
64 # include <sys/time.h>
65 # include <signal.h>
66 #endif
67
68 #include <sys/types.h>
69
70 #ifdef __cplusplus
71 extern "C" {
72 #endif
73
74 #define ECORE_CALLBACK_CANCEL 0 /**< Return value to remove a callback */
75 #define ECORE_CALLBACK_RENEW 1  /**< Return value to keep a callback */
76
77 #define ECORE_EVENT_NONE            0
78 #define ECORE_EVENT_SIGNAL_USER     1 /**< User signal event */
79 #define ECORE_EVENT_SIGNAL_HUP      2 /**< Hup signal event */
80 #define ECORE_EVENT_SIGNAL_EXIT     3 /**< Exit signal event */
81 #define ECORE_EVENT_SIGNAL_POWER    4 /**< Power signal event */
82 #define ECORE_EVENT_SIGNAL_REALTIME 5 /**< Realtime signal event */
83 #define ECORE_EVENT_COUNT           6
84
85 #define ECORE_EXE_PRIORITY_INHERIT 9999
86    
87    EAPI extern int ECORE_EXE_EVENT_ADD; /**< A child process has been added */
88    EAPI extern int ECORE_EXE_EVENT_DEL; /**< A child process has been deleted (it exited, naming consistant with the rest of ecore). */
89    EAPI extern int ECORE_EXE_EVENT_DATA; /**< Data from a child process. */
90    EAPI extern int ECORE_EXE_EVENT_ERROR; /**< Errors from a child process. */
91
92    enum _Ecore_Fd_Handler_Flags
93      {
94         ECORE_FD_READ = 1, /**< Fd Read mask */
95         ECORE_FD_WRITE = 2, /**< Fd Write mask */
96         ECORE_FD_ERROR = 4 /**< Fd Error mask */
97      };
98    typedef enum _Ecore_Fd_Handler_Flags Ecore_Fd_Handler_Flags;
99
100    enum _Ecore_Exe_Flags /* flags for executing a child with its stdin and/or stdout piped back */
101      {
102         ECORE_EXE_PIPE_READ = 1, /**< Exe Pipe Read mask */
103         ECORE_EXE_PIPE_WRITE = 2, /**< Exe Pipe Write mask */
104         ECORE_EXE_PIPE_ERROR = 4, /**< Exe Pipe error mask */
105         ECORE_EXE_PIPE_READ_LINE_BUFFERED = 8, /**< Reads are buffered until a newline and delivered 1 event per line */
106         ECORE_EXE_PIPE_ERROR_LINE_BUFFERED = 16, /**< Errors are buffered until a newline and delivered 1 event per line */
107         ECORE_EXE_PIPE_AUTO = 32, /**< stdout and stderr are buffered automatically */
108         ECORE_EXE_RESPAWN = 64, /**< FIXME: Exe is restarted if it dies */
109         ECORE_EXE_USE_SH = 128, /**< Use /bin/sh to run the command. */
110         ECORE_EXE_NOT_LEADER = 256 /**< Do not use setsid() to have the executed process be its own session leader */
111      };
112    typedef enum _Ecore_Exe_Flags Ecore_Exe_Flags;
113
114    enum _Ecore_Exe_Win32_Priority
115      {
116        ECORE_EXE_WIN32_PRIORITY_IDLE, /**< Idle priority, for monitoring the system */
117        ECORE_EXE_WIN32_PRIORITY_BELOW_NORMAL, /**< Below default priority */
118        ECORE_EXE_WIN32_PRIORITY_NORMAL, /**< Default priority */
119        ECORE_EXE_WIN32_PRIORITY_ABOVE_NORMAL, /**< Above default priority */
120        ECORE_EXE_WIN32_PRIORITY_HIGH, /**< High priority, use with care as other threads in the system will not get processor time */
121        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 */
122      };
123    typedef enum _Ecore_Exe_Win32_Priority Ecore_Exe_Win32_Priority;
124
125    enum _Ecore_Poller_Type /* Poller types */
126      {
127         ECORE_POLLER_CORE = 0 /**< The core poller interval */
128      };
129    typedef enum _Ecore_Poller_Type Ecore_Poller_Type;
130
131    typedef struct _Ecore_Exe                   Ecore_Exe; /**< A handle for spawned processes */
132    typedef struct _Ecore_Timer                 Ecore_Timer; /**< A handle for timers */
133    typedef struct _Ecore_Idler                 Ecore_Idler; /**< A handle for idlers */
134    typedef struct _Ecore_Idle_Enterer          Ecore_Idle_Enterer; /**< A handle for idle enterers */
135    typedef struct _Ecore_Idle_Exiter           Ecore_Idle_Exiter; /**< A handle for idle exiters */
136    typedef struct _Ecore_Fd_Handler            Ecore_Fd_Handler; /**< A handle for Fd handlers */
137    typedef struct _Ecore_Win32_Handler         Ecore_Win32_Handler; /**< A handle for HANDLE handlers on Windows */
138    typedef struct _Ecore_Event_Handler         Ecore_Event_Handler; /**< A handle for an event handler */
139    typedef struct _Ecore_Event_Filter          Ecore_Event_Filter; /**< A handle for an event filter */
140    typedef struct _Ecore_Event                 Ecore_Event; /**< A handle for an event */
141    typedef struct _Ecore_Animator              Ecore_Animator; /**< A handle for animators */
142    typedef struct _Ecore_Pipe                  Ecore_Pipe; /**< A handle for pipes */
143    typedef struct _Ecore_Poller                Ecore_Poller; /**< A handle for pollers */
144    typedef struct _Ecore_Event_Signal_User     Ecore_Event_Signal_User; /**< User signal event */
145    typedef struct _Ecore_Event_Signal_Hup      Ecore_Event_Signal_Hup; /**< Hup signal event */
146    typedef struct _Ecore_Event_Signal_Exit     Ecore_Event_Signal_Exit; /**< Exit signal event */
147    typedef struct _Ecore_Event_Signal_Power    Ecore_Event_Signal_Power; /**< Power signal event */
148    typedef struct _Ecore_Event_Signal_Realtime Ecore_Event_Signal_Realtime; /**< Realtime signal event */
149    typedef struct _Ecore_Exe_Event_Add         Ecore_Exe_Event_Add; /**< Spawned Exe add event */
150    typedef struct _Ecore_Exe_Event_Del         Ecore_Exe_Event_Del; /**< Spawned Exe exit event */
151    typedef struct _Ecore_Exe_Event_Data_Line   Ecore_Exe_Event_Data_Line; /**< Lines from a child process */
152    typedef struct _Ecore_Exe_Event_Data        Ecore_Exe_Event_Data; /**< Data from a child process */
153    typedef struct _Ecore_Thread                Ecore_Thread;
154
155    typedef struct _Ecore_Job Ecore_Job; /**< A job handle */
156
157    struct _Ecore_Event_Signal_User /** User signal event */
158      {
159         int   number; /**< The signal number. Either 1 or 2 */
160         void *ext_data; /**< Extension data - not used */
161
162 #ifndef _WIN32
163         siginfo_t data; /**< Signal info */
164 #endif
165      };
166
167    struct _Ecore_Event_Signal_Hup /** Hup signal event */
168      {
169         void *ext_data; /**< Extension data - not used */
170
171 #ifndef _WIN32
172         siginfo_t data; /**< Signal info */
173 #endif
174      };
175
176    struct _Ecore_Event_Signal_Exit /** Exit request event */
177      {
178         unsigned int   interrupt : 1; /**< Set if the exit request was an interrupt  signal*/
179         unsigned int   quit      : 1; /**< set if the exit request was a quit signal */
180         unsigned int   terminate : 1; /**< Set if the exit request was a terminate singal */
181         void          *ext_data;        /**< Extension data - not used */
182
183 #ifndef _WIN32
184         siginfo_t data; /**< Signal info */
185 #endif
186      };
187
188    struct _Ecore_Event_Signal_Power /** Power event */
189      {
190         void *ext_data; /**< Extension data - not used */
191
192 #ifndef _WIN32
193         siginfo_t data; /**< Signal info */
194 #endif
195      };
196
197    struct _Ecore_Event_Signal_Realtime /** Realtime event */
198      {
199         int num; /**< The realtime signal's number */
200
201 #ifndef _WIN32
202         siginfo_t data; /**< Signal info */
203 #endif
204      };
205
206    struct _Ecore_Exe_Event_Add /** Process add event */
207      {
208         Ecore_Exe *exe; /**< The handle to the added process */
209         void      *ext_data; /**< Extension data - not used */
210      };
211
212    struct _Ecore_Exe_Event_Del /** Process exit event */
213      {
214         pid_t         pid; /**< The process ID of the process that exited */
215         int           exit_code; /**< The exit code of the process */
216         Ecore_Exe    *exe; /**< The handle to the exited process, or NULL if not found */
217         int           exit_signal; /** < The signal that caused the process to exit */
218         unsigned int  exited    : 1; /** < set to 1 if the process exited of its own accord */
219         unsigned int  signalled : 1; /** < set to 1 id the process exited due to uncaught signal */
220         void         *ext_data; /**< Extension data - not used */
221 #ifndef _WIN32
222         siginfo_t     data; /**< Signal info */
223 #endif
224      };
225
226    struct _Ecore_Exe_Event_Data_Line /**< Lines from a child process */
227       {
228          char *line;
229          int   size;
230       };
231
232    struct _Ecore_Exe_Event_Data /** Data from a child process event */
233      {
234         Ecore_Exe *exe; /**< The handle to the process */
235         void *data; /**< the raw binary data from the child process that was recieved */
236         int   size; /**< the size of this data in bytes */
237         Ecore_Exe_Event_Data_Line *lines; /**< an array of line data if line buffered, the last one has it's line member set to NULL */
238      };
239
240    EAPI int  ecore_init(void);
241    EAPI int  ecore_shutdown(void);
242
243    EAPI void ecore_app_args_set(int argc, const char **argv);
244    EAPI void ecore_app_args_get(int *argc, char ***argv);
245    EAPI void ecore_app_restart(void);
246
247    EAPI Ecore_Event_Handler *ecore_event_handler_add(int type, int (*func) (void *data, int type, void *event), const void *data);
248    EAPI void                *ecore_event_handler_del(Ecore_Event_Handler *event_handler);
249    EAPI Ecore_Event         *ecore_event_add(int type, void *ev, void (*func_free) (void *data, void *ev), void *data);
250    EAPI void                *ecore_event_del(Ecore_Event *event);
251    EAPI int                  ecore_event_type_new(void);
252    EAPI Ecore_Event_Filter  *ecore_event_filter_add(void * (*func_start) (void *data), int (*func_filter) (void *data, void *loop_data, int type, void *event), void (*func_end) (void *data, void *loop_data), const void *data);
253    EAPI void                *ecore_event_filter_del(Ecore_Event_Filter *ef);
254    EAPI int                  ecore_event_current_type_get(void);
255    EAPI void                *ecore_event_current_event_get(void);
256
257
258    EAPI void        ecore_exe_run_priority_set(int pri);
259    EAPI int         ecore_exe_run_priority_get(void);
260    EAPI Ecore_Exe  *ecore_exe_run(const char *exe_cmd, const void *data);
261    EAPI Ecore_Exe  *ecore_exe_pipe_run(const char *exe_cmd, Ecore_Exe_Flags flags, const void *data);
262    EAPI void        ecore_exe_callback_pre_free_set(Ecore_Exe *exe, void (*func)(void *data, const Ecore_Exe *exe));
263    EAPI Eina_Bool   ecore_exe_send(Ecore_Exe *exe, const void *data, int size);
264    EAPI void        ecore_exe_close_stdin(Ecore_Exe *exe);
265    EAPI void        ecore_exe_auto_limits_set(Ecore_Exe *exe, int start_bytes, int end_bytes, int start_lines, int end_lines);
266    EAPI Ecore_Exe_Event_Data *ecore_exe_event_data_get(Ecore_Exe *exe, Ecore_Exe_Flags flags);
267    EAPI void        ecore_exe_event_data_free(Ecore_Exe_Event_Data *data);
268    EAPI void       *ecore_exe_free(Ecore_Exe *exe);
269    EAPI pid_t       ecore_exe_pid_get(const Ecore_Exe *exe);
270    EAPI void        ecore_exe_tag_set(Ecore_Exe *exe, const char *tag);
271    EAPI const char *ecore_exe_tag_get(const Ecore_Exe *exe);
272    EAPI const char *ecore_exe_cmd_get(const Ecore_Exe *exe);
273    EAPI void       *ecore_exe_data_get(const Ecore_Exe *exe);
274    EAPI Ecore_Exe_Flags ecore_exe_flags_get(const Ecore_Exe *exe);
275    EAPI void        ecore_exe_pause(Ecore_Exe *exe);
276    EAPI void        ecore_exe_continue(Ecore_Exe *exe);
277    EAPI void        ecore_exe_interrupt(Ecore_Exe *exe);
278    EAPI void        ecore_exe_quit(Ecore_Exe *exe);
279    EAPI void        ecore_exe_terminate(Ecore_Exe *exe);
280    EAPI void        ecore_exe_kill(Ecore_Exe *exe);
281    EAPI void        ecore_exe_signal(Ecore_Exe *exe, int num);
282    EAPI void        ecore_exe_hup(Ecore_Exe *exe);
283
284    EAPI Ecore_Idler *ecore_idler_add(int (*func) (void *data), const void *data);
285    EAPI void        *ecore_idler_del(Ecore_Idler *idler);
286
287    EAPI Ecore_Idle_Enterer *ecore_idle_enterer_add(int (*func) (void *data), const void *data);
288    EAPI Ecore_Idle_Enterer *ecore_idle_enterer_before_add(int (*func) (void *data), const void *data);
289    EAPI void               *ecore_idle_enterer_del(Ecore_Idle_Enterer *idle_enterer);
290
291    EAPI Ecore_Idle_Exiter *ecore_idle_exiter_add(int (*func) (void *data), const void *data);
292    EAPI void              *ecore_idle_exiter_del(Ecore_Idle_Exiter *idle_exiter);
293
294    EAPI void              ecore_main_loop_iterate(void);
295
296    EAPI void              ecore_main_loop_select_func_set(int (*func)(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout));
297    EAPI void             *ecore_main_loop_select_func_get(void);
298
299    EAPI Eina_Bool         ecore_main_loop_glib_integrate(void);
300    EAPI void              ecore_main_loop_glib_always_integrate_disable(void);
301        
302    EAPI void              ecore_main_loop_begin(void);
303    EAPI void              ecore_main_loop_quit(void);
304    EAPI Ecore_Fd_Handler *ecore_main_fd_handler_add(int fd, Ecore_Fd_Handler_Flags flags, int (*func) (void *data, Ecore_Fd_Handler *fd_handler), const void *data, int (*buf_func) (void *buf_data, Ecore_Fd_Handler *fd_handler), const void *buf_data);
305    EAPI void              ecore_main_fd_handler_prepare_callback_set(Ecore_Fd_Handler *fd_handler, void (*func) (void *data, Ecore_Fd_Handler *fd_handler), const void *data);
306    EAPI void             *ecore_main_fd_handler_del(Ecore_Fd_Handler *fd_handler);
307    EAPI int               ecore_main_fd_handler_fd_get(Ecore_Fd_Handler *fd_handler);
308    EAPI int               ecore_main_fd_handler_active_get(Ecore_Fd_Handler *fd_handler, Ecore_Fd_Handler_Flags flags);
309    EAPI void              ecore_main_fd_handler_active_set(Ecore_Fd_Handler *fd_handler, Ecore_Fd_Handler_Flags flags);
310
311    EAPI Ecore_Win32_Handler *ecore_main_win32_handler_add(void *h, int (*func) (void *data, Ecore_Win32_Handler *wh), const void *data);
312    EAPI void                *ecore_main_win32_handler_del(Ecore_Win32_Handler *win32_handler);
313
314    EAPI Ecore_Pipe  *ecore_pipe_add(void (*handler) (void *data, void *buffer, unsigned int nbyte), const void *data);
315    EAPI void        *ecore_pipe_del(Ecore_Pipe *p);
316    EAPI int          ecore_pipe_write(Ecore_Pipe *p, const void *buffer, unsigned int nbytes);
317    EAPI void         ecore_pipe_write_close(Ecore_Pipe *p);
318    EAPI void         ecore_pipe_read_close(Ecore_Pipe *p);
319
320    EAPI Ecore_Thread *ecore_thread_run(void (*func_heavy)(void *data), void (*func_end)(void *data), void (*func_cancel)(void *data), const void *data);
321    EAPI Eina_Bool     ecore_thread_cancel(Ecore_Thread *thread);
322
323    EAPI double ecore_time_get(void);
324    EAPI double ecore_loop_time_get(void);
325
326    EAPI Ecore_Timer *ecore_timer_add(double in, int (*func) (void *data), const void *data);
327    EAPI Ecore_Timer *ecore_timer_loop_add(double in, int (*func) (void *data), const void *data);
328    EAPI void        *ecore_timer_del(Ecore_Timer *timer);
329    EAPI void         ecore_timer_interval_set(Ecore_Timer *timer, double in);
330    EAPI double       ecore_timer_interval_get(Ecore_Timer *timer);
331    EAPI void         ecore_timer_freeze(Ecore_Timer *timer);
332    EAPI void         ecore_timer_thaw(Ecore_Timer *timer);
333    EAPI void         ecore_timer_delay(Ecore_Timer *timer, double add);
334    EAPI double       ecore_timer_pending_get(Ecore_Timer *timer);
335
336    EAPI double       ecore_timer_precision_get(void);
337    EAPI void         ecore_timer_precision_set(double precision);
338
339    EAPI Ecore_Animator *ecore_animator_add(int (*func) (void *data), const void *data);
340    EAPI void           *ecore_animator_del(Ecore_Animator *animator);
341    EAPI void            ecore_animator_freeze(Ecore_Animator *animator);
342    EAPI void            ecore_animator_thaw(Ecore_Animator *animator);
343    EAPI void            ecore_animator_frametime_set(double frametime);
344    EAPI double          ecore_animator_frametime_get(void);
345
346    EAPI void          ecore_poller_poll_interval_set(Ecore_Poller_Type type, double poll_time);
347    EAPI double        ecore_poller_poll_interval_get(Ecore_Poller_Type type);
348    EAPI Ecore_Poller *ecore_poller_add(Ecore_Poller_Type type, int interval, int (*func) (void *data), const void *data);
349    EAPI void         *ecore_poller_del(Ecore_Poller *poller);
350
351    EAPI Ecore_Job *ecore_job_add(void (*func) (void *data), const void *data);
352    EAPI void      *ecore_job_del(Ecore_Job *job);
353
354 #ifdef __cplusplus
355 }
356 #endif
357 #endif