Code refactoring 81/94381/7
authorSangyoon Jang <s89.jang@samsung.com>
Fri, 28 Oct 2016 12:43:20 +0000 (21:43 +0900)
committerSangyoon Jang <s89.jang@samsung.com>
Fri, 4 Nov 2016 08:17:42 +0000 (17:17 +0900)
- Rewrite queue management code.
   Data Struture.
    * struct backend_queue:
     store each backend's informations(backend path, slot num, job list)
    * struct backend_job:
     store each job(request)'s infomations(req type, uid, pkgid, ...)
   The pkgmgr-server has two hash tables which map each backend, each table
   use type(tpk, wgt) and slot number as key.
   And there is another table which stores informations about the job
   currently processed.

   The pkgmgr-server will push job to each queue, pop it at idler, and
   insert the job into the backend info table(using slot num as key).
   When the backend finished the job, the server will get the job info
   and free it(by removing from the table).
   All the memories for the request data will be allocated dynamically,
   and nerver duplicated.

- Remove unused code.
- Rename enums/internal apis.
- Fix some code style.

Change-Id: Ie95b369608dc6675aeccc6a66b255b28ca200059
Signed-off-by: Sangyoon Jang <s89.jang@samsung.com>
include/pkgmgr-server.h
include/pm-queue.h [deleted file]
include/queue.h [new file with mode: 0644]
src/pkgmgr-server.c
src/pm-queue.c [deleted file]
src/queue.c [new file with mode: 0644]
src/request.c
src/restriction_mode.c
src/signal.c

index 61b5696..288798e 100644 (file)
@@ -27,6 +27,8 @@
 #include <glib.h>
 #include <dlog.h>
 
+#include "queue.h"
+
 #ifdef LOG_TAG
 #undef LOG_TAG
 #endif /* LOG_TAG */
 #define INFO(fmt, args...) LOGI("[%s:%d] "fmt"\n", __func__, __LINE__, ##args)
 #endif
 
-#define CONF_FILE "/etc/package-manager/server/.config"
-#define DESKTOP_FILE_DIRS "/usr/share/install-info/desktop.conf"
-
-#define PKG_BACKEND "backend:"
-#define PKG_CONF_PATH "/etc/package-manager/pkg_path.conf"
-
 #define MAX_REQ_ID_LEN 256
 #define MAX_PKG_TYPE_LEN 128
 #define MAX_PKG_NAME_LEN 256
 #define DESKTOP_FILE_DIRS_NUM 1024
 
 enum request_type {
-       PKGMGR_REQUEST_TYPE_INSTALL,
-       PKGMGR_REQUEST_TYPE_MOUNT_INSTALL,
-       PKGMGR_REQUEST_TYPE_REINSTALL,
-       PKGMGR_REQUEST_TYPE_UNINSTALL,
-       PKGMGR_REQUEST_TYPE_MOVE,
-       PKGMGR_REQUEST_TYPE_ENABLE_PKG,
-       PKGMGR_REQUEST_TYPE_DISABLE_PKG,
-       PKGMGR_REQUEST_TYPE_ENABLE_APP,
-       PKGMGR_REQUEST_TYPE_DISABLE_APP,
-       PKGMGR_REQUEST_TYPE_GETSIZE,
-       PKGMGR_REQUEST_TYPE_CLEARDATA,
-       PKGMGR_REQUEST_TYPE_CLEARCACHE,
-       PKGMGR_REQUEST_TYPE_ENABLE_GLOBAL_APP_FOR_UID,
-       PKGMGR_REQUEST_TYPE_DISABLE_GLOBAL_APP_FOR_UID,
-       PKGMGR_REQUEST_TYPE_KILL,
-       PKGMGR_REQUEST_TYPE_CHECK,
-       PKGMGR_REQUEST_TYPE_GENERATE_LICENSE_REQUEST,
-       PKGMGR_REQUEST_TYPE_REGISTER_LICENSE,
-       PKGMGR_REQUEST_TYPE_DECRYPT_PACKAGE,
-       PKGMGR_REQUEST_TYPE_ENABLE_APP_SPLASH_SCREEN,
-       PKGMGR_REQUEST_TYPE_DISABLE_APP_SPLASH_SCREEN,
-       PKGMGR_REQUEST_TYPE_SET_RESTRICTION_MODE,
-       PKGMGR_REQUEST_TYPE_UNSET_RESTRICTION_MODE,
-       PKGMGR_REQUEST_TYPE_GET_RESTRICTION_MODE,
+       REQUEST_TYPE_INSTALL,
+       REQUEST_TYPE_MOUNT_INSTALL,
+       REQUEST_TYPE_REINSTALL,
+       REQUEST_TYPE_UNINSTALL,
+       REQUEST_TYPE_MOVE,
+       REQUEST_TYPE_ENABLE_PKG,
+       REQUEST_TYPE_DISABLE_PKG,
+       REQUEST_TYPE_ENABLE_APP,
+       REQUEST_TYPE_DISABLE_APP,
+       REQUEST_TYPE_GETSIZE,
+       REQUEST_TYPE_CLEARDATA,
+       REQUEST_TYPE_CLEARCACHE,
+       REQUEST_TYPE_ENABLE_GLOBAL_APP_FOR_UID,
+       REQUEST_TYPE_DISABLE_GLOBAL_APP_FOR_UID,
+       REQUEST_TYPE_KILL,
+       REQUEST_TYPE_CHECK,
+       REQUEST_TYPE_GENERATE_LICENSE_REQUEST,
+       REQUEST_TYPE_REGISTER_LICENSE,
+       REQUEST_TYPE_DECRYPT_PACKAGE,
+       REQUEST_TYPE_ENABLE_APP_SPLASH_SCREEN,
+       REQUEST_TYPE_DISABLE_APP_SPLASH_SCREEN,
+       REQUEST_TYPE_SET_RESTRICTION_MODE,
+       REQUEST_TYPE_UNSET_RESTRICTION_MODE,
+       REQUEST_TYPE_GET_RESTRICTION_MODE,
 };
 
-typedef struct {
-       char req_id[MAX_REQ_ID_LEN];
-       int req_type;
-       uid_t uid;
-       char pkg_type[MAX_PKG_TYPE_LEN];
-       char pkgid[MAX_PKG_NAME_LEN];
-       char appid[MAX_PKG_NAME_LEN];
-       char *args;
-} pm_dbus_msg;
-
-typedef struct backend_info_t {
-       int pid;
-       uid_t uid;
-       int req_type;
-       char req_id[MAX_REQ_ID_LEN];
-       char pkgtype[MAX_PKG_TYPE_LEN];
-       char pkgid[MAX_PKG_NAME_LEN];
-       char *args;
-} backend_info;
-
-char *_get_backend_cmd(char *type);
-
 gboolean queue_job(void *data);
