summaryrefslogtreecommitdiff
path: root/src/lib/ecore_file
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <barbieri@gmail.com>2012-12-06 13:38:34 +0000
committerGustavo Sverzut Barbieri <barbieri@gmail.com>2012-12-06 13:38:34 +0000
commit62bb4646c9fee3f535c3810a7cdba114043d14d4 (patch)
treefad3ac78c2163cb5ebebb916c5ca52e3ed5f4ef0 /src/lib/ecore_file
parent6a5eaacc6ada22808ec8515ef2b414883f4f59fe (diff)
efl/ecore_file: refactor to be more like eio in providing backends.
instead of the previous mess, just define the functions with common names and call the backend that was compiled in, similar to what eio does. also do not be silent on errors, use eina_safety_checks to issue warnings. SVN revision: 80360
Diffstat (limited to 'src/lib/ecore_file')
-rw-r--r--src/lib/ecore_file/ecore_file_monitor.c104
-rw-r--r--src/lib/ecore_file/ecore_file_monitor_inotify.c19
-rw-r--r--src/lib/ecore_file/ecore_file_monitor_poll.c15
-rw-r--r--src/lib/ecore_file/ecore_file_monitor_win32.c12
-rw-r--r--src/lib/ecore_file/ecore_file_private.h45
5 files changed, 36 insertions, 159 deletions
diff --git a/src/lib/ecore_file/ecore_file_monitor.c b/src/lib/ecore_file/ecore_file_monitor.c
index ac7d6d4dc3..6b6fb32349 100644
--- a/src/lib/ecore_file/ecore_file_monitor.c
+++ b/src/lib/ecore_file/ecore_file_monitor.c
@@ -4,66 +4,18 @@
4 4
5#include "ecore_file_private.h" 5#include "ecore_file_private.h"
6 6
7typedef enum {
8 ECORE_FILE_MONITOR_TYPE_NONE,
9#ifdef HAVE_SYS_INOTIFY_H
10 ECORE_FILE_MONITOR_TYPE_INOTIFY,
11#endif
12#ifdef HAVE_NOTIFY_WIN32
13 ECORE_FILE_MONITOR_TYPE_NOTIFY_WIN32,
14#endif
15#ifdef HAVE_POLL
16 ECORE_FILE_MONITOR_TYPE_POLL
17#endif
18} Ecore_File_Monitor_Type;
19
20static Ecore_File_Monitor_Type monitor_type = ECORE_FILE_MONITOR_TYPE_NONE;
21
22int 7int
23ecore_file_monitor_init(void) 8ecore_file_monitor_init(void)
24{ 9{
25#ifdef HAVE_SYS_INOTIFY_H 10 if (ecore_file_monitor_backend_init())
26 monitor_type = ECORE_FILE_MONITOR_TYPE_INOTIFY;
27 if (ecore_file_monitor_inotify_init())
28 return 1; 11 return 1;
29#endif
30#ifdef HAVE_NOTIFY_WIN32
31 monitor_type = ECORE_FILE_MONITOR_TYPE_NOTIFY_WIN32;
32 if (ecore_file_monitor_win32_init())
33 return 1;
34#endif
35#ifdef HAVE_POLL
36 monitor_type = ECORE_FILE_MONITOR_TYPE_POLL;
37 if (ecore_file_monitor_poll_init())
38 return 1;
39#endif
40 monitor_type = ECORE_FILE_MONITOR_TYPE_NONE;
41 return 0; 12 return 0;
42} 13}
43 14
44void 15void
45ecore_file_monitor_shutdown(void) 16ecore_file_monitor_shutdown(void)
46{ 17{
47 switch (monitor_type) 18 ecore_file_monitor_backend_shutdown();
48 {
49 case ECORE_FILE_MONITOR_TYPE_NONE:
50 break;
51#ifdef HAVE_SYS_INOTIFY_H
52 case ECORE_FILE_MONITOR_TYPE_INOTIFY:
53 ecore_file_monitor_inotify_shutdown();
54 break;
55#endif
56#ifdef HAVE_NOTIFY_WIN32
57 case ECORE_FILE_MONITOR_TYPE_NOTIFY_WIN32:
58 ecore_file_monitor_win32_shutdown();
59 break;
60#endif
61#ifdef HAVE_POLL
62 case ECORE_FILE_MONITOR_TYPE_POLL:
63 ecore_file_monitor_poll_shutdown();
64 break;
65#endif
66 }
67} 19}
68 20
69/** 21/**
@@ -94,27 +46,11 @@ ecore_file_monitor_add(const char *path,
94 Ecore_File_Monitor_Cb func, 46 Ecore_File_Monitor_Cb func,
95 void *data) 47 void *data)
96{ 48{
97 if (!path || !*path) 49 EINA_SAFETY_ON_NULL_RETURN_VAL(path, NULL);
98 return NULL; 50 EINA_SAFETY_ON_TRUE_RETURN_VAL(path[0] == '\0', NULL);
51 EINA_SAFETY_ON_NULL_RETURN_VAL(func, NULL);
99 52
100 switch (monitor_type) 53 return ecore_file_monitor_backend_add(path, func, data);
101 {
102 case ECORE_FILE_MONITOR_TYPE_NONE:
103 return NULL;
104#ifdef HAVE_SYS_INOTIFY_H
105 case ECORE_FILE_MONITOR_TYPE_INOTIFY:
106 return ecore_file_monitor_inotify_add(path, func, data);
107#endif
108#ifdef HAVE_NOTIFY_WIN32
109 case ECORE_FILE_MONITOR_TYPE_NOTIFY_WIN32:
110 return ecore_file_monitor_win32_add(path, func, data);
111#endif
112#ifdef HAVE_POLL
113 case ECORE_FILE_MONITOR_TYPE_POLL:
114 return ecore_file_monitor_poll_add(path, func, data);
115#endif
116 }
117 return NULL;
118} 54}
119 55
120/** 56/**
@@ -131,29 +67,8 @@ ecore_file_monitor_add(const char *path,
131EAPI void 67EAPI void
132ecore_file_monitor_del(Ecore_File_Monitor *em) 68ecore_file_monitor_del(Ecore_File_Monitor *em)
133{ 69{
134 if (!em) 70 EINA_SAFETY_ON_NULL_RETURN(em);
135 return; 71 ecore_file_monitor_backend_del(em);
136
137 switch (monitor_type)
138 {
139 case ECORE_FILE_MONITOR_TYPE_NONE:
140 break;
141#ifdef HAVE_SYS_INOTIFY_H
142 case ECORE_FILE_MONITOR_TYPE_INOTIFY:
143 ecore_file_monitor_inotify_del(em);
144 break;
145#endif
146#ifdef HAVE_NOTIFY_WIN32
147 case ECORE_FILE_MONITOR_TYPE_NOTIFY_WIN32:
148 ecore_file_monitor_win32_del(em);
149 break;
150#endif
151#ifdef HAVE_POLL
152 case ECORE_FILE_MONITOR_TYPE_POLL:
153 ecore_file_monitor_poll_del(em);
154 break;
155#endif
156 }
157} 72}
158 73
159/** 74/**
@@ -170,8 +85,7 @@ ecore_file_monitor_del(Ecore_File_Monitor *em)
170EAPI const char * 85EAPI const char *
171ecore_file_monitor_path_get(Ecore_File_Monitor *em) 86ecore_file_monitor_path_get(Ecore_File_Monitor *em)
172{ 87{
173 if (!em) 88 EINA_SAFETY_ON_NULL_RETURN_VAL(em, NULL);
174 return NULL;
175 return em->path; 89 return em->path;
176} 90}
177 91
diff --git a/src/lib/ecore_file/ecore_file_monitor_inotify.c b/src/lib/ecore_file/ecore_file_monitor_inotify.c
index 9cb5de83e6..9f9818dcd7 100644
--- a/src/lib/ecore_file/ecore_file_monitor_inotify.c
+++ b/src/lib/ecore_file/ecore_file_monitor_inotify.c
@@ -20,8 +20,6 @@
20 * - Listen to IN_IGNORED, emitted when the watch is removed 20 * - Listen to IN_IGNORED, emitted when the watch is removed
21 */ 21 */
22 22
23#ifdef HAVE_SYS_INOTIFY_H
24
25#include <sys/inotify.h> 23#include <sys/inotify.h>
26 24
27 25
@@ -48,7 +46,7 @@ static void _ecore_file_monitor_inotify_print(char *file, int mas
48#endif 46#endif
49 47
50int 48int
51ecore_file_monitor_inotify_init(void) 49ecore_file_monitor_backend_init(void)
52{ 50{
53 int fd; 51 int fd;
54 52
@@ -69,12 +67,12 @@ ecore_file_monitor_inotify_init(void)
69} 67}
70 68
71int 69int
72ecore_file_monitor_inotify_shutdown(void) 70ecore_file_monitor_backend_shutdown(void)
73{ 71{
74 int fd; 72 int fd;
75 73
76 while(_monitors) 74 while(_monitors)
77 ecore_file_monitor_inotify_del(_monitors); 75 ecore_file_monitor_backend_del(_monitors);
78 76
79 if (_fdh) 77 if (_fdh)
80 { 78 {
@@ -87,7 +85,7 @@ ecore_file_monitor_inotify_shutdown(void)
87} 85}
88 86
89Ecore_File_Monitor * 87Ecore_File_Monitor *
90ecore_file_monitor_inotify_add(const char *path, 88ecore_file_monitor_backend_add(const char *path,
91 void (*func) (void *data, Ecore_File_Monitor *em, 89 void (*func) (void *data, Ecore_File_Monitor *em,
92 Ecore_File_Event event, 90 Ecore_File_Event event,
93 const char *path), 91 const char *path),
@@ -100,8 +98,8 @@ ecore_file_monitor_inotify_add(const char *path,
100 98
101 if (_inotify_fd_pid != getpid()) 99 if (_inotify_fd_pid != getpid())
102 { 100 {
103 ecore_file_monitor_inotify_shutdown(); 101 ecore_file_monitor_backend_shutdown();
104 ecore_file_monitor_inotify_init(); 102 ecore_file_monitor_backend_init();
105 } 103 }
106 104
107 em = calloc(1, sizeof(Ecore_File_Monitor_Inotify)); 105 em = calloc(1, sizeof(Ecore_File_Monitor_Inotify));
@@ -124,7 +122,7 @@ ecore_file_monitor_inotify_add(const char *path,
124} 122}
125 123
126void 124void
127ecore_file_monitor_inotify_del(Ecore_File_Monitor *em) 125ecore_file_monitor_backend_del(Ecore_File_Monitor *em)
128{ 126{
129 int fd; 127 int fd;
130 128
@@ -283,7 +281,7 @@ _ecore_file_monitor_inotify_monitor(Ecore_File_Monitor *em, const char *path)
283 if (ECORE_FILE_MONITOR_INOTIFY(em)->wd < 0) 281 if (ECORE_FILE_MONITOR_INOTIFY(em)->wd < 0)
284 { 282 {
285 INF("inotify_add_watch failed, file was deleted"); 283 INF("inotify_add_watch failed, file was deleted");
286 ecore_file_monitor_inotify_del(em); 284 ecore_file_monitor_backend_del(em);
287 return 0; 285 return 0;
288 } 286 }
289 return 1; 287 return 1;
@@ -328,4 +326,3 @@ _ecore_file_monitor_inotify_print(char *file, int mask)
328 INF("Inotify unmount %s: %s", type, file); 326 INF("Inotify unmount %s: %s", type, file);
329} 327}
330#endif 328#endif
331#endif /* HAVE_SYS_INOTIFY_H */
diff --git a/src/lib/ecore_file/ecore_file_monitor_poll.c b/src/lib/ecore_file/ecore_file_monitor_poll.c
index 68889a74e8..03ac117087 100644
--- a/src/lib/ecore_file/ecore_file_monitor_poll.c
+++ b/src/lib/ecore_file/ecore_file_monitor_poll.c
@@ -8,8 +8,6 @@
8 8
9#include "ecore_file_private.h" 9#include "ecore_file_private.h"
10 10
11#ifdef HAVE_POLL
12
13/* 11/*
14 * TODO: 12 * TODO:
15 * - Implement recursive as an option! 13 * - Implement recursive as an option!
@@ -43,16 +41,16 @@ static void _ecore_file_monitor_poll_check(Ecore_File_Monitor *em);
43static int _ecore_file_monitor_poll_checking(Ecore_File_Monitor *em, char *name); 41static int _ecore_file_monitor_poll_checking(Ecore_File_Monitor *em, char *name);
44 42
45int 43int
46ecore_file_monitor_poll_init(void) 44ecore_file_monitor_backend_init(void)
47{ 45{
48 return 1; 46 return 1;
49} 47}
50 48
51int 49int
52ecore_file_monitor_poll_shutdown(void) 50ecore_file_monitor_backend_shutdown(void)
53{ 51{
54 while(_monitors) 52 while(_monitors)
55 ecore_file_monitor_poll_del(_monitors); 53 ecore_file_monitor_backend_del(_monitors);
56 54
57 if (_timer) 55 if (_timer)
58 { 56 {
@@ -63,7 +61,7 @@ ecore_file_monitor_poll_shutdown(void)
63} 61}
64 62
65Ecore_File_Monitor * 63Ecore_File_Monitor *
66ecore_file_monitor_poll_add(const char *path, 64ecore_file_monitor_backend_add(const char *path,
67 void (*func) (void *data, Ecore_File_Monitor *em, 65 void (*func) (void *data, Ecore_File_Monitor *em,
68 Ecore_File_Event event, 66 Ecore_File_Event event,
69 const char *path), 67 const char *path),
@@ -125,7 +123,7 @@ ecore_file_monitor_poll_add(const char *path,
125 } 123 }
126 else 124 else
127 { 125 {
128 ecore_file_monitor_poll_del(em); 126 ecore_file_monitor_backend_del(em);
129 return NULL; 127 return NULL;
130 } 128 }
131 129
@@ -133,7 +131,7 @@ ecore_file_monitor_poll_add(const char *path,
133} 131}
134 132
135void 133void
136ecore_file_monitor_poll_del(Ecore_File_Monitor *em) 134ecore_file_monitor_backend_del(Ecore_File_Monitor *em)
137{ 135{
138 Ecore_File *l; 136 Ecore_File *l;
139 137
@@ -337,4 +335,3 @@ _ecore_file_monitor_poll_checking(Ecore_File_Monitor *em, char *name)
337 } 335 }
338 return 0; 336 return 0;
339} 337}
340#endif
diff --git a/src/lib/ecore_file/ecore_file_monitor_win32.c b/src/lib/ecore_file/ecore_file_monitor_win32.c
index 7f3af0907b..84ac083cfd 100644
--- a/src/lib/ecore_file/ecore_file_monitor_win32.c
+++ b/src/lib/ecore_file/ecore_file_monitor_win32.c
@@ -6,8 +6,6 @@
6# include <config.h> 6# include <config.h>
7#endif 7#endif
8 8
9#ifdef HAVE_NOTIFY_WIN32
10
11# define WIN32_LEAN_AND_MEAN 9# define WIN32_LEAN_AND_MEAN
12# include <windows.h> 10# include <windows.h>
13# undef WIN32_LEAN_AND_MEAN 11# undef WIN32_LEAN_AND_MEAN
@@ -225,19 +223,19 @@ _ecore_file_monitor_win32_cb(void *data, Ecore_Win32_Handler *wh)
225} 223}
226 224
227int 225int
228ecore_file_monitor_win32_init(void) 226ecore_file_monitor_backend_init(void)
229{ 227{
230 return 1; 228 return 1;
231} 229}
232 230
233int 231int
234ecore_file_monitor_win32_shutdown(void) 232ecore_file_monitor_backend_shutdown(void)
235{ 233{
236 return 1; 234 return 1;
237} 235}
238 236
239Ecore_File_Monitor * 237Ecore_File_Monitor *
240ecore_file_monitor_win32_add(const char *path, 238ecore_file_monitor_backend_add(const char *path,
241 void (*func) (void *data, Ecore_File_Monitor *em, 239 void (*func) (void *data, Ecore_File_Monitor *em,
242 Ecore_File_Event event, 240 Ecore_File_Event event,
243 const char *path), 241 const char *path),
@@ -293,7 +291,7 @@ ecore_file_monitor_win32_add(const char *path,
293} 291}
294 292
295void 293void
296ecore_file_monitor_win32_del(Ecore_File_Monitor *em) 294ecore_file_monitor_backend_del(Ecore_File_Monitor *em)
297{ 295{
298 Ecore_File_Monitor_Win32 *m; 296 Ecore_File_Monitor_Win32 *m;
299 297
@@ -306,5 +304,3 @@ ecore_file_monitor_win32_del(Ecore_File_Monitor *em)
306 free(em->path); 304 free(em->path);
307 free(em); 305 free(em);
308} 306}
309
310#endif
diff --git a/src/lib/ecore_file/ecore_file_private.h b/src/lib/ecore_file/ecore_file_private.h
index 769f2ba014..5a091b3b04 100644
--- a/src/lib/ecore_file/ecore_file_private.h
+++ b/src/lib/ecore_file/ecore_file_private.h
@@ -81,42 +81,15 @@ struct _Ecore_File_Monitor
81 Ecore_File *files; 81 Ecore_File *files;
82}; 82};
83 83
84#ifdef HAVE_SYS_INOTIFY_H 84int ecore_file_monitor_backend_init(void);
85int ecore_file_monitor_inotify_init(void); 85int ecore_file_monitor_backend_shutdown(void);
86int ecore_file_monitor_inotify_shutdown(void); 86Ecore_File_Monitor *ecore_file_monitor_backend_add(const char *path,
87Ecore_File_Monitor *ecore_file_monitor_inotify_add(const char *path, 87 void (*func) (void *data,
88 void (*func) (void *data, 88 Ecore_File_Monitor *ecore_file_monitor,
89 Ecore_File_Monitor *ecore_file_monitor, 89 Ecore_File_Event event,
90 Ecore_File_Event event, 90 const char *path),
91 const char *path), 91 void *data);
92 void *data); 92void ecore_file_monitor_backend_del(Ecore_File_Monitor *ecore_file_monitor);
93void ecore_file_monitor_inotify_del(Ecore_File_Monitor *ecore_file_monitor);
94#endif
95
96#ifdef HAVE_NOTIFY_WIN32
97int ecore_file_monitor_win32_init(void);
98int ecore_file_monitor_win32_shutdown(void);
99Ecore_File_Monitor *ecore_file_monitor_win32_add(const char *path,
100 void (*func) (void *data,
101 Ecore_File_Monitor *ecore_file_monitor,
102 Ecore_File_Event event,
103 const char *path),
104 void *data);
105void ecore_file_monitor_win32_del(Ecore_File_Monitor *ecore_file_monitor);
106#endif
107
108#ifdef HAVE_POLL
109int ecore_file_monitor_poll_init(void);
110int ecore_file_monitor_poll_shutdown(void);
111Ecore_File_Monitor *ecore_file_monitor_poll_add(const char *path,
112 void (*func) (void *data,
113 Ecore_File_Monitor *ecore_file_monitor,
114 Ecore_File_Event event,
115 const char *path),
116 void *data);
117void ecore_file_monitor_poll_del(Ecore_File_Monitor *ecore_file_monitor);
118
119#endif
120 93
121/* ecore_file_path */ 94/* ecore_file_path */
122void ecore_file_path_init(void); 95void ecore_file_path_init(void);