summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichaël Bouchaud (yoz) <yoz@efl.so>2013-10-09 12:29:04 +0200
committerMichaël Bouchaud (yoz) <yoz@efl.so>2013-10-09 12:29:04 +0200
commit4ce3e1e72f600be69702ac918f4ff8a099d49c6d (patch)
tree87d70bce77632b9ddec5a82a7c396933af6c410a /src
parent80bcfac650e286971b9267aca33430908427b6e5 (diff)
emotion: add two events to trigger when a webcam is plugged or unplugged
Diffstat (limited to 'src')
-rw-r--r--src/lib/emotion/Emotion.h4
-rw-r--r--src/lib/emotion/emotion_webcam.c36
2 files changed, 32 insertions, 8 deletions
diff --git a/src/lib/emotion/Emotion.h b/src/lib/emotion/Emotion.h
index 454ee0f42e..34d1cc3af0 100644
--- a/src/lib/emotion/Emotion.h
+++ b/src/lib/emotion/Emotion.h
@@ -1287,7 +1287,9 @@ EAPI Evas_Object *emotion_object_image_get(const Evas_Object *obj);
1287 1287
1288typedef struct _Emotion_Webcam Emotion_Webcam; /**< Webcam description */ 1288typedef struct _Emotion_Webcam Emotion_Webcam; /**< Webcam description */
1289 1289
1290EAPI extern int EMOTION_WEBCAM_UPDATE; /**< Ecore_Event triggered when a new webcam is plugged in */ 1290EAPI extern int EMOTION_WEBCAM_UPDATE; /**< Ecore_Event triggered when a new webcam is plugged or unplugged */
1291EAPI extern int EMOTION_WEBCAM_ADD; /**< Ecore_Event triggered when a new webcam is plugged in @since 1.8*/
1292EAPI extern int EMOTION_WEBCAM_DEL; /**< Ecore_Event triggered when a webcam is unplugged @since 1.8 */
1291 1293
1292/** 1294/**
1293 * @brief Get a list of active and available webcam 1295 * @brief Get a list of active and available webcam
diff --git a/src/lib/emotion/emotion_webcam.c b/src/lib/emotion/emotion_webcam.c
index 52e6b5b457..6302742fdb 100644
--- a/src/lib/emotion/emotion_webcam.c
+++ b/src/lib/emotion/emotion_webcam.c
@@ -19,6 +19,8 @@
19#include "emotion_private.h" 19#include "emotion_private.h"
20 20
21EAPI int EMOTION_WEBCAM_UPDATE = 0; 21EAPI int EMOTION_WEBCAM_UPDATE = 0;
22EAPI int EMOTION_WEBCAM_ADD = 0;
23EAPI int EMOTION_WEBCAM_DEL = 0;
22 24
23typedef struct _Emotion_Webcams Emotion_Webcams; 25typedef struct _Emotion_Webcams Emotion_Webcams;
24 26
@@ -89,7 +91,7 @@ emotion_webcam_destroy(Emotion_Webcam *ew)
89#ifdef HAVE_EEZE 91#ifdef HAVE_EEZE
90static Eeze_Udev_Watch *eeze_watcher = NULL; 92static Eeze_Udev_Watch *eeze_watcher = NULL;
91 93
92static void 94static Eina_Bool
93_emotion_check_device(Emotion_Webcam *ew) 95_emotion_check_device(Emotion_Webcam *ew)
94{ 96{
95#ifdef HAVE_V4L2 97#ifdef HAVE_V4L2
@@ -99,7 +101,7 @@ _emotion_check_device(Emotion_Webcam *ew)
99 int fd = -1; 101 int fd = -1;
100#endif 102#endif
101 103
102 if (!ew) return; 104 if (!ew) return EINA_FALSE;
103#ifdef HAVE_V4L2 105#ifdef HAVE_V4L2
104 if (!ew->device) goto on_error; 106 if (!ew->device) goto on_error;
105 107
@@ -125,7 +127,7 @@ _emotion_check_device(Emotion_Webcam *ew)
125 127
126 if (fd >= 0) close(fd); 128 if (fd >= 0) close(fd);
127 129
128 return; 130 return EINA_TRUE;
129 131
130 on_error: 132 on_error:
131#endif 133#endif
@@ -137,6 +139,7 @@ _emotion_check_device(Emotion_Webcam *ew)
137#ifdef HAVE_V4L2 139#ifdef HAVE_V4L2
138 if (fd > 0) close(fd); 140 if (fd > 0) close(fd);
139#endif 141#endif
142 return EINA_FALSE;
140} 143}
141 144
142static Emotion_Webcam * 145static Emotion_Webcam *
@@ -183,6 +186,21 @@ _emotion_enumerate_all_webcams(void)
183} 186}
184 187
185static void 188static void
189_emotion_webcam_remove_cb(void *user_data, void *func_data EINA_UNUSED)
190{
191 Emotion_Webcam *webcam;
192
193 /* called at the end of EMOTION_WEBCAM_ADD event, to prevent the free */
194 if (!user_data)
195 return;
196
197 webcam = user_data;
198
199 EINA_REFCOUNT_UNREF(webcam)
200 emotion_webcam_destroy(webcam);
201}
202
203static void
186_emotion_eeze_events(const char *syspath, 204_emotion_eeze_events(const char *syspath,
187 Eeze_Udev_Event ev, 205 Eeze_Udev_Event ev,
188 void *data EINA_UNUSED, 206 void *data EINA_UNUSED,
@@ -196,9 +214,10 @@ _emotion_eeze_events(const char *syspath,
196 EINA_LIST_FOREACH(_emotion_webcams->webcams, l, check) 214 EINA_LIST_FOREACH(_emotion_webcams->webcams, l, check)
197 if (check->syspath == syspath) 215 if (check->syspath == syspath)
198 { 216 {
199 _emotion_webcams->webcams = eina_list_remove_list(_emotion_webcams->webcams, l); 217 _emotion_webcams->webcams =
200 EINA_REFCOUNT_UNREF(check) 218 eina_list_remove_list(_emotion_webcams->webcams, l);
201 emotion_webcam_destroy(check); 219 ecore_event_add(EMOTION_WEBCAM_DEL, check,
220 _emotion_webcam_remove_cb, check);
202 break ; 221 break ;
203 } 222 }
204 } 223 }
@@ -207,7 +226,8 @@ _emotion_eeze_events(const char *syspath,
207 Emotion_Webcam *test; 226 Emotion_Webcam *test;
208 227
209 test = _emotion_webcam_new(syspath); 228 test = _emotion_webcam_new(syspath);
210 if (test) _emotion_check_device(test); 229 if ((test) && (_emotion_check_device(test)))
230 ecore_event_add(EMOTION_WEBCAM_ADD, test, NULL, NULL);
211 } 231 }
212 ecore_event_add(EMOTION_WEBCAM_UPDATE, NULL, NULL, NULL); 232 ecore_event_add(EMOTION_WEBCAM_UPDATE, NULL, NULL, NULL);
213} 233}
@@ -217,6 +237,8 @@ _emotion_eeze_events(const char *syspath,
217Eina_Bool emotion_webcam_init(void) 237Eina_Bool emotion_webcam_init(void)
218{ 238{
219 EMOTION_WEBCAM_UPDATE = ecore_event_type_new(); 239 EMOTION_WEBCAM_UPDATE = ecore_event_type_new();
240 EMOTION_WEBCAM_ADD = ecore_event_type_new();
241 EMOTION_WEBCAM_DEL = ecore_event_type_new();
220 242
221 eet_init(); 243 eet_init();
222 _emotion_webcams_edds_new(); 244 _emotion_webcams_edds_new();