-int __return_value_to_caller(const char *req_key, GVariant *result);
-int __init_request_handler(void);
-void __fini_request_handler(void);
-void __send_app_signal(uid_t uid, const char *req_id,
+int _return_value_to_caller(const char *req_key, GVariant *result);
+int _init_request_handler(void);
+void _fini_request_handler(void);
+void _send_app_signal(uid_t uid, const char *req_id,
                const char *pkgid, const char *appid,
                const char *key, const char *val, int req_type);
-void __send_fail_signal(backend_info *info);
-int _restriction_mode_set(uid_t uid, const char *pkgid, int mode);
-int _restriction_mode_unset(uid_t uid, const char *pkgid, int mode);
-int _restriction_mode_get(uid_t uid, const char *pkgid, int *mode);
+void _send_fail_signal(struct backend_job *job);
+int _set_restriction_mode(uid_t uid, const char *pkgid, int mode);
+int _unset_restriction_mode(uid_t uid, const char *pkgid, int mode);
+int _get_restriction_mode(uid_t uid, const char *pkgid, int *mode);
 
 #endif/*  _PKGMGR_SERVER_H_ */
diff --git a/include/pm-queue.h b/include/pm-queue.h
deleted file mode 100644 (file)
index eca0ce3..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * slp-pkgmgr
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
- * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-
-
-
-
-#ifndef _PM_QUEUE_H_
-#define _PM_QUEUE_H_
-
-#include "pkgmgr-server.h"
-
-typedef struct _pm_queue_data {
-       pm_dbus_msg *msg;
-       struct _pm_queue_data *next;
-} pm_queue_data;
-
-typedef struct queue_info_map_t {
-       char pkgtype[MAX_PKG_TYPE_LEN];
-       char backend[MAX_PKG_NAME_LEN];
-       int queue_slot;
-       pm_queue_data *head;
-} queue_info_map;
-
-#define MAX_QUEUE_NUM 128
-
-int _pm_queue_init(void);
-int _pm_queue_push(uid_t uid, const char *req_id, int req_type,
-               const char *queue_type, const char *pkgid, const char *argv);
-/*position specifies the queue from which to pop request*/
-pm_dbus_msg *_pm_queue_pop(int position);
-void _pm_queue_final();
-void _pm_queue_delete(pm_dbus_msg *item);
-pm_queue_data *_add_node();
-void _print_queue(int position);
-
-#endif                         /* _PM_QUEUE_H_ */
diff --git a/include/queue.h b/include/queue.h
new file mode 100644 (file)
index 0000000..5276ee6
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef _QUEUE_H_
+#define _QUEUE_H_
+
+#include <sys/types.h>
+
+struct backend_job {
+       uid_t uid;
+       int req_type;
+       char *req_id;
+       char *pkgid;
+       char *appid;
+       char *args;
+       int backend_slot;
+       char *backend_type;
+       char *backend_path;
+};
+
+int _is_queue_empty(int pos);
+int _push_queue(uid_t uid, const char *req_id, int req_type,
+               const char *queue_type, const char *pkgid, const char *args);
+struct backend_job *_pop_queue(int pos);
+void _free_backend_job(struct backend_job *job);
+int _init_backend_queue(void);
+void _fini_backend_queue(void);
+
+#endif  // _QUEUE_H_
index 72d6cd3..d824e5e 100644 (file)
 
 #include "pkgmgr_installer.h"
 #include "pkgmgr-server.h"
-#include "pm-queue.h"
+#include "queue.h"
 #include "package-manager.h"
 
-#define BUFMAX 128
-#define NO_MATCHING_FILE 11
-
 #define OWNER_ROOT 0
 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
 #define APPFW_UID 301
@@ -80,7 +77,7 @@ typedef struct {
 Each bit position corresponds to a queue slot which
 is dynamically determined.
 */
-char backend_busy = 0;
+static char backend_busy = 0;
 extern int num_of_backends;
 
 struct signal_info_t {
@@ -91,22 +88,8 @@ struct signal_info_t {
 static int pipe_sig[2];
 static GIOChannel *pipe_io;
 static guint pipe_wid;
-
-backend_info *begin;
-extern queue_info_map *start;
-extern int entries;
-
-GMainLoop *mainloop = NULL;
-
-
-/* operation_type */
-typedef enum {
-       OPERATION_INSTALL = 0,
-       OPERATION_UNINSTALL,
-       OPERATION_ACTIVATE,
-       OPERATION_REINSTALL,
-       OPERATION_MAX
-} OPERATION_TYPE;
+static GHashTable *backend_info_table;
+static GMainLoop *mainloop = NULL;
 
 static int __check_backend_status_for_exit(void);
 static int __check_queue_status_for_exit(void);
@@ -117,59 +100,58 @@ static void sighandler(int signo);
 
 gboolean exit_server(void *data);
 
-/* To check whether a particular backend is free/busy*/
+/* To check whether a particular backend is free/busy */
 static int __is_backend_busy(int position)
 {
-       return backend_busy & 1<<position;
+       return backend_busy & (1 << position);
 }
-/*To set a particular backend as busy*/
+/* To set a particular backend as busy */
 static void __set_backend_busy(int position)
 {
-       backend_busy = backend_busy | 1<<position;
+       backend_busy = backend_busy | (1 << position);
 }
-/*To set a particular backend as free */
+/* To set a particular backend as free */
 static void __set_backend_free(int position)
 {
-       backend_busy = backend_busy & ~(1<<position);
+       backend_busy = backend_busy & ~(1 << position);
 }
 
-static gboolean pipe_io_handler(GIOChannel *io, GIOCondition cond, gpointer data)
+static gboolean pipe_io_handler(GIOChannel *io, GIOCondition cond,
+               gpointer data)
 {
-       int x;
        GError *err = NULL;
        GIOStatus s;
        gsize len;
        struct signal_info_t info;
-       backend_info *ptr = begin;
+       struct backend_job *job;
 
-       s = g_io_channel_read_chars(io, (gchar *)&info, sizeof(struct signal_info_t), &len, &err);
+       s = g_io_channel_read_chars(io, (gchar *)&info,
+                       sizeof(struct signal_info_t), &len, &err);
        if (s != G_IO_STATUS_NORMAL) {
                ERR("Signal pipe read failed: %s", err->message);
                g_error_free(err);
                return TRUE;
        }
 
-       for (x = 0; x < num_of_backends; x++, ptr++) {
-               if (ptr && ptr->pid == info.pid)
-                       break;
-       }
-
-       if (x == num_of_backends) {
+       job = (struct backend_job *)g_hash_table_lookup(backend_info_table,
+                       (gconstpointer)info.pid);
+       if (job == NULL) {
                ERR("Unknown child exit");
                return -1;
        }
 
-       __set_backend_free(x);
+       __set_backend_free(job->backend_slot);
        if (WIFSIGNALED(info.status)) {
-               __send_fail_signal(ptr);
-               DBG("backend[%s] exit with signal[%d]", ptr->pkgtype,
+               _send_fail_signal(job);
+               DBG("backend[%s] exit with signal[%d]", job->backend_type,
                                WTERMSIG(info.status));
        } else if (WEXITSTATUS(info.status)) {
-               DBG("backend[%s] exit with error", ptr->pkgtype);
+               DBG("backend[%s] exit with error", job->backend_type);
        } else {
-               DBG("backend[%s] exit", ptr->pkgtype);
+               DBG("backend[%s] exit", job->backend_type);
        }
 
+       g_hash_table_remove(backend_info_table, (gconstpointer)info.pid);
        g_idle_add(queue_job, NULL);
 
        return TRUE;
@@ -177,15 +159,9 @@ static gboolean pipe_io_handler(GIOChannel *io, GIOCondition cond, gpointer data
 
 static int __init_backend_info(void)
 {
-       backend_info *ptr;
-
-       /*Allocate memory for holding pid, pkgtype and pkgid*/
-       ptr = (backend_info*)calloc(num_of_backends, sizeof(backend_info));
-       if (ptr == NULL) {
-               DBG("Malloc Failed\n");
-               return -1;
-       }
-       begin = ptr;
+       backend_info_table = g_hash_table_new_full(g_direct_hash,
+                       g_direct_equal, NULL,
+                       (GDestroyNotify)_free_backend_job);
 
        if (pipe(pipe_sig)) {
                ERR("create pipe failed");
@@ -208,7 +184,7 @@ static void __fini_backend_info(void)
        close(pipe_sig[1]);
 
        /*Free backend info */
-       free(begin);
+       g_hash_table_destroy(backend_info_table);
 }
 
 static void sighandler(int signo)
@@ -218,7 +194,8 @@ static void sighandler(int signo)
 
        info.pid = waitpid(-1, &info.status, WNOHANG);
        if (write(pipe_sig[1], &info, sizeof(struct signal_info_t)) < 0)
-               ERR("failed to write result: %s", strerror_r(errno, buf, sizeof(buf)));
+               ERR("failed to write result: %s",
+                               strerror_r(errno, buf, sizeof(buf)));
 }
 
 static int __register_signal_handler(void)
@@ -233,7 +210,7 @@ static int __register_signal_handler(void)
        sigemptyset(&act.sa_mask);
        act.sa_flags = SA_NOCLDSTOP;
        if (sigaction(SIGCHLD, &act, NULL) < 0) {
-               ERR("signal: SIGCHLD failed\n");
+               ERR("signal: SIGCHLD failed");
                return -1;
        }
 
@@ -245,7 +222,7 @@ static int __register_signal_handler(void)
 
 static int __check_backend_status_for_exit(void)
 {
-       int i = 0;
+       int i;
        for (i = 0; i < num_of_backends; i++) {
                if (__is_backend_busy(i))
                        return 0;
@@ -255,24 +232,9 @@ static int __check_backend_status_for_exit(void)
 
 static int __check_queue_status_for_exit(void)
 {
-       pm_queue_data *head[MAX_QUEUE_NUM] = {NULL,};
-       queue_info_map *ptr = NULL;
-       ptr = start;
-       int i = 0;
-       int c = 0;
-       int slot = -1;
-       for (i = 0; i < entries; i++) {
-               if (ptr->queue_slot <= slot) {
-                       ptr++;
-               } else {
-                       head[c] = ptr->head;
-                       slot = ptr->queue_slot;
-                       c++;
-                       ptr++;
-               }
-       }
+       int i;
        for (i = 0; i < num_of_backends; i++) {
-               if (head[i])
+               if (_is_queue_empty(i) == 0)
                        return 0;
        }
        return 1;
@@ -280,19 +242,17 @@ static int __check_queue_status_for_exit(void)
 
 gboolean exit_server(void *data)
 {
-       DBG("exit_server Start\n");
+       DBG("exit_server Start");
        if (__check_backend_status_for_exit() &&
                        __check_queue_status_for_exit()) {
-               if (!getenv("PMS_STANDALONE")) {
-                       g_main_loop_quit(mainloop);
-                       return FALSE;
-               }
+               g_main_loop_quit(mainloop);
+               return FALSE;
        }
        return TRUE;
 }
 
 #ifdef TIZEN_FEATURE_CSR
-static int __check_csr(backend_info *ptr)
+static int __check_csr(const char *path)
 {
        csr_cs_context_h context = NULL;
        csr_cs_malware_h detected = NULL;
@@ -305,12 +265,12 @@ static int __check_csr(backend_info *ptr)
        }
 
        if (context) {
-               ret = csr_cs_scan_file(context, ptr->pkgid, &detected);
+               ret = csr_cs_scan_file(context, path, &detected);
                DBG("CSR result[%d]", ret);
 
                csr_cs_context_destroy(context);
                if (detected != NULL) {
-                       ERR("CSR Denied[%s] Installation", ptr->pkgid);
+                       ERR("CSR Denied[%s] Installation", path);
                        return -1;
                }
        }
@@ -606,22 +566,25 @@ static int __fork_and_exec_with_args(char **argv, uid_t uid)
        return pid;
 }
 
-static int __change_item_info(pm_dbus_msg *item, uid_t uid, bool *is_global)
+static int __change_job_info(struct backend_job *job, uid_t uid,
+               bool *is_global)
 {
        int ret = 0;
        char *pkgid = NULL;
        pkgmgrinfo_appinfo_h handle = NULL;
 
-       switch (item->req_type) {
-       case PKGMGR_REQUEST_TYPE_DISABLE_APP:
-       case PKGMGR_REQUEST_TYPE_DISABLE_GLOBAL_APP_FOR_UID:
-       case PKGMGR_REQUEST_TYPE_ENABLE_APP_SPLASH_SCREEN:
-       case PKGMGR_REQUEST_TYPE_DISABLE_APP_SPLASH_SCREEN:
-               ret = pkgmgrinfo_appinfo_get_usr_appinfo(item->pkgid, uid, &handle);
+       switch (job->req_type) {
+       case REQUEST_TYPE_DISABLE_APP:
+       case REQUEST_TYPE_DISABLE_GLOBAL_APP_FOR_UID:
+       case REQUEST_TYPE_ENABLE_APP_SPLASH_SCREEN:
+       case REQUEST_TYPE_DISABLE_APP_SPLASH_SCREEN:
+               ret = pkgmgrinfo_appinfo_get_usr_appinfo(job->pkgid, uid,
+                               &handle);
                break;
-       case PKGMGR_REQUEST_TYPE_ENABLE_APP:
-       case PKGMGR_REQUEST_TYPE_ENABLE_GLOBAL_APP_FOR_UID:
-               ret = pkgmgrinfo_appinfo_get_usr_disabled_appinfo(item->pkgid, uid, &handle);
+       case REQUEST_TYPE_ENABLE_APP:
+       case REQUEST_TYPE_ENABLE_GLOBAL_APP_FOR_UID:
+               ret = pkgmgrinfo_appinfo_get_usr_disabled_appinfo(job->pkgid,
+                               uid, &handle);
                break;
        default:
                return PMINFO_R_ERROR;
@@ -634,25 +597,27 @@ static int __change_item_info(pm_dbus_msg *item, uid_t uid, bool *is_global)
        if (ret != PMINFO_R_OK)
                goto catch;
 
-       if ((item->req_type == PKGMGR_REQUEST_TYPE_DISABLE_APP
-                       || item->req_type == PKGMGR_REQUEST_TYPE_ENABLE_APP)
-                       && *is_global) {
-                       ret = PMINFO_R_ERROR;
-                       goto catch;
-       } else if ((item->req_type == PKGMGR_REQUEST_TYPE_DISABLE_GLOBAL_APP_FOR_UID
-                       || item->req_type == PKGMGR_REQUEST_TYPE_ENABLE_GLOBAL_APP_FOR_UID)
-                       && !*is_global) {
-                       ret = PMINFO_R_ERROR;
-                       goto catch;
+       if ((job->req_type == REQUEST_TYPE_DISABLE_APP ||
+                               job->req_type == REQUEST_TYPE_ENABLE_APP) &&
+                       *is_global) {
+               ret = PMINFO_R_ERROR;
+               goto catch;
+       } else if ((job->req_type == REQUEST_TYPE_DISABLE_GLOBAL_APP_FOR_UID ||
+                               job->req_type ==
+                               REQUEST_TYPE_ENABLE_GLOBAL_APP_FOR_UID) &&
+                       !*is_global) {
+               ret = PMINFO_R_ERROR;
+               goto catch;
        }
 
        ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
        if (ret != PMINFO_R_OK)
                goto catch;
 
-       strncpy(item->appid, item->pkgid, sizeof(item->pkgid) - 1);
-       memset((item->pkgid), 0, MAX_PKG_NAME_LEN);
-       strncpy(item->pkgid, pkgid, sizeof(item->pkgid) - 1);
+       free(job->appid);
+       job->appid = strdup(job->pkgid);
+       free(job->pkgid);
+       job->pkgid = strdup(pkgid);
 
 catch:
        pkgmgrinfo_appinfo_destroy_appinfo(handle);
@@ -660,384 +625,405 @@ catch:
        return ret;
 }
 
-static int __process_install(pm_dbus_msg *item)
+static int __process_install(struct backend_job *job)
 {
        char *backend_cmd;
        char **argv;
-       char args[MAX_PKG_ARGS_LEN] = {'\0', };
+       char args[MAX_PKG_ARGS_LEN];
        int pid;
 
-       backend_cmd = _get_backend_cmd(item->pkg_type);
+       backend_cmd = job->backend_path;
        if (backend_cmd == NULL)
                return -1;
 
        snprintf(args, sizeof(args), "%s -k %s -i %s -u %d %s", backend_cmd,
-                       item->req_id, item->pkgid, (int)item->uid, item->args);
+                       job->req_id, job->pkgid, (int)job->uid, job->args);
 
        argv = __generate_argv(args);
 
        pid = __fork_and_exec_with_args(argv, APPFW_UID);
        g_strfreev(argv);
-       free(backend_cmd);
 
        return pid;
 }
 
-static int __process_mount_install(pm_dbus_msg *item)
+static int __process_mount_install(struct backend_job *job)
 {
        char *backend_cmd;
        char **argv;
-       char args[MAX_PKG_ARGS_LEN] = {'\0', };
+       char args[MAX_PKG_ARGS_LEN];
        int pid;
 
-       backend_cmd = _get_backend_cmd(item->pkg_type);
+       backend_cmd = job->backend_path;
        if (backend_cmd == NULL)
                return -1;
 
        snprintf(args, sizeof(args), "%s -k %s -w %s -u %d %s", backend_cmd,
-                                        item->req_id, item->pkgid, (int)item->uid, item->args);
+                       job->req_id, job->pkgid, (int)job->uid, job->args);
 
        argv = __generate_argv(args);
 
        pid = __fork_and_exec_with_args(argv, APPFW_UID);
        g_strfreev(argv);
-       free(backend_cmd);
 
        return pid;
 }
 
-static int __process_reinstall(pm_dbus_msg *item)
+static int __process_reinstall(struct backend_job *job)
 {
        char *backend_cmd;
        char **argv;
        char args[MAX_PKG_ARGS_LEN];
        int pid;
 
-       backend_cmd = _get_backend_cmd(item->pkg_type);
+       backend_cmd = job->backend_path;
        if (backend_cmd == NULL)
                return -1;
 
        snprintf(args, sizeof(args), "%s -k %s -r %s -u %d", backend_cmd,
-                       item->req_id, item->pkgid, (int)item->uid);
+                       job->req_id, job->pkgid, (int)job->uid);
        argv = __generate_argv(args);
 
        pid = __fork_and_exec_with_args(argv, APPFW_UID);
 
        g_strfreev(argv);
-       free(backend_cmd);
 
        return pid;
 }
 
-static int __process_uninstall(pm_dbus_msg *item)
+static int __process_uninstall(struct backend_job *job)
 {
        char *backend_cmd;
        char **argv;
        char args[MAX_PKG_ARGS_LEN];
        int pid;
 
-       backend_cmd = _get_backend_cmd(item->pkg_type);
+       backend_cmd = job->backend_path;
        if (backend_cmd == NULL)
                return -1;
 
        snprintf(args, sizeof(args), "%s -k %s -d %s -u %d", backend_cmd,
-                       item->req_id, item->pkgid, (int)item->uid);
+                       job->req_id, job->pkgid, (int)job->uid);
        argv = __generate_argv(args);
 
        pid = __fork_and_exec_with_args(argv, APPFW_UID);
 
        g_strfreev(argv);
-       free(backend_cmd);
 
        return pid;
 }
 
-static int __process_move(pm_dbus_msg *item)
+static int __process_move(struct backend_job *job)
 {
        char *backend_cmd;
        char **argv;
        char args[MAX_PKG_ARGS_LEN];
        int pid;
 
-       backend_cmd = _get_backend_cmd(item->pkg_type);
+       backend_cmd = job->backend_path;
        if (backend_cmd == NULL)
                return -1;
 
        snprintf(args, sizeof(args), "%s -k %s -m %s -u %d -t %s", backend_cmd,
-                       item->req_id, item->pkgid, (int)item->uid, item->args);
+                       job->req_id, job->pkgid, (int)job->uid, job->args);
        argv = __generate_argv(args);
 
        pid = __fork_and_exec_with_args(argv, APPFW_UID);
 
        g_strfreev(argv);
-       free(backend_cmd);
 
        return pid;
 }
 
-static int __process_enable_pkg(pm_dbus_msg *item)
+static int __process_enable_pkg(struct backend_job *job)
 {
        char *backend_cmd;
        char **argv;
        char args[MAX_PKG_ARGS_LEN];
        int pid;
 
-       backend_cmd = _get_backend_cmd(item->pkg_type);
+       backend_cmd = job->backend_path;
        if (backend_cmd == NULL)
                return -1;
 
        snprintf(args, sizeof(args), "%s -k %s -u %d -A %s", backend_cmd,
-                       item->req_id, (int)item->uid, item->pkgid);
+                       job->req_id, (int)job->uid, job->pkgid);
        argv = __generate_argv(args);
 
        pid = __fork_and_exec_with_args(argv, APPFW_UID);
 
        g_strfreev(argv);
-       free(backend_cmd);
 
        return pid;
 }
 
-static int __process_disable_pkg(pm_dbus_msg *item)
+static int __process_disable_pkg(struct backend_job *job)
 {
        char *backend_cmd;
        char **argv;
        char args[MAX_PKG_ARGS_LEN];
        int pid;
 
-       backend_cmd = _get_backend_cmd(item->pkg_type);
+       backend_cmd = job->backend_path;
        if (backend_cmd == NULL)
                return -1;
 
        snprintf(args, sizeof(args), "%s -k %s -u %d -D %s", backend_cmd,
-                       item->req_id, (int)item->uid, item->pkgid);
+                       job->req_id, (int)job->uid, job->pkgid);
        argv = __generate_argv(args);
 
        pid = __fork_and_exec_with_args(argv, APPFW_UID);
 
        g_strfreev(argv);
-       free(backend_cmd);
 
        return pid;
 }
 
-static int __process_enable_app(pm_dbus_msg *item)
+static int __process_enable_app(struct backend_job *job)
 {
        int ret = -1;
        bool is_global = false;
 
-       /* get actual pkgid and replace it to appid which is currently stored at pkgid variable */
-       ret = __change_item_info(item, item->uid, &is_global);
-       if (ret != PMINFO_R_OK || strlen(item->appid) == 0) {
-               __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid,
+       /* get actual pkgid and replace it to appid which is currently stored
+        * at pkgid variable
+        */
+       ret = __change_job_info(job, job->uid, &is_global);
+       if (ret != PMINFO_R_OK || strlen(job->appid) == 0) {
+               _send_app_signal(job->uid, job->req_id, job->pkgid, job->pkgid,
                                PKGMGR_INSTALLER_START_KEY_STR,
-                               PKGMGR_INSTALLER_APP_ENABLE_EVENT_STR, item->req_type);
-               __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid,
-                               PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR,
-                               item->req_type);
+                               PKGMGR_INSTALLER_APP_ENABLE_EVENT_STR,
+                               job->req_type);
+               _send_app_signal(job->uid, job->req_id, job->pkgid, job->pkgid,
+                               PKGMGR_INSTALLER_END_KEY_STR,
+                               PKGMGR_INSTALLER_FAIL_EVENT_STR,
+                               job->req_type);
                return ret;
        }
 
-       __send_app_signal(item->uid, item->req_id, item->pkgid, item->appid,
+       _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid,
                        PKGMGR_INSTALLER_START_KEY_STR,
-                       PKGMGR_INSTALLER_APP_ENABLE_EVENT_STR, item->req_type);
+                       PKGMGR_INSTALLER_APP_ENABLE_EVENT_STR, job->req_type);
 
-       ret = pkgmgr_parser_update_app_disable_info_in_usr_db(item->appid, item->uid, 0);
+       ret = pkgmgr_parser_update_app_disable_info_in_usr_db(job->appid,
+                       job->uid, 0);
        if (ret != PMINFO_R_OK)
-               __send_app_signal(item->uid, item->req_id, item->pkgid, item->appid,
-                               PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR,
-                               item->req_type);
+               _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid,
+                               PKGMGR_INSTALLER_END_KEY_STR,
+                               PKGMGR_INSTALLER_FAIL_EVENT_STR,
+                               job->req_type);
        else
-               __send_app_signal(item->uid, item->req_id, item->pkgid, item->appid,
-                               PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_OK_EVENT_STR,
-                               item->req_type);
-
+               _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid,
+                               PKGMGR_INSTALLER_END_KEY_STR,
+                               PKGMGR_INSTALLER_OK_EVENT_STR,
+                               job->req_type);
 
        return ret;
 }
 
-static int __process_disable_app(pm_dbus_msg *item)
+static int __process_disable_app(struct backend_job *job)
 {
        int ret = -1;
        bool is_global = false;
 
-       /* get actual pkgid and replace it to appid which is currently stored at pkgid variable */
-       ret = __change_item_info(item, item->uid, &is_global);
-       if (ret != PMINFO_R_OK || strlen(item->appid) == 0) {
-               __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid,
+       /* get actual pkgid and replace it to appid which is currently stored
+        * at pkgid variable
+        */
+       ret = __change_job_info(job, job->uid, &is_global);
+       if (ret != PMINFO_R_OK || strlen(job->appid) == 0) {
+               _send_app_signal(job->uid, job->req_id, job->pkgid, job->pkgid,
                                PKGMGR_INSTALLER_START_KEY_STR,
-                               PKGMGR_INSTALLER_APP_DISABLE_EVENT_STR, item->req_type);
-               __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid,
-                               PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR,
-                               item->req_type);
+                               PKGMGR_INSTALLER_APP_DISABLE_EVENT_STR,
+                               job->req_type);
+               _send_app_signal(job->uid, job->req_id, job->pkgid, job->pkgid,
+                               PKGMGR_INSTALLER_END_KEY_STR,
+                               PKGMGR_INSTALLER_FAIL_EVENT_STR,
+                               job->req_type);
                return ret;
        }
 
-       __send_app_signal(item->uid, item->req_id, item->pkgid, item->appid,
+       _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid,
                        PKGMGR_INSTALLER_START_KEY_STR,
-                       PKGMGR_INSTALLER_APP_DISABLE_EVENT_STR, item->req_type);
+                       PKGMGR_INSTALLER_APP_DISABLE_EVENT_STR, job->req_type);
 
-       ret = __kill_app(item->appid, item->uid);
+       ret = __kill_app(job->appid, job->uid);
        if (ret != 0) {
-               __send_app_signal(item->uid, item->req_id, item->pkgid, item->appid,
-                               PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR,
-                               item->req_type);
+               _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid,
+                               PKGMGR_INSTALLER_END_KEY_STR,
+                               PKGMGR_INSTALLER_FAIL_EVENT_STR,
+                               job->req_type);
        }
 
