summaryrefslogtreecommitdiff
path: root/src/lib/efreet
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2015-06-24 19:24:21 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2015-06-24 19:28:17 +0900
commit5abfefe99ea290191ef59f840b11c64fb9792edb (patch)
treef156bef3d97b775df535604fba800fa7f2d2cf2e /src/lib/efreet
parentc6011926bad960136af132a97b54cb38199638fe (diff)
efl - efreetd service move from dbus session bus to ecore ipc
this fixes warnings about no efreet dbus session bus in non session environments as brought up on the mailing lists with: Subject: Re: [E-devel] [EGIT] [core/efl] master 01/01: edje: unset efreet cache update flag to prevent dbus connections this moves all of efreetd client and server to ecore ipc, with client auto-launching efreetd if not found as a service and trying for up to 500ms to connect. efreetd times out on last connection or no connections after 10sec so it wont hang around forever if not in use. it seems to work in my testing, so let me know if there is an issue. @fix
Diffstat (limited to 'src/lib/efreet')
-rw-r--r--src/lib/efreet/efreet_cache.c415
1 files changed, 221 insertions, 194 deletions
diff --git a/src/lib/efreet/efreet_cache.c b/src/lib/efreet/efreet_cache.c
index 2200ee2a7c..6253954400 100644
--- a/src/lib/efreet/efreet_cache.c
+++ b/src/lib/efreet/efreet_cache.c
@@ -15,7 +15,7 @@
15#include <Eet.h> 15#include <Eet.h>
16#include <Ecore.h> 16#include <Ecore.h>
17#include <Ecore_File.h> 17#include <Ecore_File.h>
18#include <Eldbus.h> 18#include <Ecore_Ipc.h>
19 19
20/* define macros and variable for using the eina logging system */ 20/* define macros and variable for using the eina logging system */
21#define EFREET_MODULE_LOG_DOM _efreet_cache_log_dom 21#define EFREET_MODULE_LOG_DOM _efreet_cache_log_dom
@@ -35,13 +35,11 @@ struct _Efreet_Old_Cache
35 Eet_File *ef; 35 Eet_File *ef;
36}; 36};
37 37
38/* TODO: Common define location with daemon */ 38static Ecore_Ipc_Server *ipc = NULL;
39#define BUS "org.enlightenment.Efreet" 39static Eina_Prefix *pfx = NULL;
40#define PATH "/org/enlightenment/Efreet" 40static Ecore_Event_Handler *hnd_add = NULL;
41#define INTERFACE "org.enlightenment.Efreet" 41static Ecore_Event_Handler *hnd_del = NULL;
42 42static Ecore_Event_Handler *hnd_data = NULL;
43static Eldbus_Connection *conn = NULL;
44static Eldbus_Proxy *proxy = NULL;
45 43
46static Eina_Lock _lock; 44static Eina_Lock _lock;
47 45
@@ -97,10 +95,6 @@ static void efreet_cache_icon_theme_free(Efreet_Icon_Theme *theme);
97static Eina_Bool efreet_cache_check(Eet_File **ef, const char *path, int major); 95static Eina_Bool efreet_cache_check(Eet_File **ef, const char *path, int major);
98static void *efreet_cache_close(Eet_File *ef); 96static void *efreet_cache_close(Eet_File *ef);
99 97
100static void on_send_register(void *data, const Eldbus_Message *msg, Eldbus_Pending *pending);
101static void desktop_cache_update(void *context, const Eldbus_Message *msg);
102static void icon_cache_update(void *context, const Eldbus_Message *msg);
103
104static void icon_cache_update_free(void *data, void *ev); 98static void icon_cache_update_free(void *data, void *ev);
105 99
106static void *hash_array_string_add(void *hash, const char *key, void *data); 100static void *hash_array_string_add(void *hash, const char *key, void *data);
@@ -109,6 +103,122 @@ EAPI int EFREET_EVENT_ICON_CACHE_UPDATE = 0;
109EAPI int EFREET_EVENT_DESKTOP_CACHE_UPDATE = 0; 103EAPI int EFREET_EVENT_DESKTOP_CACHE_UPDATE = 0;
110EAPI int EFREET_EVENT_DESKTOP_CACHE_BUILD = 0; 104EAPI int EFREET_EVENT_DESKTOP_CACHE_BUILD = 0;
111 105
106#define IPC_HEAD(_type) \
107 Ecore_Ipc_Event_Server_##_type *e = event; \
108 if (e->server != ipc) \
109 return ECORE_CALLBACK_PASS_ON
110
111static void
112_ipc_launch(void)
113{
114 char buf[PATH_MAX];
115 int num = 0;
116
117 if (!pfx) snprintf(buf, sizeof(buf), "efreetd");
118 else snprintf(buf, sizeof(buf), "%s/efreetd", eina_prefix_bin_get(pfx));
119 ecore_exe_run(buf, NULL);
120 while ((!ipc) && (num < 500))
121 {
122 num++;
123 usleep(1000);
124 ipc = ecore_ipc_server_connect(ECORE_IPC_LOCAL_USER, "efreetd", 0, NULL);
125 }
126}
127
128static Eina_Bool
129_cb_server_add(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
130{
131 IPC_HEAD(Add);
132 return ECORE_CALLBACK_DONE;
133}
134
135static Eina_Bool
136_cb_server_del(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
137{
138 IPC_HEAD(Del);
139 ipc = NULL;
140 _ipc_launch();
141 return ECORE_CALLBACK_DONE;
142}
143
144static Eina_Bool
145_cb_server_data(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
146{
147 IPC_HEAD(Data);
148 if (e->major == 1) // registration
149 {
150 if (e->minor == 1)
151 ecore_event_add(EFREET_EVENT_DESKTOP_CACHE_BUILD, NULL, NULL, NULL);
152 }
153 else if (e->major == 2) // icon cache update
154 {
155 if (e->minor == 1)
156 {
157 Efreet_Event_Cache_Update *ev;
158
159 efreet_cache_desktop_close();
160
161 ev = NEW(Efreet_Event_Cache_Update, 1);
162 if (ev)
163 ecore_event_add(EFREET_EVENT_DESKTOP_CACHE_UPDATE, ev, NULL, NULL);
164 }
165 else
166 ecore_event_add(EFREET_EVENT_DESKTOP_CACHE_BUILD, NULL, NULL, NULL);
167 }
168 else if (e->major == 3) // desktop cache update
169 {
170 Efreet_Event_Cache_Update *ev = NULL;
171 Efreet_Old_Cache *d = NULL;
172 Eina_List *l = NULL;
173
174 if (e->minor == 1)
175 {
176 ev = NEW(Efreet_Event_Cache_Update, 1);
177 if (!ev) goto error;
178
179 IF_RELEASE(theme_name);
180
181 // Save all old caches
182 d = NEW(Efreet_Old_Cache, 1);
183 if (!d) goto error;
184 d->hash = themes;
185 d->ef = icon_theme_cache;
186 l = eina_list_append(l, d);
187
188 d = NEW(Efreet_Old_Cache, 1);
189 if (!d) goto error;
190 d->hash = icons;
191 d->ef = icon_cache;
192 l = eina_list_append(l, d);
193
194 d = NEW(Efreet_Old_Cache, 1);
195 if (!d) goto error;
196 d->hash = fallbacks;
197 d->ef = fallback_cache;
198 l = eina_list_append(l, d);
199
200 // Create new empty caches
201 themes = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_icon_theme_free));
202 icons = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_icon_free));
203 fallbacks = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_icon_fallback_free));
204
205 icon_theme_cache = NULL;
206 icon_cache = NULL;
207 fallback_cache = NULL;
208
209 // Send event
210 ecore_event_add(EFREET_EVENT_ICON_CACHE_UPDATE, ev, icon_cache_update_free, l);
211 goto done;
212 }
213error:
214 IF_FREE(ev);
215 EINA_LIST_FREE(l, d)
216 free(d);
217 }
218done:
219 return ECORE_CALLBACK_DONE;
220}
221
112int 222int
113efreet_cache_init(void) 223efreet_cache_init(void)
114{ 224{
@@ -139,31 +249,43 @@ efreet_cache_init(void)
139 fallbacks = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_icon_fallback_free)); 249 fallbacks = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_icon_fallback_free));
140 desktops = eina_hash_string_superfast_new(NULL); 250 desktops = eina_hash_string_superfast_new(NULL);
141 251
142 eldbus_init(); 252 ecore_ipc_init();
253 // XXX: connect to efreetd
254
143 if (efreet_cache_update) 255 if (efreet_cache_update)
144 { 256 {
145 conn = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SESSION); 257 pfx = eina_prefix_new
146 if (conn) 258 (NULL, efreet_icon_cache_file, "EFREET", "efreet", "checkme",
147 { 259 PACKAGE_BIN_DIR, PACKAGE_LIB_DIR, PACKAGE_DATA_DIR, PACKAGE_DATA_DIR);
148 Eldbus_Object *obj; 260 ipc = ecore_ipc_server_connect(ECORE_IPC_LOCAL_USER, "efreetd", 0, NULL);
149 261 if (!ipc) _ipc_launch();
150 obj = eldbus_object_get(conn, BUS, PATH); 262 if (ipc)
151 proxy = eldbus_proxy_get(obj, INTERFACE); 263 {
152 eldbus_proxy_signal_handler_add(proxy, "IconCacheUpdate", icon_cache_update, NULL); 264 const char *s;
153 eldbus_proxy_signal_handler_add(proxy, "DesktopCacheUpdate", desktop_cache_update, NULL); 265 int len = 0;
154 266
155 eldbus_proxy_call(proxy, "Register", on_send_register, NULL, -1, "s", efreet_language_get()); 267 hnd_add = ecore_event_handler_add(ECORE_IPC_EVENT_SERVER_ADD,
156 268 _cb_server_add, NULL);
157 /* 269 hnd_del = ecore_event_handler_add(ECORE_IPC_EVENT_SERVER_DEL,
158 * TODO: Needed? 270 _cb_server_del, NULL);
159 eldbus_name_owner_changed_callback_add(conn, BUS, on_name_owner_changed, 271 hnd_data = ecore_event_handler_add(ECORE_IPC_EVENT_SERVER_DATA,
160 conn, EINA_TRUE); 272 _cb_server_data, NULL);
161 */ 273 s = efreet_language_get();
162 } 274 if (s) len = strlen(s);
163 else 275 ecore_ipc_server_send(ipc, 1, 0, 0, 0, 0, s, len);
164 { 276 }
165 /* TODO: Run cache process directly */ 277 else
166 } 278 {
279 Efreet_Event_Cache_Update *ev;
280
281 WRN("Can't contact efreetd daemon for desktop/icon etc. changes");
282 ev = NEW(Efreet_Event_Cache_Update, 1);
283 if (ev)
284 {
285 ev->error = 1;
286 ecore_event_add(EFREET_EVENT_DESKTOP_CACHE_BUILD, ev, NULL, NULL);
287 }
288 }
167 } 289 }
168 290
169 return 1; 291 return 1;
@@ -226,19 +348,16 @@ efreet_cache_shutdown(void)
226 util_cache = efreet_cache_close(util_cache); 348 util_cache = efreet_cache_close(util_cache);
227 IF_RELEASE(util_cache_file); 349 IF_RELEASE(util_cache_file);
228 350
229 /* 351 if (ipc) ecore_ipc_server_del(ipc);
230 * TODO: Needed?? 352 if (pfx) eina_prefix_free(pfx);
231 eldbus_name_owner_changed_callback_del(conn, BUS, on_name_owner_changed, conn); 353 if (hnd_add) ecore_event_handler_del(hnd_add);
232 */ 354 if (hnd_del) ecore_event_handler_del(hnd_del);
233 if (conn) 355 if (hnd_data) ecore_event_handler_del(hnd_data);
234 { 356 ipc = NULL;
235 Eldbus_Object *obj = eldbus_proxy_object_get(proxy); 357 pfx = NULL;
236 eldbus_proxy_unref(proxy); 358 hnd_add = NULL;
237 eldbus_object_unref(obj); 359 hnd_del = NULL;
238 eldbus_connection_unref(conn); 360 hnd_data = NULL;
239 }
240
241 eldbus_shutdown();
242 361
243 eina_lock_free(&_lock); 362 eina_lock_free(&_lock);
244 363
@@ -924,65 +1043,67 @@ efreet_cache_desktop_free(Efreet_Desktop *desktop)
924void 1043void
925efreet_cache_desktop_add(Efreet_Desktop *desktop) 1044efreet_cache_desktop_add(Efreet_Desktop *desktop)
926{ 1045{
927 Eldbus_Message *msg; 1046 char *path;
928 Eldbus_Message_Iter *iter, *array_of_string; 1047
929 char *path; 1048 if ((!efreet_cache_update) || (!ipc)) return;
930 1049 if (!eina_main_loop_is()) return;
931 if ((!efreet_cache_update) || (!proxy))
932 return;
933 /* TODO: Chunk updates */
934 if (!eina_main_loop_is()) return;
935 /* 1050 /*
936 * TODO: Call in thread with: 1051 * TODO: Call in thread with:
937 ecore_thread_main_loop_begin(); 1052 * ecore_thread_main_loop_begin();
938 ecore_thread_main_loop_end(); 1053 * ecore_thread_main_loop_end();
939 */ 1054 */
940 path = ecore_file_dir_get(desktop->orig_path); 1055 path = ecore_file_dir_get(desktop->orig_path);
941 msg = eldbus_proxy_method_call_new(proxy, "AddDesktopDirs"); 1056 if (!path) return;
942 iter = eldbus_message_iter_get(msg); 1057 ecore_ipc_server_send(ipc, 2, 0, 0, 0, 0, path, strlen(path));
943 array_of_string = eldbus_message_iter_container_new(iter, 'a',"s"); 1058 free(path);
944 eldbus_message_iter_basic_append(array_of_string, 's', path);
945 eldbus_message_iter_container_close(iter, array_of_string);
946 eldbus_proxy_send(proxy, msg, NULL, NULL, -1);
947 free(path);
948} 1059}
949 1060
950void 1061void
951efreet_cache_icon_exts_add(Eina_List *exts) 1062efreet_cache_icon_exts_add(Eina_List *exts)
952{ 1063{
953 Eldbus_Message *msg; 1064 Eina_List *l;
954 Eldbus_Message_Iter *iter, *array_of_string; 1065 const char *s;
955 Eina_List *l; 1066 Eina_Binbuf *buf;
956 const char *ext; 1067 int num = 0;
957 1068 unsigned char nil[1] = { 0 };
958 if ((!efreet_cache_update) || (!proxy)) 1069
959 return; 1070 if ((!efreet_cache_update) || (!ipc)) return;
960 msg = eldbus_proxy_method_call_new(proxy, "AddIconExts"); 1071 buf = eina_binbuf_new();
961 iter = eldbus_message_iter_get(msg); 1072 if (!buf) return;
962 array_of_string = eldbus_message_iter_container_new(iter, 'a',"s"); 1073 EINA_LIST_FOREACH(exts, l, s)
963 EINA_LIST_FOREACH(exts, l, ext) 1074 {
964 eldbus_message_iter_basic_append(array_of_string, 's', ext); 1075 if (num > 0) eina_binbuf_append_length(buf, nil, 1);
965 eldbus_message_iter_container_close(iter, array_of_string); 1076 eina_binbuf_append_length(buf, (unsigned char *)s, strlen(s));
966 eldbus_proxy_send(proxy, msg, NULL, NULL, -1); 1077 num++;
1078 }
1079 ecore_ipc_server_send(ipc, 5 /* add icon exts */, 0, 0, 0, 0,
1080 eina_binbuf_string_get(buf),
1081 eina_binbuf_length_get(buf));
1082 eina_binbuf_free(buf);
967} 1083}
968 1084
969void 1085void
970efreet_cache_icon_dirs_add(Eina_List *dirs) 1086efreet_cache_icon_dirs_add(Eina_List *dirs)
971{ 1087{
972 Eldbus_Message *msg; 1088 Eina_List *l;
973 Eldbus_Message_Iter *iter, *array_of_string; 1089 const char *s;
974 Eina_List *l; 1090 Eina_Binbuf *buf;
975 const char *dir; 1091 int num = 0;
976 1092 unsigned char nil[1] = { 0 };
977 if ((!efreet_cache_update) || (!proxy)) 1093
978 return; 1094 if ((!efreet_cache_update) || (!ipc)) return;
979 msg = eldbus_proxy_method_call_new(proxy, "AddIconDirs"); 1095 buf = eina_binbuf_new();
980 iter = eldbus_message_iter_get(msg); 1096 if (!buf) return;
981 array_of_string = eldbus_message_iter_container_new(iter, 'a',"s"); 1097 EINA_LIST_FOREACH(dirs, l, s)
982 EINA_LIST_FOREACH(dirs, l, dir) 1098 {
983 eldbus_message_iter_basic_append(array_of_string, 's', dir); 1099 if (num > 0) eina_binbuf_append_length(buf, nil, 1);
984 eldbus_message_iter_container_close(iter, array_of_string); 1100 eina_binbuf_append_length(buf, (unsigned char *)s, strlen(s));
985 eldbus_proxy_send(proxy, msg, NULL, NULL, -1); 1101 num++;
1102 }
1103 ecore_ipc_server_send(ipc, 4 /* add icon dirs */, 0, 0, 0, 0,
1104 eina_binbuf_string_get(buf),
1105 eina_binbuf_length_get(buf));
1106 eina_binbuf_free(buf);
986} 1107}
987 1108
988void 1109void
@@ -1025,9 +1146,12 @@ efreet_cache_desktop_close(void)
1025void 1146void
1026efreet_cache_desktop_build(void) 1147efreet_cache_desktop_build(void)
1027{ 1148{
1028 if ((!efreet_cache_update) || (!proxy)) 1149 const char *s;
1029 return; 1150 int len = 0;
1030 eldbus_proxy_call(proxy, "BuildDesktopCache", NULL, NULL, -1, "s", efreet_language_get()); 1151 if ((!efreet_cache_update) || (!ipc)) return;
1152 s = efreet_language_get();
1153 if (s) len = strlen(s);
1154 ecore_ipc_server_send(ipc, 3 /* build desktop cache */, 0, 0, 0, 0, s, len);
1031} 1155}
1032 1156
1033static Eina_Bool 1157static Eina_Bool
@@ -1122,103 +1246,6 @@ efreet_cache_util_names(const char *key)
1122} 1246}
1123 1247
1124static void 1248static void
1125on_send_register(void *data EINA_UNUSED, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
1126{
1127 const char *errname, *errmsg;
1128 Eina_Bool exists;
1129
1130 if (eldbus_message_error_get(msg, &errname, &errmsg))
1131 {
1132 Efreet_Event_Cache_Update *ev = NULL;
1133
1134 WRN("%s %s", errname, errmsg);
1135
1136 ev = NEW(Efreet_Event_Cache_Update, 1);
1137 if (ev)
1138 {
1139 ev->error = 1;
1140 ecore_event_add(EFREET_EVENT_DESKTOP_CACHE_BUILD, ev, NULL, NULL);
1141 }
1142 }
1143 else if (eldbus_message_arguments_get(msg, "b", &exists) && exists)
1144 ecore_event_add(EFREET_EVENT_DESKTOP_CACHE_BUILD, NULL, NULL, NULL);
1145}
1146
1147static void
1148desktop_cache_update(void *context EINA_UNUSED, const Eldbus_Message *msg)
1149{
1150 Eina_Bool update;
1151
1152 if (eldbus_message_arguments_get(msg, "b", &update))
1153 {
1154 if (update)
1155 {
1156 Efreet_Event_Cache_Update *ev = NULL;
1157
1158 efreet_cache_desktop_close();
1159
1160 ev = NEW(Efreet_Event_Cache_Update, 1);
1161 if (ev)
1162 ecore_event_add(EFREET_EVENT_DESKTOP_CACHE_UPDATE, ev, NULL, NULL);
1163 }
1164 ecore_event_add(EFREET_EVENT_DESKTOP_CACHE_BUILD, NULL, NULL, NULL);
1165 }
1166}
1167
1168static void
1169icon_cache_update(void *context EINA_UNUSED, const Eldbus_Message *msg)
1170{
1171 Efreet_Event_Cache_Update *ev = NULL;
1172 Efreet_Old_Cache *d = NULL;
1173 Eina_List *l = NULL;
1174 Eina_Bool update;
1175
1176 if (eldbus_message_arguments_get(msg, "b", &update) && update)
1177 {
1178 ev = NEW(Efreet_Event_Cache_Update, 1);
1179 if (!ev) goto error;
1180
1181 IF_RELEASE(theme_name);
1182
1183 /* Save all old caches */
1184 d = NEW(Efreet_Old_Cache, 1);
1185 if (!d) goto error;
1186 d->hash = themes;
1187 d->ef = icon_theme_cache;
1188 l = eina_list_append(l, d);
1189
1190 d = NEW(Efreet_Old_Cache, 1);
1191 if (!d) goto error;
1192 d->hash = icons;
1193 d->ef = icon_cache;
1194 l = eina_list_append(l, d);
1195
1196 d = NEW(Efreet_Old_Cache, 1);
1197 if (!d) goto error;
1198 d->hash = fallbacks;
1199 d->ef = fallback_cache;
1200 l = eina_list_append(l, d);
1201
1202 /* Create new empty caches */
1203 themes = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_icon_theme_free));
1204 icons = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_icon_free));
1205 fallbacks = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_icon_fallback_free));
1206
1207 icon_theme_cache = NULL;
1208 icon_cache = NULL;
1209 fallback_cache = NULL;
1210
1211 /* Send event */
1212 ecore_event_add(EFREET_EVENT_ICON_CACHE_UPDATE, ev, icon_cache_update_free, l);
1213 }
1214 return;
1215error:
1216 IF_FREE(ev);
1217 EINA_LIST_FREE(l, d)
1218 free(d);
1219}
1220
1221static void
1222icon_cache_update_free(void *data, void *ev) 1249icon_cache_update_free(void *data, void *ev)
1223{ 1250{
1224 Efreet_Old_Cache *d; 1251 Efreet_Old_Cache *d;