summaryrefslogtreecommitdiff
path: root/legacy/ecore/src/lib
diff options
context:
space:
mode:
authorCarsten Haitzler <raster@rasterman.com>2003-09-23 08:09:32 +0000
committerCarsten Haitzler <raster@rasterman.com>2003-09-23 08:09:32 +0000
commita5c2425084f670998654b7cf002d961dce963e82 (patch)
tree26bb48a4db414be854a6028c43364c23a02b4d3b /legacy/ecore/src/lib
parentcddaadb4477f3cc1b36d4f4fe68ba1f6abfa8a3d (diff)
damn you salizar! damn you!
errr. i mean. ecore moves to HEAD! SVN revision: 7475
Diffstat (limited to 'legacy/ecore/src/lib')
-rw-r--r--legacy/ecore/src/lib/Makefile.am9
-rw-r--r--legacy/ecore/src/lib/ecore/Ecore.h130
-rw-r--r--legacy/ecore/src/lib/ecore/Makefile.am24
-rw-r--r--legacy/ecore/src/lib/ecore/ecore.c117
-rw-r--r--legacy/ecore/src/lib/ecore/ecore_app.c83
-rw-r--r--legacy/ecore/src/lib/ecore/ecore_events.c551
-rw-r--r--legacy/ecore/src/lib/ecore/ecore_exe.c272
-rw-r--r--legacy/ecore/src/lib/ecore/ecore_idle_enterer.c116
-rw-r--r--legacy/ecore/src/lib/ecore/ecore_idler.c119
-rw-r--r--legacy/ecore/src/lib/ecore/ecore_list.c172
-rw-r--r--legacy/ecore/src/lib/ecore/ecore_main.c525
-rw-r--r--legacy/ecore/src/lib/ecore/ecore_private.h192
-rw-r--r--legacy/ecore/src/lib/ecore/ecore_signal.c276
-rw-r--r--legacy/ecore/src/lib/ecore/ecore_time.c22
-rw-r--r--legacy/ecore/src/lib/ecore/ecore_timer.c231
-rw-r--r--legacy/ecore/src/lib/ecore_con/Ecore_Con.h90
-rw-r--r--legacy/ecore/src/lib/ecore_con/Makefile.am30
-rw-r--r--legacy/ecore/src/lib/ecore_con/ecore_con.c957
-rw-r--r--legacy/ecore/src/lib/ecore_con/ecore_con_private.h51
-rw-r--r--legacy/ecore/src/lib/ecore_evas/Ecore_Evas.h107
-rw-r--r--legacy/ecore/src/lib/ecore_evas/Makefile.am65
-rw-r--r--legacy/ecore/src/lib/ecore_evas/ecore_evas.c1457
-rw-r--r--legacy/ecore/src/lib/ecore_evas/ecore_evas_fb.c507
-rw-r--r--legacy/ecore/src/lib/ecore_evas/ecore_evas_private.h164
-rw-r--r--legacy/ecore/src/lib/ecore_evas/ecore_evas_x.c1226
-rw-r--r--legacy/ecore/src/lib/ecore_fb/Ecore_Fb.h90
-rw-r--r--legacy/ecore/src/lib/ecore_fb/Makefile.am30
-rw-r--r--legacy/ecore/src/lib/ecore_fb/ecore_fb.c1330
-rw-r--r--legacy/ecore/src/lib/ecore_fb/ecore_fb_private.h30
-rw-r--r--legacy/ecore/src/lib/ecore_ipc/Ecore_Ipc.h105
-rw-r--r--legacy/ecore/src/lib/ecore_ipc/Makefile.am34
-rw-r--r--legacy/ecore/src/lib/ecore_ipc/ecore_ipc.c790
-rw-r--r--legacy/ecore/src/lib/ecore_ipc/ecore_ipc_private.h31
-rw-r--r--legacy/ecore/src/lib/ecore_job/Ecore_Job.h19
-rw-r--r--legacy/ecore/src/lib/ecore_job/Makefile.am30
-rw-r--r--legacy/ecore/src/lib/ecore_job/ecore_job.c91
-rw-r--r--legacy/ecore/src/lib/ecore_job/ecore_job_private.h16
-rw-r--r--legacy/ecore/src/lib/ecore_x/Ecore_X.h535
-rw-r--r--legacy/ecore/src/lib/ecore_x/Makefile.am51
-rw-r--r--legacy/ecore/src/lib/ecore_x/ecore_x.c790
-rw-r--r--legacy/ecore/src/lib/ecore_x/ecore_x_error.c92
-rw-r--r--legacy/ecore/src/lib/ecore_x/ecore_x_events.c801
-rw-r--r--legacy/ecore/src/lib/ecore_x/ecore_x_gc.c30
-rw-r--r--legacy/ecore/src/lib/ecore_x/ecore_x_pixmap.c43
-rw-r--r--legacy/ecore/src/lib/ecore_x/ecore_x_private.h81
-rw-r--r--legacy/ecore/src/lib/ecore_x/ecore_x_window.c339
-rw-r--r--legacy/ecore/src/lib/ecore_x/ecore_x_window_prop.c370
-rw-r--r--legacy/ecore/src/lib/ecore_x/ecore_x_window_shape.c15
48 files changed, 13236 insertions, 0 deletions
diff --git a/legacy/ecore/src/lib/Makefile.am b/legacy/ecore/src/lib/Makefile.am
new file mode 100644
index 0000000000..cd9919f1d4
--- /dev/null
+++ b/legacy/ecore/src/lib/Makefile.am
@@ -0,0 +1,9 @@
1## Process this file with automake to produce Makefile.in
2SUBDIRS = \
3ecore \
4ecore_job \
5ecore_x \
6ecore_fb \
7ecore_evas \
8ecore_con \
9ecore_ipc
diff --git a/legacy/ecore/src/lib/ecore/Ecore.h b/legacy/ecore/src/lib/ecore/Ecore.h
new file mode 100644
index 0000000000..cd4b330aeb
--- /dev/null
+++ b/legacy/ecore/src/lib/ecore/Ecore.h
@@ -0,0 +1,130 @@
1#ifndef _ECORE_H
2#define _ECORE_H
3
4#include <sys/types.h>
5#include <unistd.h>
6#include <stdio.h>
7#include <stdlib.h>
8#include <string.h>
9
10#ifdef __cplusplus
11extern "C" {
12#endif
13
14#define ECORE_EVENT_NONE 0
15#define ECORE_EVENT_EXE_EXIT 1 /**< Spawned Exe has exit event */
16#define ECORE_EVENT_SIGNAL_USER 2 /**< User signal event */
17#define ECORE_EVENT_SIGNAL_HUP 3 /**< Hup signal event */
18#define ECORE_EVENT_SIGNAL_EXIT 4 /**< Exit signal event */
19#define ECORE_EVENT_SIGNAL_POWER 5 /**< Power signal event */
20#define ECORE_EVENT_COUNT 6
21
22#ifndef _ECORE_PRIVATE_H
23 enum _Ecore_Fd_Handler_Flags
24 {
25 ECORE_FD_READ = 1, /**< Fd Read mask */
26 ECORE_FD_WRITE = 2 /**< Fd Write mask */
27 };
28 typedef enum _Ecore_Fd_Handler_Flags Ecore_Fd_Handler_Flags;
29
30 typedef void Ecore_Exe; /**< A handle for spawned processes */
31 typedef void Ecore_Timer; /**< A handle for timers */
32 typedef void Ecore_Idler; /**< A handle for idlers */
33 typedef void Ecore_Idle_Enterer; /**< A handle for idle enterers */
34 typedef void Ecore_Fd_Handler; /**< A handle for Fd hanlders */
35 typedef void Ecore_Event_Handler; /**< A handle for an event handler */
36 typedef void Ecore_Event_Filter; /**< A handle for an event filter */
37 typedef void Ecore_Event; /**< A handle for an event */
38#endif
39 typedef struct _Ecore_Event_Exe_Exit Ecore_Event_Exe_Exit; /**< Spawned Exe exit event */
40 typedef struct _Ecore_Event_Signal_User Ecore_Event_Signal_User; /**< User signal event */
41 typedef struct _Ecore_Event_Signal_Hup Ecore_Event_Signal_Hup; /**< Hup signal event */
42 typedef struct _Ecore_Event_Signal_Exit Ecore_Event_Signal_Exit; /**< Exit signal event */
43 typedef struct _Ecore_Event_Signal_Power Ecore_Event_Signal_Power; /**< Power signal event */
44
45 struct _Ecore_Event_Exe_Exit /** Process exit event */
46 {
47 pid_t pid; /**< The process ID of the process that exited */
48 int exit_code; /**< The exit code of the process */
49 Ecore_Exe *exe; /**< The handle to the exited process, or NULL if not found */
50 void *ext_data; /**< Extension data - not used */
51 };
52
53 struct _Ecore_Event_Signal_User /** User signal event */
54 {
55 int number; /**< The signal number. Either 1 or 2 */
56 void *ext_data; /**< Extension data - not used */
57 };
58
59 struct _Ecore_Event_Signal_Hup /** Hup signal event */
60 {
61 void *ext_data; /**< Extension data - not used */
62 };
63
64 struct _Ecore_Event_Signal_Exit /** Exit request event */
65 {
66 int interrupt : 1; /**< Set if the exit request was an interrupt signal*/
67 int quit : 1; /**< set if the exit request was a quit signal */
68 int terminate : 1; /**< Set if the exit request was a terminate singal */
69 void *ext_data; /**< Extension data - not used */
70 };
71
72 struct _Ecore_Event_Signal_Power /** Power event */
73 {
74 void *ext_data; /**< Extension data - not used */
75 };
76
77 int ecore_init(void);
78 void ecore_shutdown(void);
79
80 void ecore_app_args_set(int argc, const char **argv);
81 void ecore_app_args_get(int *argc, char ***argv);
82 void ecore_app_restart(void);
83
84 Ecore_Event_Handler *ecore_event_handler_add(int type, int (*func) (void *data, int type, void *event), const void *data);
85 void *ecore_event_handler_del(Ecore_Event_Handler *event_handler);
86 Ecore_Event *ecore_event_add(int type, void *ev, void (*func_free) (void *data, void *ev), void *data);
87 void *ecore_event_del(Ecore_Event *event);
88 int ecore_event_type_new(void);
89 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);
90 void *ecore_event_filter_del(Ecore_Event_Filter *ef);
91 int ecore_event_current_type_get(void);
92 void *ecore_event_current_event_get(void);
93
94
95
96 Ecore_Exe *ecore_exe_run(const char *exe_cmd, const void *data);
97 void *ecore_exe_free(Ecore_Exe *exe);
98 pid_t ecore_exe_pid_get(Ecore_Exe *exe);
99 void *ecore_exe_data_get(Ecore_Exe *exe);
100 void ecore_exe_pause(Ecore_Exe *exe);
101 void ecore_exe_continue(Ecore_Exe *exe);
102 void ecore_exe_terminate(Ecore_Exe *exe);
103 void ecore_exe_kill(Ecore_Exe *exe);
104 void ecore_exe_signal(Ecore_Exe *exe, int num);
105 void ecore_exe_hup(Ecore_Exe *exe);
106
107 Ecore_Idler *ecore_idler_add(int (*func) (void *data), const void *data);
108 void *ecore_idler_del(Ecore_Idler *idler);
109
110 Ecore_Idle_Enterer *ecore_idle_enterer_add(int (*func) (void *data), const void *data);
111 void *ecore_idle_enterer_del(Ecore_Idle_Enterer *idle_enterer);
112
113 void ecore_main_loop_iterate(void);
114 void ecore_main_loop_begin(void);
115 void ecore_main_loop_quit(void);
116 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);
117 void *ecore_main_fd_handler_del(Ecore_Fd_Handler *fd_handler);
118 int ecore_main_fd_handler_fd_get(Ecore_Fd_Handler *fd_handler);
119 int ecore_main_fd_handler_active_get(Ecore_Fd_Handler *fd_handler, Ecore_Fd_Handler_Flags flags);
120 void ecore_main_fd_handler_active_set(Ecore_Fd_Handler *fd_handler, Ecore_Fd_Handler_Flags flags);
121
122 double ecore_time_get(void);
123
124 Ecore_Timer *ecore_timer_add(double in, int (*func) (void *data), const void *data);
125 void *ecore_timer_del(Ecore_Timer *timer);
126
127#ifdef __cplusplus
128}
129#endif
130#endif
diff --git a/legacy/ecore/src/lib/ecore/Makefile.am b/legacy/ecore/src/lib/ecore/Makefile.am
new file mode 100644
index 0000000000..ac23bb588a
--- /dev/null
+++ b/legacy/ecore/src/lib/ecore/Makefile.am
@@ -0,0 +1,24 @@
1## Process this file with automake to produce Makefile.in
2
3INCLUDES =
4
5lib_LTLIBRARIES = libecore.la
6include_HEADERS = \
7Ecore.h
8
9libecore_la_SOURCES = \
10ecore.c \
11ecore_app.c \
12ecore_events.c \
13ecore_exe.c \
14ecore_idle_enterer.c \
15ecore_idler.c \
16ecore_list.c \
17ecore_main.c \
18ecore_signal.c \
19ecore_time.c \
20ecore_timer.c \
21ecore_private.h
22
23libecore_la_LIBADD =
24libecore_la_LDFLAGS = -version-info 1:0:0
diff --git a/legacy/ecore/src/lib/ecore/ecore.c b/legacy/ecore/src/lib/ecore/ecore.c
new file mode 100644
index 0000000000..0bf5421a27
--- /dev/null
+++ b/legacy/ecore/src/lib/ecore/ecore.c
@@ -0,0 +1,117 @@
1#include "ecore_private.h"
2#include "Ecore.h"
3
4static const char *_ecore_magic_string_get(Ecore_Magic m);
5
6/**
7 * Set up connections, signal handlers, sockets etc.
8 * @return 1 or greater on success, 0 otherwise
9 *
10 * This function sets up all singal handlers and the basic event loop. If it
11 * succeeds, 1 will be returned, otherwise 0 will be returned.
12 *
13 * @code
14 * #include <Ecore.h>
15 *
16 * int main(int argc, char **argv)
17 * {
18 * if (!ecore_init())
19 * {
20 * printf("ERROR: Cannot init Ecore!\n");
21 * return -1;
22 * }
23 * ecore_main_loop_begin();
24 * ecore_shutdown();
25 * }
26 * @endcode
27 * <hr><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
28 */
29int
30ecore_init(void)
31{
32 _ecore_signal_init();
33 return 1;
34}
35
36/**
37 * Shut down connections, signal handlers sockets etc.
38 *
39 * This function shuts down all things set up in ecore_init() and cleans up all
40 * event queues, handlers, filters, timers, idlers, idle enterers etc. set up
41 * after ecore_init() was called.
42 *
43 * Do not call this function from any callback that may be called from the main
44 * loop, as the main loop will then fall over and not function properly.
45 * <hr><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
46*/
47void
48ecore_shutdown(void)
49{
50 _ecore_exe_shutdown();
51 _ecore_idle_enterer_shutdown();
52 _ecore_idler_shutdown();
53 _ecore_timer_shutdown();
54 _ecore_event_shutdown();
55 _ecore_main_shutdown();
56 _ecore_signal_shutdown();
57}
58
59void
60_ecore_magic_fail(void *d, Ecore_Magic m, Ecore_Magic req_m, const char *fname)
61{
62 fprintf(stderr,
63 "\n"
64 "*** ECORE ERROR: Ecore Magic Check Failed!!!\n"
65 "*** IN FUNCTION: %s()\n", fname);
66 if (!d)
67 fprintf(stderr, " Input handle pointer is NULL!\n");
68 else if (m == ECORE_MAGIC_NONE)
69 fprintf(stderr, " Input handle has already been freed!\n");
70 else if (m != req_m)
71 fprintf(stderr, " Input handle is wrong type\n"
72 " Expected: %08x - %s\n"
73 " Supplied: %08x - %s\n",
74 (unsigned int)req_m, _ecore_magic_string_get(req_m),
75 (unsigned int)m, _ecore_magic_string_get(m));
76 fprintf(stderr,
77 "*** NAUGHTY PROGRAMMER!!!\n"
78 "*** SPANK SPANK SPANK!!!\n"
79 "*** Now go fix your code. Tut tut tut!\n"
80 "\n");
81 if (getenv("ECORE_ERROR_ABORT")) abort();
82}
83
84static const char *
85_ecore_magic_string_get(Ecore_Magic m)
86{
87 switch (m)
88 {
89 case ECORE_MAGIC_NONE:
90 return "None (Freed Object)";
91 break;
92 case ECORE_MAGIC_EXE:
93 return "Ecore_Exe (Executable)";
94 break;
95 case ECORE_MAGIC_TIMER:
96 return "Ecore_Timer (Timer)";
97 break;
98 case ECORE_MAGIC_IDLER:
99 return "Ecore_Idler (Idler)";
100 break;
101 case ECORE_MAGIC_IDLE_ENTERER:
102 return "Ecore_Idle_Enterer (Idler Enterer)";
103 break;
104 case ECORE_MAGIC_FD_HANDLER:
105 return "Ecore_Fd_Handler (Fd Handler)";
106 break;
107 case ECORE_MAGIC_EVENT_HANDLER:
108 return "Ecore_Event_Handler (Event Handler)";
109 break;
110 case ECORE_MAGIC_EVENT:
111 return "Ecore_Event (Event)";
112 break;
113 default:
114 return "<UNKNOWN>";
115 };
116 return "<UNKNOWN>";
117}
diff --git a/legacy/ecore/src/lib/ecore/ecore_app.c b/legacy/ecore/src/lib/ecore/ecore_app.c
new file mode 100644
index 0000000000..a41f731655
--- /dev/null
+++ b/legacy/ecore/src/lib/ecore/ecore_app.c
@@ -0,0 +1,83 @@
1#include "ecore_private.h"
2#include "Ecore.h"
3
4static int app_argc = 0;
5static char **app_argv = NULL;
6
7/**
8 * Set up the programs command-line arguments.
9 * @param argc The same as passed as argc to the programs main() function
10 * @param argv The same as passed as argv to the programs main() function
11 *
12 * A call to this function will store the programs command-line arguments
13 * for later use by ecore_app_restart() or ecore_app_args_get().
14 *
15 * @code
16 * #include <Ecore.h>
17 *
18 * int timer_once(void *data)
19 * {
20 * int argc;
21 * char **argv;
22 * int i;
23 *
24 * ecore_app_args_get(&argc, &argv);
25 * for (i = 0; i < argc; i++) printf("ARG %i: %s\n", i, argv[i]);
26 * return 0;
27 * }
28 *
29 * int main(int argc, char **argv)
30 * {
31 * ecore_init();
32 * ecore_app_args_set(argc, argv);
33 * ecore_timer_add(5.0, timer_once, NULL);
34 * ecore_main_loop_begin();
35 * ecore_shutdown();
36 * }
37 * @endcode
38 * <hr><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
39 */
40void
41ecore_app_args_set(int argc, const char **argv)
42{
43 if ((argc < 1) ||
44 (!argv)) return;
45 app_argc = argc;
46 app_argv = (char **)argv;
47}
48
49/**
50 * Return the programs stored command-line arguments.
51 * @param argc A pointer to the return value to hold argc
52 * @param argv A pointer to the return value to hold argv
53 *
54 * When called, this funciton returns the arguments for the program stored by
55 * ecore_app_args_set(). The integer pointed to by @p argc will be filled, if
56 * the pointer is not NULL, and the string array pointer @p argv will be filled
57 * also if the pointer is not NULL. The values they are filled with will be the
58 * same set by ecore_app_args_set().
59 * <hr><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
60 */
61void
62ecore_app_args_get(int *argc, char ***argv)
63{
64 if (argc) *argc = app_argc;
65 if (argv) *argv = app_argv;
66}
67
68/**
69 * Restart the program executable with the command-line arguments stored.
70 *
71 * This function will restart & re-execute this program in place of itself
72 * using the command-line arguments stored by ecore_app_args_set(). This is
73 * an easy way for a program to restart itself for cleanup purposes,
74 * configuration reasons or in the event of a crash.
75 *
76 * FIXME: Currently not implimented.
77 * <hr><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
78 */
79void
80ecore_app_restart(void)
81{
82 /* FIXME: exec self using argv, argc etc. */
83}
diff --git a/legacy/ecore/src/lib/ecore/ecore_events.c b/legacy/ecore/src/lib/ecore/ecore_events.c
new file mode 100644
index 0000000000..e89306a276
--- /dev/null
+++ b/legacy/ecore/src/lib/ecore/ecore_events.c
@@ -0,0 +1,551 @@
1#include "ecore_private.h"
2#include "Ecore.h"
3
4static int events_num = 0;
5static Ecore_Event *events = NULL;
6
7static Ecore_Event_Handler *event_handlers = NULL;
8static int event_handlers_delete_me = 0;
9
10static Ecore_Event_Filter *event_filters = NULL;
11static int event_filters_delete_me = 0;
12
13static int event_id_max = ECORE_EVENT_COUNT;
14
15static int ecore_raw_event_type = ECORE_EVENT_NONE;
16static void *ecore_raw_event_event = NULL;
17
18
19/**
20 * Add an event handler.
21 * @param type The type of the event this handler will get called for
22 * @param func The function to call when the event is found in the queue
23 * @param data A data pointer to pass to the called function @p func
24 * @return A new Event handler, or NULL on failure
25 *
26 * Add an event handler to the list of handlers. This will, on success, return
27 * a handle to the event handler object that was created, that can be used
28 * later to remove the handler using ecore_event_handler_del(). The @p type
29 * parameter is the iteger of the event type that will trigger this callback
30 * to be called. The callback @p func is called when this event is processed
31 * and will be passed the event type, a pointer to the private event
32 * structure that is specific to that event type, and a data pointer that is
33 * provided in this call as the @p data parameter.
34 *
35 * When the callback @p func is called, it must return 1 or 0. If it returns
36 * 1, It will keep being called as per normal, when events come into the event
37 * queue. If it returns 0, it will be removed from the list of event handlers
38 * and be destroyed. If this happens the event handler object returned is no
39 * longer valid, and the handler will not be called again after it returns 0.
40 *
41 * @code
42 * #include <Ecore.h>
43 *
44 * Ecore_Event_Handler *handler1 = NULL, *handler2 = NULL;
45 *
46 * int event_hup(void *data, int ev_type, void *ev)
47 * {
48 * printf("Hup signal! Remove the exit handler.\n");
49 * ecore_event_handler_del(handler1);
50 * return 0;
51 * }
52 *
53 * int event_exit(void *data, int ev_type, void *ev)
54 * {
55 * Ecore_Event_Signal_Exit *e;
56 *
57 * e = (Ecore_Event_Signal_Exit *)ev;
58 * printf("This callback handles event type: %i\n", ECORE_EVENT_SIGNAL_EXIT);
59 * printf("Event type recieved: %i\n", ev_type);
60 * if (e->interrupt) printf("Exit: interrupt\n");
61 * if (e->quit) printf("Exit: quit\n");
62 * if (e->terminate) printf("Exit: terminate\n");
63 * ecore_main_loop_quit();
64 * return 1;
65 * }
66 *
67 * int main(int argc, char **argv)
68 * {
69 * ecore_init();
70 * ecore_app_args_set(argc, argv);
71 * handler1 = ecore_event_handler_add(ECORE_EVENT_SIGNAL_EXIT,
72 * event_exit, NULL);
73 * handler2 = ecore_event_handler_add(ECORE_EVENT_SIGNAL_HUP,
74 * event_hup, NULL);
75 * ecore_main_loop_begin();
76 * ecore_shutdown();
77 * }
78 * @endcode
79 * <hr><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
80 */
81Ecore_Event_Handler *
82ecore_event_handler_add(int type, int (*func) (void *data, int type, void *event), const void *data)
83{
84 Ecore_Event_Handler *eh;
85
86 if (!func) return NULL;
87 if ((type <= ECORE_EVENT_NONE) || (type >= event_id_max)) return NULL;
88 eh = calloc(1, sizeof(Ecore_Event_Handler));
89 if (!eh) return NULL;
90 ECORE_MAGIC_SET(eh, ECORE_MAGIC_EVENT_HANDLER);
91 eh->type = type;
92 eh->func = func;
93 eh->data = (void *)data;
94 event_handlers = _ecore_list_append(event_handlers, eh);
95 return eh;
96}
97
98/**
99 * Delete an event handler.
100 * @param event_handler Event handler handle to delete
101 * @return Data passed to handler
102 *
103 * Delete a specified event handler from the handler list. On success this will
104 * delete the event handler and return the pointer passed as @p data when the
105 * handler was added by ecore_event_handler_add(). On failure NULL will be
106 * returned. Once a handler is deleted it will no longer be called.
107 * <hr><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
108 */
109void *
110ecore_event_handler_del(Ecore_Event_Handler *event_handler)
111{
112 if (!ECORE_MAGIC_CHECK(event_handler, ECORE_MAGIC_EVENT_HANDLER))
113 {
114 ECORE_MAGIC_FAIL(event_handler, ECORE_MAGIC_EVENT_HANDLER,
115 "ecore_event_handler_del");
116 return NULL;
117 }
118 event_handler->delete_me = 1;
119 event_handlers_delete_me = 1;
120 return event_handler->data;
121}
122
123/**
124 * Add an event to the event queue.
125 * @param type The event type to add to the end of the event queue
126 * @param ev The private data structure for this event type
127 * @param func_free The function to be called to free this private structure
128 * @param data The data pointer to be passed to the free function
129 * @return A Handle for that event
130 *
131 * On success this function returns a handle to an event on the event queue, or
132 * NULL if it fails. If it succeeds, an event of type @p type will be added
133 * to the queue for processing by event handlers added by
134 * ecore_event_handler_add(). The @p ev parameter will be a pointer to the event
135 * private data that is specific to that event type. When the event is no
136 * longer needed, @p func_free will be called and passed the private sructure
137 * pointer for cleaning up. If @p func_free is NULL, nothnig will be called.
138 * This function is passed @p data as its data parameter.
139 * <hr><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
140 */
141Ecore_Event *
142ecore_event_add(int type, void *ev, void (*func_free) (void *data, void *ev), void *data)
143{
144 if (!func_free) return NULL;
145 if (!ev) return NULL;
146 if (type <= ECORE_EVENT_NONE) return NULL;
147 if (type >= event_id_max) return NULL;
148 return _ecore_event_add(type, ev, func_free, data);
149}
150
151/**
152 * Delete an event from the queue.
153 * @param event The event handle to delete
154 * @return The data pointer originally set for the event free function
155 *
156 * This deletes the event @p event from the event queue, and returns the
157 * @p data parameer originally set when adding it with ecore_event_add(). This
158 * does not immediately call the free function, and it may be called later on
159 * cleanup, and so if the free function depends on the data pointer to work,
160 * you should defer cleaning of this till the free function is called later.
161 * <hr><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
162 */
163void *
164ecore_event_del(Ecore_Event *event)
165{
166 if (!ECORE_MAGIC_CHECK(event, ECORE_MAGIC_EVENT))
167 {
168 ECORE_MAGIC_FAIL(event, ECORE_MAGIC_EVENT,
169 "ecore_event_del");
170 return NULL;
171 }
172 event->delete_me = 1;
173 return event->data;
174}
175
176/**
177 * Allocate a new event type id sensibly and return the new id.
178 * @return A new event type id.
179 *
180 * This function allocates a new event type id and returns it. Once an event
181 * type has been allocated it can never be de-allocated during the life of
182 * the program. There is no guarantee of the contents of this event ID, or how
183 * it is calculated, except that the ID will be unique to the current instance
184 * of the process.
185 * <hr><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
186 */
187int
188ecore_event_type_new(void)
189{
190 event_id_max++;
191 return event_id_max - 1;
192}
193
194/**
195 * Add a filter the current event queue.
196 * @param func_start Function to call just before filtering and return data
197 * @param func_filter Function to call on each event
198 * @param func_end Function to call after the queu has been filtered
199 * @param data Data to pass to the filter functions
200 * @return A filter handle
201 *
202 * This adds a filter to call callbacks to loop through the event queue and
203 * filter events out of the queue. On failure NULL is returned. On success a
204 * Filter handle is returned. Filters are called on the queue just before
205 * Event handler processing to try and remove redundant events. Just as
206 * processing starts @p func_start is called and passed the @p data pointer.
207 * This function returns a pointer that is used as loop_data that is now passed to
208 * @p func_filter as loop_data. @p func_filter is also passed @p data and the
209 * event type and private event structure. If this callback returns 0, the
210 * event is removed from the queue. If it returns 1, the event is kept. When
211 * processing is finished @p func_end is called and is passed the loop_data
212 * and @p data pointer to clean up.
213 * <hr><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
214 */
215Ecore_Event_Filter *
216ecore_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)
217{
218 Ecore_Event_Filter *ef;
219
220 if (!func_filter) return NULL;
221 ef = calloc(1, sizeof(Ecore_Event_Filter));
222 if (!ef) return NULL;
223 ECORE_MAGIC_SET(ef, ECORE_MAGIC_EVENT_FILTER);
224 ef->func_start = func_start;
225 ef->func_filter = func_filter;
226 ef->func_end = func_end;
227 ef->data = (void *)data;
228 event_filters = _ecore_list_append(event_filters, ef);
229 return ef;
230}
231
232/**
233 * Delete an event filter.
234 * @param ef The event filter handle
235 * @return The data set for the filter
236 *
237 * Delete a filter that has been added by its @p ef handle. On success this
238 * will return the data pointer set when this filter was added. On failure
239 * NULL is returned.
240 * <hr><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
241 */
242void *
243ecore_event_filter_del(Ecore_Event_Filter *ef)
244{
245 if (!ECORE_MAGIC_CHECK(ef, ECORE_MAGIC_EVENT_FILTER))
246 {
247 ECORE_MAGIC_FAIL(ef, ECORE_MAGIC_EVENT_FILTER,
248 "ecore_event_filter_del");
249 return NULL;
250 }
251 ef->delete_me = 1;
252 event_filters_delete_me = 1;
253 return ef->data;
254}
255
256/**
257 * Return the current event type being handled.
258 * @return The current event type being handled if inside a handler callback
259 *
260 * If the program is currently inside an Ecore event handler callback this
261 * will return the type of the current event being processed. If Ecore is
262 * not inside an event handler, ECORE_EVENT_NONE is returned.
263 *
264 * This is useful when certain Ecore modules such as Ecore_Evas "swallow"
265 * events and not all the original information is passed on. In special cases
266 * this extra information may be useful or needed and using this call can let
267 * the program know if the event type being handled is one it wants to get more
268 * information about.
269 * <hr><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
270 */
271int
272ecore_event_current_type_get(void)
273{
274 return ecore_raw_event_type;
275}
276
277/**
278 * Return the current event type pointer handled.
279 * @return The current event pointer being handled if inside a handler callback
280 *
281 * If the program is currently inside an Ecore event handler callback this
282 * will return the pointer of the current event being processed. If Ecore is
283 * not inside an event handler, NULL will be returned.
284 *
285 * This is useful when certain Ecore modules such as Ecore_Evas "swallow"
286 * events and not all the original information is passed on. In special cases
287 * this extra information may be useful or needed and using this call can let
288 * the program access the event data if the type of the event is handled by
289 * the program.
290 * <hr><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
291 */
292void *
293ecore_event_current_event_get(void)
294{
295 return ecore_raw_event_event;
296}
297
298void
299_ecore_event_shutdown(void)
300{
301 while (events) _ecore_event_del(events);
302 while (event_handlers)
303 {
304 Ecore_Event_Handler *eh;
305
306 eh = event_handlers;
307 event_handlers = _ecore_list_remove(event_handlers, eh);
308 ECORE_MAGIC_SET(eh, ECORE_MAGIC_NONE);
309 free(eh);
310 }
311 event_handlers_delete_me = 0;
312 while (event_filters)
313 {
314 Ecore_Event_Filter *ef;
315
316 ef = event_filters;
317 event_filters = _ecore_list_remove(event_filters, ef);
318 ECORE_MAGIC_SET(ef, ECORE_MAGIC_NONE);
319 free(ef);
320 }
321 event_filters_delete_me = 0;
322}
323
324int
325_ecore_event_exist(void)
326{
327 if (events) return 1;
328 return 0;
329}
330
331Ecore_Event *
332_ecore_event_add(int type, void *ev, void (*func_free) (void *data, void *ev), void *data)
333{
334 Ecore_Event *e;
335
336 e = calloc(1, sizeof(Ecore_Event));
337 if (!e) return NULL;
338 ECORE_MAGIC_SET(e, ECORE_MAGIC_EVENT);
339 e->type = type;
340 e->event = ev;
341 e->func_free = func_free;
342 e->data = data;
343 events = _ecore_list_append(events, e);
344 events_num++;
345 return e;
346}
347
348void *
349_ecore_event_del(Ecore_Event *event)
350{
351 void *data;
352
353 data = event->data;
354 event->func_free(event->data, event->event);
355 events = _ecore_list_remove(events, event);
356 ECORE_MAGIC_SET(event, ECORE_MAGIC_NONE);
357 free(event);
358 events_num--;
359 return data;
360}
361
362static void
363_ecore_event_filter_del(Ecore_Event_Filter *ef)
364{
365 ECORE_MAGIC_SET(ef, ECORE_MAGIC_NONE);
366 event_filters = _ecore_list_remove(event_filters, ef);
367 free(ef);
368}
369
370void
371_ecore_event_call(void)
372{
373 Ecore_List *l;
374
375 for (l = (Ecore_List *)event_filters; l; l = l->next)
376 {
377 Ecore_Event_Filter *ef;
378
379 ef = (Ecore_Event_Filter *)l;
380 if (!ef->delete_me)
381 {
382 Ecore_List *ll;
383
384 if (ef->func_start)
385 ef->loop_data = ef->func_start(ef->data);
386 for (ll = (Ecore_List *)events; ll; ll = ll->next)
387 {
388 Ecore_Event *e;
389
390 e = (Ecore_Event *)ll;
391 if (!ef->func_filter(ef->loop_data, ef->data,
392 e->type, e->event))
393 ecore_event_del(e);
394 }
395 if (ef->func_end)
396 ef->func_end(ef->data, ef->loop_data);
397 }
398 }
399 if (event_filters_delete_me)
400 {
401 for (l = (Ecore_List *)event_filters; l; l = l->next)
402 {
403 Ecore_Event_Filter *ef;
404
405 ef = (Ecore_Event_Filter *)l;
406 l = l->next;
407 if (ef->delete_me)
408 {
409 event_filters = _ecore_list_remove(event_filters, ef);
410 ECORE_MAGIC_SET(ef, ECORE_MAGIC_NONE);
411 free(ef);
412 }
413 }
414 event_filters_delete_me = 0;
415 }
416 for (l = (Ecore_List *)events; l; l = l->next)
417 {
418 Ecore_List *ll;
419 Ecore_Event *e;
420
421 e = (Ecore_Event *)l;
422 if (!e->delete_me)
423 {
424 ecore_raw_event_type = e->type;
425 ecore_raw_event_event = e->event;
426 for (ll = (Ecore_List *)event_handlers; ll; ll = ll->next)
427 {
428 Ecore_Event_Handler *eh;
429
430 eh = (Ecore_Event_Handler *)ll;
431 if (!eh->delete_me)
432 {
433 if (eh->type == e->type)
434 {
435 if (!eh->func(eh->data, e->type, e->event))
436 break;
437 }
438 }
439 }
440 ecore_raw_event_type = ECORE_EVENT_NONE;
441 ecore_raw_event_event = NULL;
442 }
443 }
444 while (events) _ecore_event_del(events);
445 if (!event_handlers_delete_me) return;
446 for (l = (Ecore_List *)event_handlers; l;)
447 {
448 Ecore_Event_Handler *eh;
449
450 eh = (Ecore_Event_Handler *)l;
451 l = l->next;
452 if (eh->delete_me)
453 {
454 event_handlers = _ecore_list_remove(event_handlers, eh);
455 ECORE_MAGIC_SET(eh, ECORE_MAGIC_NONE);
456 free(eh);
457 }
458 }
459 event_handlers_delete_me = 0;
460}
461
462void *
463_ecore_event_exe_exit_new(void)
464{
465 Ecore_Event_Exe_Exit *e;
466
467 e = calloc(1, sizeof(Ecore_Event_Exe_Exit));
468 return e;
469}
470
471void
472_ecore_event_exe_exit_free(void *data, void *ev)
473{
474 Ecore_Event_Exe_Exit *e;
475
476 e = ev;
477 if (e->exe) _ecore_exe_free(e->exe);
478 free(e);
479}
480
481void *
482_ecore_event_signal_user_new(void)
483{
484 Ecore_Event_Signal_User *e;
485
486 e = calloc(1, sizeof(Ecore_Event_Signal_User));
487 return e;
488}
489
490void
491_ecore_event_signal_user_free(void *data, void *ev)
492{
493 Ecore_Event_Signal_User *e;
494
495 e = ev;
496 free(e);
497}
498
499void *
500_ecore_event_signal_hup_new(void)
501{
502 Ecore_Event_Signal_Hup *e;
503
504 e = calloc(1, sizeof(Ecore_Event_Signal_Hup));
505 return e;
506}
507
508void
509_ecore_event_signal_hup_free(void *data, void *ev)
510{
511 Ecore_Event_Signal_Hup *e;
512
513 e = ev;
514 free(e);
515}
516
517void *
518_ecore_event_signal_exit_new(void)
519{
520 Ecore_Event_Signal_Exit *e;
521
522 e = calloc(1, sizeof(Ecore_Event_Signal_Exit));
523 return e;
524}
525
526void
527_ecore_event_signal_exit_free(void *data, void *ev)
528{
529 Ecore_Event_Signal_Exit *e;
530
531 e = ev;
532 free(e);
533}
534
535void *
536_ecore_event_signal_power_new(void)
537{
538 Ecore_Event_Signal_Power *e;
539
540 e = calloc(1, sizeof(Ecore_Event_Signal_Power));
541 return e;
542}
543
544void
545_ecore_event_signal_power_free(void *data, void *ev)
546{
547 Ecore_Event_Signal_Power *e;
548
549 e = ev;
550 free(e);
551}
diff --git a/legacy/ecore/src/lib/ecore/ecore_exe.c b/legacy/ecore/src/lib/ecore/ecore_exe.c
new file mode 100644
index 0000000000..2fb9aba7cd
--- /dev/null
+++ b/legacy/ecore/src/lib/ecore/ecore_exe.c
@@ -0,0 +1,272 @@
1#include "ecore_private.h"
2#include "Ecore.h"
3
4#include <sys/types.h>
5#include <signal.h>
6#include <unistd.h>
7
8static Ecore_Exe *exes = NULL;
9
10/**
11 * Spawn off a child process and return a handle to that process.
12 * @param exe_cmd The command-line to run as if typed in a shell
13 * @param data A generic data pointer to attach to the process handle
14 * @return A process handle to the spawned off process
15 *
16 * This function will fork and execute the command line @p exe_cmd as specified
17 * using the system shell (/bin/sh). The data pointer @p data is attached to
18 * the process handle returned. The application does not need to free or keep
19 * the process handle returned unless it has a use for it. It should be noted
20 * that the process handle is only valid until a child process terminated
21 * event is recieved. After all handlers for this child process terminated
22 * event have been called, this process handle will be freed and cleaned up
23 * by Ecore, and so any references to it will become invalid.
24 * <hr><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
25 */
26Ecore_Exe *
27ecore_exe_run(const char *exe_cmd, const void *data)
28{
29 Ecore_Exe *exe;
30 pid_t pid;
31
32 if (!exe_cmd) return NULL;
33 pid = fork();
34 if (pid)
35 {
36 exe = calloc(1, sizeof(Ecore_Exe));
37 if (!exe)
38 {
39 kill(pid, SIGKILL);
40 return NULL;
41 }
42 ECORE_MAGIC_SET(exe, ECORE_MAGIC_EXE);
43 exe->pid = pid;
44 exe->data = (void *)data;
45 exes = _ecore_list_append(exes, exe);
46 return exe;
47 }
48 setsid();
49 execl("/bin/sh", "/bin/sh", "-c", exe_cmd, NULL);
50 exit(0);
51 return NULL;
52}
53
54/**
55 * Free an exe handle.
56 * @param exe
57 * @return The data pointer set on execution of the program
58 *
59 * This frees an exe handle (but does not affect the process that was spawned
60 * that this handle was a result of) and returns the data pointer set on
61 * executable start. This does mean there is no handle for the spawned
62 * process anymore.
63 * <hr><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
64 */
65void *
66ecore_exe_free(Ecore_Exe *exe)
67{
68 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
69 {
70 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE,
71 "ecore_exe_free");
72 return NULL;
73 }
74 return _ecore_exe_free(exe);
75}
76
77/**
78 * Get the process ID of a spawned process.
79 * @param exe The process handle returned by ecore_exe_run()
80 * @return A system process ID of the process handle
81 *
82 * This function returns the system process ID of a spawned off child process.
83 * <hr><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
84 */
85pid_t
86ecore_exe_pid_get(Ecore_Exe *exe)
87{
88 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
89 {
90 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE,
91 "ecore_exe_pid_get");
92 return -1;
93 }
94 return exe->pid;
95}
96
97/**
98 * Get the data pointer attached to a process handle.
99 * @param exe The process handle returned by ecore_exe_run()
100 * @return An pointer to the attached data of the process handle
101 *
102 * This function returns the data pointer attached to the spawned off process
103 * whose handle is @p exe.
104 * <hr><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
105 */
106void *
107ecore_exe_data_get(Ecore_Exe *exe)
108{
109 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
110 {
111 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE,
112 "ecore_exe_data_get");
113 return NULL;
114 }
115 return exe->data;
116}
117
118/**
119 * Pause a spawned process.
120 * @param exe The process handle to control
121 *
122 * This function pauses a process that was spawned.
123 * <hr><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
124 */
125void
126ecore_exe_pause(Ecore_Exe *exe)
127{
128 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
129 {
130 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE,
131 "ecore_exe_pause");
132 return;
133 }
134 kill(exe->pid, SIGSTOP);
135}
136
137/**
138 * Continue a paused process.
139 * @param exe The process handle to control
140 *
141 * This Continues a process. This is only useful if the process has already
142 * been paused by something like ecore_exe_pause().
143 * <hr><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
144 */
145void
146ecore_exe_continue(Ecore_Exe *exe)
147{
148 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
149 {
150 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE,
151 "ecore_exe_continue");
152 return;
153 }
154 kill(exe->pid, SIGCONT);
155}
156
157/**
158 * Terminate a process.
159 * @param exe The process handle to control
160 *
161 * This function asks a process to terminate.
162 * <hr><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
163 */
164void
165ecore_exe_terminate(Ecore_Exe *exe)
166{
167 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
168 {
169 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE,
170 "ecore_exe_terminate");
171 return;
172 }
173 kill(exe->pid, SIGTERM);
174}
175
176/**
177 * Kill a process.
178 * @param exe The process handle to control
179 *
180 * This function ills off a process, and that process has no choice and will
181 * exit as a result of this function, without having a chance to clean up,
182 * save data, or safely shut down.
183 * <hr><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
184 */
185void
186ecore_exe_kill(Ecore_Exe *exe)
187{
188 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
189 {
190 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE,
191 "ecore_exe_kill");
192 return;
193 }
194 kill(exe->pid, SIGKILL);
195}
196
197/**
198 * Send a user signal to a process.
199 * @param exe The process handle to control
200 * @param num The signal number to send to the process
201 *
202 * This function sends a user signal (SIGUSR) to a process. @p num determines
203 * what numbered user signal to send. This may be either 1 or 2. Other values
204 * are illegal and will be ignored, with this function doing nothing.
205 * <hr><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
206 */
207void
208ecore_exe_signal(Ecore_Exe *exe, int num)
209{
210 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
211 {
212 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE,
213 "ecore_exe_signal");
214 return;
215 }
216 if (num == 1)
217 kill(exe->pid, SIGUSR1);
218 else if (num == 2)
219 kill(exe->pid, SIGUSR2);
220}
221
222/**
223 * Send a HUP signal to a process.
224 * @param exe The process handle to control
225 *
226 * This function sends a HUP signal to the specified process.
227 * <hr><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
228 */
229void
230ecore_exe_hup(Ecore_Exe *exe)
231{
232 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
233 {
234 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE,
235 "ecore_exe_hup");
236 return;
237 }
238 kill(exe->pid, SIGHUP);
239}
240
241void
242_ecore_exe_shutdown(void)
243{
244 while (exes) _ecore_exe_free(exes);
245}
246
247Ecore_Exe *
248_ecore_exe_find(pid_t pid)
249{
250 Ecore_List *l;
251
252 for (l = (Ecore_List *)exes; l; l = l->next)
253 {
254 Ecore_Exe *exe;
255
256 exe = (Ecore_Exe *)l;
257 if (exe->pid == pid) return exe;
258 }
259 return NULL;
260}
261
262void *
263_ecore_exe_free(Ecore_Exe *exe)
264{
265 void *data;
266
267 data = exe->data;
268 exes = _ecore_list_remove(exes, exe);
269 ECORE_MAGIC_SET(exe, ECORE_MAGIC_NONE);
270 free(exe);
271 return data;
272}
diff --git a/legacy/ecore/src/lib/ecore/ecore_idle_enterer.c b/legacy/ecore/src/lib/ecore/ecore_idle_enterer.c
new file mode 100644
index 0000000000..509070baf7
--- /dev/null
+++ b/legacy/ecore/src/lib/ecore/ecore_idle_enterer.c
@@ -0,0 +1,116 @@
1#include "ecore_private.h"
2#include "Ecore.h"
3
4static Ecore_Idle_Enterer *idle_enterers = NULL;
5static int idle_enterers_delete_me = 0;
6
7/**
8 * Add an idle enterer handler.
9 * @param func The function to call when entering an idle state.
10 * @param data The data to be passed to the @p func call
11 * @return A handle to the idle enterer callback
12 *
13 * This function adds an idle enterer handler and returns its handle on success
14 * or NULL on failure. Idle enterers are called just before he program goes
15 * int an idle state where it is waiting on timers to time out, data to come
16 * in on file descriptors, etc. The program will be in a "sleeping" state
17 * after all the idle enterer callbacks are called. This is a good callback to
18 * use to update your program's state if it has a state engine. Do all your
19 * heavy processing here to update state (like drawing etc.). When @p func
20 * is called, it will be passed the pointer @p data.
21 * <hr><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
22 */
23Ecore_Idle_Enterer *
24ecore_idle_enterer_add(int (*func) (void *data), const void *data)
25{
26 Ecore_Idle_Enterer *ie;
27
28 if (!func) return NULL;
29 ie = calloc(1, sizeof(Ecore_Idle_Enterer));
30 if (!ie) return NULL;
31 ECORE_MAGIC_SET(ie, ECORE_MAGIC_IDLE_ENTERER);
32 ie->func = func;
33 ie->data = (void *)data;
34 idle_enterers = _ecore_list_append(idle_enterers, ie);
35 return ie;
36}
37
38/**
39 * Delete an idle enter handler.
40 * @param idle_enterer The idle enterer to delete
41 *
42 * Delete the specified @p idle_enterer from the set of idle_enterers that are
43 * executed during main loop execution. On success the data pointer that was
44 * being passed to the idle handler function, set by ecore_idle_enterer_add()
45 * will be returned.
46 * <hr><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
47 */
48void *
49ecore_idle_enterer_del(Ecore_Idle_Enterer *idle_enterer)
50{
51 if (!ECORE_MAGIC_CHECK(idle_enterer, ECORE_MAGIC_IDLE_ENTERER))
52 {
53 ECORE_MAGIC_FAIL(idle_enterer, ECORE_MAGIC_IDLE_ENTERER,
54 "ecore_idle_enterer_del");
55 return NULL;
56 }
57 idle_enterer->delete_me = 1;
58 idle_enterers_delete_me = 1;
59 return idle_enterer->data;
60}
61
62void
63_ecore_idle_enterer_shutdown(void)
64{
65 while (idle_enterers)
66 {
67 Ecore_Idle_Enterer *ie;
68
69 ie = idle_enterers;
70 idle_enterers = _ecore_list_remove(idle_enterers, ie);
71 ECORE_MAGIC_SET(ie, ECORE_MAGIC_NONE);
72 free(ie);
73 }
74 idle_enterers_delete_me = 0;
75}
76
77void
78_ecore_idle_enterer_call(void)
79{
80 Ecore_List *l;
81
82 for (l = (Ecore_List *)idle_enterers; l; l = l->next)
83 {
84 Ecore_Idle_Enterer *ie;
85
86 ie = (Ecore_Idle_Enterer *)l;
87 if (!ie->delete_me)
88 {
89 if (!ie->func(ie->data)) ecore_idle_enterer_del(ie);
90 }
91 }
92 if (idle_enterers_delete_me)
93 {
94 for (l = (Ecore_List *)idle_enterers; l;)
95 {
96 Ecore_Idle_Enterer *ie;
97
98 ie = (Ecore_Idle_Enterer *)l;
99 l = l->next;
100 if (ie->delete_me)
101 {
102 idle_enterers = _ecore_list_remove(idle_enterers, ie);
103 ECORE_MAGIC_SET(ie, ECORE_MAGIC_NONE);
104 free(ie);
105 }
106 }
107 idle_enterers_delete_me = 0;
108 }
109}
110
111int
112_ecore_idle_enterer_exist(void)
113{
114 if (idle_enterers) return 1;
115 return 0;
116}
diff --git a/legacy/ecore/src/lib/ecore/ecore_idler.c b/legacy/ecore/src/lib/ecore/ecore_idler.c
new file mode 100644
index 0000000000..7cc3d27f5d
--- /dev/null
+++ b/legacy/ecore/src/lib/ecore/ecore_idler.c
@@ -0,0 +1,119 @@
1#include "ecore_private.h"
2#include "Ecore.h"
3
4static Ecore_Idler *idlers = NULL;
5static int idlers_delete_me = 0;
6
7/**
8 * Add an idler handler.
9 * @param func The function to call when idling.
10 * @param data The data to be passed to this @p func call
11 * @return A idler handle
12 *
13 * This function adds an idler handler and returns its handle on success, or
14 * NULL on failure. Idlers will get called after idle enterer calls have all
15 * been called and the program is in an idle state waiting on data or timers.
16 * If no idler functions are set the process literally goes to sleep and uses
17 * no CPU. If You have idler functions set they will be called continuously
18 * during this "idle" time with your process consuming as much CPU as it can
19 * get to do so. This is useful for when there are interfaces that require
20 * polling and timers will mean too slow a response from the process if polling
21 * is done by timers.
22 * <hr><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
23 */
24Ecore_Idler *
25ecore_idler_add(int (*func) (void *data), const void *data)
26{
27 Ecore_Idler *ie;
28
29 if (!func) return NULL;
30 ie = calloc(1, sizeof(Ecore_Idler));
31 if (!ie) return NULL;
32 ECORE_MAGIC_SET(ie, ECORE_MAGIC_IDLER);
33 ie->func = func;
34 ie->data = (void *)data;
35 idlers = _ecore_list_append(idlers, ie);
36 return ie;
37}
38
39/**
40 * Delete an idler handler.
41 * @param idler The idler to delete
42 *
43 * Delete the specified @p idler from the set of idlers that are executed
44 * during main loop execution. On success the data pointer set by
45 * ecore_idler_add() and passed to the idler function is returned, or NULL
46 * on failure.
47 * <hr><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
48 */
49void *
50ecore_idler_del(Ecore_Idler *idler)
51{
52 if (!ECORE_MAGIC_CHECK(idler, ECORE_MAGIC_IDLER))
53 {
54 ECORE_MAGIC_FAIL(idler, ECORE_MAGIC_IDLER,
55 "ecore_idler_del");
56 return NULL;
57 }
58 idler->delete_me = 1;
59 idlers_delete_me = 1;
60 return idler->data;
61}
62
63void
64_ecore_idler_shutdown(void)
65{
66 while (idlers)
67 {
68 Ecore_Idler *ie;
69
70 ie = idlers;
71 idlers = _ecore_list_remove(idlers, ie);
72 ECORE_MAGIC_SET(ie, ECORE_MAGIC_NONE);
73 free(ie);
74 }
75 idlers_delete_me = 0;
76}
77
78int
79_ecore_idler_call(void)
80{
81 Ecore_List *l;
82
83 for (l = (Ecore_List *)idlers; l; l = l->next)
84 {
85 Ecore_Idler *ie;
86
87 ie = (Ecore_Idler *)l;
88 if (!ie->delete_me)
89 {
90 if (!ie->func(ie->data)) ecore_idler_del(ie);
91 }
92 }
93 if (idlers_delete_me)
94 {
95 for (l = (Ecore_List *)idlers; l;)
96 {
97 Ecore_Idler *ie;
98
99 ie = (Ecore_Idler *)l;
100 l = l->next;
101 if (ie->delete_me)
102 {
103 idlers = _ecore_list_remove(idlers, ie);
104 ECORE_MAGIC_SET(ie, ECORE_MAGIC_NONE);
105 free(ie);
106 }
107 }
108 idlers_delete_me = 0;
109 }
110 if (idlers) return 1;
111 return 0;
112}
113
114int
115_ecore_idler_exist(void)
116{
117 if (idlers) return 1;
118 return 0;
119}
diff --git a/legacy/ecore/src/lib/ecore/ecore_list.c b/legacy/ecore/src/lib/ecore/ecore_list.c
new file mode 100644
index 0000000000..2048a19e7c
--- /dev/null
+++ b/legacy/ecore/src/lib/ecore/ecore_list.c
@@ -0,0 +1,172 @@
1#include "ecore_private.h"
2#include "Ecore.h"
3
4void *
5_ecore_list_append(void *in_list, void *in_item)
6{
7 Ecore_List *l, *new_l;
8 Ecore_List *list, *item;
9
10 list = in_list;
11 item = in_item;
12 new_l = item;
13 new_l->next = NULL;
14 if (!list)
15 {
16 new_l->prev = NULL;
17 new_l->last = new_l;
18 return new_l;
19 }
20 if (list->last) l = list->last;
21 else for (l = list; l; l = l->next);
22 l->next = new_l;
23 new_l->prev = l;
24 list->last = new_l;
25 return list;
26}
27
28void *
29_ecore_list_prepend(void *in_list, void *in_item)
30{
31 Ecore_List *new_l;
32 Ecore_List *list, *item;
33
34 list = in_list;
35 item = in_item;
36 new_l = item;
37 new_l->prev = NULL;
38 if (!list)
39 {
40 new_l->next = NULL;
41 new_l->last = new_l;
42 return new_l;
43 }
44 new_l->next = list;
45 list->prev = new_l;
46 new_l->last = list->last;
47 list->last = NULL;
48 return new_l;
49}
50
51void *
52_ecore_list_append_relative(void *in_list, void *in_item, void *in_relative)
53{
54 Ecore_List *l;
55 Ecore_List *list, *item, *relative;
56
57 list = in_list;
58 item = in_item;
59 relative = in_relative;
60 for (l = list; l; l = l->next)
61 {
62 if (l == relative)
63 {
64 Ecore_List *new_l;
65
66 new_l = item;
67 if (l->next)
68 {
69 new_l->next = l->next;
70 l->next->prev = new_l;
71 }
72
73 else new_l->next = NULL;
74 l->next = new_l;
75 new_l->prev = l;
76 if (!new_l->next)
77 list->last = new_l;
78 return list;
79 }
80 }
81 return _ecore_list_append(list, item);
82}
83
84void *
85_ecore_list_prepend_relative(void *in_list, void *in_item, void *in_relative)
86{
87 Ecore_List *l;
88 Ecore_List *list, *item, *relative;
89
90 list = in_list;
91 item = in_item;
92 relative = in_relative;
93 for (l = list; l; l = l->next)
94 {
95 if (l == relative)
96 {
97 Ecore_List *new_l;
98
99 new_l = item;
100 new_l->prev = l->prev;
101 new_l->next = l;
102 l->prev = new_l;
103 if (new_l->prev)
104 {
105 new_l->prev->next = new_l;
106 if (!new_l->next)
107 list->last = new_l;
108 return list;
109 }
110 else
111 {
112 if (!new_l->next)
113 new_l->last = new_l;
114 else
115 {
116 new_l->last = list->last;
117 list->last = NULL;
118 }
119 return new_l;
120 }
121 }
122 }
123 return _ecore_list_prepend(list, item);
124}
125
126void *
127_ecore_list_remove(void *in_list, void *in_item)
128{
129 Ecore_List *return_l;
130 Ecore_List *list, *item;
131
132 /* checkme */
133 if(!in_list)
134 return in_list;
135
136 list = in_list;
137 item = in_item;
138 if (!item) return list;
139 if (item->next)
140 item->next->prev = item->prev;
141 if (item->prev)
142 {
143 item->prev->next = item->next;
144 return_l = list;
145 }
146 else
147 {
148 return_l = item->next;
149 if (return_l)
150 return_l->last = list->last;
151 }
152 if (item == list->last)
153 list->last = item->prev;
154 item->next = NULL;
155 item->prev = NULL;
156 return return_l;
157}
158
159void *
160_ecore_list_find(void *in_list, void *in_item)
161{
162 Ecore_List *l;
163 Ecore_List *list, *item;
164
165 list = in_list;
166 item = in_item;
167 for (l = list; l; l = l->next)
168 {
169 if (l == item) return item;
170 }
171 return NULL;
172}
diff --git a/legacy/ecore/src/lib/ecore/ecore_main.c b/legacy/ecore/src/lib/ecore/ecore_main.c
new file mode 100644
index 0000000000..e025fadc32
--- /dev/null
+++ b/legacy/ecore/src/lib/ecore/ecore_main.c
@@ -0,0 +1,525 @@
1#include "ecore_private.h"
2#include "Ecore.h"
3
4#include <sys/time.h>
5#include <sys/types.h>
6#include <unistd.h>
7#include <errno.h>
8
9static int _ecore_main_select(double timeout);
10static void _ecore_main_fd_handlers_cleanup(void);
11static void _ecore_main_fd_handlers_call(void);
12static int _ecore_main_fd_handlers_buf_call(void);
13static void _ecore_main_loop_iterate_internal(int once_only);
14
15static int in_main_loop = 0;
16static int do_quit = 0;
17static Ecore_Fd_Handler *fd_handlers = NULL;
18static int fd_handlers_delete_me = 0;
19
20/**
21 * Run 1 iteration of the main loop and process everything on the queue.
22 *
23 * This function Processes 1 iteration of the main loop, handling anything on
24 * the queue. See ecore_main_loop_begin() for more information.
25 * <hr><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
26 */
27void
28ecore_main_loop_iterate(void)
29{
30 _ecore_main_loop_iterate_internal(1);
31}
32
33/**
34 * Run the application main loop.
35 *
36 * This function does not return until ecore_main_loop_quit() is called. It
37 * will keep looping internally and call all callbacks set up to handle timers,
38 * idle state and events Ecore recieves from X, fd's, IPC, signals etc. and
39 * anything else that has registered a handler with ecore itself.
40 * <hr><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
41 */
42void
43ecore_main_loop_begin(void)
44{
45 in_main_loop++;
46 for (;do_quit == 0;) _ecore_main_loop_iterate_internal(0);
47 do_quit = 0;
48 in_main_loop--;
49}
50
51/**
52 * Quit the main loop after it is done processing.
53 *
54 * This function will flag a quit of the main loop once the current loop has
55 * finished processing all events. It will not quit instantly, so expect more
56 * callbacks to be called after this command has been issued.
57 * <hr><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
58 */
59void
60ecore_main_loop_quit(void)
61{
62 do_quit = 1;
63}
64
65/**
66 * Add a handler for read/write notification of a file descriptor.
67 * @param fd The file descriptor to watch
68 * @param flags To watch it for read and/or write ability
69 * @param func The function to call when the file descriptor becomes active
70 * @param data The data to pass to the @p func call
71 * @param buf_func The function to call to check if any data has been buffered and already read from the fd.
72 * @param buf_data The data to pass to the @p buf_func call
73 * @return A fd handler handle
74 *
75 * This adds a fd handler, calling @p func whenever the fd is active for
76 * read or write (or both) depending what flags were set as @p flags. On
77 * failure NULL is returned. The @p func call will the triggered during
78 * execution of ecore_main_loop_begin() when a file descriptor (fd) is
79 * available for reading or writing (or both). The #p buf_func call is called
80 * during event loop handling to check if data that has already been read from
81 * the file descriptor is in a buffer and is available to read. This function
82 * is optional and can be NULL. If it is called it will be passed @p buf_data
83 * as the data parameter.
84 *
85 * Example:
86 *
87 * @code
88 * int fd;
89 * Ecore_Fd_Handler *fdh;
90 *
91 * fd = open("/tmp/fifo", O_RDONLY);
92 * fdh = ecore_main_fd_handler_add(fd, ECORE_FD_READ, func_read_fifo, NULL);
93 * @endcode
94 * <hr><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
95 */
96Ecore_Fd_Handler *
97ecore_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)
98{
99 Ecore_Fd_Handler *fdh;
100
101 if ((fd < 0) ||
102 (flags == 0) ||
103 (!func)) return NULL;
104 fdh = calloc(1, sizeof(Ecore_Fd_Handler));
105 if (!fdh) return NULL;
106 ECORE_MAGIC_SET(fdh, ECORE_MAGIC_FD_HANDLER);
107 fdh->fd = fd;
108 fdh->flags = flags;
109 fdh->read_active = 0;
110 fdh->write_active = 0;
111 fdh->delete_me = 0;
112 fdh->func = func;
113 fdh->data = (void *)data;
114 fdh->buf_func = buf_func;
115 fdh->buf_data = (void *)buf_data;
116 fd_handlers = _ecore_list_append(fd_handlers, fdh);
117 return fdh;
118}
119
120/**
121 * Delete a handler for file descriptors.
122 *
123 * @param fd_handler The handler to delete
124 * @return The data pointer set for the fd_handler
125 *
126 * This deletes a file descriptore (fd) handler and on success returns the data
127 * pointer that was being passed to it, set by ecore_main_fd_handler_add().
128 * NUll is returned on failure.
129 */
130void *
131ecore_main_fd_handler_del(Ecore_Fd_Handler *fd_handler)
132{
133 if (!ECORE_MAGIC_CHECK(fd_handler, ECORE_MAGIC_FD_HANDLER))
134 {
135 ECORE_MAGIC_FAIL(fd_handler, ECORE_MAGIC_FD_HANDLER,
136 "ecore_main_fd_handler_del");
137 return NULL;
138 }
139 fd_handler->delete_me = 1;
140 fd_handlers_delete_me = 1;
141 return fd_handler->data;
142}
143
144/**
145 * Return the file descriptor that the handler is handling
146 * @param fd_handler The fd handler to query
147 * @return The fd the handler is watching
148 *
149 * This returns the fd the @p fd_handler is monitoring.
150 */
151int
152ecore_main_fd_handler_fd_get(Ecore_Fd_Handler *fd_handler)
153{
154 if (!ECORE_MAGIC_CHECK(fd_handler, ECORE_MAGIC_FD_HANDLER))
155 {
156 ECORE_MAGIC_FAIL(fd_handler, ECORE_MAGIC_FD_HANDLER,
157 "ecore_main_fd_handler_fd_get");
158 return -1;
159 }
160 return fd_handler->fd;
161}
162
163/**
164 * Return if read or write is active on the fd
165 * @param fd_handler The handler to query
166 * @param flags The flags to query
167 * @return The active state of read or write on the fd, or both
168 *
169 * Return if the fd the handler is watching is active for read, write or both.
170 * The @p flags parameter determines what youw ant to query, and 1 is returned
171 * if the hanldere reports an active state for any of the values in
172 * @p flags since this is the same bitmask the handler was set up with. 0 is
173 * returned if the fd is not active for the @p flags passed in.
174 */
175int
176ecore_main_fd_handler_active_get(Ecore_Fd_Handler *fd_handler, Ecore_Fd_Handler_Flags flags)
177{
178 int ret;
179
180 if (!ECORE_MAGIC_CHECK(fd_handler, ECORE_MAGIC_FD_HANDLER))
181 {
182 ECORE_MAGIC_FAIL(fd_handler, ECORE_MAGIC_FD_HANDLER,
183 "ecore_main_fd_handler_active_get");
184 return 0;
185 }
186 ret = 0;
187 if ((flags & ECORE_FD_READ) && (fd_handler->read_active)) ret = 1;
188 if ((flags & ECORE_FD_WRITE) && (fd_handler->write_active)) ret = 1;
189 return ret;
190}
191
192/**
193 * Set what active stream the fd should be monitoring
194 * @param fd_handler The handler to modify
195 * @param flags The flags to be watching
196 *
197 * This function changes if an fd shoudl be watched for read, write or both.
198 */
199void
200ecore_main_fd_handler_active_set(Ecore_Fd_Handler *fd_handler, Ecore_Fd_Handler_Flags flags)
201{
202 if (!ECORE_MAGIC_CHECK(fd_handler, ECORE_MAGIC_FD_HANDLER))
203 {
204 ECORE_MAGIC_FAIL(fd_handler, ECORE_MAGIC_FD_HANDLER,
205 "ecore_main_fd_handler_active_set");
206 return;
207 }
208 fd_handler->flags = flags;
209}
210
211void
212_ecore_main_shutdown(void)
213{
214 if (in_main_loop)
215 {
216 fprintf(stderr,
217 "\n"
218 "*** ECORE WARINING: Calling ecore_shutdown() while still in the main loop.\n"
219 "*** Program may crash or behave strangely now.\n");
220 return;
221 }
222 while (fd_handlers)
223 {
224 Ecore_Fd_Handler *fdh;
225
226 fdh = fd_handlers;
227 fd_handlers = _ecore_list_remove(fd_handlers, fdh);
228 ECORE_MAGIC_SET(fdh, ECORE_MAGIC_NONE);
229 free(fdh);
230 }
231 fd_handlers_delete_me = 0;
232}
233
234static int
235_ecore_main_select(double timeout)
236{
237 struct timeval tv, *t;
238 fd_set rfds, wfds;
239 int max_fd;
240 int ret;
241 Ecore_List *l;
242
243 t = NULL;
244 if (timeout > 0.0)
245 {
246 int sec, usec;
247
248 sec = (int)timeout;
249 usec = (int)((timeout - (double)sec) * 1000000);
250 tv.tv_sec = sec;
251 tv.tv_usec = usec;
252 t = &tv;
253 }
254 else if (timeout == 0.0)
255 {
256 tv.tv_sec = 0;
257 tv.tv_usec = 0;
258 t = &tv;
259 }
260 max_fd = 0;
261 FD_ZERO(&rfds);
262 FD_ZERO(&wfds);
263 for (l = (Ecore_List *)fd_handlers; l; l = l->next)
264 {
265 Ecore_Fd_Handler *fdh;
266
267 fdh = (Ecore_Fd_Handler *)l;
268 if (fdh->flags & ECORE_FD_READ)
269 {
270 FD_SET(fdh->fd, &rfds);
271 if (fdh->fd > max_fd) max_fd = fdh->fd;
272 }
273 if (fdh->flags & ECORE_FD_WRITE)
274 {
275 FD_SET(fdh->fd, &wfds);
276 if (fdh->fd > max_fd) max_fd = fdh->fd;
277 }
278 }
279 if (_ecore_signal_count_get()) return -1;
280 ret = select(max_fd + 1, &rfds, &wfds, NULL, t);
281 if (ret < 0)
282 {
283 if (errno == EINTR) return -1;
284 }
285 if (ret > 0)
286 {
287 for (l = (Ecore_List *)fd_handlers; l; l = l->next)
288 {
289 Ecore_Fd_Handler *fdh;
290
291 fdh = (Ecore_Fd_Handler *)l;
292 if (!fdh->delete_me)
293 {
294 if (FD_ISSET(fdh->fd, &rfds))
295 fdh->read_active = 1;
296 if (FD_ISSET(fdh->fd, &wfds))
297 fdh->write_active = 1;
298 }
299 }
300 _ecore_main_fd_handlers_cleanup();
301 return 1;
302 }
303 return 0;
304}
305
306static void
307_ecore_main_fd_handlers_cleanup(void)
308{
309 Ecore_List *l;
310
311 if (!fd_handlers_delete_me) return;
312 for (l = (Ecore_List *)fd_handlers; l;)
313 {
314 Ecore_Fd_Handler *fdh;
315
316 fdh = (Ecore_Fd_Handler *)l;
317 l = l->next;
318 if (fdh->delete_me)
319 {
320 fd_handlers = _ecore_list_remove(fd_handlers, fdh);
321 ECORE_MAGIC_SET(fdh, ECORE_MAGIC_NONE);
322 free(fdh);
323 }
324 }
325 fd_handlers_delete_me = 0;
326}
327
328static void
329_ecore_main_fd_handlers_call(void)
330{
331 Ecore_List *l;
332
333 for (l = (Ecore_List *)fd_handlers; l; l = l->next)
334 {
335 Ecore_Fd_Handler *fdh;
336
337 fdh = (Ecore_Fd_Handler *)l;
338 if (!fdh->delete_me)
339 {
340 if ((fdh->read_active) || (fdh->write_active))
341 {
342 if (!fdh->func(fdh->data, fdh))
343 {
344 fdh->delete_me = 1;
345 fd_handlers_delete_me = 1;
346 }
347 fdh->read_active = 0;
348 fdh->write_active = 0;
349 }
350 }
351 }
352}
353
354static int
355_ecore_main_fd_handlers_buf_call(void)
356{
357 Ecore_List *l;
358 int ret;
359
360 ret = 0;
361 for (l = (Ecore_List *)fd_handlers; l; l = l->next)
362 {
363 Ecore_Fd_Handler *fdh;
364
365 fdh = (Ecore_Fd_Handler *)l;
366 if (!fdh->delete_me)
367 {
368 if (fdh->buf_func)
369 {
370 if (fdh->buf_func(fdh->buf_data, fdh))
371 {
372 ret |= fdh->func(fdh->data, fdh);
373 fdh->read_active = 1;
374 }
375 }
376 }
377 }
378 return ret;
379}
380
381static void
382_ecore_main_loop_iterate_internal(int once_only)
383{
384 double next_time;
385 int have_event;
386 int have_signal;
387
388 in_main_loop++;
389 /* expire any timers */
390 {
391 double now;
392
393 now = ecore_time_get();
394 while (_ecore_timer_call(now));
395 _ecore_timer_cleanup();
396 }
397 /* any timers re-added as a result of these are allowed to go */
398 _ecore_timer_enable_new();
399 /* process signals into events .... */
400 while (_ecore_signal_count_get()) _ecore_signal_call();
401 if (_ecore_event_exist())
402 {
403 have_event = 1;
404 have_signal = 1;
405 goto process_events;
406 }
407 /* call idle enterers ... */
408 if (!once_only)
409 _ecore_idle_enterer_call();
410 else
411 {
412 int ret;
413
414 have_event = have_signal = 0;
415 ret = _ecore_main_select(0);
416
417 if (ret > 0) have_event = 1;
418 if (_ecore_signal_count_get() > 0) have_signal = 1;
419
420 if (have_signal || have_event)
421 goto process_events;
422 }
423
424 /* if these calls caused any biuffered events to appear - deal with them */
425 while (_ecore_main_fd_handlers_buf_call());
426 /* if ther are any - jump to processing them */
427 if (_ecore_event_exist())
428 {
429 have_event = 1;
430 have_signal = 1;
431 goto process_events;
432 }
433 if (once_only)
434 {
435 _ecore_idle_enterer_call();
436 in_main_loop--;
437 return;
438 }
439
440 start_loop:
441 /* init flags */
442 have_event = have_signal = 0;
443 next_time = _ecore_timer_next_get();
444 /* no timers */
445 if (next_time < 0)
446 {
447 /* no idlers */
448 if (!_ecore_idler_exist())
449 {
450 int ret;
451
452 ret = _ecore_main_select(-1);
453 if (ret > 0) have_event = 1;
454 if (_ecore_signal_count_get() > 0) have_signal = 1;
455 }
456 /* idlers */
457 else
458 {
459 for (;;)
460 {
461 int ret;
462
463 if (!_ecore_idler_call()) goto start_loop;
464 if (_ecore_event_exist()) break;
465 ret = _ecore_main_select(0);
466 if (ret > 0) have_event = 1;
467 if (_ecore_signal_count_get() > 0) have_signal = 1;
468 if (have_event || have_signal) break;
469 next_time = _ecore_timer_next_get();
470 if (next_time >= 0) goto start_loop;
471 }
472 }
473 }
474 /* timers */
475 else
476 {
477 /* no idlers */
478 if (!_ecore_idler_exist())
479 {
480 int ret;
481
482 ret = _ecore_main_select(next_time);
483 if (ret > 0) have_event = 1;
484 if (_ecore_signal_count_get() > 0) have_signal = 1;
485 }
486 /* idlers */
487 else
488 {
489 for (;;)
490 {
491 double cur_time, t;
492 int ret;
493
494 if (!_ecore_idler_call()) goto start_loop;
495 if (_ecore_event_exist()) break;
496 ret = _ecore_main_select(0);
497 if (ret > 0) have_event = 1;
498 if (_ecore_signal_count_get() > 0) have_signal = 1;
499 if ((have_event) || (have_signal)) break;
500 cur_time = ecore_time_get();
501 t = ecore_time_get() - cur_time;
502 if (t >= next_time) break;
503 next_time = _ecore_timer_next_get();
504 if (next_time < 0) goto start_loop;
505 }
506 }
507 }
508 /* call the fd handler per fd that became alive... */
509 /* this should read or write any data to the monitored fd and then */
510 /* post events onto the ecore event pipe if necessary */
511 process_events:
512 if (have_event) _ecore_main_fd_handlers_call();
513 do
514 {
515 /* process signals into events .... */
516 while (_ecore_signal_count_get()) _ecore_signal_call();
517
518 /* handle events ... */
519 _ecore_event_call();
520 _ecore_main_fd_handlers_cleanup();
521 }
522 while (_ecore_main_fd_handlers_buf_call());
523 if (once_only) _ecore_idle_enterer_call();
524 in_main_loop--;
525}
diff --git a/legacy/ecore/src/lib/ecore/ecore_private.h b/legacy/ecore/src/lib/ecore/ecore_private.h
new file mode 100644
index 0000000000..8e76a1af3a
--- /dev/null
+++ b/legacy/ecore/src/lib/ecore/ecore_private.h
@@ -0,0 +1,192 @@
1#ifndef _ECORE_PRIVATE_H
2#define _ECORE_PRIVATE_H
3
4#include <stdio.h>
5#include <stdlib.h>
6#include <sys/time.h>
7#include <sys/types.h>
8#include <unistd.h>
9#include <signal.h>
10
11#define ECORE_MAGIC_NONE 0x1234fedc
12#define ECORE_MAGIC_EXE 0xf7e812f5
13#define ECORE_MAGIC_TIMER 0xf7d713f4
14#define ECORE_MAGIC_IDLER 0xf7c614f3
15#define ECORE_MAGIC_IDLE_ENTERER 0xf7b515f2
16#define ECORE_MAGIC_FD_HANDLER 0xf7a416f1
17#define ECORE_MAGIC_EVENT_HANDLER 0xf79317f0
18#define ECORE_MAGIC_EVENT_FILTER 0xf78218ff
19#define ECORE_MAGIC_EVENT 0xf77119fe
20
21#define ECORE_MAGIC Ecore_Magic __magic
22
23#define ECORE_MAGIC_SET(d, m) (d)->__magic = (m)
24#define ECORE_MAGIC_CHECK(d, m) ((d) && ((d)->__magic == (m)))
25#define ECORE_MAGIC_FAIL(d, m, fn) _ecore_magic_fail((d), (d) ? (d)->__magic : 0, (m), (fn));
26
27typedef int Ecore_Magic;
28
29typedef struct _Ecore_List Ecore_List;
30
31struct _Ecore_List
32{
33 Ecore_List *next, *prev;
34 Ecore_List *last;
35};
36
37#ifndef _ECORE_H
38enum _Ecore_Fd_Handler_Flags
39{
40 ECORE_FD_READ = 1,
41 ECORE_FD_WRITE = 2
42};
43typedef enum _Ecore_Fd_Handler_Flags Ecore_Fd_Handler_Flags;
44
45typedef struct _Ecore_Exe Ecore_Exe;
46typedef struct _Ecore_Timer Ecore_Timer;
47typedef struct _Ecore_Idler Ecore_Idler;
48typedef struct _Ecore_Idle_Enterer Ecore_Idle_Enterer;
49typedef struct _Ecore_Fd_Handler Ecore_Fd_Handler;
50typedef struct _Ecore_Event_Handler Ecore_Event_Handler;
51typedef struct _Ecore_Event_Filter Ecore_Event_Filter;
52typedef struct _Ecore_Event Ecore_Event;
53
54struct _Ecore_Exe
55{
56 Ecore_List __list_data;
57 ECORE_MAGIC;
58 pid_t pid;
59 void *data;
60};
61
62struct _Ecore_Timer
63{
64 Ecore_List __list_data;
65 ECORE_MAGIC;
66 double in;
67 double at;
68 char delete_me : 1;
69 char just_added : 1;
70 int (*func) (void *data);
71 void *data;
72};
73
74struct _Ecore_Idler
75{
76 Ecore_List __list_data;
77 ECORE_MAGIC;
78 int delete_me : 1;
79 int (*func) (void *data);
80 void *data;
81};
82
83struct _Ecore_Idle_Enterer
84{
85 Ecore_List __list_data;
86 ECORE_MAGIC;
87 int delete_me : 1;
88 int (*func) (void *data);
89 void *data;
90};
91
92struct _Ecore_Fd_Handler
93{
94 Ecore_List __list_data;
95 ECORE_MAGIC;
96 int fd;
97 Ecore_Fd_Handler_Flags flags;
98 int read_active : 1;
99 int write_active : 1;
100 int delete_me : 1;
101 int (*func) (void *data, Ecore_Fd_Handler *fd_handler);
102 void *data;
103 int (*buf_func) (void *data, Ecore_Fd_Handler *fd_handler);
104 void *buf_data;
105};
106
107struct _Ecore_Event_Handler
108{
109 Ecore_List __list_data;
110 ECORE_MAGIC;
111 int type;
112 int delete_me : 1;
113 int (*func) (void *data, int type, void *event);
114 void *data;
115};
116
117struct _Ecore_Event_Filter
118{
119 Ecore_List __list_data;
120 ECORE_MAGIC;
121 int delete_me : 1;
122 void * (*func_start) (void *data);
123 int (*func_filter) (void *data, void *loop_data, int type, void *event);
124 void (*func_end) (void *data, void *loop_data);
125 void *loop_data;
126 void *data;
127};
128
129struct _Ecore_Event
130{
131 Ecore_List __list_data;
132 ECORE_MAGIC;
133 int type;
134 void *event;
135 int delete_me : 1;
136 void (*func_free) (void *data, void *ev);
137 void *data;
138};
139#endif
140
141void _ecore_magic_fail(void *d, Ecore_Magic m, Ecore_Magic req_m, const char *fname);
142
143void _ecore_timer_shutdown(void);
144void _ecore_timer_cleanup(void);
145void _ecore_timer_enable_new(void);
146double _ecore_timer_next_get(void);
147int _ecore_timer_call(double when);
148
149void _ecore_idler_shutdown(void);
150int _ecore_idler_call(void);
151int _ecore_idler_exist(void);
152
153void _ecore_idle_enterer_shutdown(void);
154void _ecore_idle_enterer_call(void);
155int _ecore_idle_enterer_exist(void);
156
157void _ecore_event_shutdown(void);
158int _ecore_event_exist(void);
159Ecore_Event *_ecore_event_add(int type, void *ev, void (*func_free) (void *data, void *ev), void *data);
160void *_ecore_event_del(Ecore_Event *event);
161void _ecore_event_call(void);
162
163void *_ecore_event_exe_exit_new(void);
164void _ecore_event_exe_exit_free(void *data, void *ev);
165void *_ecore_event_signal_user_new(void);
166void _ecore_event_signal_user_free(void *data, void *ev);
167void *_ecore_event_signal_hup_new(void);
168void _ecore_event_signal_hup_free(void *data, void *ev);
169void *_ecore_event_signal_exit_new(void);
170void _ecore_event_signal_exit_free(void *data, void *ev);
171void *_ecore_event_signal_power_new(void);
172void _ecore_event_signal_power_free(void *data, void *ev);
173
174void _ecore_main_shutdown(void);
175
176void _ecore_signal_shutdown(void);
177void _ecore_signal_init(void);
178int _ecore_signal_count_get(void);
179void _ecore_signal_call(void);
180
181void _ecore_exe_shutdown(void);
182Ecore_Exe *_ecore_exe_find(pid_t pid);
183void *_ecore_exe_free(Ecore_Exe *exe);
184
185void *_ecore_list_append (void *in_list, void *in_item);
186void *_ecore_list_prepend (void *in_list, void *in_item);
187void *_ecore_list_append_relative (void *in_list, void *in_item, void *in_relative);
188void *_ecore_list_prepend_relative (void *in_list, void *in_item, void *in_relative);
189void *_ecore_list_remove (void *in_list, void *in_item);
190void *_ecore_list_find (void *in_list, void *in_item);
191
192#endif
diff --git a/legacy/ecore/src/lib/ecore/ecore_signal.c b/legacy/ecore/src/lib/ecore/ecore_signal.c
new file mode 100644
index 0000000000..dd175449b6
--- /dev/null
+++ b/legacy/ecore/src/lib/ecore/ecore_signal.c
@@ -0,0 +1,276 @@
1#include "ecore_private.h"
2#include "Ecore.h"
3
4#include <sys/types.h>
5#include <sys/wait.h>
6#include <signal.h>
7#include <unistd.h>
8
9static void _ecore_signal_callback_set(int sig, void (*func)(int sig));
10static void _ecore_signal_callback_ignore(int sig);
11static void _ecore_signal_callback_sigchld(int sig);
12static void _ecore_signal_callback_sigusr1(int sig);
13static void _ecore_signal_callback_sigusr2(int sig);
14static void _ecore_signal_callback_sighup(int sig);
15static void _ecore_signal_callback_sigquit(int sig);
16static void _ecore_signal_callback_sigint(int sig);
17static void _ecore_signal_callback_sigterm(int sig);
18static void _ecore_signal_callback_sigpwr(int sig);
19
20static int sigchld_count = 0;
21static int sigusr1_count = 0;
22static int sigusr2_count = 0;
23static int sighup_count = 0;
24static int sigquit_count = 0;
25static int sigint_count = 0;
26static int sigterm_count = 0;
27static int sigpwr_count = 0;
28
29static int sig_count = 0;
30
31void
32_ecore_signal_shutdown(void)
33{
34 _ecore_signal_callback_set(SIGPIPE, SIG_DFL);
35 _ecore_signal_callback_set(SIGALRM, SIG_DFL);
36 _ecore_signal_callback_set(SIGCHLD, SIG_DFL);
37 _ecore_signal_callback_set(SIGUSR1, SIG_DFL);
38 _ecore_signal_callback_set(SIGUSR2, SIG_DFL);
39 _ecore_signal_callback_set(SIGHUP, SIG_DFL);
40 _ecore_signal_callback_set(SIGQUIT, SIG_DFL);
41 _ecore_signal_callback_set(SIGINT, SIG_DFL);
42 _ecore_signal_callback_set(SIGTERM, SIG_DFL);
43 #ifdef SIGPWR
44 _ecore_signal_callback_set(SIGPWR, SIG_DFL);
45 #endif
46 sigchld_count = 0;
47 sigusr1_count = 0;
48 sigusr2_count = 0;
49 sighup_count = 0;
50 sigquit_count = 0;
51 sigint_count = 0;
52 sigterm_count = 0;
53 sigpwr_count = 0;
54 sig_count = 0;
55}
56
57void
58_ecore_signal_init(void)
59{
60 _ecore_signal_callback_set(SIGPIPE, _ecore_signal_callback_ignore);
61 _ecore_signal_callback_set(SIGALRM, _ecore_signal_callback_ignore);
62 _ecore_signal_callback_set(SIGCHLD, _ecore_signal_callback_sigchld);
63 _ecore_signal_callback_set(SIGUSR1, _ecore_signal_callback_sigusr1);
64 _ecore_signal_callback_set(SIGUSR2, _ecore_signal_callback_sigusr2);
65 _ecore_signal_callback_set(SIGHUP, _ecore_signal_callback_sighup);
66 _ecore_signal_callback_set(SIGQUIT, _ecore_signal_callback_sigquit);
67 _ecore_signal_callback_set(SIGINT, _ecore_signal_callback_sigint);
68 _ecore_signal_callback_set(SIGTERM, _ecore_signal_callback_sigterm);
69 #ifdef SIGPWR
70 _ecore_signal_callback_set(SIGPWR, _ecore_signal_callback_sigpwr);
71 #endif
72}
73
74int
75_ecore_signal_count_get(void)
76{
77 return sig_count;
78}
79
80void
81_ecore_signal_call(void)
82{
83 while (sigchld_count > 0)
84 {
85 pid_t pid;
86 int status;
87
88 while ((pid = waitpid(-1, &status, WNOHANG)) > 0)
89 {
90 if (WIFEXITED(status))
91 {
92 Ecore_Event_Exe_Exit *e;
93
94 e = _ecore_event_exe_exit_new();
95 if (e)
96 {
97 e->exit_code = WEXITSTATUS(status);
98 e->pid = pid;
99 e->exe = _ecore_exe_find(pid);
100 _ecore_event_add(ECORE_EVENT_EXE_EXIT, e,
101 _ecore_event_exe_exit_free, NULL);
102 }
103 }
104 }
105 sigchld_count--;
106 sig_count--;
107 }
108 while (sigusr1_count > 0)
109 {
110 Ecore_Event_Signal_User *e;
111
112 e = _ecore_event_signal_user_new();
113 if (e)
114 {
115 e->number = 1;
116 _ecore_event_add(ECORE_EVENT_SIGNAL_USER, e,
117 _ecore_event_signal_user_free, NULL);
118 }
119 sigusr1_count--;
120 sig_count--;
121 }
122 while (sigusr2_count > 0)
123 {
124 Ecore_Event_Signal_User *e;
125
126 e = _ecore_event_signal_user_new();
127 if (e)
128 {
129 e->number = 2;
130 _ecore_event_add(ECORE_EVENT_SIGNAL_USER, e,
131 _ecore_event_signal_user_free, NULL);
132 }
133 sigusr2_count--;
134 sig_count--;
135 }
136 while (sighup_count > 0)
137 {
138 Ecore_Event_Signal_Hup *e;
139
140 e = _ecore_event_signal_hup_new();
141 if (e)
142 {
143 _ecore_event_add(ECORE_EVENT_SIGNAL_HUP, e,
144 _ecore_event_signal_hup_free, NULL);
145 }
146 sighup_count--;
147 sig_count--;
148 }
149 while (sigquit_count > 0)
150 {
151 Ecore_Event_Signal_Exit *e;
152
153 e = _ecore_event_signal_exit_new();
154 if (e)
155 {
156 e->quit = 1;
157 _ecore_event_add(ECORE_EVENT_SIGNAL_EXIT, e,
158 _ecore_event_signal_exit_free, NULL);
159 }
160 sigquit_count--;
161 sig_count--;
162 }
163 while (sigint_count > 0)
164 {
165 Ecore_Event_Signal_Exit *e;
166
167 e = _ecore_event_signal_exit_new();
168 if (e)
169 {
170 e->interrupt = 1;
171 _ecore_event_add(ECORE_EVENT_SIGNAL_EXIT, e,
172 _ecore_event_signal_exit_free, NULL);
173 }
174 sigint_count--;
175 sig_count--;
176 }
177 while (sigterm_count > 0)
178 {
179 Ecore_Event_Signal_Exit *e;
180
181 e = _ecore_event_signal_exit_new();
182 if (e)
183 {
184 e->terminate = 1;
185 _ecore_event_add(ECORE_EVENT_SIGNAL_EXIT, e,
186 _ecore_event_signal_exit_free, NULL);
187 }
188 sigterm_count--;
189 sig_count--;
190 }
191 while (sigpwr_count > 0)
192 {
193 Ecore_Event_Signal_Power *e;
194
195 e = _ecore_event_signal_power_new();
196 if (e)
197 {
198 _ecore_event_add(ECORE_EVENT_SIGNAL_POWER, e,
199 _ecore_event_signal_power_free, NULL);
200 }
201 sigpwr_count--;
202 sig_count--;
203 }
204}
205
206static void
207_ecore_signal_callback_set(int sig, void (*func)(int sig))
208{
209 struct sigaction sa;
210
211 sa.sa_handler = func;
212 sa.sa_flags = SA_RESTART;
213 sigemptyset(&sa.sa_mask);
214 sigaction(sig, &sa, NULL);
215}
216
217static void
218_ecore_signal_callback_ignore(int sig)
219{
220}
221
222static void
223_ecore_signal_callback_sigchld(int sig)
224{
225 sigchld_count++;
226 sig_count++;
227}
228
229static void
230_ecore_signal_callback_sigusr1(int sig)
231{
232 sigusr1_count++;
233 sig_count++;
234}
235
236static void
237_ecore_signal_callback_sigusr2(int sig)
238{
239 sigusr2_count++;
240 sig_count++;
241}
242
243static void
244_ecore_signal_callback_sighup(int sig)
245{
246 sighup_count++;
247 sig_count++;
248}
249
250static void
251_ecore_signal_callback_sigquit(int sig)
252{
253 sigquit_count++;
254 sig_count++;
255}
256
257static void
258_ecore_signal_callback_sigint(int sig)
259{
260 sigint_count++;
261 sig_count++;
262}
263
264static void
265_ecore_signal_callback_sigterm(int sig)
266{
267 sigterm_count++;
268 sig_count++;
269}
270
271static void
272_ecore_signal_callback_sigpwr(int sig)
273{
274 sigpwr_count++;
275 sig_count++;
276}
diff --git a/legacy/ecore/src/lib/ecore/ecore_time.c b/legacy/ecore/src/lib/ecore/ecore_time.c
new file mode 100644
index 0000000000..749859399d
--- /dev/null
+++ b/legacy/ecore/src/lib/ecore/ecore_time.c
@@ -0,0 +1,22 @@
1#include "ecore_private.h"
2#include "Ecore.h"
3
4#include <sys/time.h>
5
6/**
7 * Get the current system time as a floating point value in seconds.
8 * @return The current time (since the epoch start) in seconds
9 *
10 * This function returns the current system time in seconds from 12:00am
11 * 1st Janruary 1970. The time is returned as a double precision floating point
12 * value to allow for fractions of a second to be determined.
13 * <hr><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
14 */
15double
16ecore_time_get(void)
17{
18 struct timeval timev;
19
20 gettimeofday(&timev, NULL);
21 return (double)timev.tv_sec + (((double)timev.tv_usec) / 1000000);
22}
diff --git a/legacy/ecore/src/lib/ecore/ecore_timer.c b/legacy/ecore/src/lib/ecore/ecore_timer.c
new file mode 100644
index 0000000000..0965a7aa20
--- /dev/null
+++ b/legacy/ecore/src/lib/ecore/ecore_timer.c
@@ -0,0 +1,231 @@
1#include "ecore_private.h"
2#include "Ecore.h"
3
4/* FIXME: write code for timers... */
5
6static void _ecore_timer_set(Ecore_Timer *timer, double at, double in, int (*func) (void *data), void *data);
7
8static int timers_added = 0;
9static int timers_delete_me = 0;
10static Ecore_Timer *timers = NULL;
11
12/**
13 * Add a timer to tick off in a specified time during main loop execution.
14 * @param in The number of seconds in which to expire the timer
15 * @param func The function to call when it expires
16 * @param data The data to pass to the function
17 * @return
18 *
19 * This function adds a timer and returns its handle on success and NULL on
20 * failure. The function @p func will be called in @p in seconds from the
21 * time this function call was made. The function @p func is passed the
22 * @p data pointer as its parameter.
23 *
24 * When the timer @p func is called, it must return a value of either 1 or 0.
25 * If it returns 1, it will be re-scheduled to repeat in the same interval
26 * after this timer was triggered (ie if this timer was triggered with an
27 * @p in value of 1.0 then the next timer will be triggered at the time this
28 * timer was called plus 1.0).
29 *
30 * @code
31 * #include <Ecore.h>
32 *
33 * Ecore_Timer *timer1 = NULL, *timer2 = NULL, *timer3 = NULL;
34 *
35 * int timer_tick(void *data)
36 * {
37 * printf("Tick timer %3.2f\n", ecore_time_get());
38 * return 1;
39 * }
40 *
41 * int timer_repeat(void *data)
42 * {
43 * printf("Repeat timer called at %3.2f seconds, data %p\n",
44 * ecore_time_get(), data);
45 * return 1;
46 * }
47 *
48 * int timer_once(void *data)
49 * {
50 * printf("Once only timer called at %3.2f seconds, data %p\n",
51 * ecore_time_get(), data);
52 * ecore_timer_del(timer2);
53 * return 0;
54 * }
55 *
56 * int main(int argc, char **argv)
57 * {
58 * ecore_init();
59 * ecore_app_args_set(argc, argv);
60 * timer1 = ecore_timer_add(5.0, timer_once, NULL);
61 * timer2 = ecore_timer_add(0.5, timer_repeat, NULL);
62 * timer3 = ecore_timer_add(1.0, timer_tick, NULL);
63 * ecore_main_loop_begin();
64 * ecore_shutdown();
65 * }
66 * @endcode
67 * <hr><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
68 */
69Ecore_Timer *
70ecore_timer_add(double in, int (*func) (void *data), const void *data)
71{
72 double now;
73 Ecore_Timer *timer;
74
75 if (!func) return NULL;
76 if (in < 0.0) in = 0.0;
77 timer = calloc(1, sizeof(Ecore_Timer));
78 if (!timer) return NULL;
79 ECORE_MAGIC_SET(timer, ECORE_MAGIC_TIMER);
80 now = ecore_time_get();
81 _ecore_timer_set(timer, now + in, in, func, (void *)data);
82 return timer;
83}
84
85/**
86 * Delete the specified timer from the timer list.
87 * @param timer
88 * @return The data pointer set for the timer
89 *
90 * Delete the specified @p timer from the set of timers that are executed
91 * during main loop execution. This function returns the data parameter that
92 * was being passed to the callback on success, or NULL on failure. After this
93 * call returns the specified timer object @p timer is invalid and should not
94 * be used again. It will not get called again after deletion.
95 * <hr><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
96 */
97void *
98ecore_timer_del(Ecore_Timer *timer)
99{
100 if (!ECORE_MAGIC_CHECK(timer, ECORE_MAGIC_TIMER))
101 {
102 ECORE_MAGIC_FAIL(timer, ECORE_MAGIC_TIMER,
103 "ecore_timer_del");
104 return NULL;
105 }
106 if (timer->delete_me) return timer->data;
107 timers_delete_me++;
108 timer->delete_me = 1;
109 return timer->data;
110}
111
112void
113_ecore_timer_shutdown(void)
114{
115 while (timers)
116 {
117 Ecore_Timer *timer;
118
119 timer = timers;
120 timers = _ecore_list_remove(timers, timer);
121 ECORE_MAGIC_SET(timer, ECORE_MAGIC_NONE);
122 free(timer);
123 }
124}
125
126void
127_ecore_timer_cleanup(void)
128{
129 Ecore_List *l;
130
131 if (!timers_delete_me) return;
132 for (l = (Ecore_List *)timers; l;)
133 {
134 Ecore_Timer *timer;
135
136 timer = (Ecore_Timer *)l;
137 l = l->next;
138 if (timer->delete_me)
139 {
140 timers = _ecore_list_remove(timers, timer);
141 ECORE_MAGIC_SET(timer, ECORE_MAGIC_NONE);
142 free(timer);
143 timers_delete_me--;
144 if (timers_delete_me == 0) return;
145 }
146 }
147 timers_delete_me = 0;
148}
149
150void
151_ecore_timer_enable_new(void)
152{
153 Ecore_List *l;
154
155 if (!timers_added) return;
156 timers_added = 0;
157 for (l = (Ecore_List *)timers; l; l = l->next)
158 {
159 Ecore_Timer *timer;
160
161 timer = (Ecore_Timer *)l;
162 timer->just_added = 0;
163 }
164}
165
166double
167_ecore_timer_next_get(void)
168{
169 double now;
170 double in;
171
172 if (!timers) return -1;
173 now = ecore_time_get();
174 in = timers->at - now;
175 if (in < 0) in = 0;
176 return in;
177}
178
179int
180_ecore_timer_call(double when)
181{
182 Ecore_List *l;
183 Ecore_Timer *timer;
184
185 if (!timers) return 0;
186 for (l = (Ecore_List *)timers; l; l = l->next)
187 {
188 timer = (Ecore_Timer *)l;
189 if ((timer->at <= when) &&
190 (!timer->just_added) &&
191 (!timer->delete_me))
192 {
193 timers = _ecore_list_remove(timers, timer);
194 _ecore_timer_call(when);
195 if (timer->func(timer->data))
196 _ecore_timer_set(timer, timer->at + timer->in, timer->in, timer->func, timer->data);
197 else
198 free(timer);
199 return 1;
200 }
201 }
202 return 0;
203}
204
205static void
206_ecore_timer_set(Ecore_Timer *timer, double at, double in, int (*func) (void *data), void *data)
207{
208 Ecore_List *l;
209
210 timers_added = 1;
211 timer->at = at;
212 timer->in = in;
213 timer->func = func;
214 timer->data = data;
215 timer->just_added = 1;
216 if (timers)
217 {
218 for (l = ((Ecore_List *)(timers))->last; l; l = l->prev)
219 {
220 Ecore_Timer *t2;
221
222 t2 = (Ecore_Timer *)l;
223 if (timer->at > t2->at)
224 {
225 timers = _ecore_list_append_relative(timers, timer, t2);
226 return;
227 }
228 }
229 }
230 timers = _ecore_list_prepend(timers, timer);
231}
diff --git a/legacy/ecore/src/lib/ecore_con/Ecore_Con.h b/legacy/ecore/src/lib/ecore_con/Ecore_Con.h
new file mode 100644
index 0000000000..56b2a430f3
--- /dev/null
+++ b/legacy/ecore/src/lib/ecore_con/Ecore_Con.h
@@ -0,0 +1,90 @@
1#ifndef _ECORE_CON_H
2#define _ECORE_CON_H
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8#ifndef _ECORE_CON_PRIVATE_H
9 typedef void Ecore_Con_Server; /**< A connection handle */
10 typedef void Ecore_Con_Client; /**< A connection handle */
11
12 typedef enum _Ecore_Con_Type
13 {
14 ECORE_CON_LOCAL_USER,
15 ECORE_CON_LOCAL_SYSTEM,
16 ECORE_CON_REMOTE_SYSTEM,
17 } Ecore_Con_Type;
18
19#endif
20
21 typedef struct _Ecore_Con_Event_Client_Add Ecore_Con_Event_Client_Add;
22 typedef struct _Ecore_Con_Event_Client_Del Ecore_Con_Event_Client_Del;
23 typedef struct _Ecore_Con_Event_Server_Add Ecore_Con_Event_Server_Add;
24 typedef struct _Ecore_Con_Event_Server_Del Ecore_Con_Event_Server_Del;
25 typedef struct _Ecore_Con_Event_Client_Data Ecore_Con_Event_Client_Data;
26 typedef struct _Ecore_Con_Event_Server_Data Ecore_Con_Event_Server_Data;
27
28 struct _Ecore_Con_Event_Client_Add
29 {
30 Ecore_Con_Client *client;
31 };
32
33 struct _Ecore_Con_Event_Client_Del
34 {
35 Ecore_Con_Client *client;
36 };
37
38 struct _Ecore_Con_Event_Server_Add
39 {
40 Ecore_Con_Server *server;
41 };
42
43 struct _Ecore_Con_Event_Server_Del
44 {
45 Ecore_Con_Server *server;
46 };
47
48 struct _Ecore_Con_Event_Client_Data
49 {
50 Ecore_Con_Client *client;
51 void *data;
52 int size;
53 };
54
55 struct _Ecore_Con_Event_Server_Data
56 {
57 Ecore_Con_Server *server;
58 void *data;
59 int size;
60 };
61
62 extern int ECORE_CON_EVENT_CLIENT_ADD;
63 extern int ECORE_CON_EVENT_CLIENT_DEL;
64 extern int ECORE_CON_EVENT_SERVER_ADD;
65 extern int ECORE_CON_EVENT_SERVER_DEL;
66 extern int ECORE_CON_EVENT_CLIENT_DATA;
67 extern int ECORE_CON_EVENT_SERVER_DATA;
68
69 int ecore_con_init(void);
70 int ecore_con_shutdown(void);
71
72 Ecore_Con_Server *ecore_con_server_add(Ecore_Con_Type type, char *name, int port, const void *data);
73
74 Ecore_Con_Server *ecore_con_server_connect(Ecore_Con_Type type, char *name, int port, const void *data);
75 void *ecore_con_server_del(Ecore_Con_Server *svr);
76 void *ecore_con_server_data_get(Ecore_Con_Server *svr);
77 int ecore_con_server_connected_get(Ecore_Con_Server *svr);
78 int ecore_con_server_send(Ecore_Con_Server *svr, void *data, int size);
79
80 int ecore_con_client_send(Ecore_Con_Client *cl, void *data, int size);
81 Ecore_Con_Server *ecore_con_client_server_get(Ecore_Con_Client *cl);
82 void *ecore_con_client_del(Ecore_Con_Client *cl);
83 void ecore_con_client_data_set(Ecore_Con_Client *cl, const void *data);
84 void *ecore_con_client_data_get(Ecore_Con_Client *cl);
85
86#ifdef __cplusplus
87}
88#endif
89
90#endif
diff --git a/legacy/ecore/src/lib/ecore_con/Makefile.am b/legacy/ecore/src/lib/ecore_con/Makefile.am
new file mode 100644
index 0000000000..fb9fa6b8bf
--- /dev/null
+++ b/legacy/ecore/src/lib/ecore_con/Makefile.am
@@ -0,0 +1,30 @@
1## Process this file with automake to produce Makefile.in
2
3INCLUDES = \
4-I$(top_srcdir)/src/lib/ecore
5
6libecore_con_la_LDFLAGS = -version-info 1:0:0 \
7-L$(top_builddir)/src/lib/ecore/.libs
8
9if BUILD_ECORE_CON
10
11lib_LTLIBRARIES = libecore_con.la
12include_HEADERS = \
13Ecore_Con.h
14
15libecore_con_la_SOURCES = \
16ecore_con.c \
17ecore_con_private.h
18
19libecore_con_la_LIBADD = \
20$(top_builddir)/src/lib/ecore/libecore.la
21
22libecore_con_la_DEPENDENCIES = \
23$(top_builddir)/src/lib/ecore/libecore.la
24
25endif
26
27EXTRA_DIST = \
28Ecore_Con.h \
29ecore_con.c \
30ecore_con_private.h
diff --git a/legacy/ecore/src/lib/ecore_con/ecore_con.c b/legacy/ecore/src/lib/ecore_con/ecore_con.c
new file mode 100644
index 0000000000..3afc0ffe5b
--- /dev/null
+++ b/legacy/ecore/src/lib/ecore_con/ecore_con.c
@@ -0,0 +1,957 @@
1#include "Ecore.h"
2#include "ecore_private.h"
3#include "ecore_con_private.h"
4#include "Ecore_Con.h"
5
6#include <sys/types.h>
7#include <sys/stat.h>
8#include <arpa/inet.h>
9#include <sys/socket.h>
10#include <sys/un.h>
11#include <errno.h>
12#include <unistd.h>
13#include <stdlib.h>
14#include <fcntl.h>
15#include <netdb.h>
16
17static void _ecore_con_server_free(Ecore_Con_Server *svr);
18static void _ecore_con_client_free(Ecore_Con_Client *cl);
19static int _ecore_con_svr_handler(void *data, Ecore_Fd_Handler *fd_handler);
20static int _ecore_con_cl_handler(void *data, Ecore_Fd_Handler *fd_handler);
21static int _ecore_con_svr_cl_handler(void *data, Ecore_Fd_Handler *fd_handler);
22static void _ecore_con_server_flush(Ecore_Con_Server *svr);
23static void _ecore_con_client_flush(Ecore_Con_Client *cl);
24static void _ecore_con_event_client_add_free(void *data, void *ev);
25static void _ecore_con_event_client_del_free(void *data, void *ev);
26static void _ecore_con_event_server_add_free(void *data, void *ev);
27static void _ecore_con_event_server_del_free(void *data, void *ev);
28static void _ecore_con_event_client_data_free(void *data, void *ev);
29static void _ecore_con_event_server_data_free(void *data, void *ev);
30
31int ECORE_CON_EVENT_CLIENT_ADD = 0;
32int ECORE_CON_EVENT_CLIENT_DEL = 0;
33int ECORE_CON_EVENT_SERVER_ADD = 0;
34int ECORE_CON_EVENT_SERVER_DEL = 0;
35int ECORE_CON_EVENT_CLIENT_DATA = 0;
36int ECORE_CON_EVENT_SERVER_DATA = 0;
37
38static Ecore_Con_Server *servers = NULL;
39static int init_count = 0;
40
41#define LENGTH_OF_SOCKADDR_UN(s) (strlen((s)->sun_path) + (size_t)(((struct sockaddr_un *)NULL)->sun_path))
42
43/**
44 * To be documented.
45 *
46 * FIXME: To be fixed.
47 * <hr><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
48 */
49int
50ecore_con_init(void)
51{
52 init_count++;
53 if (!ECORE_CON_EVENT_CLIENT_ADD)
54 {
55 ECORE_CON_EVENT_CLIENT_ADD = ecore_event_type_new();
56 ECORE_CON_EVENT_CLIENT_DEL = ecore_event_type_new();
57 ECORE_CON_EVENT_SERVER_ADD = ecore_event_type_new();
58 ECORE_CON_EVENT_SERVER_DEL = ecore_event_type_new();
59 ECORE_CON_EVENT_CLIENT_DATA = ecore_event_type_new();
60 ECORE_CON_EVENT_SERVER_DATA = ecore_event_type_new();
61 }
62 return init_count;
63}
64
65/**
66 * To be documented.
67 *
68 * FIXME: To be fixed.
69 * <hr><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
70 */
71int
72ecore_con_shutdown(void)
73{
74 if (init_count > 0)
75 {
76 init_count--;
77 if (init_count > 0) return init_count;
78 while (servers) _ecore_con_server_free(servers);
79 }
80 return 0;
81}
82
83/**
84 * To be documented.
85 *
86 * FIXME: To be fixed.
87 * <hr><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
88 */
89Ecore_Con_Server *
90ecore_con_server_add(Ecore_Con_Type type,
91 char *name,
92 int port,
93 const void *data)
94{
95 Ecore_Con_Server *svr;
96 struct sockaddr_in socket_addr;
97 struct sockaddr_un socket_unix;
98 struct linger lin;
99 char buf[4096];
100
101 if (port < 0) return NULL;
102 /* local user socket: FILE: ~/.ecore/[name]/[port] */
103 /* local system socket: FILE: /tmp/.ecore_service|[name]|[port] */
104 /* remote system socket: TCP/IP: [name]:[port] */
105 svr = calloc(1, sizeof(Ecore_Con_Server));
106 if (!svr) return NULL;
107
108 if ((type == ECORE_CON_LOCAL_USER) ||
109 (type == ECORE_CON_LOCAL_SYSTEM))
110 {
111 char *homedir;
112 struct stat st;
113 mode_t pmode, mask;
114
115 if (!name) goto error;
116 mask =
117 S_IRGRP | S_IWGRP | S_IXGRP |
118 S_IROTH | S_IWOTH | S_IXOTH;
119 if (type == ECORE_CON_LOCAL_USER)
120 {
121 homedir = getenv("HOME");
122 if (!homedir) homedir = getenv("TMP");
123 if (!homedir) homedir = "/tmp";
124 mask = S_IRUSR | S_IWUSR | S_IXUSR;
125 snprintf(buf, sizeof(buf), "%s/.ecore", homedir);
126 if (stat(buf, &st) < 0) mkdir(buf, mask);
127 snprintf(buf, sizeof(buf), "%s/.ecore/%s", homedir, name);
128 if (stat(buf, &st) < 0) mkdir(buf, mask);
129 snprintf(buf, sizeof(buf), "%s/.ecore/%s/%i", homedir, name, port);
130 mask =
131 S_IRGRP | S_IWGRP | S_IXGRP |
132 S_IROTH | S_IWOTH | S_IXOTH;
133 }
134 else if (type == ECORE_CON_LOCAL_SYSTEM)
135 {
136 mask = 0;
137 snprintf(buf, sizeof(buf), "/tmp/.ecore_service|%s|%i", name, port);
138 }
139 pmode = umask(mask);
140 svr->fd = socket(AF_UNIX, SOCK_STREAM, 0);
141 if (svr->fd < 0)
142 {
143 umask(pmode);
144 goto error;
145 }
146 if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0)
147 {
148 umask(pmode);
149 goto error;
150 }
151 if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0)
152 {
153 umask(pmode);
154 goto error;
155 }
156 lin.l_onoff = 1;
157 lin.l_linger = 100;
158 if (setsockopt(svr->fd, SOL_SOCKET, SO_LINGER, &lin, sizeof(struct linger)) < 0)
159 {
160 umask(pmode);
161 goto error;
162 }
163 socket_unix.sun_family = AF_UNIX;
164 strncpy(socket_unix.sun_path, buf, sizeof(socket_unix.sun_path));
165 if (bind(svr->fd, (struct sockaddr *)&socket_unix, LENGTH_OF_SOCKADDR_UN(&socket_unix)) < 0)
166 {
167 umask(pmode);
168 goto error;
169 }
170 if (listen(svr->fd, 4096) < 0)
171 {
172 umask(pmode);
173 goto error;
174 }
175 svr->path = strdup(buf);
176 if (!svr->path)
177 {
178 umask(pmode);
179 goto error;
180 }
181 svr->fd_handler = ecore_main_fd_handler_add(svr->fd,
182 ECORE_FD_READ,
183 _ecore_con_svr_handler, svr,
184 NULL, NULL);
185 umask(pmode);
186 if (!svr->fd_handler) goto error;
187 }
188 else if (type == ECORE_CON_REMOTE_SYSTEM)
189 {
190 svr->fd = socket(AF_INET, SOCK_STREAM, 0);
191 if (svr->fd < 0) goto error;
192 if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
193 if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
194 lin.l_onoff = 1;
195 lin.l_linger = 100;
196 if (setsockopt(svr->fd, SOL_SOCKET, SO_LINGER, &lin, sizeof(struct linger)) < 0) goto error;
197 socket_addr.sin_family = AF_INET;
198 socket_addr.sin_port = htons(port);
199 socket_addr.sin_addr.s_addr = htonl(INADDR_ANY);
200 if (bind(svr->fd, (struct sockaddr *)&socket_addr, sizeof(struct sockaddr_in)) < 0) goto error;
201 if (listen(svr->fd, 4096) < 0) goto error;
202 svr->fd_handler = ecore_main_fd_handler_add(svr->fd,
203 ECORE_FD_READ,
204 _ecore_con_svr_handler, svr,
205 NULL, NULL);
206 if (!svr->fd_handler) goto error;
207 }
208
209 svr->name = strdup(name);
210 if (!svr->name) goto error;
211 svr->type = type;
212 svr->port = port;
213 svr->data = (void *)data;
214 svr->created = 1;
215 servers = _ecore_list_append(servers, svr);
216 ECORE_MAGIC_SET(svr, ECORE_MAGIC_CON_SERVER);
217 return svr;
218
219 error:
220 if (svr->name) free(svr->name);
221 if (svr->path) free(svr->path);
222 if (svr->fd >= 0) close(svr->fd);
223 if (svr->fd_handler) ecore_main_fd_handler_del(svr->fd_handler);
224 if (svr->buf) free(svr->buf);
225 free(svr);
226 return NULL;
227}
228
229/**
230 * To be documented.
231 *
232 * FIXME: To be fixed.
233 * <hr><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
234 */
235Ecore_Con_Server *
236ecore_con_server_connect(Ecore_Con_Type type,
237 char *name,
238 int port,
239 const void *data)
240{
241 Ecore_Con_Server *svr;
242 struct sockaddr_un socket_unix;
243 struct sockaddr_in socket_addr;
244 int curstate;
245 char buf[4096];
246
247 if (!name) return NULL;
248 if (port < 0) return NULL;
249 /* local user socket: FILE: ~/.ecore/[name]/[port] */
250 /* local system socket: FILE: /tmp/.ecore_service|[name]|[port] */
251 /* remote system socket: TCP/IP: [name]:[port] */
252 svr = calloc(1, sizeof(Ecore_Con_Server));
253 if (!svr) return NULL;
254
255 if ((type == ECORE_CON_LOCAL_USER) ||
256 (type == ECORE_CON_LOCAL_SYSTEM))
257 {
258 char *homedir;
259
260 if (type == ECORE_CON_LOCAL_USER)
261 {
262 homedir = getenv("HOME");
263 if (!homedir) homedir = getenv("TMP");
264 if (!homedir) homedir = "/tmp";
265 snprintf(buf, sizeof(buf), "%s/.ecore/%s/%i", homedir, name, port);
266 }
267 else if (type == ECORE_CON_LOCAL_SYSTEM)
268 snprintf(buf, sizeof(buf), "/tmp/.ecore_service|%s|%i", name, port);
269 svr->fd = socket(AF_UNIX, SOCK_STREAM, 0);
270 if (svr->fd < 0) goto error;
271 if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
272 if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
273 if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, &curstate, sizeof(curstate)) < 0) goto error;
274 socket_unix.sun_family = AF_UNIX;
275 strncpy(socket_unix.sun_path, buf, sizeof(socket_unix.sun_path));
276 if (connect(svr->fd, (struct sockaddr *)&socket_unix, LENGTH_OF_SOCKADDR_UN(&socket_unix)) < 0) goto error;
277 svr->path = strdup(buf);
278 if (!svr->path) goto error;
279 svr->fd_handler = ecore_main_fd_handler_add(svr->fd,
280 ECORE_FD_READ,
281 _ecore_con_cl_handler, svr,
282 NULL, NULL);
283 if (!svr->fd_handler) goto error;
284 {
285 /* we got our server! */
286 Ecore_Con_Event_Server_Add *e;
287
288 e = calloc(1, sizeof(Ecore_Con_Event_Server_Add));
289 if (e)
290 {
291 e->server = svr;
292 ecore_event_add(ECORE_CON_EVENT_SERVER_ADD, e,
293 _ecore_con_event_server_add_free, NULL);
294 }
295 }
296 }
297 else if (type == ECORE_CON_REMOTE_SYSTEM)
298 {
299 struct hostent *he;
300
301 /* FIXME: gethostbyname is blocking... */
302 if (!(he = gethostbyname(name))) goto error;
303 svr->fd = socket(AF_INET, SOCK_STREAM, 0);
304 if (svr->fd < 0) goto error;
305 if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
306 if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
307 if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, &curstate, sizeof(curstate)) < 0) goto error;
308 socket_addr.sin_family = AF_INET;
309 socket_addr.sin_port = htons(port);
310 memcpy((struct in_addr *)&socket_addr.sin_addr,
311 he->h_addr, sizeof(struct in_addr));
312 if (connect(svr->fd, (struct sockaddr *)&socket_addr, sizeof(struct sockaddr_in)) < 0)
313 {
314 if (errno != EINPROGRESS)
315 goto error;
316 svr->connecting = 1;
317 svr->fd_handler = ecore_main_fd_handler_add(svr->fd,
318 ECORE_FD_READ | ECORE_FD_WRITE,
319 _ecore_con_cl_handler, svr,
320 NULL, NULL);
321 }
322 else
323 svr->fd_handler = ecore_main_fd_handler_add(svr->fd,
324 ECORE_FD_READ,
325 _ecore_con_cl_handler, svr,
326 NULL, NULL);
327 if (!svr->fd_handler) goto error;
328 }
329
330 svr->name = strdup(name);
331 if (!svr->name) goto error;
332 svr->type = type;
333 svr->port = port;
334 svr->data = (void *)data;
335 svr->created = 0;
336 servers = _ecore_list_append(servers, svr);
337 ECORE_MAGIC_SET(svr, ECORE_MAGIC_CON_SERVER);
338 return svr;
339
340 error:
341 if (svr->name) free(svr->name);
342 if (svr->path) free(svr->path);
343 if (svr->fd >= 0) close(svr->fd);
344 if (svr->fd_handler) ecore_main_fd_handler_del(svr->fd_handler);
345 free(svr);
346 return NULL;
347}
348
349/**
350 * To be documented.
351 *
352 * FIXME: To be fixed.
353 * <hr><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
354 */
355void *
356ecore_con_server_del(Ecore_Con_Server *svr)
357{
358 void *data;
359
360 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
361 {
362 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER,
363 "ecore_con_server_del");
364 return NULL;
365 }
366 data = svr->data;
367 _ecore_con_server_free(svr);
368 return data;
369}
370
371/**
372 * To be documented.
373 *
374 * FIXME: To be fixed.
375 * <hr><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
376 */
377void *
378ecore_con_server_data_get(Ecore_Con_Server *svr)
379{
380 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
381 {
382 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER,
383 "ecore_con_server_data_get");
384 return NULL;
385 }
386 return svr->data;
387}
388
389/**
390 * To be documented.
391 *
392 * FIXME: To be fixed.
393 * <hr><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
394 */
395int
396ecore_con_server_connected_get(Ecore_Con_Server *svr)
397{
398 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
399 {
400 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER,
401 "ecore_con_server_connected_get");
402 return 0;
403 }
404 if (svr->connecting) return 0;
405 return 1;
406}
407
408/**
409 * To be documented.
410 *
411 * FIXME: To be fixed.
412 * <hr><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
413 */
414int
415ecore_con_server_send(Ecore_Con_Server *svr, void *data, int size)
416{
417 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
418 {
419 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER,
420 "ecore_con_server_send");
421 return 0;
422 }
423 if (svr->dead) return 1;
424 if (!data) return 0;
425 if (size < 1) return 0;
426 ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ | ECORE_FD_WRITE);
427 if (svr->buf)
428 {
429 unsigned char *newbuf;
430
431 newbuf = realloc(svr->buf, svr->buf_size + size);
432 if (newbuf) svr->buf = newbuf;
433 else return 0;
434 memcpy(svr->buf + svr->buf_size, data, size);
435 svr->buf_size += size;
436 }
437 else
438 {
439 svr->buf = malloc(size);
440 if (!svr->buf) return 0;
441 svr->buf_size = size;
442 memcpy(svr->buf, data, size);
443 }
444 _ecore_con_server_flush(svr);
445 return 1;
446}
447
448/**
449 * To be documented.
450 *
451 * FIXME: To be fixed.
452 * <hr><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
453 */
454int
455ecore_con_client_send(Ecore_Con_Client *cl, void *data, int size)
456{
457 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
458 {
459 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT,
460 "ecore_con_client_send");
461 return 0;
462 }
463 if (cl->dead) return 0;
464 if (!data) return 0;
465 if (size < 1) return 0;
466 ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_READ | ECORE_FD_WRITE);
467 if (cl->buf)
468 {
469 unsigned char *newbuf;
470
471 newbuf = realloc(cl->buf, cl->buf_size + size);
472 if (newbuf) cl->buf = newbuf;
473 else return 0;
474 memcpy(cl->buf + cl->buf_size, data, size);
475 cl->buf_size += size;
476 }
477 else
478 {
479 cl->buf = malloc(size);
480 if (!cl->buf) return 0;
481 cl->buf_size = size;
482 memcpy(cl->buf, data, size);
483 }
484 _ecore_con_client_flush(cl);
485 return 1;
486}
487
488/**
489 * To be documented.
490 *
491 * FIXME: To be fixed.
492 * <hr><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
493 */
494Ecore_Con_Server *
495ecore_con_client_server_get(Ecore_Con_Client *cl)
496{
497 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
498 {
499 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT,
500 "ecore_con_client_server_get");
501 return NULL;
502 }
503 return cl->server;
504}
505
506/**
507 * To be documented.
508 *
509 * FIXME: To be fixed.
510 * <hr><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
511 */
512void *
513ecore_con_client_del(Ecore_Con_Client *cl)
514{
515 void *data;
516
517 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
518 {
519 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT,
520 "ecore_con_client_del");
521 return NULL;
522 }
523 data = cl->data;
524 _ecore_con_client_free(cl);
525 return cl->data;
526}
527
528/**
529 * To be documented.
530 *
531 * FIXME: To be fixed.
532 * <hr><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
533 */
534void
535ecore_con_client_data_set(Ecore_Con_Client *cl, const void *data)
536{
537 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
538 {
539 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT,
540 "ecore_con_client_data_set");
541 return;
542 }
543 cl->data = (void *)data;
544}
545
546/**
547 * To be documented.
548 *
549 * FIXME: To be fixed.
550 * <hr><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
551 */
552void *
553ecore_con_client_data_get(Ecore_Con_Client *cl)
554{
555 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
556 {
557 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT,
558 "ecore_con_client_data_get");
559 return NULL;
560 }
561 return cl->data;
562}
563
564static void
565_ecore_con_server_free(Ecore_Con_Server *svr)
566{
567 ECORE_MAGIC_SET(svr, ECORE_MAGIC_NONE);
568 while ((svr->buf) && (!svr->dead)) _ecore_con_server_flush(svr);
569 if (svr->buf) free(svr->buf);
570 servers = _ecore_list_remove(servers, svr);
571 while (svr->clients)
572 _ecore_con_client_free((Ecore_Con_Client *)svr->clients);
573 if ((svr->created) && (svr->path)) unlink(svr->path);
574 if (svr->fd >= 0) close(svr->fd);
575 if (svr->name) free(svr->name);
576 if (svr->path) free(svr->path);
577 if (svr->fd_handler) ecore_main_fd_handler_del(svr->fd_handler);
578 free(svr);
579}
580
581static void
582_ecore_con_client_free(Ecore_Con_Client *cl)
583{
584 ECORE_MAGIC_SET(cl, ECORE_MAGIC_NONE);
585 while ((cl->buf) && (!cl->dead)) _ecore_con_client_flush(cl);
586 if (cl->buf) free(cl->buf);
587 cl->server->clients = _ecore_list_remove(cl->server->clients, cl);
588 if (cl->fd >= 0) close(cl->fd);
589 if (cl->fd_handler) ecore_main_fd_handler_del(cl->fd_handler);
590 free(cl);
591}
592
593static int
594_ecore_con_svr_handler(void *data, Ecore_Fd_Handler *fd_handler)
595{
596 Ecore_Con_Server *svr;
597 int new_fd;
598 struct sockaddr_in incoming;
599 size_t size_in;
600
601 svr = data;
602 if (svr->dead) return 1;
603 /* a new client */
604 size_in = sizeof(struct sockaddr_in);
605 new_fd = accept(svr->fd, (struct sockaddr *)&incoming, &size_in);
606 if (new_fd >= 0)
607 {
608 Ecore_Con_Client *cl;
609
610 cl = calloc(1, sizeof(Ecore_Con_Client));
611 if (!cl)
612 {
613 close(new_fd);
614 return 1;
615 }
616 fcntl(new_fd, F_SETFL, O_NONBLOCK);
617 fcntl(new_fd, F_SETFD, FD_CLOEXEC);
618 cl->fd = new_fd;
619 cl->server = svr;
620 cl->fd_handler = ecore_main_fd_handler_add(cl->fd,
621 ECORE_FD_READ,
622 _ecore_con_svr_cl_handler, cl,
623 NULL, NULL);
624 ECORE_MAGIC_SET(cl, ECORE_MAGIC_CON_CLIENT);
625 svr->clients = _ecore_list_append(svr->clients, cl);
626 {
627 Ecore_Con_Event_Client_Add *e;
628
629 e = calloc(1, sizeof(Ecore_Con_Event_Client_Add));
630 if (e)
631 {
632 e->client = cl;
633 ecore_event_add(ECORE_CON_EVENT_CLIENT_ADD, e,
634 _ecore_con_event_client_add_free, NULL);
635 }
636 }
637 }
638 return 1;
639}
640
641static int
642_ecore_con_cl_handler(void *data, Ecore_Fd_Handler *fd_handler)
643{
644 Ecore_Con_Server *svr;
645
646 svr = data;
647 if (svr->dead) return 1;
648 if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ))
649 {
650 unsigned char *inbuf = NULL;
651 int inbuf_num = 0;
652
653 for (;;)
654 {
655 char buf[65536];
656 int num;
657
658 num = read(svr->fd, buf, 65536);
659 if (num < 1)
660 {
661 if (inbuf)
662 {
663 Ecore_Con_Event_Server_Data *e;
664
665 e = calloc(1, sizeof(Ecore_Con_Event_Server_Data));
666 if (e)
667 {
668 e->server = svr;
669 e->data = inbuf;
670 e->size = inbuf_num;
671 ecore_event_add(ECORE_CON_EVENT_SERVER_DATA, e,
672 _ecore_con_event_server_data_free, NULL);
673 }
674 }
675 if ((errno == EIO) || (errno == EBADF) ||
676 (errno == EPIPE) || (errno == EINVAL) ||
677 (errno == ENOSPC) || (num == 0)/* is num == 0 right? */)
678 {
679 /* we lost our server! */
680 Ecore_Con_Event_Server_Del *e;
681
682 e = calloc(1, sizeof(Ecore_Con_Event_Server_Del));
683 if (e)
684 {
685 e->server = svr;
686 ecore_event_add(ECORE_CON_EVENT_SERVER_DEL, e,
687 _ecore_con_event_server_del_free, NULL);
688 }
689 svr->dead = 1;
690 ecore_main_fd_handler_del(svr->fd_handler);
691 svr->fd_handler = NULL;
692 }
693 break;
694 }
695 else
696 {
697 inbuf = realloc(inbuf, inbuf_num + num);
698 memcpy(inbuf + inbuf_num, buf, num);
699 inbuf_num += num;
700 }
701 }
702 }
703 else if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE))
704 {
705 if (svr->connecting)
706 {
707 int so_err;
708 socklen_t size;
709
710 svr->connecting = 0;
711 so_err = 0;
712 size = sizeof(int);
713 if (getsockopt(svr->fd, SOL_SOCKET, SO_ERROR, &so_err, &size) < 0) so_err = -1;
714 if (so_err != 0)
715 {
716 /* we lost our server! */
717 Ecore_Con_Event_Server_Del *e;
718
719 e = calloc(1, sizeof(Ecore_Con_Event_Server_Del));
720 if (e)
721 {
722 e->server = svr;
723 ecore_event_add(ECORE_CON_EVENT_SERVER_DEL, e,
724 _ecore_con_event_server_del_free, NULL);
725 }
726 svr->dead = 1;
727 ecore_main_fd_handler_del(svr->fd_handler);
728 svr->fd_handler = NULL;
729 ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ);
730 return 1;
731 }
732 else
733 {
734 {
735 /* we got our server! */
736 Ecore_Con_Event_Server_Add *e;
737
738 e = calloc(1, sizeof(Ecore_Con_Event_Server_Add));
739 if (e)
740 {
741 e->server = svr;
742 ecore_event_add(ECORE_CON_EVENT_SERVER_ADD, e,
743 _ecore_con_event_server_add_free, NULL);
744 }
745 }
746 if (!svr->buf)
747 ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ);
748 }
749 }
750 _ecore_con_server_flush(svr);
751 }
752 return 1;
753}
754
755static int
756_ecore_con_svr_cl_handler(void *data, Ecore_Fd_Handler *fd_handler)
757{
758 Ecore_Con_Client *cl;
759
760 cl = data;
761 if (cl->dead) return 1;