-       ret = pkgmgr_parser_update_app_disable_info_in_usr_db(item->appid, item->uid, 1);
+       ret = pkgmgr_parser_update_app_disable_info_in_usr_db(job->appid,
+                       job->uid, 1);
        if (ret != PMINFO_R_OK)
-               __send_app_signal(item->uid, item->req_id, item->pkgid, item->appid,
-                               PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR,
-                               item->req_type);
+               _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid,
+                               PKGMGR_INSTALLER_END_KEY_STR,
+                               PKGMGR_INSTALLER_FAIL_EVENT_STR,
+                               job->req_type);
        else
-               __send_app_signal(item->uid, item->req_id, item->pkgid, item->appid,
-                               PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_OK_EVENT_STR,
-                               item->req_type);
+               _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid,
+                               PKGMGR_INSTALLER_END_KEY_STR,
+                               PKGMGR_INSTALLER_OK_EVENT_STR,
+                               job->req_type);
 
        return ret;
 }
 
-static int __process_enable_global_app_for_uid(pm_dbus_msg *item)
+static int __process_enable_global_app_for_uid(struct backend_job *job)
 {
        int ret = -1;
        bool is_global = true;
 
-       /* get actual pkgid and replace it to appid which is currently stored at pkgid variable */
-       ret = __change_item_info(item, item->uid, &is_global);
-       if (ret != PMINFO_R_OK || strlen(item->appid) == 0) {
-               __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid,
+       /* get actual pkgid and replace it to appid which is currently stored
+        * at pkgid variable
+        */
+       ret = __change_job_info(job, job->uid, &is_global);
+       if (ret != PMINFO_R_OK || strlen(job->appid) == 0) {
+               _send_app_signal(job->uid, job->req_id, job->pkgid, job->pkgid,
                                PKGMGR_INSTALLER_START_KEY_STR,
-                               PKGMGR_INSTALLER_GLOBAL_APP_ENABLE_FOR_UID, item->req_type);
-               __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid,
-                               PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR,
-                               item->req_type);
+                               PKGMGR_INSTALLER_GLOBAL_APP_ENABLE_FOR_UID,
+                               job->req_type);
+               _send_app_signal(job->uid, job->req_id, job->pkgid, job->pkgid,
+                               PKGMGR_INSTALLER_END_KEY_STR,
+                               PKGMGR_INSTALLER_FAIL_EVENT_STR,
+                               job->req_type);
                return ret;
        }
 
-       __send_app_signal(item->uid, item->req_id, item->pkgid, item->appid,
+       _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid,
                        PKGMGR_INSTALLER_START_KEY_STR,
-                       PKGMGR_INSTALLER_GLOBAL_APP_ENABLE_FOR_UID, item->req_type);
+                       PKGMGR_INSTALLER_GLOBAL_APP_ENABLE_FOR_UID,
+                       job->req_type);
 
-       ret = pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(item->appid, item->uid, 0);
+       ret = pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(
+                       job->appid, job->uid, 0);
        if (ret != PMINFO_R_OK)
-               __send_app_signal(item->uid, item->req_id, item->pkgid, item->appid,
-                               PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR,
-                               item->req_type);
+               _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid,
+                               PKGMGR_INSTALLER_END_KEY_STR,
+                               PKGMGR_INSTALLER_FAIL_EVENT_STR,
+                               job->req_type);
        else
-               __send_app_signal(item->uid, item->req_id, item->pkgid, item->appid,
-                               PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_OK_EVENT_STR,
-                               item->req_type);
+               _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid,
+                               PKGMGR_INSTALLER_END_KEY_STR,
+                               PKGMGR_INSTALLER_OK_EVENT_STR,
+                               job->req_type);
 
        return ret;
 }
 
-static int __process_disable_global_app_for_uid(pm_dbus_msg *item)
+static int __process_disable_global_app_for_uid(struct backend_job *job)
 {
        int ret = -1;
        bool is_global = true;
 
-       /* get actual pkgid and replace it to appid which is currently stored at pkgid variable */
-       ret = __change_item_info(item, GLOBAL_USER, &is_global);
-       if (ret != PMINFO_R_OK || strlen(item->appid) == 0) {
-               __send_app_signal(item->uid, item->req_id,
-                               item->pkgid, item->pkgid,
+       /* get actual pkgid and replace it to appid which is currently stored
+        * at pkgid variable
+        */
+       ret = __change_job_info(job, GLOBAL_USER, &is_global);
+       if (ret != PMINFO_R_OK || strlen(job->appid) == 0) {
+               _send_app_signal(job->uid, job->req_id,
+                               job->pkgid, job->pkgid,
                                PKGMGR_INSTALLER_START_KEY_STR,
-                               PKGMGR_INSTALLER_GLOBAL_APP_DISABLE_FOR_UID, item->req_type);
-               __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid,
-                               PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR,
-                               item->req_type);
+                               PKGMGR_INSTALLER_GLOBAL_APP_DISABLE_FOR_UID,
+                               job->req_type);
+               _send_app_signal(job->uid, job->req_id, job->pkgid, job->pkgid,
+                               PKGMGR_INSTALLER_END_KEY_STR,
+                               PKGMGR_INSTALLER_FAIL_EVENT_STR,
+                               job->req_type);
                return ret;
        }
 
-       __send_app_signal(item->uid, item->req_id,
-                       item->pkgid, item->appid,
+       _send_app_signal(job->uid, job->req_id,
+                       job->pkgid, job->appid,
                        PKGMGR_INSTALLER_START_KEY_STR,
-                       PKGMGR_INSTALLER_GLOBAL_APP_DISABLE_FOR_UID, item->req_type);
+                       PKGMGR_INSTALLER_GLOBAL_APP_DISABLE_FOR_UID,
+                       job->req_type);
 
-       ret = __kill_app(item->appid, item->uid);
-       ret = pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(item->appid,
-               item->uid, 1);
+       ret = __kill_app(job->appid, job->uid);
+       ret = pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(
+                       job->appid, job->uid, 1);
 
        if (ret != PMINFO_R_OK)
-               __send_app_signal(item->uid, item->req_id, item->pkgid, item->appid,
-                               PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR,
-                               item->req_type);
+               _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid,
+                               PKGMGR_INSTALLER_END_KEY_STR,
+                               PKGMGR_INSTALLER_FAIL_EVENT_STR,
+                               job->req_type);
        else
-               __send_app_signal(item->uid, item->req_id, item->pkgid, item->appid,
-                               PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_OK_EVENT_STR,
-                               item->req_type);
+               _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid,
+                               PKGMGR_INSTALLER_END_KEY_STR,
+                               PKGMGR_INSTALLER_OK_EVENT_STR,
+                               job->req_type);
 
        return ret;
 }
 
-static int __process_getsize(pm_dbus_msg *item)
+static int __process_getsize(struct backend_job *job)
 {
        static const char *backend_cmd = "/usr/bin/pkg_getsize";
        char **argv;
        char args[MAX_PKG_ARGS_LEN];
        int pid;
 
-       snprintf(args, sizeof(args), "%s %s %s -k %s", backend_cmd, item->pkgid,
-                       item->args, item->req_id);
+       snprintf(args, sizeof(args), "%s %s %s -k %s", backend_cmd, job->pkgid,
+                       job->args, job->req_id);
        argv = __generate_argv(args);
-       pid = __fork_and_exec_with_args(argv, item->uid);
+       pid = __fork_and_exec_with_args(argv, job->uid);
 
        g_strfreev(argv);
 
        return pid;
 }
 
