1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
|
#include "e.h"
/* local subsystem functions */
static void _e_msgbus_request_name_cb(void *data,
DBusMessage *msg,
DBusError *err);
static DBusMessage *_e_msgbus_core_restart_cb(E_DBus_Object *obj,
DBusMessage *msg);
static DBusMessage *_e_msgbus_core_shutdown_cb(E_DBus_Object *obj,
DBusMessage *msg);
static DBusMessage *_e_msgbus_module_load_cb(E_DBus_Object *obj,
DBusMessage *msg);
static DBusMessage *_e_msgbus_module_unload_cb(E_DBus_Object *obj,
DBusMessage *msg);
static DBusMessage *_e_msgbus_module_enable_cb(E_DBus_Object *obj,
DBusMessage *msg);
static DBusMessage *_e_msgbus_module_disable_cb(E_DBus_Object *obj,
DBusMessage *msg);
static DBusMessage *_e_msgbus_module_list_cb(E_DBus_Object *obj,
DBusMessage *msg);
static DBusMessage *_e_msgbus_profile_set_cb(E_DBus_Object *obj,
DBusMessage *msg);
static DBusMessage *_e_msgbus_profile_get_cb(E_DBus_Object *obj,
DBusMessage *msg);
static DBusMessage *_e_msgbus_profile_list_cb(E_DBus_Object *obj,
DBusMessage *msg);
static DBusMessage *_e_msgbus_profile_add_cb(E_DBus_Object *obj,
DBusMessage *msg);
static DBusMessage *_e_msgbus_profile_delete_cb(E_DBus_Object *obj,
DBusMessage *msg);
/* local subsystem globals */
static E_Msgbus_Data *_e_msgbus_data = NULL;
/* externally accessible functions */
EINTERN int
e_msgbus_init(void)
{
E_DBus_Interface *iface;
_e_msgbus_data = E_NEW(E_Msgbus_Data, 1);
e_dbus_init();
#ifdef HAVE_HAL
e_hal_init();
#endif
_e_msgbus_data->conn = e_dbus_bus_get(DBUS_BUS_SESSION);
if (!_e_msgbus_data->conn)
{
printf("WARNING: Cannot get DBUS_BUS_SESSION\n");
return 0;
}
e_dbus_request_name(_e_msgbus_data->conn, "org.enlightenment.wm.service", 0, _e_msgbus_request_name_cb, NULL);
_e_msgbus_data->obj = e_dbus_object_add(_e_msgbus_data->conn, "/org/enlightenment/wm/RemoteObject", NULL);
iface = e_dbus_interface_new("org.enlightenment.wm.Core");
if (!iface)
{
printf("WARNING: Cannot add org.enlightenment.wm.Core interface\n");
return 0;
}
e_dbus_object_interface_attach(_e_msgbus_data->obj, iface);
e_dbus_interface_unref(iface);
/* Hardcore methods */
e_dbus_interface_method_add(iface, "Restart", "", "", _e_msgbus_core_restart_cb);
e_dbus_interface_method_add(iface, "Shutdown", "", "", _e_msgbus_core_shutdown_cb);
iface = e_dbus_interface_new("org.enlightenment.wm.Module");
if (!iface)
{
printf("WARNING: Cannot add org.enlightenment.wm.Module interface\n");
return 0;
}
e_dbus_object_interface_attach(_e_msgbus_data->obj, iface);
e_dbus_interface_unref(iface);
/* Module methods */
e_dbus_interface_method_add(iface, "Load", "s", "", _e_msgbus_module_load_cb);
e_dbus_interface_method_add(iface, "Unload", "s", "", _e_msgbus_module_unload_cb);
e_dbus_interface_method_add(iface, "Enable", "s", "", _e_msgbus_module_enable_cb);
e_dbus_interface_method_add(iface, "Disable", "s", "", _e_msgbus_module_disable_cb);
e_dbus_interface_method_add(iface, "List", "", "a(si)", _e_msgbus_module_list_cb);
iface = e_dbus_interface_new("org.enlightenment.wm.Profile");
if (!iface)
{
printf("WARNING: Cannot add org.enlightenment.wm.Profile interface\n");
return 0;
}
e_dbus_object_interface_attach(_e_msgbus_data->obj, iface);
e_dbus_interface_unref(iface);
/* Profile methods */
e_dbus_interface_method_add(iface, "Set", "s", "", _e_msgbus_profile_set_cb);
e_dbus_interface_method_add(iface, "Get", "", "s", _e_msgbus_profile_get_cb);
e_dbus_interface_method_add(iface, "List", "", "as", _e_msgbus_profile_list_cb);
e_dbus_interface_method_add(iface, "Add", "s", "", _e_msgbus_profile_add_cb);
e_dbus_interface_method_add(iface, "Delete", "s", "", _e_msgbus_profile_delete_cb);
return 1;
}
EINTERN int
e_msgbus_shutdown(void)
{
if (_e_msgbus_data->obj)
{
e_dbus_object_free(_e_msgbus_data->obj);
}
if (_e_msgbus_data->conn)
{
e_dbus_connection_close(_e_msgbus_data->conn);
}
#ifdef HAVE_HAL
e_hal_shutdown();
#endif
e_dbus_shutdown();
E_FREE(_e_msgbus_data);
_e_msgbus_data = NULL;
return 1;
}
EAPI void
e_msgbus_interface_attach(E_DBus_Interface *iface)
{
if (!_e_msgbus_data->obj) return;
e_dbus_object_interface_attach(_e_msgbus_data->obj, iface);
}
EAPI void
e_msgbus_interface_detach(E_DBus_Interface *iface)
{
if (!_e_msgbus_data->obj) return;
e_dbus_object_interface_detach(_e_msgbus_data->obj, iface);
}
static void
_e_msgbus_request_name_cb(void *data __UNUSED__,
DBusMessage *msg __UNUSED__,
DBusError *err __UNUSED__)
{
//TODO Handle Errors
}
/* Core Handlers */
static DBusMessage *
_e_msgbus_core_restart_cb(E_DBus_Object *obj __UNUSED__,
DBusMessage *msg)
{
e_sys_action_do(E_SYS_RESTART, NULL);
return dbus_message_new_method_return(msg);
}
static DBusMessage *
_e_msgbus_core_shutdown_cb(E_DBus_Object *obj __UNUSED__,
DBusMessage *msg)
{
e_sys_action_do(E_SYS_EXIT, NULL);
return dbus_message_new_method_return(msg);
}
/* Modules Handlers */
static DBusMessage *
_e_msgbus_module_load_cb(E_DBus_Object *obj __UNUSED__,
DBusMessage *msg)
{
DBusMessageIter iter;
char *module;
dbus_message_iter_init(msg, &iter);
dbus_message_iter_get_basic(&iter, &module);
if (!e_module_find(module))
{
e_module_new(module);
e_config_save_queue();
}
return dbus_message_new_method_return(msg);
}
static DBusMessage *
_e_msgbus_module_unload_cb(E_DBus_Object *obj __UNUSED__,
DBusMessage *msg)
{
DBusMessageIter iter;
char *module;
E_Module *m;
dbus_message_iter_init(msg, &iter);
dbus_message_iter_get_basic(&iter, &module);
if ((m = e_module_find(module)))
{
e_module_disable(m);
e_object_del(E_OBJECT(m));
e_config_save_queue();
}
return dbus_message_new_method_return(msg);
}
static DBusMessage *
_e_msgbus_module_enable_cb(E_DBus_Object *obj __UNUSED__,
DBusMessage *msg)
{
DBusMessageIter iter;
char *module;
E_Module *m;
dbus_message_iter_init(msg, &iter);
dbus_message_iter_get_basic(&iter, &module);
if ((m = e_module_find(module)))
{
e_module_enable(m);
e_config_save_queue();
}
return dbus_message_new_method_return(msg);
}
static DBusMessage *
_e_msgbus_module_disable_cb(E_DBus_Object *obj __UNUSED__,
DBusMessage *msg)
{
DBusMessageIter iter;
char *module;
E_Module *m;
dbus_message_iter_init(msg, &iter);
dbus_message_iter_get_basic(&iter, &module);
if ((m = e_module_find(module)))
{
e_module_disable(m);
e_config_save_queue();
}
return dbus_message_new_method_return(msg);
}
static DBusMessage *
_e_msgbus_module_list_cb(E_DBus_Object *obj __UNUSED__,
DBusMessage *msg)
{
Eina_List *l;
E_Module *mod;
DBusMessage *reply;
DBusMessageIter iter;
DBusMessageIter arr;
reply = dbus_message_new_method_return(msg);
dbus_message_iter_init_append(reply, &iter);
dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(si)", &arr);
EINA_LIST_FOREACH(e_module_list(), l, mod)
{
DBusMessageIter sub;
const char *name;
int enabled;
name = mod->name;
enabled = mod->enabled;
dbus_message_iter_open_container(&arr, DBUS_TYPE_STRUCT, NULL, &sub);
dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &(name));
dbus_message_iter_append_basic(&sub, DBUS_TYPE_INT32, &(enabled));
dbus_message_iter_close_container(&arr, &sub);
}
dbus_message_iter_close_container(&iter, &arr);
return reply;
}
/* Profile Handlers */
static DBusMessage *
_e_msgbus_profile_set_cb(E_DBus_Object *obj __UNUSED__,
DBusMessage *msg)
{
DBusMessageIter iter;
char *profile;
dbus_message_iter_init(msg, &iter);
dbus_message_iter_get_basic(&iter, &profile);
e_config_save_flush();
e_config_profile_set(profile);
e_config_profile_save();
e_config_save_block_set(1);
e_sys_action_do(E_SYS_RESTART, NULL);
return dbus_message_new_method_return(msg);
}
static DBusMessage *
_e_msgbus_profile_get_cb(E_DBus_Object *obj __UNUSED__,
DBusMessage *msg)
{
DBusMessageIter iter;
DBusMessage *reply;
const char *profile;
profile = e_config_profile_get();
reply = dbus_message_new_method_return(msg);
dbus_message_iter_init_append(reply, &iter);
dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &profile);
return reply;
}
static DBusMessage *
_e_msgbus_profile_list_cb(E_DBus_Object *obj __UNUSED__,
DBusMessage *msg)
{
Eina_List *l;
const char *name;
DBusMessage *reply;
DBusMessageIter iter;
DBusMessageIter arr;
reply = dbus_message_new_method_return(msg);
dbus_message_iter_init_append(reply, &iter);
dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "s", &arr);
EINA_LIST_FOREACH(e_config_profile_list(), l, name)
{
dbus_message_iter_append_basic(&arr, DBUS_TYPE_STRING, &name);
}
dbus_message_iter_close_container(&iter, &arr);
return reply;
}
static DBusMessage *
_e_msgbus_profile_add_cb(E_DBus_Object *obj __UNUSED__,
DBusMessage *msg)
{
DBusMessageIter iter;
char *profile;
dbus_message_iter_init(msg, &iter);
dbus_message_iter_get_basic(&iter, &profile);
e_config_profile_add(profile);
return dbus_message_new_method_return(msg);
}
static DBusMessage *
_e_msgbus_profile_delete_cb(E_DBus_Object *obj __UNUSED__,
DBusMessage *msg)
{
DBusMessageIter iter;
char *profile;
dbus_message_iter_init(msg, &iter);
dbus_message_iter_get_basic(&iter, &profile);
if (!strcmp(e_config_profile_get(), profile))
{
DBusMessage *ret;
ret = dbus_message_new_error(msg, "org.enlightenment.DBus.InvalidArgument",
"Can't delete active profile");
return ret;
}
e_config_profile_del(profile);
return dbus_message_new_method_return(msg);
}
|