6 #include "comm_config.h"
8 #include "pkgmgr-server.h"
9 #include "package-manager-debug.h"
11 static const char instropection_xml[] =
13 " <interface name='org.tizen.pkgmgr'>"
14 " <method name='install'>"
15 " <arg type='s' name='reqid' direction='in'/>"
16 " <arg type='s' name='pkgtype' direction='in'/>"
17 " <arg type='s' name='pkgpath' direction='in'/>"
18 " <arg type='s' name='args' direction='in'/>"
19 " <arg type='i' name='ret' direction='out'/>"
21 " <method name='reinstall'>"
22 " <arg type='s' name='reqid' direction='in'/>"
23 " <arg type='s' name='pkgtype' direction='in'/>"
24 " <arg type='s' name='pkgid' direction='in'/>"
25 " <arg type='s' name='args' direction='in'/>"
26 " <arg type='i' name='ret' direction='out'/>"
28 " <method name='uninstall'>"
29 " <arg type='s' name='reqid' direction='in'/>"
30 " <arg type='s' name='pkgtype' direction='in'/>"
31 " <arg type='s' name='pkgid' direction='in'/>"
32 " <arg type='s' name='args' direction='in'/>"
33 " <arg type='i' name='ret' direction='out'/>"
35 " <method name='cleardata'>"
36 " <arg type='s' name='reqid' direction='in'/>"
37 " <arg type='s' name='pkgtype' direction='in'/>"
38 " <arg type='s' name='pkgid' direction='in'/>"
39 " <arg type='s' name='args' direction='in'/>"
40 " <arg type='i' name='ret' direction='out'/>"
42 " <method name='move'>"
43 " <arg type='s' name='reqid' direction='in'/>"
44 " <arg type='s' name='pkgtype' direction='in'/>"
45 " <arg type='s' name='pkgid' direction='in'/>"
46 " <arg type='s' name='args' direction='in'/>"
47 " <arg type='i' name='ret' direction='out'/>"
49 " <method name='activate'>"
50 " <arg type='s' name='reqid' direction='in'/>"
51 " <arg type='s' name='pkgtype' direction='in'/>"
52 " <arg type='s' name='pkgid' direction='in'/>"
53 " <arg type='s' name='args' direction='in'/>"
54 " <arg type='i' name='ret' direction='out'/>"
56 " <method name='deactivate'>"
57 " <arg type='s' name='reqid' direction='in'/>"
58 " <arg type='s' name='pkgtype' direction='in'/>"
59 " <arg type='s' name='pkgid' direction='in'/>"
60 " <arg type='s' name='args' direction='in'/>"
61 " <arg type='i' name='ret' direction='out'/>"
63 " <method name='getsize'>"
64 " <arg type='s' name='reqid' direction='in'/>"
65 " <arg type='s' name='pkgtype' direction='in'/>"
66 " <arg type='s' name='pkgid' direction='in'/>"
67 " <arg type='s' name='args' direction='in'/>"
68 " <arg type='i' name='ret' direction='out'/>"
70 " <method name='clearcache'>"
71 " <arg type='s' name='reqid' direction='in'/>"
72 " <arg type='s' name='pkgtype' direction='in'/>"
73 " <arg type='s' name='pkgid' direction='in'/>"
74 " <arg type='i' name='ret' direction='out'/>"
76 " <method name='kill'>"
77 " <arg type='s' name='reqid' direction='in'/>"
78 " <arg type='s' name='pkgtype' direction='in'/>"
79 " <arg type='s' name='pkgid' direction='in'/>"
80 " <arg type='i' name='ret' direction='out'/>"
82 " <method name='check'>"
83 " <arg type='s' name='reqid' direction='in'/>"
84 " <arg type='s' name='pkgtype' direction='in'/>"
85 " <arg type='s' name='pkgid' direction='in'/>"
86 " <arg type='i' name='ret' direction='out'/>"
90 static GDBusNodeInfo *instropection_data;
92 static guint owner_id;
94 static int __handle_request_install(uid_t uid, GVariant *parameters)
102 g_variant_get(parameters, "(&s&s&s&s)", &reqid, &pkgtype, &pkgpath,
105 item = _pm_queue_create_item(uid, reqid, COMM_REQ_TO_INSTALLER,
106 pkgtype, pkgpath, args);
110 if (_pm_queue_push(item))
116 static int __handle_request_reinstall(uid_t uid, GVariant *parameters)
124 g_variant_get(parameters, "(&s&s&s&s)", &reqid, &pkgtype, &pkgid,
127 item = _pm_queue_create_item(uid, reqid, COMM_REQ_TO_INSTALLER,
128 pkgtype, pkgid, args);
132 if (_pm_queue_push(item))
138 static int __handle_request_uninstall(uid_t uid, GVariant *parameters)
146 g_variant_get(parameters, "(&s&s&s&s)", &reqid, &pkgtype, &pkgid,
149 item = _pm_queue_create_item(uid, reqid, COMM_REQ_TO_INSTALLER,
150 pkgtype, pkgid, args);
154 if (_pm_queue_push(item))
160 static int __handle_request_cleardata(uid_t uid, GVariant *parameters)
168 g_variant_get(parameters, "(&s&s&s&s)", &reqid, &pkgtype, &pkgid,
171 item = _pm_queue_create_item(uid, reqid, COMM_REQ_TO_CLEARER,
172 pkgtype, pkgid, args);
176 if (_pm_queue_push(item))
182 static int __handle_request_move(uid_t uid, GVariant *parameters)
190 g_variant_get(parameters, "(&s&s&s&s)", &reqid, &pkgtype, &pkgid,
193 item = _pm_queue_create_item(uid, reqid, COMM_REQ_TO_MOVER,
194 pkgtype, pkgid, args);
198 if (_pm_queue_push(item))
204 static int __handle_request_activate(uid_t uid, GVariant *parameters)
212 g_variant_get(parameters, "(&s&s&s&s)", &reqid, &pkgtype, &pkgid,
215 item = _pm_queue_create_item(uid, reqid, COMM_REQ_TO_ACTIVATOR,
216 pkgtype, pkgid, args);
220 if (_pm_queue_push(item))
226 static int __handle_request_deactivate(uid_t uid, GVariant *parameters)
234 g_variant_get(parameters, "(&s&s&s&s)", &reqid, &pkgtype, &pkgid,
237 item = _pm_queue_create_item(uid, reqid, COMM_REQ_TO_ACTIVATOR,
238 pkgtype, pkgid, args);
242 if (_pm_queue_push(item))
248 static int __handle_request_getsize(uid_t uid, GVariant *parameters)
256 g_variant_get(parameters, "(&s&s&s&s)", &reqid, &pkgtype, &pkgid,
259 item = _pm_queue_create_item(uid, reqid, COMM_REQ_GET_SIZE,
260 pkgtype, pkgid, args);
264 if (_pm_queue_push(item))
270 static int __handle_request_clearcache(uid_t uid, GVariant *parameters)
277 g_variant_get(parameters, "(&s&s&s)", &reqid, &pkgtype, &pkgid);
279 item = _pm_queue_create_item(uid, reqid, COMM_REQ_CLEAR_CACHE_DIR,
280 pkgtype, pkgid, NULL);
284 if (_pm_queue_push(item))
290 static int __handle_request_kill(uid_t uid, GVariant *parameters)
297 g_variant_get(parameters, "(&s&s&s)", &reqid, &pkgtype, &pkgid);
299 item = _pm_queue_create_item(uid, reqid, COMM_REQ_KILL_APP,
300 pkgtype, pkgid, NULL);
304 if (_pm_queue_push(item))
310 static int __handle_request_check(uid_t uid, GVariant *parameters)
317 g_variant_get(parameters, "(&s&s&s)", &reqid, &pkgtype, &pkgid);
319 item = _pm_queue_create_item(uid, reqid, COMM_REQ_CHECK_APP,
320 pkgtype, pkgid, NULL);
324 if (_pm_queue_push(item))
330 static uid_t __get_caller_uid(GDBusConnection *connection, const char *name)
336 result = g_dbus_connection_call_sync(connection,
337 "org.freedesktop.DBus", "/org/freedesktop/DBus",
338 "org.freedesktop.DBus", "GetConnectionUnixUser",
339 g_variant_new("(s)", name), NULL,
340 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
341 if (result == NULL) {
342 ERR("failed to get caller uid: %s", err->message);
347 g_variant_get(result, "(u)", &uid);
352 static void __handle_method_call(GDBusConnection *connection,
353 const gchar *sender, const gchar *object_path,
354 const gchar *interface_name, const gchar *method_name,
355 GVariant *parameters, GDBusMethodInvocation *invocation,
361 uid = __get_caller_uid(connection,
362 g_dbus_method_invocation_get_sender(invocation));
363 if (uid == (uid_t)-1)
366 if (g_strcmp0(method_name, "install") == 0)
367 ret = __handle_request_install(uid, parameters);
368 else if (g_strcmp0(method_name, "reinstall") == 0)
369 ret = __handle_request_reinstall(uid, parameters);
370 else if (g_strcmp0(method_name, "uninstall") == 0)
371 ret = __handle_request_uninstall(uid, parameters);
372 else if (g_strcmp0(method_name, "cleardata") == 0)
373 ret = __handle_request_cleardata(uid, parameters);
374 else if (g_strcmp0(method_name, "move") == 0)
375 ret = __handle_request_move(uid, parameters);
376 else if (g_strcmp0(method_name, "activate") == 0)
377 ret = __handle_request_activate(uid, parameters);
378 else if (g_strcmp0(method_name, "deactivate") == 0)
379 ret = __handle_request_deactivate(uid, parameters);
380 else if (g_strcmp0(method_name, "getsize") == 0)
381 ret = __handle_request_getsize(uid, parameters);
382 else if (g_strcmp0(method_name, "clearcache") == 0)
383 ret = __handle_request_clearcache(uid, parameters);
384 else if (g_strcmp0(method_name, "kill") == 0)
385 ret = __handle_request_kill(uid, parameters);
386 else if (g_strcmp0(method_name, "check") == 0)
387 ret = __handle_request_check(uid, parameters);
391 g_dbus_method_invocation_return_value(invocation,
392 g_variant_new("(i)", ret));
395 g_idle_add(queue_job, NULL);
398 static const GDBusInterfaceVTable interface_vtable =
400 __handle_method_call,
405 static void __on_bus_acquired(GDBusConnection *connection, const gchar *name,
409 DBG("on bus acquired");
411 reg_id = g_dbus_connection_register_object(connection,
412 COMM_PKGMGR_DBUS_OBJECT_PATH,
413 instropection_data->interfaces[0],
414 &interface_vtable, NULL, NULL, NULL);
417 ERR("failed to register object");
420 static void __on_name_acquired(GDBusConnection *connection, const gchar *name,
423 DBG("on name acquired: %s", name);
426 static void __on_name_lost(GDBusConnection *connection, const gchar *name,
429 DBG("on name lost: %s", name);
432 int __init_request_handler(void)
434 instropection_data = g_dbus_node_info_new_for_xml(instropection_xml, NULL);
436 owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM, COMM_PKGMGR_DBUS_SERVICE,
437 G_BUS_NAME_OWNER_FLAGS_NONE, __on_bus_acquired,
438 __on_name_acquired, __on_name_lost, NULL, NULL);
443 void __fini_request_handler(void)
445 g_bus_unown_name(owner_id);
446 g_dbus_node_info_unref(instropection_data);