-static int __process_cleardata(pm_dbus_msg *item)
+static int __process_cleardata(struct backend_job *job)
 {
        char *backend_cmd;
        char **argv;
        char args[MAX_PKG_ARGS_LEN];
        int pid;
 
-       backend_cmd = _get_backend_cmd(item->pkg_type);
+       backend_cmd = job->backend_path;
        if (backend_cmd == NULL)
                return -1;
 
        /* TODO: set movetype */
        snprintf(args, sizeof(args), "%s -k %s -c %s -u %d", backend_cmd,
-                       item->req_id, item->pkgid, (int)item->uid);
+                       job->req_id, job->pkgid, (int)job->uid);
        argv = __generate_argv(args);
 
        pid = __fork_and_exec_with_args(argv, APPFW_UID);
 
        g_strfreev(argv);
-       free(backend_cmd);
 
        return pid;
 }
 
-static int __process_clearcache(pm_dbus_msg *item)
+static int __process_clearcache(struct backend_job *job)
 {
        static const char *backend_cmd = "/usr/bin/pkg_clearcache";
        char **argv;
        char args[MAX_PKG_ARGS_LEN];
        int pid;
 
-       snprintf(args, sizeof(args), "%s %s", backend_cmd, item->pkgid);
+       snprintf(args, sizeof(args), "%s %s", backend_cmd, job->pkgid);
        argv = __generate_argv(args);
-       pid = __fork_and_exec_with_args(argv, item->uid);
+       pid = __fork_and_exec_with_args(argv, job->uid);
 
        g_strfreev(argv);
 
        return pid;
 }
 
