summaryrefslogtreecommitdiff
path: root/src/lib/efl/interfaces/efl_vpath_manager.c
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2016-04-01 10:45:07 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2016-04-05 16:22:59 +0900
commit6291c61556a531da874242830689e37362db1638 (patch)
treeefb7e25710fff06462064e05c32fc958e38fc6b2 /src/lib/efl/interfaces/efl_vpath_manager.c
parenta7400abbf688b62ec82356e870d122a09545849e (diff)
efl: vpath subsystem
this adds a core vpath subsystem to efl that allows paths like: ~/file.jpg ~user/file.jpg (:tmp/file.jpg (:config/file.jpg (:videos/file.mp4 (:pictures/file.jpg (:app.config/mycfg.cfg etc. to be translated/looked up. it is desitgned to be async and call event callbacks when ready. the reason for this complexity is fo in future also handle: file:///whatever/file.jpg http://blah.com/file.jpg https://blah.com/file.jpg ssh://blah.com:~/file.jpg etc. @feature
Diffstat (limited to 'src/lib/efl/interfaces/efl_vpath_manager.c')
-rw-r--r--src/lib/efl/interfaces/efl_vpath_manager.c89
1 files changed, 89 insertions, 0 deletions
diff --git a/src/lib/efl/interfaces/efl_vpath_manager.c b/src/lib/efl/interfaces/efl_vpath_manager.c
new file mode 100644
index 0000000..fdf5e9a
--- /dev/null
+++ b/src/lib/efl/interfaces/efl_vpath_manager.c
@@ -0,0 +1,89 @@
1#include "config.h"
2#include "Efl.h"
3
4#define MY_CLASS EFL_VPATH_MANAGER_CLASS
5
6typedef struct _Efl_Vpath_Manager_Data Efl_Vpath_Manager_Data;
7typedef struct _Efl_Vpath_Manager_Entry Efl_Vpath_Manager_Entry;
8
9struct _Efl_Vpath_Manager_Data
10{
11 Eina_List *list;
12};
13
14struct _Efl_Vpath_Manager_Entry
15{
16 Efl_Vpath *vpath;
17 int priority;
18};
19
20static Efl_Vpath_Manager_Data vpath_manager =
21{
22 NULL
23};
24
25EOLIAN static Efl_Vpath_File *
26_efl_vpath_manager_fetch(Eo *obj EINA_UNUSED, void *pd EINA_UNUSED, const char *path)
27{
28 Efl_Vpath_Manager_Entry *entry;
29 Eina_List *l;
30 Efl_Vpath_File *file;
31
32 EINA_LIST_FOREACH(vpath_manager.list, l, entry)
33 {
34 file = efl_vpath_fetch(entry->vpath, path);
35 if (file) return file;
36 }
37 file = eo_add(EFL_VPATH_FILE_CLASS, NULL);
38 if (file)
39 {
40 efl_vpath_file_path_set(file, path);
41 efl_vpath_file_result_set(file, path);
42 }
43 return file;
44}
45
46static int
47_register_sort_cb(Efl_Vpath_Manager_Entry *e1, Efl_Vpath_Manager_Entry *e2)
48{
49 // sort higher numbers first in list
50 return (e2->priority - e1->priority);
51}
52
53static Eina_Bool
54_cb_vpath_del(void *data, const Eo_Event *event)
55{
56 efl_vpath_manager_unregister(data, event->obj);
57 eo_event_callback_del(event->obj, EO_BASE_EVENT_DEL, _cb_vpath_del, data);
58 return EINA_TRUE;
59}
60
61EOLIAN static void
62_efl_vpath_manager_register(Eo *obj, void *pd EINA_UNUSED, int priority, Efl_Vpath *vpath)
63{
64 Efl_Vpath_Manager_Entry *entry = malloc(sizeof(Efl_Vpath_Manager_Entry));
65 entry->vpath = vpath;
66 entry->priority = priority;
67 eo_event_callback_add(vpath, EO_BASE_EVENT_DEL, _cb_vpath_del, obj);
68 vpath_manager.list = eina_list_sorted_insert
69 (vpath_manager.list, EINA_COMPARE_CB(_register_sort_cb), entry);
70}
71
72EOLIAN static void
73_efl_vpath_manager_unregister(Eo *obj EINA_UNUSED, void *pd EINA_UNUSED, Efl_Vpath *vpath)
74{
75 Efl_Vpath_Manager_Entry *entry;
76 Eina_List *l;
77
78 EINA_LIST_FOREACH(vpath_manager.list, l, entry)
79 {
80 if (entry->vpath == vpath)
81 {
82 vpath_manager.list = eina_list_remove_list(vpath_manager.list, l);
83 free(entry);
84 return;
85 }
86 }
87}
88
89#include "interfaces/efl_vpath_manager.eo.c"