summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric Bail <cedric@osg.samsung.com>2016-10-25 16:54:29 -0700
committerCedric Bail <cedric@osg.samsung.com>2016-10-25 16:54:55 -0700
commitfb8d139ad01349a598863397fb4ad54ba6998baa (patch)
tree908cbe0f17a34b7e75954ee485461aec49b32c08
parent919829aa7d9f9302f30cc245f593793ba8753b46 (diff)
eio: fetch mime type asynchronously.
-rw-r--r--src/lib/eio/eio_model.c61
-rw-r--r--src/lib/eio/eio_model_private.h2
2 files changed, 54 insertions, 9 deletions
diff --git a/src/lib/eio/eio_model.c b/src/lib/eio/eio_model.c
index 64a7213..0302135 100644
--- a/src/lib/eio/eio_model.c
+++ b/src/lib/eio/eio_model.c
@@ -70,7 +70,6 @@ _eio_stat_done_cb(void *data, Eio_File *handler EINA_UNUSED, const Eina_Stat *st
70 eina_list_free(priv->property_promises); 70 eina_list_free(priv->property_promises);
71 priv->property_promises = NULL; 71 priv->property_promises = NULL;
72 72
73 eio_file_cancel(priv->stat_file);
74 priv->stat_file = NULL; 73 priv->stat_file = NULL;
75} 74}
76 75
@@ -289,18 +288,43 @@ _eio_model_efl_model_properties_get(Eo *obj EINA_UNUSED, Eio_Model_Data *_pd)
289/** 288/**
290 * Property Get 289 * Property Get
291 */ 290 */
291static void
292_on_idle_mime(void *data, const Efl_Event *ev)
293{
294 Eio_Model_Data *priv = data;
295 Efl_Promise *p;
296 const char *value;
297
298 // Make sure that we are not over consuming time in the main loop
299 if (ecore_time_get() - ecore_loop_time_get() > 0.004) return ;
300
301 // Are we done yet ?
302 efl_event_callback_del(ev->object, EFL_LOOP_EVENT_IDLE_ENTER, _on_idle_mime, priv);
303 if (!priv->fetching_mime) return ;
304
305 value = efreet_mime_type_get(priv->path);
306
307 EINA_LIST_FREE(priv->fetching_mime, p)
308 {
309 Eina_Value *v;
310
311 v = eina_value_new(EINA_VALUE_TYPE_STRING);
312 eina_value_set(v, value);
313 efl_promise_value_set(p, v, (Eina_Free_Cb)&eina_value_free);
314 }
315}
316
292static Efl_Future* 317static Efl_Future*
293_eio_model_efl_model_property_get(Eo *obj EINA_UNUSED, Eio_Model_Data *priv, const char *property) 318_eio_model_efl_model_property_get(Eo *obj, Eio_Model_Data *priv, const char *property)
294{ 319{
295 _Eio_Property_Name property_name; 320 _Eio_Property_Name property_name;
296 const char* value = NULL; 321 const char* value = NULL;
297 Efl_Promise *promise; 322 Efl_Promise *promise;
298 Efl_Future *future; 323 Efl_Future *future;
299 324
300 Eo *loop = efl_provider_find(obj, EFL_LOOP_CLASS); 325 promise = efl_add(EFL_PROMISE_CLASS, obj);
301 promise = efl_add(EFL_PROMISE_CLASS, loop);
302 future = efl_promise_future_get(promise); 326 future = efl_promise_future_get(promise);
303 327
304 EINA_SAFETY_ON_NULL_RETURN_VAL(priv, future); 328 EINA_SAFETY_ON_NULL_RETURN_VAL(priv, future);
305 329
306 if (property == NULL) 330 if (property == NULL)
@@ -348,15 +372,23 @@ _eio_model_efl_model_property_get(Eo *obj EINA_UNUSED, Eio_Model_Data *priv, con
348 372
349 switch(property_name) 373 switch(property_name)
350 { 374 {
375 case EIO_MODEL_PROP_MIME_TYPE:
376 {
377 if (!priv->fetching_mime)
378 efl_event_callback_add(efl_provider_find(obj, EFL_LOOP_CLASS),
379 EFL_LOOP_EVENT_IDLE_ENTER, _on_idle_mime, priv);
380 priv->fetching_mime = eina_list_append(priv->fetching_mime, promise);
381 break;
382 }
351 case EIO_MODEL_PROP_FILENAME: 383 case EIO_MODEL_PROP_FILENAME:
352 case EIO_MODEL_PROP_PATH: 384 case EIO_MODEL_PROP_PATH:
353 case EIO_MODEL_PROP_MIME_TYPE:
354 { 385 {
355 Eina_Value* v = eina_value_new(EINA_VALUE_TYPE_STRING); 386 Eina_Value* v = eina_value_new(EINA_VALUE_TYPE_STRING);
356 eina_value_set(v, value); 387 eina_value_set(v, value);
357 efl_promise_value_set(promise, v, (Eina_Free_Cb)&eina_value_free); 388 efl_promise_value_set(promise, v, (Eina_Free_Cb)&eina_value_free);
389
390 break;
358 } 391 }
359 break;
360 default: 392 default:
361 { 393 {
362 _Eio_Property_Promise* p = calloc(1, sizeof(_Eio_Property_Promise)); 394 _Eio_Property_Promise* p = calloc(1, sizeof(_Eio_Property_Promise));
@@ -364,10 +396,10 @@ _eio_model_efl_model_property_get(Eo *obj EINA_UNUSED, Eio_Model_Data *priv, con
364 p->property = property_name;; 396 p->property = property_name;;
365 priv->property_promises = eina_list_prepend(priv->property_promises, p); 397 priv->property_promises = eina_list_prepend(priv->property_promises, p);
366 398
367 if(!priv->stat_file) 399 if (!priv->stat_file)
368 _eio_stat_do(priv); 400 _eio_stat_do(priv);
401 break;
369 } 402 }
370 break;
371 } 403 }
372 return future; 404 return future;
373} 405}
@@ -687,8 +719,19 @@ _eio_model_path_set(Eo *obj EINA_UNUSED, Eio_Model_Data *priv, const char *path)
687static void 719static void
688_eio_model_efl_object_destructor(Eo *obj , Eio_Model_Data *priv) 720_eio_model_efl_object_destructor(Eo *obj , Eio_Model_Data *priv)
689{ 721{
722 Efl_Promise *p;
690 Eo *child; 723 Eo *child;
691 724
725 if (priv->fetching_mime)
726 efl_event_callback_del(efl_provider_find(obj, EFL_LOOP_CLASS),
727 EFL_LOOP_EVENT_IDLE_ENTER, _on_idle_mime, priv);
728
729 EINA_LIST_FREE(priv->fetching_mime, p)
730 {
731 efl_promise_failed_set(p, EINA_ERROR_FUTURE_CANCEL);
732 efl_del(p);
733 }
734
692 _eio_model_efl_model_monitor_del(priv); 735 _eio_model_efl_model_monitor_del(priv);
693 736
694 eina_spinlock_free(&priv->filter_lock); 737 eina_spinlock_free(&priv->filter_lock);
diff --git a/src/lib/eio/eio_model_private.h b/src/lib/eio/eio_model_private.h
index 7944274..3bf179c 100644
--- a/src/lib/eio/eio_model_private.h
+++ b/src/lib/eio/eio_model_private.h
@@ -74,6 +74,8 @@ struct _Eio_Model_Data
74 Eio_Filter_Direct_Cb filter_cb; 74 Eio_Filter_Direct_Cb filter_cb;
75 void *filter_userdata; 75 void *filter_userdata;
76 Eina_Spinlock filter_lock; /**< filter callback is called from another thread */ 76 Eina_Spinlock filter_lock; /**< filter callback is called from another thread */
77
78 Eina_List *fetching_mime;
77}; 79};
78 80
79#endif 81#endif