-static int __process_kill(pm_dbus_msg *item)
+static int __process_kill(struct backend_job *job)
 {
        int ret;
        pkgmgrinfo_pkginfo_h handle;
        pkgcmd_data *pdata;
 
-       ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(item->pkgid, item->uid,
+       ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(job->pkgid, job->uid,
                        &handle);
        if (ret < 0) {
                ERR("Failed to get handle");
-               __return_value_to_caller(item->req_id,
+               _return_value_to_caller(job->req_id,
                                g_variant_new("(ii)", PKGMGR_R_ERROR, 0));
                return -1;
        }
@@ -1045,23 +1031,23 @@ static int __process_kill(pm_dbus_msg *item)
        pdata = calloc(1, sizeof(pkgcmd_data));
        if (pdata == NULL) {
                ERR("memory alloc failed");
-               __return_value_to_caller(item->req_id,
+               _return_value_to_caller(job->req_id,
                                g_variant_new("(ii)", PKGMGR_R_ENOMEM, 0));
                return -1;
        }
        pdata->cmd = strdup("kill");
        if (pdata->cmd == NULL) {
                ERR("out of memory");
-               __return_value_to_caller(item->req_id,
+               _return_value_to_caller(job->req_id,
                                g_variant_new("(ii)", PKGMGR_R_ENOMEM, 0));
                free(pdata);
                return -1;
        }
-       pdata->uid = item->uid;
+       pdata->uid = job->uid;
        ret = pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_ALL_APP,
-                       __pkgcmd_app_cb, pdata, item->uid);
+                       __pkgcmd_app_cb, pdata, job->uid);
 
-       __return_value_to_caller(item->req_id,
+       _return_value_to_caller(job->req_id,
                        g_variant_new("(ii)", PKGMGR_R_OK, pdata->pid));
 
        free(pdata->cmd);
@@ -1075,17 +1061,17 @@ static int __process_kill(pm_dbus_msg *item)
        return 0;
 }
 
-static int __process_check(pm_dbus_msg *item)
+static int __process_check(struct backend_job *job)
 {
        int ret;
        pkgmgrinfo_pkginfo_h handle;
        pkgcmd_data *pdata;
 
-       ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(item->pkgid, item->uid,
+       ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(job->pkgid, job->uid,
                        &handle);
        if (ret < 0) {
                ERR("Failed to get handle");
-               __return_value_to_caller(item->req_id,
+               _return_value_to_caller(job->req_id,
                                g_variant_new("(ii)", PKGMGR_R_ERROR, 0));
                return -1;
        }
@@ -1093,23 +1079,23 @@ static int __process_check(pm_dbus_msg *item)
        pdata = calloc(1, sizeof(pkgcmd_data));
        if (pdata == NULL) {
                ERR("memory alloc failed");
-               __return_value_to_caller(item->req_id,
+               _return_value_to_caller(job->req_id,
                                g_variant_new("(ii)", PKGMGR_R_ENOMEM, 0));
                return -1;
        }
        pdata->cmd = strdup("check");
        if (pdata->cmd == NULL) {
                ERR("out of memory");
-               __return_value_to_caller(item->req_id,
+               _return_value_to_caller(job->req_id,
                                g_variant_new("(ii)", PKGMGR_R_ENOMEM, 0));
                free(pdata);
                return -1;
        }
-       pdata->uid = item->uid;
+       pdata->uid = job->uid;
        ret = pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_ALL_APP,
-                       __pkgcmd_app_cb, pdata, item->uid);
+                       __pkgcmd_app_cb, pdata, job->uid);
 
-       __return_value_to_caller(item->req_id,
+       _return_value_to_caller(job->req_id,
                        g_variant_new("(ii)", PKGMGR_R_OK, pdata->pid));
 
        free(pdata->cmd);
@@ -1123,7 +1109,7 @@ static int __process_check(pm_dbus_msg *item)
        return 0;
 }
 
-static int __process_generate_license_request(pm_dbus_msg *item)
+static int __process_generate_license_request(struct backend_job *job)
 {
        int ret;
        char *resp_data;
@@ -1132,7 +1118,7 @@ static int __process_generate_license_request(pm_dbus_msg *item)
        char license_url[MAX_PKG_ARGS_LEN];
        unsigned int license_url_len;
 
-       resp_data = item->args;
+       resp_data = job->args;
        req_data_len = sizeof(req_data);
        license_url_len = sizeof(license_url);
 
@@ -1140,135 +1126,134 @@ static int __process_generate_license_request(pm_dbus_msg *item)
                        req_data, &req_data_len, license_url, &license_url_len);
        if (ret != TADC_SUCCESS) {
                ERR("drm_tizen_generate_license_request failed: %d", ret);
-               __return_value_to_caller(item->req_id, g_variant_new("(iss)",
+               _return_value_to_caller(job->req_id, g_variant_new("(iss)",
                                        PKGMGR_R_ESYSTEM, "", ""));
                return -1;
        }
 
-       __return_value_to_caller(item->req_id,
+       _return_value_to_caller(job->req_id,
                        g_variant_new("(iss)", PKGMGR_R_OK, req_data,
                                license_url));
 
        return 0;
 }
 
-static int __process_register_license(pm_dbus_msg *item)
+static int __process_register_license(struct backend_job *job)
 {
        int ret;
        char *resp_data;
 
-       resp_data = item->args;
+       resp_data = job->args;
 
        ret = drm_tizen_register_license(resp_data, strlen(resp_data));
        if (ret != TADC_SUCCESS) {
                ERR("drm_tizen_register_license failed: %d", ret);
-               __return_value_to_caller(item->req_id,
+               _return_value_to_caller(job->req_id,
                                g_variant_new("(i)", PKGMGR_R_ESYSTEM));
                return -1;
        }
 
-       __return_value_to_caller(item->req_id,
+       _return_value_to_caller(job->req_id,
                        g_variant_new("(i)", PKGMGR_R_OK));
 
        return 0;
 }
 
-static int __process_decrypt_package(pm_dbus_msg *item)
+static int __process_decrypt_package(struct backend_job *job)
 {
        int ret;
        char *drm_file_path;
        char *decrypted_file_path;
 
-       drm_file_path = item->pkgid;
-       decrypted_file_path = item->args;
+       drm_file_path = job->pkgid;
+       decrypted_file_path = job->args;
 
        /* TODO: check ownership of decrypted file */
        ret = drm_tizen_decrypt_package(drm_file_path, strlen(drm_file_path),
                        decrypted_file_path, strlen(decrypted_file_path));
        if (ret != TADC_SUCCESS) {
                ERR("drm_tizen_register_license failed: %d", ret);
-               __return_value_to_caller(item->req_id,
+               _return_value_to_caller(job->req_id,
                                g_variant_new("(i)", PKGMGR_R_ESYSTEM));
                return -1;
        }
 
-       __return_value_to_caller(item->req_id,
+       _return_value_to_caller(job->req_id,
                        g_variant_new("(i)", PKGMGR_R_OK));
 
        return 0;
 }
 
-static int __process_update_app_splash_screen(pm_dbus_msg *item, int flag)
+static int __process_update_app_splash_screen(struct backend_job *job, int flag)
 {
        int ret;
        bool is_global = false;
        const char *val;
 
-       ret = __change_item_info(item, item->uid, &is_global);
-       if (ret != PMINFO_R_OK || strlen(item->appid) == 0)
+       ret = __change_job_info(job, job->uid, &is_global);
+       if (ret != PMINFO_R_OK || strlen(job->appid) == 0)
                return -1;
 
        val = flag ? PKGMGR_INSTALLER_APP_ENABLE_SPLASH_SCREEN_EVENT_STR :
                PKGMGR_INSTALLER_APP_DISABLE_SPLASH_SCREEN_EVENT_STR;
-       __send_app_signal(item->uid, item->req_id, item->pkgid, item->appid,
-                       PKGMGR_INSTALLER_START_KEY_STR, val, item->req_type);
+       _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid,
+                       PKGMGR_INSTALLER_START_KEY_STR, val, job->req_type);
 
        if (is_global)
-               ret = pkgmgr_parser_update_global_app_splash_screen_display_info_in_usr_db(
-                               item->appid, item->uid, flag);
+               ret = pkgmgr_parser_update_global_app_splash_screen_display_info_in_usr_db(job->appid, job->uid, flag);
        else
                ret = pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db(
-                       item->appid, item->uid, flag);
+                       job->appid, job->uid, flag);
        if (ret != PMINFO_R_OK)
-               __send_app_signal(item->uid, item->req_id, item->pkgid,
-                               item->appid, PKGMGR_INSTALLER_END_KEY_STR,
+               _send_app_signal(job->uid, job->req_id, job->pkgid,
+                               job->appid, PKGMGR_INSTALLER_END_KEY_STR,
                                PKGMGR_INSTALLER_FAIL_EVENT_STR,
-                               item->req_type);
+                               job->req_type);
        else
-               __send_app_signal(item->uid, item->req_id, item->pkgid,
-                               item->appid, PKGMGR_INSTALLER_END_KEY_STR,
+               _send_app_signal(job->uid, job->req_id, job->pkgid,
+                               job->appid, PKGMGR_INSTALLER_END_KEY_STR,
                                PKGMGR_INSTALLER_OK_EVENT_STR,
-                               item->req_type);
+                               job->req_type);
 
        return ret;
 }
 
-static int __process_set_restriction_mode(pm_dbus_msg *item)
+static int __process_set_restriction_mode(struct backend_job *job)
 {
        int ret;
        int mode;
 
-       mode = atoi(item->args);
-       ret = _restriction_mode_set(item->uid, item->pkgid, mode);
+       mode = atoi(job->args);
+       ret = _set_restriction_mode(job->uid, job->pkgid, mode);
 
-       __return_value_to_caller(item->req_id,
+       _return_value_to_caller(job->req_id,
                        g_variant_new("(i)", ret));
 
        return ret;
 }
 
-static int __process_unset_restriction_mode(pm_dbus_msg *item)
+static int __process_unset_restriction_mode(struct backend_job *job)
 {
        int ret;
        int mode;
 
-       mode = atoi(item->args);
-       ret = _restriction_mode_unset(item->uid, item->pkgid, mode);
+       mode = atoi(job->args);
+       ret = _unset_restriction_mode(job->uid, job->pkgid, mode);
 
-       __return_value_to_caller(item->req_id,
+       _return_value_to_caller(job->req_id,
                        g_variant_new("(i)", ret));
 
        return ret;
 }
 
-static int __process_get_restriction_mode(pm_dbus_msg *item)
+static int __process_get_restriction_mode(struct backend_job *job)
 {
        int ret;
        int mode = -1;
 
-       ret = _restriction_mode_get(item->uid, item->pkgid, &mode);
+       ret = _get_restriction_mode(job->uid, job->pkgid, &mode);
 
-       __return_value_to_caller(item->req_id,
+       _return_value_to_caller(job->req_id,
                        g_variant_new("(ii)", mode, ret));
 
        return ret;
@@ -1276,230 +1261,170 @@ static int __process_get_restriction_mode(pm_dbus_msg *item)
 
 gboolean queue_job(void *data)
 {
-       pm_dbus_msg *item = NULL;
-       backend_info *ptr;
+       struct backend_job *job = NULL;
        int x;
        int ret;
 
        /* Pop a job from queue */
-       for (x = 0, ptr = begin; x < num_of_backends; x++, ptr++) {
+       for (x = 0; x < num_of_backends; x++) {
                if (__is_backend_busy(x))
                        continue;
 
-               item = _pm_queue_pop(x);
-               if (item && item->req_type != -1)
+               job = _pop_queue(x);
+               if (job)
                        break;
-               free(item);
        }
 
        /* all backend messages queue are empty or busy */
-       if (x == num_of_backends)
+       if (x == num_of_backends || job == NULL) {
+               DBG("no job left");
                return FALSE;
+       }
 
-       /*save pkg type and pkg name for future*/
-       strncpy(ptr->req_id, item->req_id, MAX_REQ_ID_LEN - 1);
-       strncpy(ptr->pkgtype, item->pkg_type, MAX_PKG_TYPE_LEN - 1);
-       strncpy(ptr->pkgid, item->pkgid, MAX_PKG_NAME_LEN - 1);
-       free(ptr->args);
-       if (item->args)
-               ptr->args = strdup(item->args);
-       memset((item->appid), 0, MAX_PKG_NAME_LEN);
-       ptr->uid = item->uid;
-       ptr->req_type = item->req_type;
-       DBG("handle request type [%d]", item->req_type);
+       /* set current backend job */
+       DBG("handle request type [%d]", job->req_type);
 
 #ifdef TIZEN_FEATURE_CSR
-       if (item->req_type == PKGMGR_REQUEST_TYPE_INSTALL ||
-                       item->req_type == PKGMGR_REQUEST_TYPE_MOUNT_INSTALL ||
-                       item->req_type == PKGMGR_REQUEST_TYPE_REINSTALL) {
-               ret = __check_csr(ptr);
+       if (job->req_type == REQUEST_TYPE_INSTALL ||
+                       job->req_type == REQUEST_TYPE_MOUNT_INSTALL ||
+                       job->req_type == REQUEST_TYPE_REINSTALL) {
+               ret = __check_csr(job->pkgid);
                if (ret != 0) {
                        ret = -1;
-                       __send_fail_signal(ptr);
-                       goto end;
+                       _send_fail_signal(job);
+                       _free_backend_job(job);
+                       return FALSE;
                }
        }
 #endif
 
-       switch (item->req_type) {
-       case PKGMGR_REQUEST_TYPE_INSTALL:
+       switch (job->req_type) {
+       case REQUEST_TYPE_INSTALL:
                __set_backend_busy(x);
-               ret = __process_install(item);
+               ret = __process_install(job);
+               g_hash_table_insert(backend_info_table, (gpointer)ret,
+                               (gpointer)job);
                break;
-       case PKGMGR_REQUEST_TYPE_MOUNT_INSTALL:
+       case REQUEST_TYPE_MOUNT_INSTALL:
                __set_backend_busy(x);
-               ret = __process_mount_install(item);
+               ret = __process_mount_install(job);
+               g_hash_table_insert(backend_info_table, (gpointer)ret,
+                               (gpointer)job);
                break;
-       case PKGMGR_REQUEST_TYPE_REINSTALL:
+       case REQUEST_TYPE_REINSTALL:
                __set_backend_busy(x);
-               ret = __process_reinstall(item);
+               ret = __process_reinstall(job);
+               g_hash_table_insert(backend_info_table, (gpointer)ret,
+                               (gpointer)job);
                break;
-       case PKGMGR_REQUEST_TYPE_UNINSTALL:
+       case REQUEST_TYPE_UNINSTALL:
                __set_backend_busy(x);
-               ret = __process_uninstall(item);
+               ret = __process_uninstall(job);
+               g_hash_table_insert(backend_info_table, (gpointer)ret,
+                               (gpointer)job);
                break;
-       case PKGMGR_REQUEST_TYPE_MOVE:
+       case REQUEST_TYPE_MOVE:
                __set_backend_busy(x);
-               ret = __process_move(item);
+               ret = __process_move(job);
+               g_hash_table_insert(backend_info_table, (gpointer)ret,
+                               (gpointer)job);
                break;
-       case PKGMGR_REQUEST_TYPE_ENABLE_PKG:
+       case REQUEST_TYPE_ENABLE_PKG:
                __set_backend_busy(x);
-               ret = __process_enable_pkg(item);
+               ret = __process_enable_pkg(job);
+               g_hash_table_insert(backend_info_table, (gpointer)ret,
+                               (gpointer)job);
                break;
-       case PKGMGR_REQUEST_TYPE_DISABLE_PKG:
+       case REQUEST_TYPE_DISABLE_PKG:
                __set_backend_busy(x);
-               ret = __process_disable_pkg(item);
+               ret = __process_disable_pkg(job);
+               g_hash_table_insert(backend_info_table, (gpointer)ret,
+                               (gpointer)job);
                break;
-       case PKGMGR_REQUEST_TYPE_ENABLE_APP:
-               ret = __process_enable_app(item);
+       case REQUEST_TYPE_ENABLE_APP:
+               ret = __process_enable_app(job);
                break;
-       case PKGMGR_REQUEST_TYPE_DISABLE_APP:
-               ret = __process_disable_app(item);
+       case REQUEST_TYPE_DISABLE_APP:
+               ret = __process_disable_app(job);
                break;
-       case PKGMGR_REQUEST_TYPE_GETSIZE:
+       case REQUEST_TYPE_GETSIZE:
                __set_backend_busy(x);
-               ret = __process_getsize(item);
+               ret = __process_getsize(job);
                break;
-       case PKGMGR_REQUEST_TYPE_CLEARDATA:
+       case REQUEST_TYPE_CLEARDATA:
                __set_backend_busy(x);
-               ret = __process_cleardata(item);
+               ret = __process_cleardata(job);
                break;
-       case PKGMGR_REQUEST_TYPE_CLEARCACHE:
+       case REQUEST_TYPE_CLEARCACHE:
                __set_backend_busy(x);
-               ret = __process_clearcache(item);
+               ret = __process_clearcache(job);
+               _free_backend_job(job);
                break;
-       case PKGMGR_REQUEST_TYPE_ENABLE_GLOBAL_APP_FOR_UID:
-               ret = __process_enable_global_app_for_uid(item);
+       case REQUEST_TYPE_ENABLE_GLOBAL_APP_FOR_UID:
+               ret = __process_enable_global_app_for_uid(job);
+               _free_backend_job(job);
                break;
-       case PKGMGR_REQUEST_TYPE_DISABLE_GLOBAL_APP_FOR_UID:
-               ret = __process_disable_global_app_for_uid(item);
+       case REQUEST_TYPE_DISABLE_GLOBAL_APP_FOR_UID:
+               ret = __process_disable_global_app_for_uid(job);
+               _free_backend_job(job);
                break;
-       case PKGMGR_REQUEST_TYPE_KILL:
-               ret = __process_kill(item);
+       case REQUEST_TYPE_KILL:
+               ret = __process_kill(job);
+               _free_backend_job(job);
                break;
-       case PKGMGR_REQUEST_TYPE_CHECK:
-               ret = __process_check(item);
+       case REQUEST_TYPE_CHECK:
+               ret = __process_check(job);
+               _free_backend_job(job);
                break;
-       case PKGMGR_REQUEST_TYPE_GENERATE_LICENSE_REQUEST:
-               ret = __process_generate_license_request(item);
+       case REQUEST_TYPE_GENERATE_LICENSE_REQUEST:
+               ret = __process_generate_license_request(job);
+               _free_backend_job(job);
                break;
-       case PKGMGR_REQUEST_TYPE_REGISTER_LICENSE:
-               ret = __process_register_license(item);
+       case REQUEST_TYPE_REGISTER_LICENSE:
+               ret = __process_register_license(job);
+               _free_backend_job(job);
                break;
-       case PKGMGR_REQUEST_TYPE_DECRYPT_PACKAGE:
-               ret = __process_decrypt_package(item);
+       case REQUEST_TYPE_DECRYPT_PACKAGE:
+               ret = __process_decrypt_package(job);
+               _free_backend_job(job);
                break;
-       case PKGMGR_REQUEST_TYPE_ENABLE_APP_SPLASH_SCREEN:
-               ret = __process_update_app_splash_screen(item, 1);
+       case REQUEST_TYPE_ENABLE_APP_SPLASH_SCREEN:
+               ret = __process_update_app_splash_screen(job, 1);
+               _free_backend_job(job);
                break;
-       case PKGMGR_REQUEST_TYPE_DISABLE_APP_SPLASH_SCREEN:
-               ret = __process_update_app_splash_screen(item, 0);
+       case REQUEST_TYPE_DISABLE_APP_SPLASH_SCREEN:
+               ret = __process_update_app_splash_screen(job, 0);
+               _free_backend_job(job);
                break;
-       case PKGMGR_REQUEST_TYPE_SET_RESTRICTION_MODE:
-               ret = __process_set_restriction_mode(item);
+       case REQUEST_TYPE_SET_RESTRICTION_MODE:
+               ret = __process_set_restriction_mode(job);
+               _free_backend_job(job);
                break;
-       case PKGMGR_REQUEST_TYPE_UNSET_RESTRICTION_MODE:
-               ret = __process_unset_restriction_mode(item);
+       case REQUEST_TYPE_UNSET_RESTRICTION_MODE:
+               ret = __process_unset_restriction_mode(job);
+               _free_backend_job(job);
                break;
-       case PKGMGR_REQUEST_TYPE_GET_RESTRICTION_MODE:
-               ret = __process_get_restriction_mode(item);
+       case REQUEST_TYPE_GET_RESTRICTION_MODE:
+               ret = __process_get_restriction_mode(job);
+               _free_backend_job(job);
                break;
        default:
                ret = -1;
                break;
        }
 
-#ifdef TIZEN_FEATURE_CSR
-end:
-#endif
-       ptr->pid = ret;
-       free(item);
-
        return FALSE;
 }
 
-#define IS_WHITESPACE(CHAR) \
-((CHAR == ' ' || CHAR == '\t' || CHAR == '\r' || CHAR == '\n') ? TRUE : FALSE)
-
-void _app_str_trim(char *input)
-{
-       char *trim_str = input;
-
-       if (input == NULL)
-               return;
-
-       while (*input != 0) {
-               if (!IS_WHITESPACE(*input)) {
-                       *trim_str = *input;
-                       trim_str++;
-               }
-               input++;
-       }
-
-       *trim_str = 0;
-       return;
-}
-
-char *_get_backend_cmd(char *type)
-{
-       FILE *fp = NULL;
-       char buffer[1024] = { 0 };
-       char *command = NULL;
-       int size = 0;
-
-       fp = fopen(PKG_CONF_PATH, "r");
-       if (fp == NULL)
-               return NULL;
-
-       char *path = NULL;
-       while (fgets(buffer, 1024, fp) != NULL) {
-               if (buffer[0] == '#')
-                       continue;
-
-               _app_str_trim(buffer);
-
-               if ((path = strstr(buffer, PKG_BACKEND)) != NULL) {
-                       DBG("buffer [%s]", buffer);
-                       path = path + strlen(PKG_BACKEND);
-                       DBG("path [%s]", path);
-
-                       command =
-                           (char *)malloc(sizeof(char) * strlen(path) +
-                                          strlen(type) + 1);
-                       if (command == NULL) {
-                               fclose(fp);
-                               return NULL;
-                       }
-
-                       size = strlen(path) + strlen(type) + 1;
-                       snprintf(command, size, "%s%s", path, type);
-                       command[strlen(path) + strlen(type)] = '\0';
-                       DBG("command [%s]", command);
-
-                       if (fp != NULL)
-                               fclose(fp);
-
-                       return command;
-               }
-
-               memset(buffer, 0x00, 1024);
-       }
-
-       if (fp != NULL)
-               fclose(fp);
-
-       return NULL;            /* cannot find proper command */
-}
-
 int main(int argc, char *argv[])
 {
        int r;
 
        DBG("server start");
 
-       r = _pm_queue_init();
+       r = _init_backend_queue();
        if (r) {
-               DBG("Queue Initialization Failed\n");
+               DBG("Queue Initialization Failed");
                return -1;
        }
 
@@ -1509,7 +1434,7 @@ int main(int argc, char *argv[])
                return -1;
        }
 
-       r = __init_request_handler();
+       r = _init_request_handler();
        if (r) {
                ERR("dbus init failed");
                return -1;
@@ -1534,9 +1459,9 @@ int main(int argc, char *argv[])
        g_main_loop_run(mainloop);
 
        DBG("Quit main loop.");
-       __fini_request_handler();
+       _fini_request_handler();
        __fini_backend_info();
-       _pm_queue_final();
+       _fini_backend_queue();
 
        DBG("package manager server terminated.");
 
diff --git a/src/pm-queue.c b/src/pm-queue.c
deleted file mode 100644 (file)
index 7085367..0000000
+++ /dev/null
@@ -1,479 +0,0 @@
-/*
- * slp-pkgmgr
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
- * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <dirent.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <ctype.h>
-
-#include "pkgmgr-server.h"
-#include "pm-queue.h"
-
-#ifndef BACKEND_DIR
-#define BACKEND_DIR "/etc/package-manager/backend"
-#endif
-
-static pm_queue_data *__get_head_from_pkgtype(const char *pkg_type);
-static void __update_head_from_pkgtype(pm_queue_data *data);
-static int __entry_exist(char *backend);
-static int __is_pkg_supported(const char *pkgtype);
-
-queue_info_map *start = NULL;
-int entries = 0;
-int slot = 0;
-int num_of_backends = 0;
-
-/*Function to check whether a particular package type
-is supported or not. It parses the queue info map
-to get the information.
-It will prevent the accidental hanging of server.
-Returns 1 if found.*/
-static int __is_pkg_supported(const char *pkgtype)
-{
-       queue_info_map *ptr = NULL;
-       ptr = start;
-       int i = 0;
-       for (i = 0; i < entries; i++) {
-               if (!strncmp(ptr->pkgtype, pkgtype, MAX_PKG_TYPE_LEN))
-                       return 1;
-               else
-                       ptr++;
-       }
-       return 0;
-}
-
-/*tells whether a particular backend exists in the
-* info map or not.
-* on Success it return the queue slot of the already present entry
-* on Failure -1 is returned*/
-static int __entry_exist(char *backend)
-{
-       queue_info_map *ptr = NULL;
-       ptr = start;
-       int i = 0;
-       for (i = 0; i < entries; i++) {
-               if (!strncmp(ptr->backend, backend, MAX_PKG_NAME_LEN))
-                       return ptr->queue_slot;
-               else
-                       ptr++;
-       }
-       return -1;
-}
-
-/*In case of first push, it updates the queue head
-and copies it to all duplicate entries in queue info map*/
-static void __update_head_from_pkgtype(pm_queue_data *data)
-{
-       queue_info_map *ptr = NULL;
-       ptr = start;
-       int slot = -1;
-       int i = 0;
-       for (i = 0; i < entries; i++) {
-               if (!strncmp(ptr->pkgtype, data->msg->pkg_type, MAX_PKG_TYPE_LEN)) {
-                       ptr->head = data;
-                       slot = ptr->queue_slot;
-               } else {
-                       ptr++;
-               }
-       }
-       /*update head for each duplicate entry*/
-       ptr = start;
-       for (i = 0; i < entries; i++) {
-               if (ptr->queue_slot == slot && !ptr->head)
-                       ptr->head = data;
-
-               ptr++;
-       }
-       return;
-}
-
-/*Gets the queue head based on pkg type*/
-static pm_queue_data *__get_head_from_pkgtype(const char *pkg_type)
-{
-       queue_info_map *ptr = NULL;
-       ptr = start;
-       int i = 0;
-       for (i = 0; i < entries; i++) {
-               if (!strncmp(ptr->pkgtype, pkg_type, MAX_PKG_TYPE_LEN))
-                       return ptr->head;
-               else
-                       ptr++;
-       }
-       return NULL;
-
-}
-
-int _pm_queue_init(void)
-{
-       /*Find the num of backends currently supported and initialize
-       that many queues. It is dynamically determined.*/
-       struct dirent **namelist;
-       struct stat fileinfo = {0};
-       queue_info_map *ptr = NULL;
-       int n = 0;
-       int c = 0;
-       int i = 0;
-       int ret = 0;
-       char abs_filename[MAX_PKG_NAME_LEN] = {'\0'};
-       char buf[MAX_PKG_NAME_LEN] = {'\0'};
-       n = scandir(BACKEND_DIR, &namelist, NULL, alphasort);
-       if (n < 0) {
-               perror("scandir");
-               return -1;
-       }
-       i = n;
-       /* Find number of backends (symlinks + executables)
-       The backend dir should not conatin any other file except the backends. */
-       while (n--) {
-               if (!strcmp(namelist[n]->d_name, ".") ||
-                               !strcmp(namelist[n]->d_name, ".."))
-                               continue;
-               snprintf(abs_filename, MAX_PKG_NAME_LEN, "%s/%s",
-                               BACKEND_DIR, namelist[n]->d_name);
-               if (lstat(abs_filename, &fileinfo)) {
-                       perror("lstat");
-                       continue;
-               }
-               if (S_ISDIR(fileinfo.st_mode))
-                       continue;
-               c++;
-               memset(abs_filename, 0x00, MAX_PKG_NAME_LEN);
-       }
-       /* Add entries to info map. */
-       ptr = (queue_info_map*)calloc(c , sizeof(queue_info_map));
-       memset(ptr, '\0', c * sizeof(queue_info_map));
-       start = ptr;
-       for (n = 0; n < c ; n++) {
-               ptr->backend[0] = '\0';
-               ptr->head = NULL;
-               ptr->queue_slot = -2; /* -1 can be error return */
-               ptr->pkgtype[0] = '\0';
-               ptr++;
-       }
-       n = i;
-       ptr = start;
-       while (n--) {
-               if (!strcmp(namelist[n]->d_name, ".") ||
-                               !strcmp(namelist[n]->d_name, ".."))
-                               continue;
-               snprintf(abs_filename, MAX_PKG_NAME_LEN, "%s/%s",
-                       BACKEND_DIR, namelist[n]->d_name);
-               if (lstat(abs_filename, &fileinfo) < 0) {
-                       perror(abs_filename);
-                       return -1;
-               }
-               if (S_ISDIR(fileinfo.st_mode))
-                       continue;
-               /*Found backend*/
-               if (S_ISLNK(fileinfo.st_mode)) {
-                       /*found a symlink*/
-                       ret = readlink(abs_filename, buf, MAX_PKG_NAME_LEN - 1);
-                       if (ret == -1) {
-                               perror("readlink");
-                               return -1;
-                       }
-                       buf[ret] = '\0';
-               } else {
-                       /*executable*/
-                       snprintf(buf, sizeof(buf), "%s", abs_filename);
-               }
-               ret = __entry_exist(buf);
-               if (ret == -1) {
-                       snprintf(ptr->backend, sizeof(ptr->backend), "%s", buf);
-                       snprintf(ptr->pkgtype, sizeof(ptr->pkgtype), "%s", namelist[n]->d_name);
-                       ptr->queue_slot = slot;
-                       ptr->head = NULL;
-                       entries++;
-                       slot++;
-                       ptr++;
-               } else {
-                       snprintf(ptr->backend, sizeof(ptr->backend), "%s", buf);
-                       snprintf(ptr->pkgtype, sizeof(ptr->pkgtype), "%s", namelist[n]->d_name);
-                       ptr->queue_slot = ret;
-                       ptr->head = NULL;
-                       entries++;
-                       ptr++;
-               }
-               free(namelist[n]);
-               memset(buf, 0x00, MAX_PKG_NAME_LEN);
-               continue;
-       }
-       free(namelist);
-       num_of_backends = slot;
-
-#ifdef DEBUG_INFO
-       /*Debug info*/
-       DBG("Queue Info Map");
-       DBG("Number of Backends is %d", num_of_backends);
-       DBG("Number of Entries is %d", entries);
-       DBG("Backend\tType\tSlot\tHead");
-       ptr = start;
-       for (n = 0; n < entries; n++) {
-               DBG("%s\t%s\t%d\t%p", ptr->backend, ptr->pkgtype, ptr->queue_slot, ptr->head);
-               ptr++;
-       }
-#endif
-
-       return 0;
-}
-
-static void __convert_to_lower_case(char *dst, const char *src)
-{
-       int i;
-
-       for (i = 0; src[i] != '\0'; i++)
-               dst[i] = tolower(src[i]);
-       dst[i] = '\0';
-}
-
-int _pm_queue_push(uid_t uid, const char *req_id, int req_type,
-               const char *queue_type, const char *pkgid, const char *args)
-{
-       pm_queue_data *data = NULL;
-       pm_queue_data *cur = NULL;
-       pm_queue_data *tmp = NULL;
-       char type[MAX_PKG_NAME_LEN];
-       int ret;
-
-       __convert_to_lower_case(type, queue_type);
-
-       ret = __is_pkg_supported(type);
-       if (ret == 0)
-               return -1;
-
-       cur = __get_head_from_pkgtype(type);
-       tmp = cur;
-
-       /* TODO: use glist */
-       data = _add_node();
-       if (!data) { /* fail to allocate mem */
-               ERR("Fail to allocate memory\n");
-               return -1;
-       }
-
-       snprintf(data->msg->req_id, sizeof(data->msg->req_id), "%s", req_id);
-       data->msg->req_type = req_type;
-       data->msg->uid = uid;
-       snprintf(data->msg->pkg_type, sizeof(data->msg->pkg_type), "%s", type);
-       snprintf(data->msg->pkgid, sizeof(data->msg->pkgid), "%s", pkgid);
-       if (args)
-               data->msg->args = strdup(args);
-
-       data->next = NULL;
-
-       if (cur == NULL) {
-               /* first push */
-               cur = data;
-               __update_head_from_pkgtype(data);
-       } else {
-               while (tmp->next)
-                       tmp = tmp->next;
-
-               tmp->next = data;
-       }
-       return 0;
-}
-
-/*pop request from queue slot "position" */
-pm_dbus_msg *_pm_queue_pop(int position)
-{
-       pm_dbus_msg *ret;
-       pm_queue_data *cur = NULL;
-       pm_queue_data *saveptr = NULL;
-       queue_info_map *ptr = NULL;
-       int i = 0;
-
-       ret = (pm_dbus_msg *) malloc(sizeof(pm_dbus_msg));
-       if (!ret) {
-               ERR("Mem alloc error");
-               return NULL;
-       }
-       memset(ret, 0x00, sizeof(pm_dbus_msg));
-       ptr = start;
-       for (i = 0; i < entries; i++) {
-               if (ptr->queue_slot == position) {
-                               cur = ptr->head;
-                               break;
-               }
-               ptr++;
-       }
-
-       if (!cur) {             /* queue is empty */
-               ret->req_type = -1;
-               return ret;
-       }
-
-       snprintf(ret->req_id, sizeof(ret->req_id), "%s", cur->msg->req_id);
-       ret->req_type = cur->msg->req_type;
-       ret->uid = cur->msg->uid;
-       snprintf(ret->pkg_type, sizeof(ret->pkg_type), "%s", cur->msg->pkg_type);
-       snprintf(ret->pkgid, sizeof(ret->pkgid), "%s", cur->msg->pkgid);
-       if (cur->msg->args)
-               ret->args = strdup(cur->msg->args);
-
-       ptr->head = cur->next;
-       saveptr = ptr->head;
-       cur->next = NULL;
-       free(cur->msg);
-       free(cur);
-       /* update head for each duplicate queue entry */
-       ptr = start;
-       for (i = 0; i < entries; i++) {
-               if (ptr->queue_slot == position)
-                       ptr->head = saveptr;
-
-               ptr++;
-       }
-       return ret;
-}
-
-/* populate an array of all queue heads and delete them one by one */
-void _pm_queue_final()
-{
-       int c = 0;
-       int i = 0;
-       int slot = -1;
-       pm_queue_data *cur = NULL;
-       pm_queue_data *tail = NULL;
-       pm_queue_data *prev = NULL;
-       pm_queue_data *head[MAX_QUEUE_NUM] = {NULL,};
-       queue_info_map *ptr = NULL;
-       ptr = start;
-
-       for (i = 0; i < num_of_backends; i++)
-               head[i] = NULL;
-
-       for (i = 0; i < entries; i++) {
-               if (ptr->queue_slot <= slot) {
-                       ptr++;
-               } else {
-                       head[c] = ptr->head;
-                       slot = ptr->queue_slot;
-                       c++;
-                       ptr++;
-               }
-       }
-
-       c = 0;
-       while (c < num_of_backends) {
-               if (!head[c]) { /* in case of head is NULL */
-                       c = c + 1;
-                       continue;
-               }
-
-               while (head[c]->next) {
-                       cur = head[c]->next;
-
-                       while (cur->next) {
-                               prev = cur;
-                               cur = cur->next;
-                       }
-
-                       tail = cur;
-
-                       free(tail->msg);
-                       free(tail);
-                       prev->next = NULL;
-               }
-
-               free(head[c]->msg->args);
-               free(head[c]->msg);
-               free(head[c]);
-
-               head[c] = NULL;
-               c = c + 1;
-       }
-       /*Free the info map*/
-       if (start) {
-               free(start);
-               start = NULL;
-       }
-}
-
-pm_queue_data *_add_node()
-{
-       pm_queue_data *newnode = NULL;
-
-       newnode = (pm_queue_data *) malloc(sizeof(pm_queue_data));
-       if (!newnode) { /* if NULL */
-               ERR("Mem alloc error");
-               return NULL;
-       }
-       memset(newnode, 0x00, sizeof(pm_queue_data));
-
-       newnode->msg = (pm_dbus_msg *) malloc(sizeof(pm_dbus_msg));
-       if (!newnode->msg) {
-               ERR("Mem alloc error");
-               free(newnode);
-               return NULL;
-       }
-       memset(newnode->msg, 0x00, sizeof(pm_dbus_msg));
-
-       return newnode;
-}
-
-void _pm_queue_delete(pm_dbus_msg *item)
-{
-       /* Assume that pacakge name is unique */
-       pm_queue_data *cur = NULL;
-       pm_queue_data *prev = NULL;
-       cur = __get_head_from_pkgtype(item->pkg_type);
-       prev = cur;
-       if (cur) {
-               while (cur->next) {
-                       if (!strcmp(item->pkgid, cur->msg->pkgid)) {
-                               prev->next = cur->next;
-                               free(cur->msg);
-                               free(cur);
-                               break;
-                       }
-                       prev = cur;
-                       cur = cur->next;
-               }
-       }
-}
-
-void _print_queue(int position)
-{
-       pm_queue_data *cur = NULL;
-       queue_info_map *ptr = start;
-       int i = 0;
-       for (i = 0; i < entries; i++) {
-               if (ptr->queue_slot == position) {
-                               cur = ptr->head;
-                               break;
-               }
-               ptr++;
-       }
-       int index = 1;
-       if (!cur)
-               return;
-
-       while (cur) {
-               index++;
-               cur = cur->next;
-       }
-}
diff --git a/src/queue.c b/src/queue.c
new file mode 100644 (file)
index 0000000..2d741ae
--- /dev/null
@@ -0,0 +1,197 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#define _XOPEN_SOURCE 500
+#include <ftw.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include <glib.h>
+
+#include "pkgmgr-server.h"
+#include "queue.h"
+
+#define BACKEND_DIR "/etc/package-manager/backend"
+#define NOPENFD 20
+
+struct backend_queue {
+       char *path;
+       char *type;
+       int slot;
+       GList *job_list;
+};
+
+static GHashTable *queue_type_table;
+static GHashTable *queue_slot_table;
+
+int num_of_backends;
+
+int _is_queue_empty(int pos)
+{
+       struct backend_queue *queue;
+
+       queue = (struct backend_queue *)g_hash_table_lookup(queue_slot_table,
+                       (gconstpointer)pos);
+       if (queue == NULL) {
+               ERR("cannot find queue of slot %d", pos);
+               return -1;
+       }
+
+       if (queue->job_list == NULL)
+               return 1;
+
+       return 0;
+}
+
+struct backend_job *_pop_queue(int pos)
+{
+       struct backend_queue *queue;
+       struct backend_job *job;
+       GList *tmp;
+
+       queue = (struct backend_queue *)g_hash_table_lookup(queue_slot_table,
+                       (gconstpointer)pos);
+       if (queue == NULL) {
+               ERR("cannot find queue of slot %d", pos);
+               return NULL;
+       }
+
+       tmp = g_list_first(queue->job_list);
+       if (tmp == NULL)
+               return NULL;
+       job = (struct backend_job *)tmp->data;
+       queue->job_list = g_list_delete_link(queue->job_list, tmp);
+
+       return job;
+}
+
+int _push_queue(uid_t uid, const char *req_id, int req_type,
+               const char *queue_type, const char *pkgid, const char *args)
+{
+       struct backend_queue *queue;
+       struct backend_job *job;
+
+       queue = (struct backend_queue *)g_hash_table_lookup(queue_type_table,
+                       (gconstpointer)queue_type);
+       if (queue == NULL) {
+               ERR("no such queue: %s", queue_type);
+               return -1;
+       }
+
+       job = calloc(1, sizeof(struct backend_job));
+       job->uid = uid;
+       if (req_id)
+               job->req_id = strdup(req_id);
+       job->req_type = req_type;
+       if (pkgid)
+               job->pkgid = strdup(pkgid);
+       if (args)
+               job->args = strdup(args);
+       /* just assign pointer value */
+       job->backend_slot = queue->slot;
+       job->backend_type = queue->type;
+       job->backend_path = queue->path;
+
+       queue->job_list = g_list_append(queue->job_list, (gpointer)job);
+
+       return 0;
+}
+
+static int __init_backends(const char *fpath, const struct stat *sb,
+               int typeflag, struct FTW *ftwbuf)
+{
+       struct backend_queue *queue;
+
+       if (typeflag != FTW_F && typeflag != FTW_SL)
+               return 0;
+
+       queue = calloc(1, sizeof(struct backend_queue));
+       if (typeflag == FTW_F) {
+               queue->path = strdup(fpath);
+       } else if (typeflag == FTW_SL) {
+               queue->path = malloc(sb->st_size + 1);
+               if (readlink(fpath, queue->path, sb->st_size + 1) < 0) {
+                       ERR("failed to readlink for %s", fpath);
+                       free(queue->path);
+                       free(queue);
+                       return -1;
+               }
+       }
+       queue->type = strdup(fpath + ftwbuf->base);
+       queue->slot = num_of_backends++;
+       g_hash_table_insert(queue_type_table, (gpointer)queue->type,
+                       (gpointer)queue);
+       g_hash_table_insert(queue_slot_table, (gpointer)queue->slot,
+                       (gpointer)queue);
+
+       DBG("backend detected: %s(%s)", queue->type, queue->path);
+
+       return 0;
+}
+
+static gboolean __str_equal(gconstpointer v1, gconstpointer v2)
+{
+       const char *str1 = (const char *)v1;
+       const char *str2 = (const char *)v2;
+
+       /* ignore case */
+       return strcasecmp(str1, str2) == 0;
+}
+
+void _free_backend_job(struct backend_job *job)
+{
+       free(job->req_id);
+       free(job->pkgid);
+       free(job->appid);
+       free(job->args);
+       free(job);
+}
+
+static void __free_backend_queue(gpointer data)
+{
+       struct backend_queue *queue = (struct backend_queue *)data;
+
+       g_list_free_full(queue->job_list, (GDestroyNotify)_free_backend_job);
+       free(queue->path);
+       free(queue->type);
+       free(queue);
+}
+
+void _fini_backend_queue(void)
+{
+       g_hash_table_destroy(queue_slot_table);
+       g_hash_table_destroy(queue_type_table);
+}
+
+int _init_backend_queue(void)
+{
+       queue_type_table = g_hash_table_new_full(g_str_hash, __str_equal,
+                       NULL, __free_backend_queue);
+       queue_slot_table = g_hash_table_new(g_direct_hash, g_direct_equal);
+
+       if (nftw(BACKEND_DIR, __init_backends, NOPENFD, FTW_PHYS))
+               return -1;
+
+       DBG("number of backends: %d", num_of_backends);
+
+       return 0;
+}
index 3ae16c7..5f4668b 100644 (file)
@@ -7,7 +7,7 @@
 #include <gum/gum-user.h>
 #include <gum/common/gum-user-types.h>
 
-#include "pm-queue.h"
+#include "queue.h"
 #include "pkgmgr-server.h"
 #include "package-manager.h"
 
@@ -276,7 +276,8 @@ static int __handle_request_install(uid_t uid,
        int i = 0;
        int len = 0;
 
-       g_variant_get(parameters, "(u&s&s@as)", &target_uid, &pkgtype, &pkgpath, &value);
+       g_variant_get(parameters, "(u&s&s@as)", &target_uid, &pkgtype, &pkgpath,
+                       &value);
        tmp_args = (gchar **)g_variant_get_strv(value, &args_count);
 
        for (i = 0; i < args_count; i++)
@@ -319,7 +320,7 @@ static int __handle_request_install(uid_t uid,
                goto catch;
        }
 
-       if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_INSTALL, pkgtype,
+       if (_push_queue(target_uid, reqkey, REQUEST_TYPE_INSTALL, pkgtype,
                                pkgpath, args)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(is)", PKGMGR_R_ESYSTEM, ""));
@@ -357,7 +358,8 @@ static int __handle_request_mount_install(uid_t uid,
        int i = 0;
        int len = 0;
 
-       g_variant_get(parameters, "(u&s&s@as)", &target_uid, &pkgtype, &pkgpath, &value);
+       g_variant_get(parameters, "(u&s&s@as)", &target_uid, &pkgtype, &pkgpath,
+                       &value);
        tmp_args = (gchar **)g_variant_get_strv(value, &args_count);
 
        for (i = 0; i < args_count; i++)
@@ -400,8 +402,8 @@ static int __handle_request_mount_install(uid_t uid,
                goto catch;
        }
 
-       if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_MOUNT_INSTALL,
-                       pkgtype, pkgpath, args)) {
+       if (_push_queue(target_uid, reqkey, REQUEST_TYPE_MOUNT_INSTALL,
+                               pkgtype, pkgpath, args)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(is)", PKGMGR_R_ESYSTEM, ""));
                ret = -1;
@@ -443,8 +445,8 @@ static int __handle_request_reinstall(uid_t uid,
                                g_variant_new("(is)", PKGMGR_R_ENOMEM, ""));
                return -1;
        }
-       if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_REINSTALL, pkgtype,
-                               pkgid, "")) {
+       if (_push_queue(target_uid, reqkey, REQUEST_TYPE_REINSTALL, pkgtype,
+                               pkgid, NULL)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(is)", PKGMGR_R_ESYSTEM, ""));
                free(reqkey);
@@ -479,8 +481,8 @@ static int __handle_request_uninstall(uid_t uid,
                                g_variant_new("(is)", PKGMGR_R_ENOMEM, ""));
                return -1;
        }
-       if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_UNINSTALL, pkgtype,
-                               pkgid, "")) {
+       if (_push_queue(target_uid, reqkey, REQUEST_TYPE_UNINSTALL, pkgtype,
+                               pkgid, NULL)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(is)", PKGMGR_R_ESYSTEM, ""));
                free(reqkey);
@@ -504,7 +506,8 @@ static int __handle_request_move(uid_t uid,
        int move_type = -1;
        char buf[4] = { '\0' };
 
-       g_variant_get(parameters, "(u&s&si)", &target_uid, &pkgtype, &pkgid, &move_type);
+       g_variant_get(parameters, "(u&s&si)", &target_uid, &pkgtype, &pkgid,
+                       &move_type);
        if (target_uid == (uid_t)-1 || pkgtype == NULL || pkgid == NULL) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(is)", PKGMGR_R_ECOMM, ""));
@@ -519,7 +522,7 @@ static int __handle_request_move(uid_t uid,
        }
 
        snprintf(buf, sizeof(buf), "%d", move_type);
-       if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_MOVE, pkgtype,
+       if (_push_queue(target_uid, reqkey, REQUEST_TYPE_MOVE, pkgtype,
                                pkgid, buf)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(is)", PKGMGR_R_ESYSTEM, ""));
@@ -558,9 +561,8 @@ static int __handle_request_enable_pkgs(uid_t uid,
                        return -1;
                }
 
-               if (_pm_queue_push(target_uid, reqkey,
-                                       PKGMGR_REQUEST_TYPE_ENABLE_PKG,
-                                       pkgtype, pkgid, "")) {
+               if (_push_queue(target_uid, reqkey, REQUEST_TYPE_ENABLE_PKG,
+                                       pkgtype, pkgid, NULL)) {
                        g_dbus_method_invocation_return_value(invocation,
                                        g_variant_new("(i)", PKGMGR_R_ESYSTEM));
                        free(reqkey);
@@ -600,9 +602,8 @@ static int __handle_request_disable_pkgs(uid_t uid,
                        return -1;
                }
 
-               if (_pm_queue_push(target_uid, reqkey,
-                                       PKGMGR_REQUEST_TYPE_DISABLE_PKG,
-                                       pkgtype, pkgid, "")) {
+               if (_push_queue(target_uid, reqkey, REQUEST_TYPE_DISABLE_PKG,
+                                       pkgtype, pkgid, NULL)) {
                        g_dbus_method_invocation_return_value(invocation,
                                        g_variant_new("(i)", PKGMGR_R_ESYSTEM));
                        free(reqkey);
@@ -641,8 +642,8 @@ static int __handle_request_enable_app(uid_t uid,
                goto catch;
        }
 
-       if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_ENABLE_APP, "default",
-                               appid, "")) {
+       if (_push_queue(target_uid, reqkey, REQUEST_TYPE_ENABLE_APP, "default",
+                               appid, NULL)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(is)", PKGMGR_R_ESYSTEM, ""));
                ret = -1;
@@ -684,8 +685,8 @@ static int __handle_request_disable_app(uid_t uid,
                goto catch;
        }
 
-       if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_DISABLE_APP, "default",
-                               appid, "")) {
+       if (_push_queue(target_uid, reqkey, REQUEST_TYPE_DISABLE_APP, "default",
+                               appid, NULL)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(is)", PKGMGR_R_ESYSTEM, ""));
                ret = -1;
@@ -727,8 +728,9 @@ static int __handle_request_enable_global_app_for_uid(uid_t uid,
                goto catch;
        }
 
-       if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_ENABLE_GLOBAL_APP_FOR_UID, "default",
-                               appid, "")) {
+       if (_push_queue(target_uid, reqkey,
+                               REQUEST_TYPE_ENABLE_GLOBAL_APP_FOR_UID,
+                               "default", appid, NULL)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(is)", PKGMGR_R_ESYSTEM, ""));
                ret = -1;
@@ -770,8 +772,9 @@ static int __handle_request_disable_global_app_for_uid(uid_t uid,
                goto catch;
        }
 
-       if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_DISABLE_GLOBAL_APP_FOR_UID, "default",
-                               appid, "")) {
+       if (_push_queue(target_uid, reqkey,
+                               REQUEST_TYPE_DISABLE_GLOBAL_APP_FOR_UID,
+                               "default", appid, NULL)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(is)", PKGMGR_R_ESYSTEM, ""));
                ret = -1;
@@ -814,7 +817,7 @@ static int __handle_request_getsize(uid_t uid,
        }
 
        snprintf(buf, sizeof(buf), "%d", get_type);
-       if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_GETSIZE, "pkgtool",
+       if (_push_queue(target_uid, reqkey, REQUEST_TYPE_GETSIZE, "pkgtool",
                                pkgid, buf)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(is)", PKGMGR_R_ESYSTEM, ""));
@@ -851,8 +854,8 @@ static int __handle_request_cleardata(uid_t uid,
                return -1;
        }
 
-       if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_CLEARDATA, pkgtype,
-                               pkgid, "")) {
+       if (_push_queue(target_uid, reqkey, REQUEST_TYPE_CLEARDATA, pkgtype,
+                               pkgid, NULL)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(i)", PKGMGR_R_ESYSTEM));
                free(reqkey);
@@ -880,8 +883,8 @@ static int __handle_request_clearcache(uid_t uid,
                return -1;
        }
 
-       if (_pm_queue_push(target_uid, "", PKGMGR_REQUEST_TYPE_CLEARCACHE,
-                               "pkgtool",  pkgid, "")) {
+       if (_push_queue(target_uid, NULL, REQUEST_TYPE_CLEARCACHE,
+                               "pkgtool",  pkgid, NULL)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(i)", PKGMGR_R_ESYSTEM));
                return -1;
@@ -914,8 +917,8 @@ static int __handle_request_kill(uid_t uid,
                return -1;
        }
 
-       if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_KILL,
-                               "default", pkgid, "")) {
+       if (_push_queue(target_uid, reqkey, REQUEST_TYPE_KILL,
+                               "default", pkgid, NULL)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(ii)", PKGMGR_R_ESYSTEM, 0));
                free(reqkey);
@@ -950,8 +953,8 @@ static int __handle_request_check(uid_t uid,
                return -1;
        }
 
-       if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_CHECK,
-                               "default", pkgid, "")) {
+       if (_push_queue(target_uid, reqkey, REQUEST_TYPE_CHECK,
+                               "default", pkgid, NULL)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(ii)", PKGMGR_R_ESYSTEM, 0));
                free(reqkey);
@@ -986,9 +989,9 @@ static int __handle_request_generate_license_request(uid_t uid,
                return -1;
        }
 
-       if (_pm_queue_push(uid, reqkey,
-                               PKGMGR_REQUEST_TYPE_GENERATE_LICENSE_REQUEST,
-                               "default", "", resp_data)) {
+       if (_push_queue(uid, reqkey,
+                               REQUEST_TYPE_GENERATE_LICENSE_REQUEST,
+                               "default", NULL, resp_data)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(iss)", PKGMGR_R_ESYSTEM, "",
                                        ""));
@@ -1023,8 +1026,8 @@ static int __handle_request_register_license(uid_t uid,
                return -1;
        }
 
-       if (_pm_queue_push(uid, reqkey, PKGMGR_REQUEST_TYPE_REGISTER_LICENSE,
-                               "default", "", resp_data)) {
+       if (_push_queue(uid, reqkey, REQUEST_TYPE_REGISTER_LICENSE,
+                               "default", NULL, resp_data)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(i)", PKGMGR_R_ESYSTEM));
                free(reqkey);
@@ -1060,8 +1063,9 @@ static int __handle_request_decrypt_package(uid_t uid,
                return -1;
        }
 
-       if (_pm_queue_push(uid, reqkey, PKGMGR_REQUEST_TYPE_DECRYPT_PACKAGE,
-                               "default", drm_file_path, decrypted_file_path)) {
+       if (_push_queue(uid, reqkey, REQUEST_TYPE_DECRYPT_PACKAGE,
+                               "default", drm_file_path,
+                               decrypted_file_path)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(i)", PKGMGR_R_ESYSTEM));
                free(reqkey);
@@ -1099,8 +1103,8 @@ static int __update_app_splash_screen(uid_t uid,
                return -1;
        }
 
-       if (_pm_queue_push(target_uid, reqkey, req_type, "default",
-                               appid, "")) {
+       if (_push_queue(target_uid, reqkey, req_type, "default",
+                               appid, NULL)) {
                ERR("Failed to push request");
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(i)", PKGMGR_R_ESYSTEM));
@@ -1121,14 +1125,14 @@ static int __handle_request_enable_app_splash_screen(uid_t uid,
                GDBusMethodInvocation *invocation, GVariant *parameters)
 {
        return __update_app_splash_screen(uid, invocation, parameters,
-                       PKGMGR_REQUEST_TYPE_ENABLE_APP_SPLASH_SCREEN);
+                       REQUEST_TYPE_ENABLE_APP_SPLASH_SCREEN);
 }
 
 static int __handle_request_disable_app_splash_screen(uid_t uid,
                GDBusMethodInvocation *invocation, GVariant *parameters)
 {
        return __update_app_splash_screen(uid, invocation, parameters,
-                       PKGMGR_REQUEST_TYPE_DISABLE_APP_SPLASH_SCREEN);
+                       REQUEST_TYPE_DISABLE_APP_SPLASH_SCREEN);
 }
 
 static int __handle_request_set_restriction_mode(uid_t uid,
@@ -1155,8 +1159,8 @@ static int __handle_request_set_restriction_mode(uid_t uid,
        }
 
        snprintf(buf, sizeof(buf), "%d", mode);
-       if (_pm_queue_push(target_uid, reqkey,
-                               PKGMGR_REQUEST_TYPE_SET_RESTRICTION_MODE,
+       if (_push_queue(target_uid, reqkey,
+                               REQUEST_TYPE_SET_RESTRICTION_MODE,
                                "default", pkgid, buf)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(i)", PKGMGR_R_ESYSTEM));
@@ -1195,8 +1199,8 @@ static int __handle_request_unset_restriction_mode(uid_t uid,
        }
 
        snprintf(buf, sizeof(buf), "%d", mode);
-       if (_pm_queue_push(target_uid, reqkey,
-                               PKGMGR_REQUEST_TYPE_UNSET_RESTRICTION_MODE,
+       if (_push_queue(target_uid, reqkey,
+                               REQUEST_TYPE_UNSET_RESTRICTION_MODE,
                                "default", pkgid, buf)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(i)", PKGMGR_R_ESYSTEM));
@@ -1232,9 +1236,9 @@ static int __handle_request_get_restriction_mode(uid_t uid,
                return -1;
        }
 
-       if (_pm_queue_push(target_uid, reqkey,
-                               PKGMGR_REQUEST_TYPE_GET_RESTRICTION_MODE,
-                               "default", pkgid, "")) {
+       if (_push_queue(target_uid, reqkey,
+                               REQUEST_TYPE_GET_RESTRICTION_MODE,
+                               "default", pkgid, NULL)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(ii)", -1, PKGMGR_R_ESYSTEM));
                free(reqkey);
@@ -1290,7 +1294,8 @@ static void __handle_method_call(GDBusConnection *connection,
        if (g_strcmp0(method_name, "install") == 0)
                ret = __handle_request_install(uid, invocation, parameters);
        else if (g_strcmp0(method_name, "mount_install") == 0)
-               ret = __handle_request_mount_install(uid, invocation, parameters);
+               ret = __handle_request_mount_install(uid, invocation,
+                               parameters);
        else if (g_strcmp0(method_name, "reinstall") == 0)
                ret = __handle_request_reinstall(uid, invocation, parameters);
        else if (g_strcmp0(method_name, "uninstall") == 0)
@@ -1312,9 +1317,11 @@ static void __handle_method_call(GDBusConnection *connection,
        else if (g_strcmp0(method_name, "disable_app") == 0)
                ret = __handle_request_disable_app(uid, invocation, parameters);
        else if (g_strcmp0(method_name, "enable_global_app_for_uid") == 0)
-               ret = __handle_request_enable_global_app_for_uid(uid, invocation, parameters);
+               ret = __handle_request_enable_global_app_for_uid(uid,
+                               invocation, parameters);
        else if (g_strcmp0(method_name, "disable_global_app_for_uid") == 0)
-               ret = __handle_request_disable_global_app_for_uid(uid, invocation, parameters);
+               ret = __handle_request_disable_global_app_for_uid(uid,
+                               invocation, parameters);
        else if (g_strcmp0(method_name, "kill") == 0)
                ret = __handle_request_kill(uid, invocation, parameters);
        else if (g_strcmp0(method_name, "check") == 0)
@@ -1350,7 +1357,7 @@ static void __handle_method_call(GDBusConnection *connection,
                g_idle_add(queue_job, NULL);
 }
 
-int __return_value_to_caller(const char *req_key, GVariant *result)
+int _return_value_to_caller(const char *req_key, GVariant *result)
 {
        GDBusMethodInvocation *invocation;
 
@@ -1403,9 +1410,10 @@ static void __on_name_lost(GDBusConnection *connection, const gchar *name,
        DBG("on name lost: %s", name);
 }
 
-int __init_request_handler(void)
+int _init_request_handler(void)
 {
-       instropection_data = g_dbus_node_info_new_for_xml(instropection_xml, NULL);
+       instropection_data = g_dbus_node_info_new_for_xml(instropection_xml,
+                       NULL);
 
        owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM, PKGMGR_DBUS_SERVICE,
                        G_BUS_NAME_OWNER_FLAGS_NONE, __on_bus_acquired,
@@ -1419,7 +1427,7 @@ int __init_request_handler(void)
        return 0;
 }
 
-void __fini_request_handler(void)
+void _fini_request_handler(void)
 {
        g_hash_table_destroy(req_table);
        g_bus_unown_name(owner_id);
index a3a05fc..98cc83d 100644 (file)
@@ -290,7 +290,7 @@ static int __get_pkg_restriction_mode(uid_t uid, const char *pkgid, int *mode)
        return 0;
 }
 
-int _restriction_mode_set(uid_t uid, const char *pkgid, int mode)
+int _set_restriction_mode(uid_t uid, const char *pkgid, int mode)
 {
        if (pkgid && strlen(pkgid))
                return __update_pkg_restriction_mode(uid, pkgid, mode,
@@ -299,7 +299,7 @@ int _restriction_mode_set(uid_t uid, const char *pkgid, int mode)
                return __set_restriction_mode(uid, mode);
 }
 
-int _restriction_mode_unset(uid_t uid, const char *pkgid, int mode)
+int _unset_restriction_mode(uid_t uid, const char *pkgid, int mode)
 {
        if (pkgid && strlen(pkgid))
                return __update_pkg_restriction_mode(uid, pkgid, mode,
@@ -308,7 +308,7 @@ int _restriction_mode_unset(uid_t uid, const char *pkgid, int mode)
                return __unset_restriction_mode(uid, mode);
 }
 
-int _restriction_mode_get(uid_t uid, const char *pkgid, int *mode)
+int _get_restriction_mode(uid_t uid, const char *pkgid, int *mode)
 {
        if (pkgid && strlen(pkgid))
                return __get_pkg_restriction_mode(uid, pkgid, mode);
index 536f8b3..f6ad233 100644 (file)
@@ -56,7 +56,7 @@ static void __free_uid_list(uid_t *uids)
        free(uids);
 }
 
-void __send_app_signal(uid_t uid, const char *req_id,
+void _send_app_signal(uid_t uid, const char *req_id,
                const char *pkgid, const char *appid,
                const char *key, const char *val, int req_type)
 {
@@ -75,24 +75,24 @@ void __send_app_signal(uid_t uid, const char *req_id,
                goto catch;
 
        switch (req_type) {
-       case PKGMGR_REQUEST_TYPE_ENABLE_GLOBAL_APP_FOR_UID:
-       case PKGMGR_REQUEST_TYPE_ENABLE_APP:
+       case REQUEST_TYPE_ENABLE_GLOBAL_APP_FOR_UID:
+       case REQUEST_TYPE_ENABLE_APP:
                if (pkgmgr_installer_set_request_type(pi,
                                        PKGMGR_REQ_ENABLE_APP))
                        goto catch;
                break;
-       case PKGMGR_REQUEST_TYPE_DISABLE_GLOBAL_APP_FOR_UID:
-       case PKGMGR_REQUEST_TYPE_DISABLE_APP:
+       case REQUEST_TYPE_DISABLE_GLOBAL_APP_FOR_UID:
+       case REQUEST_TYPE_DISABLE_APP:
                if (pkgmgr_installer_set_request_type(pi,
                                        PKGMGR_REQ_DISABLE_APP))
                        goto catch;
                break;
-       case PKGMGR_REQUEST_TYPE_ENABLE_APP_SPLASH_SCREEN:
+       case REQUEST_TYPE_ENABLE_APP_SPLASH_SCREEN:
                if (pkgmgr_installer_set_request_type(pi,
                                        PKGMGR_REQ_ENABLE_APP_SPLASH_SCREEN))
                        goto catch;
                break;
-       case PKGMGR_REQUEST_TYPE_DISABLE_APP_SPLASH_SCREEN:
+       case REQUEST_TYPE_DISABLE_APP_SPLASH_SCREEN:
                if (pkgmgr_installer_set_request_type(pi,
                                        PKGMGR_REQ_DISABLE_APP_SPLASH_SCREEN))
                        goto catch;
@@ -117,7 +117,7 @@ catch:
        return;
 }
 
-void __send_fail_signal(backend_info *info)
+void _send_fail_signal(struct backend_job *job)
 {
        int req_type;
        pkgmgr_installer *pi;
@@ -130,20 +130,20 @@ void __send_fail_signal(backend_info *info)
                ERR("Failure in creating the pkgmgr_installer object");
                return;
        }
-       pkgmgr_installer_set_session_id(pi, info->req_id);
-       switch (info->req_type) {
-       case PKGMGR_REQUEST_TYPE_INSTALL:
-       case PKGMGR_REQUEST_TYPE_MOUNT_INSTALL:
-       case PKGMGR_REQUEST_TYPE_REINSTALL:
+       pkgmgr_installer_set_session_id(pi, job->req_id);
+       switch (job->req_type) {
+       case REQUEST_TYPE_INSTALL:
+       case REQUEST_TYPE_MOUNT_INSTALL:
+       case REQUEST_TYPE_REINSTALL:
                req_type = PKGMGR_REQ_INSTALL;
                break;
-       case PKGMGR_REQUEST_TYPE_UNINSTALL:
+       case REQUEST_TYPE_UNINSTALL:
                req_type = PKGMGR_REQ_UNINSTALL;
                break;
-       case PKGMGR_REQUEST_TYPE_MOVE:
+       case REQUEST_TYPE_MOVE:
                req_type = PKGMGR_REQ_MOVE;
                break;
-       case PKGMGR_REQUEST_TYPE_GETSIZE:
+       case REQUEST_TYPE_GETSIZE:
                req_type = PKGMGR_REQ_GETSIZE;
                break;
        default:
@@ -151,16 +151,14 @@ void __send_fail_signal(backend_info *info)
                break;
        }
        pkgmgr_installer_set_request_type(pi, req_type);
-       pkgmgr_installer_send_signal(pi, info->pkgtype, info->pkgid,
+       pkgmgr_installer_send_signal(pi, job->backend_type, job->pkgid,
                        "end", "fail");
-       n = __get_uid_list(info->uid, &uids);
+       n = __get_uid_list(job->uid, &uids);
        for (i = 0; i < n; i++)
                pkgmgr_installer_send_signal_for_uid(pi, uids[i],
-                               info->pkgtype, info->pkgid, "end", "fail");
+                               job->backend_type, job->pkgid, "end", "fail");
 
        __free_uid_list(uids);
        pkgmgr_installer_free(pi);
        return;
 }
-
-