Add new functions to handling running components 60/204260/8
authorHwankyu Jhun <h.jhun@samsung.com>
Mon, 22 Apr 2019 10:23:48 +0000 (19:23 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Tue, 23 Apr 2019 02:17:44 +0000 (11:17 +0900)
Adds:
 - aul_comp_context_create()
 - aul_comp_context_create_usr()
 - aul_comp_context_destroy()
 - aul_comp_context_clone()
 - aul_comp_context_is_running()
 - aul_comp_context_resume()
 - aul_comp_context_pause()
 - aul_comp_context_terminate_bg_comp()
 - aul_comp_context_terminate()

Requires:
 - https://review.tizen.org/gerrit/#/c/platform/core/appfw/aul-1/+/204260/
 - https://review.tizen.org/gerrit/#/c/platform/core/appfw/amd/+/204266/

Change-Id: I6bdec5c297cb36e3044470525c028bc58bc943d5
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
include/aul.h
include/aul_cmd.h
include/aul_comp_context.h
src/aul_cmd.c
src/aul_comp_context.c
src/aul_launch.c
tool/compmgr_tool.c

index ab4b959..e642b1a 100644 (file)
@@ -73,6 +73,8 @@ typedef enum _aul_type {
        AUL_SUSPEND,
        AUL_WIDGET_CONTENT,
        AUL_UPDATE_REQUESTED,
+       AUL_TERMINATE_INST,
+       AUL_TERMINATE_BG_INST,
 } aul_type;
 
 typedef enum aul_widget_lifecycle_event {
index dbe6727..c476c80 100755 (executable)
@@ -152,6 +152,16 @@ enum app_cmd {
        APP_GROUP_GET_IDLE_INFO = 119,
        COMP_CONTEXT_FOREACH = 120,
 
+       COMP_CONTEXT_GET = 121,
+       COMP_CONTEXT_IS_RUNNING = 122,
+       COMP_CONTEXT_RESUME = 123,
+       COMP_CONTEXT_PAUSE = 124,
+       COMP_CONTEXT_TERMINATE_BG_COMP = 125,
+       COMP_CONTEXT_TERMINATE = 126,
+       APP_RESUME_INSTANCE = 127,
+       APP_PAUSE_INSTANCE = 128,
+       APP_TERM_BG_INSTANCE = 129,
+
        APP_CMD_MAX
 };
 
index 15212ab..b12514c 100644 (file)
@@ -34,6 +34,7 @@ typedef struct aul_comp_context_s *aul_comp_context_h;
 /**
  * @brief Called to get the component context for each component.
  * @since_tizen 5.5
+ * @remarks You MUST NOT release @a handle using aul_comp_context_destroy().
  *
  * @param[in]   handle          The component context handle
  * @param[in]   user_data       The user data passed from the foreach function
@@ -155,6 +156,136 @@ int aul_comp_context_get_status(aul_comp_context_h handle, int *status);
  */
 int aul_comp_context_is_sub_comp(aul_comp_context_h handle, bool *is_sub_comp);
 
+/**
+ * @brief Creates the component context handle.
+ * @since_tizen 5.5
+ * @remarks You MUST release @c clone using aul_comp_context_destroy().
+ *
+ * @param[in]   comp_id         The component ID
+ * @param[out]  handle          The component context handle
+ * @return      @c 0 on success,
+ *              otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ * @see aul_comp_context_destroy()
+ */
+int aul_comp_context_create(const char *comp_id, aul_comp_context_h *handle);
+
+/**
+ * @brief Creates the component context handle.
+ * @since_tizen 5.5
+ * @remarks You MUST release @c clone using aul_comp_context_destroy().
+ *
+ * @param[in]   comp_id         The component ID
+ * @parma[in]   uid             The user ID
+ * @param[out]  handle          The component context handle
+ * @return      @c 0 on success,
+ *              otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ * @see aul_comp_context_destroy()
+ */
+int aul_comp_context_create_usr(const char *comp_id, uid_t uid,
+               aul_comp_context_h *handle);
+
+/**
+ * @brief Destroys the component context handle.
+ * @since_tizen 5.5
+ *
+ * @param[in]   handle          The component context handle
+ * @return      @c 0 on success,
+ *              otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_context_destroy(aul_comp_context_h handle);
+
+/**
+ * @brief Clones the component context handle.
+ * @since_tizen 5.5
+ * @remarks You MUST release @c clone using aul_comp_context_destroy().
+ *
+ * @param[in]   handle          The component context handle
+ * @param[out]  clone           A newly created component context handle, if sucessfully cloned
+ * @return      @c 0 on success,
+ *              otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ * @see aul_comp_context_destroy()
+ */
+int aul_comp_context_clone(aul_comp_context_h handle,
+               aul_comp_context_h *clone);
+
+/**
+ * @brief Checks whether the component is running or not.
+ * @since_tizen 5.5
+ *
+ * @param[in]   handle          The component context handle
+ * @param[out]  running         @c true if the component is running, \n
+ *                              otherwise @c false if not running
+ * @return      @c 0 on success,
+ *              otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_context_is_running(aul_comp_context_h handle, bool *running);
+
+/**
+ * @brief Sends the request for resuming the component.
+ * @since_tizen 5.5
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/appmanager.launch
+ *
+ * @param[in]   handle          The component context handle
+ * @return      @c 0 on success,
+ *              otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_context_resume(aul_comp_context_h handle);
+
+/**
+ * @brief Sends the request for pausing the component.
+ * @since_tizen 5.5
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/appmanager.launch
+ *
+ * @param[in]   handle          The component context handle
+ * @return      @c 0 on success,
+ *              otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_context_pause(aul_comp_context_h handle);
+
+/**
+ * @brief Sends the request for terminating the background component.
+ * @since_tizen 5.5
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/appmanager.kill.bgapp
+ *
+ * @param[in]   handle          The component context handle
+ * @return      @c 0 on success,
+ *              otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_context_terminate_bg_comp(aul_comp_context_h handle);
+
+/**
+ * @brief Sends the request for terminating the running component.
+ * @since_tizen 5.5
+ * @privlevel platform
+ * @privilege %http://tizen.org/privilege/appmanager.kill
+ *
+ * @param[in]   handle          The component context handle
+ * @return      @c 0 on success,
+ *              otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_context_terminate(aul_comp_context_h handle);
+
 #ifdef __cplusplus
 }
 #endif
index 7e39fa7..3fc32cd 100755 (executable)
@@ -266,6 +266,24 @@ API const char *aul_cmd_convert_to_string(int cmd)
                return "APP_GROUP_GET_IDLE_INFO";
        case COMP_CONTEXT_FOREACH:
                return "COMP_CONTEXT_FOREACH";
+       case COMP_CONTEXT_GET:
+               return "COMP_CONTEXT_GET";
+       case COMP_CONTEXT_IS_RUNNING:
+               return "COMP_CONTEXT_IS_RUNNING";
+       case COMP_CONTEXT_RESUME:
+               return "COMP_CONTEXT_RESUME";
+       case COMP_CONTEXT_PAUSE:
+               return "COMP_CONTEXT_PAUSE";
+       case COMP_CONTEXT_TERMINATE_BG_COMP:
+               return "COMP_CONTEXT_TERMINATE_BG_COMP";
+       case COMP_CONTEXT_TERMINATE:
+               return "COMP_CONTEXT_TERMINATE";
+       case APP_RESUME_INSTANCE:
+               return "APP_RESUME_INSTANCE";
+       case APP_PAUSE_INSTANCE:
+               return "APP_PAUSE_INSTANCE";
+       case APP_TERM_BG_INSTANCE:
+               return "APP_TERM_BG_INSTANCE";
        default:
                return "CUSTOM_COMMAND";
        }
index 6128929..9cf6912 100644 (file)
 #include "aul.h"
 
 struct aul_comp_context_s {
-       const char *comp_id;
-       const char *instance_id;
-       const char *app_id;
-       const char *type;
+       char *comp_id;
+       char *instance_id;
+       char *app_id;
+       char *type;
        pid_t pid;
        int status;
        bool is_sub_comp;
@@ -47,7 +47,7 @@ struct cb_data_s {
 static void __running_context_cb(app_pkt_t *pkt, void *user_data)
 {
        struct cb_data_s *cb_data = (struct cb_data_s *)user_data;
-       struct aul_comp_context_s context;
+       struct aul_comp_context_s context = { 0, };
        bundle *b = NULL;
        const char *val;
 
@@ -88,10 +88,10 @@ static void __running_context_cb(app_pkt_t *pkt, void *user_data)
        }
        context.is_sub_comp = atoi(val);
 
-       context.comp_id = bundle_get_val(b, AUL_K_COMPONENT_ID);
-       context.instance_id = bundle_get_val(b, AUL_K_INSTANCE_ID);
-       context.app_id = bundle_get_val(b, AUL_K_APPID);
-       context.type = bundle_get_val(b, AUL_K_COMPONENT_TYPE);
+       bundle_get_str(b, AUL_K_COMPONENT_ID, &context.comp_id);
+       bundle_get_str(b, AUL_K_INSTANCE_ID, &context.instance_id);
+       bundle_get_str(b, AUL_K_APPID, &context.app_id);
+       bundle_get_str(b, AUL_K_COMPONENT_TYPE, &context.type);
 
        cb_data->callback(&context, cb_data->user_data);
        bundle_free(b);
@@ -226,3 +226,363 @@ API int aul_comp_context_is_sub_comp(aul_comp_context_h context,
 
        return AUL_R_OK;
 }
+
+static void __destroy_comp_context(aul_comp_context_h handle)
+{
+       struct aul_comp_context_s *context;
+
+       context = (struct aul_comp_context_s *)handle;
+       if (!context)
+               return;
+
+       if (context->comp_id)
+               free(context->comp_id);
+       if (context->instance_id)
+               free(context->instance_id);
+       if (context->app_id)
+               free(context->app_id);
+       if (context->type)
+               free(context->type);
+       free(context);
+}
+
+static struct aul_comp_context_s *__create_comp_context(bundle *b)
+{
+       struct aul_comp_context_s *context;
+       const char *val;
+
+       context = calloc(1, sizeof(struct aul_comp_context_s));
+       if (!context) {
+               _E("Out of memory");
+               return NULL;
+       }
+
+       val = bundle_get_val(b, AUL_K_PID);
+       if (!val) {
+               _E("Failed to get process ID");
+               goto err;
+       }
+       context->pid = atoi(val);
+
+       val = bundle_get_val(b, AUL_K_STATUS);
+       if (!val) {
+               _E("Failed to get component status");
+               goto err;
+       }
+       context->status = atoi(val);
+
+       val = bundle_get_val(b, AUL_K_IS_SUB_COMP);
+       if (!val) {
+               _E("Failed to get the flag for checking sub comp");
+               goto err;
+       }
+       context->status = atoi(val);
+
+       val = bundle_get_val(b, AUL_K_COMPONENT_ID);
+       if (!val) {
+               _E("Failed to get component ID");
+               goto err;
+       }
+
+       context->comp_id = strdup(val);
+       if (!context->comp_id) {
+               _E("Failed to duplicate component ID");
+               goto err;
+       }
+
+       val = bundle_get_val(b, AUL_K_INSTANCE_ID);
+       if (!val) {
+               _E("Failed to get instance ID");
+               goto err;
+       }
+
+       context->instance_id = strdup(val);
+       if (!context->instance_id) {
+               _E("Failed to duplicate instance ID");
+               goto err;
+       }
+
+       val = bundle_get_val(b, AUL_K_APPID);
+       if (!val) {
+               _E("Failed to get application ID");
+               goto err;
+       }
+
+       context->app_id = strdup(val);
+       if (!context->app_id) {
+               _E("Failed to duplicate application ID");
+               goto err;
+       }
+
+       val = bundle_get_val(b, AUL_K_COMPONENT_TYPE);
+       if (!val) {
+               _E("Failed to get component type");
+               goto err;
+       }
+
+       context->type = strdup(val);
+       if (!context->type) {
+               _E("Failed to duplicate component type");
+               goto err;
+       }
+
+       return context;
+
+err:
+       if (context)
+               __destroy_comp_context(context);
+
+       return NULL;
+}
+
+API int aul_comp_context_create(const char *comp_id, aul_comp_context_h *handle)
+{
+       return aul_comp_context_create_usr(comp_id, getuid(), handle);
+}
+
+API int aul_comp_context_create_usr(const char *comp_id, uid_t uid,
+               aul_comp_context_h *handle)
+{
+       struct aul_comp_context_s *context;
+       app_pkt_t *pkt = NULL;
+       char buf[32];
+       bundle *b;
+       int ret;
+       int fd;
+
+       if (!comp_id || !handle) {
+               _E("Invalid parameter");
+               return AUL_R_EINVAL;
+       }
+
+       b = bundle_create();
+       if (!b) {
+               _E("Out of memory");
+               return AUL_R_ERROR;
+       }
+
+       snprintf(buf, sizeof(buf), "%d", uid);
+       bundle_add(b, AUL_K_TARGET_UID, buf);
+       bundle_add(b, AUL_K_COMPONENT_ID, comp_id);
+
+       fd = aul_sock_send_bundle(AUL_UTIL_PID, uid, COMP_CONTEXT_GET,
+                       b, AUL_SOCK_ASYNC);
+       bundle_free(b);
+       if (fd < 0) {
+               _E("Failed to send request. error(%d)", fd);
+               return aul_error_convert(fd);
+       }
+
+       ret = aul_sock_recv_reply_pkt(fd, &pkt);
+       if (ret < 0) {
+               _E("Failed to receive packet. error(%d)", ret);
+               return aul_error_convert(ret);
+       }
+
+       b = NULL;
+       if (pkt->opt & AUL_SOCK_BUNDLE)
+               b = bundle_decode(pkt->data, pkt->len);
+       free(pkt);
+
+       if (!b) {
+               _E("Failed to decode bundle");
+               return AUL_R_ERROR;
+       }
+
+       context = __create_comp_context(b);
+       if (!context) {
+               bundle_free(b);
+               return AUL_R_ERROR;
+       }
+       bundle_free(b);
+
+       *handle = (aul_comp_context_h)context;
+
+       return AUL_R_OK;
+}
+
+API int aul_comp_context_destroy(aul_comp_context_h handle)
+{
+       if (!handle) {
+               _E("Invalid parameter");
+               return AUL_R_EINVAL;
+       }
+
+       __destroy_comp_context(handle);
+
+       return AUL_R_OK;
+}
+
+API int aul_comp_context_clone(aul_comp_context_h handle,
+               aul_comp_context_h *clone)
+{
+       struct aul_comp_context_s *context;
+       struct aul_comp_context_s *new_context;
+
+       if (!handle || !clone) {
+               _E("Invalid parameter");
+               return AUL_R_EINVAL;
+       }
+
+       context = (struct aul_comp_context_s *)handle;
+       new_context = calloc(1, sizeof(struct aul_comp_context_s));
+       if (!new_context) {
+               _E("Out of memory");
+               return AUL_R_ERROR;
+       }
+
+       new_context->comp_id = strdup(context->comp_id);
+       if (!new_context->comp_id) {
+               _E("Failed to duplicate component ID");
+               goto err;
+       }
+
+       new_context->instance_id = strdup(context->instance_id);
+       if (!new_context->instance_id) {
+               _E("Failed to duplicate instance ID");
+               goto err;
+       }
+
+       new_context->app_id = strdup(context->app_id);
+       if (!new_context->app_id) {
+               _E("Failed to duplicate application ID");
+               goto err;
+       }
+
+       new_context->type = strdup(context->type);
+       if (!new_context->type) {
+               _E("Failed to duplicate component type");
+               goto err;
+       }
+
+       new_context->pid = context->pid;
+       new_context->status = context->status;
+       new_context->is_sub_comp = context->is_sub_comp;
+
+       *clone = (aul_comp_context_h)new_context;
+
+       return AUL_R_OK;
+err:
+       if (new_context)
+               __destroy_comp_context(new_context);
+
+       return AUL_R_ERROR;
+}
+
+static int __send_request(aul_comp_context_h handle, int cmd)
+{
+       struct aul_comp_context_s *context;
+       bundle *b;
+       int ret;
+
+       context = (struct aul_comp_context_s *)handle;
+       b = bundle_create();
+       if (!b) {
+               _E("Out of memory");
+               return AUL_R_ERROR;
+       }
+
+       bundle_add(b, AUL_K_COMPONENT_ID, context->comp_id);
+       bundle_add(b, AUL_K_INSTANCE_ID, context->instance_id);
+
+       ret = aul_sock_send_bundle(AUL_UTIL_PID, getuid(), cmd,
+                       b, AUL_SOCK_NONE);
+       bundle_free(b);
+       if (ret < 0)
+               return aul_error_convert(ret);
+
+       return ret;
+}
+
+API int aul_comp_context_is_running(aul_comp_context_h handle,
+               bool *running)
+{
+       int ret;
+
+       if (!handle || !running) {
+               _E("Invalid parameter");
+               return AUL_R_EINVAL;
+       }
+
+       ret = __send_request(handle, COMP_CONTEXT_IS_RUNNING);
+       if (ret < 0) {
+               _E("Failed to send request. error(%d)", ret);
+               return ret;
+       }
+
+       *running = (bool)ret;
+
+       return AUL_R_OK;
+}
+
+API int aul_comp_context_resume(aul_comp_context_h handle)
+{
+       int ret;
+
+       if (!handle) {
+               _E("Invalid parameter");
+               return AUL_R_EINVAL;
+       }
+
+       ret = __send_request(handle, COMP_CONTEXT_RESUME);
+       if (ret < 0) {
+               _E("Failed to send request. error(%d)", ret);
+               return ret;
+       }
+
+       return AUL_R_OK;
+}
+
+API int aul_comp_context_pause(aul_comp_context_h handle)
+{
+       int ret;
+
+       if (!handle) {
+               _E("Invalid parameter");
+               return AUL_R_EINVAL;
+       }
+
+       ret = __send_request(handle, COMP_CONTEXT_PAUSE);
+       if (ret < 0) {
+               _E("Failed to send request. error(%d)", ret);
+               return ret;
+       }
+
+       return AUL_R_OK;
+}
+
+API int aul_comp_context_terminate_bg_comp(aul_comp_context_h handle)
+{
+       int ret;
+
+       if (!handle) {
+               _E("Invalid parameter");
+               return AUL_R_EINVAL;
+       }
+
+       ret = __send_request(handle, COMP_CONTEXT_TERMINATE_BG_COMP);
+       if (ret < 0) {
+               _E("Failed to send request. error(%d)", ret);
+               return ret;
+       }
+
+       return AUL_R_OK;
+}
+
+API int aul_comp_context_terminate(aul_comp_context_h handle)
+{
+       int ret;
+
+       if (!handle) {
+               _E("Invalid parameter");
+               return AUL_R_EINVAL;
+       }
+
+       ret = __send_request(handle, COMP_CONTEXT_TERMINATE);
+       if (ret < 0) {
+               _E("Failed to send request. error(%d)", ret);
+               return ret;
+       }
+
+       return AUL_R_OK;
+}
index 6153307..637c78b 100644 (file)
@@ -221,7 +221,22 @@ static void __dispatch_watchdog_ping(aul_request_h req)
 
 static void __dispatch_app_term_inst(aul_request_h req)
 {
-       __invoke_aul_handler(AUL_TERMINATE, req->b);
+       __invoke_aul_handler(AUL_TERMINATE_INST, req->b);
+}
+
+static void __dispatch_app_resume_inst(aul_request_h req)
+{
+       __invoke_aul_handler(AUL_RESUME, req->b);
+}
+
+static void __dispatch_app_pause_inst(aul_request_h req)
+{
+       __invoke_aul_handler(AUL_PAUSE, req->b);
+}
+
+static void __dispatch_app_term_bg_inst(aul_request_h req)
+{
+       __invoke_aul_handler(AUL_TERMINATE_BG_INST, req->b);
 }
 
 static dispatcher __dispatcher[] = {
@@ -250,6 +265,9 @@ static dispatcher __dispatcher[] = {
        [APP_SEND_LAUNCH_REQUEST] = __dispatch_app_start,
        [APP_SEND_LAUNCH_REQUEST_SYNC] = __dispatch_app_start,
        [APP_TERM_INSTANCE_ASYNC] = __dispatch_app_term_inst,
+       [APP_RESUME_INSTANCE] = __dispatch_app_resume_inst,
+       [APP_PAUSE_INSTANCE] = __dispatch_app_pause_inst,
+       [APP_TERM_BG_INSTANCE] = __dispatch_app_term_bg_inst,
 };
 
 static gboolean __aul_launch_handler(GIOChannel *io, GIOCondition condition,
index 7c2c183..d413f57 100644 (file)
 enum command_e {
        CMD_LIST,
        CMD_RUNNING_LIST,
+       CMD_GET,
+       CMD_IS_RUNNING,
+       CMD_RESUME,
+       CMD_PAUSE,
+       CMD_TERMINATE_BG_COMP,
+       CMD_TERMINATE,
        CMD_MAX,
 };
 
 enum option_e {
        OPT_USER,
+       OPT_INSTANCE,
        OPT_MAX,
 };
 
@@ -48,6 +55,12 @@ struct command {
        void (*finish)(void *data);
 };
 
+struct cmd_arg {
+       char *comp_id;
+       char *instance_id;
+       uid_t uid;
+};
+
 static GMainLoop *loop;
 static gchar *help;
 static gpointer cmd_opt[CMD_MAX];
@@ -71,6 +84,60 @@ static GOptionEntry cmd_entries[] = {
                .arg_description = NULL
        },
        {
+               .long_name = "get",
+               .short_name = 'g',
+               .flags = 0,
+               .arg = G_OPTION_ARG_STRING,
+               .arg_data = &cmd_opt[CMD_GET],
+               .description = "Show the running component information",
+               .arg_description = "The component ID"
+       },
+       {
+               .long_name = "is-running",
+               .short_name = 'n',
+               .flags = 0,
+               .arg = G_OPTION_ARG_STRING,
+               .arg_data = &cmd_opt[CMD_IS_RUNNING],
+               .description = "Check whether the component is running or not",
+               .arg_description = "The component ID"
+       },
+       {
+               .long_name = "resume",
+               .short_name = 'o',
+               .flags = 0,
+               .arg = G_OPTION_ARG_STRING,
+               .arg_data = &cmd_opt[CMD_RESUME],
+               .description = "Resume the running component",
+               .arg_description = "The component ID"
+       },
+       {
+               .long_name = "pause",
+               .short_name = 'p',
+               .flags = 0,
+               .arg = G_OPTION_ARG_STRING,
+               .arg_data = &cmd_opt[CMD_PAUSE],
+               .description = "Pause the running component",
+               .arg_description = "The component ID"
+       },
+       {
+               .long_name = "terminate-bg-comp",
+               .short_name = 'b',
+               .flags = 0,
+               .arg = G_OPTION_ARG_STRING,
+               .arg_data = &cmd_opt[CMD_TERMINATE_BG_COMP],
+               .description = "Terminate the background component",
+               .arg_description = "The component ID"
+       },
+       {
+               .long_name = "terminate",
+               .short_name = 't',
+               .flags = 0,
+               .arg = G_OPTION_ARG_STRING,
+               .arg_data = &cmd_opt[CMD_TERMINATE],
+               .description = "Terminate the running component",
+               .arg_description = "The component ID"
+       },
+       {
                NULL
        }
 };
@@ -86,6 +153,16 @@ static GOptionEntry opt_entries[] = {
                .arg_description = "USER ID"
        },
        {
+               .long_name = "instance",
+               .short_name = 'i',
+               .flags = 0,
+               .arg = G_OPTION_ARG_INT,
+               .arg_data = &opt[OPT_INSTANCE],
+               .description = "Specify the instance ID",
+               .arg_description = "The instance ID"
+
+       },
+       {
                NULL
        }
 };
@@ -104,6 +181,25 @@ static GOptionGroup *__get_opt_group(void)
        return group;
 }
 
+static int __cmd_common_init(void *data)
+{
+       struct cmd_arg *cmd_arg = (struct cmd_arg *)data;
+       aul_comp_info_h handle = NULL;
+       int ret;
+
+       ret = aul_comp_info_create_usr(cmd_arg->comp_id, cmd_arg->uid,
+                       &handle);
+       if (ret != AUL_R_OK) {
+               printf("Failed to create component(%s) info\n",
+                               cmd_arg->comp_id);
+               return -1;
+       }
+
+       aul_comp_info_destroy(handle);
+
+       return 0;
+}
+
 static void __cmd_common_finish(void *data)
 {
        g_main_loop_quit(loop);
@@ -268,6 +364,166 @@ static int __cmd_running_list_run(void *data)
        return ret;
 }
 
+static int __cmd_get_run(void *data)
+{
+       struct cmd_arg *cmd_arg = (struct cmd_arg *)data;
+       aul_comp_context_h handle = NULL;
+       int member_count = 0;
+       int ret;
+
+       ret = aul_comp_context_create_usr(cmd_arg->comp_id, cmd_arg->uid,
+                       &handle);
+       if (ret != AUL_R_OK) {
+               printf("Failed to find running component(%s) context\n",
+                               cmd_arg->comp_id);
+               return -1;
+       }
+
+       __comp_context_cb(handle, (void *)&member_count);
+       aul_comp_context_destroy(handle);
+       printf("[GET] result: %d\n", ret);
+
+       return 0;
+}
+
+static int __cmd_is_running_run(void *data)
+{
+       struct cmd_arg *cmd_arg = (struct cmd_arg *)data;
+       aul_comp_context_h handle = NULL;
+       bool is_running = false;
+       int ret;
+
+       ret = aul_comp_context_create_usr(cmd_arg->comp_id, cmd_arg->uid,
+                       &handle);
+       if (ret != AUL_R_OK) {
+               printf("Failed to find running component(%s) context\n",
+                               cmd_arg->comp_id);
+               return -1;
+       }
+
+       ret = aul_comp_context_is_running(handle, &is_running);
+       if (ret != AUL_R_OK) {
+               printf("Failed to check running\n");
+               aul_comp_context_destroy(handle);
+               return -1;
+       }
+
+       aul_comp_context_destroy(handle);
+       printf("[IS_RUNNING] %s is %s\n",
+                       cmd_arg->comp_id,
+                       is_running ? "running" : "not running");
+
+       return 0;
+}
+
+static int __cmd_resume_run(void *data)
+{
+       struct cmd_arg *cmd_arg = (struct cmd_arg *)data;
+       aul_comp_context_h handle = NULL;
+       int ret;
+
+       ret = aul_comp_context_create_usr(cmd_arg->comp_id, cmd_arg->uid,
+                       &handle);
+       if (ret != AUL_R_OK) {
+               printf("Failed to find running component(%s) context\n",
+                               cmd_arg->comp_id);
+               return -1;
+       }
+
+       ret = aul_comp_context_resume(handle);
+       if (ret != AUL_R_OK) {
+               printf("Failed to send the resume request\n");
+               aul_comp_context_destroy(handle);
+               return -1;
+       }
+
+       aul_comp_context_destroy(handle);
+       printf("[RESUME] result: %d\n", ret);
+
+       return 0;
+}
+
+static int __cmd_pause_run(void *data)
+{
+       struct cmd_arg *cmd_arg = (struct cmd_arg *)data;
+       aul_comp_context_h handle = NULL;
+       int ret;
+
+       ret = aul_comp_context_create_usr(cmd_arg->comp_id, cmd_arg->uid,
+                       &handle);
+       if (ret != AUL_R_OK) {
+               printf("Failed to find running component(%s) context\n",
+                               cmd_arg->comp_id);
+               return -1;
+       }
+
+       ret = aul_comp_context_pause(handle);
+       if (ret != AUL_R_OK) {
+               printf("Failed to send the pause request\n");
+               aul_comp_context_destroy(handle);
+               return -1;
+       }
+
+       aul_comp_context_destroy(handle);
+       printf("[PAUSE] result: %d\n", ret);
+
+       return 0;
+}
+
+static int __cmd_terminate_bg_comp_run(void *data)
+{
+       struct cmd_arg *cmd_arg = (struct cmd_arg *)data;
+       aul_comp_context_h handle = NULL;
+       int ret;
+
+       ret = aul_comp_context_create_usr(cmd_arg->comp_id, cmd_arg->uid,
+                       &handle);
+       if (ret != AUL_R_OK) {
+               printf("Failed to find running component(%s) context\n",
+                               cmd_arg->comp_id);
+               return -1;
+       }
+
+       ret = aul_comp_context_terminate_bg_comp(handle);
+       if (ret != AUL_R_OK) {
+               printf("Failed to send the terminate bg comp request\n");
+               aul_comp_context_destroy(handle);
+               return -1;
+       }
+
+       aul_comp_context_destroy(handle);
+       printf("[TERMINATE_BG_COMP] result: %d\n", ret);
+
+       return 0;
+}
+
+static int __cmd_terminate_run(void *data)
+{
+       struct cmd_arg *cmd_arg = (struct cmd_arg *)data;
+       aul_comp_context_h handle = NULL;
+       int ret;
+
+       ret = aul_comp_context_create_usr(cmd_arg->comp_id, cmd_arg->uid,
+                       &handle);
+       if (ret != AUL_R_OK) {
+               printf("Failed to find running component(%s) context\n",
+                               cmd_arg->comp_id);
+               return -1;
+       }
+
+       ret = aul_comp_context_terminate(handle);
+       if (ret != AUL_R_OK) {
+               printf("Failed to send the terminate request\n");
+               aul_comp_context_destroy(handle);
+               return -1;
+       }
+
+       aul_comp_context_destroy(handle);
+       printf("[TERMINATE] result: %d\n", ret);
+
+       return 0;
+}
+
 static struct command cmd_table[] = {
        [CMD_LIST] = {
                .name = "list",
@@ -281,6 +537,42 @@ static struct command cmd_table[] = {
                .run = __cmd_running_list_run,
                .finish = __cmd_common_finish
        },
+       [CMD_GET] = {
+               .name = "get",
+               .init = __cmd_common_init,
+               .run = __cmd_get_run,
+               .finish = __cmd_common_finish
+       },
+       [CMD_IS_RUNNING] = {
+               .name = "is-running",
+               .init = __cmd_common_init,
+               .run = __cmd_is_running_run,
+               .finish = __cmd_common_finish
+       },
+       [CMD_RESUME] = {
+               .name = "resume",
+               .init = __cmd_common_init,
+               .run = __cmd_resume_run,
+               .finish = __cmd_common_finish
+       },
+       [CMD_PAUSE] = {
+               .name = "pause",
+               .init = __cmd_common_init,
+               .run = __cmd_pause_run,
+               .finish = __cmd_common_finish
+       },
+       [CMD_TERMINATE_BG_COMP] = {
+               .name = "terminate-bg-comp",
+               .init = __cmd_common_init,
+               .run = __cmd_terminate_bg_comp_run,
+               .finish = __cmd_common_finish
+       },
+       [CMD_TERMINATE] = {
+               .name = "terminate",
+               .init = __cmd_common_init,
+               .run = __cmd_terminate_run,
+               .finish = __cmd_common_finish
+       },
 };
 
 static struct command *__find_cmd(void)
@@ -329,11 +621,39 @@ static gboolean __run_cmd(gpointer data)
        return G_SOURCE_REMOVE;
 }
 
+static struct cmd_arg *__create_cmd_arg(int argc, char **argv)
+{
+       struct cmd_arg *cmd_arg;
+       int i;
+
+       cmd_arg = calloc(1, sizeof(struct cmd_arg));
+       if (!cmd_arg)
+               return NULL;
+
+       for (i = CMD_GET; i <= CMD_TERMINATE; i++) {
+               if (cmd_opt[i]) {
+                       cmd_arg->comp_id = cmd_opt[i];
+                       break;
+               }
+       }
+
+       if (opt[OPT_USER])
+               cmd_arg->uid = GPOINTER_TO_INT(opt[OPT_USER]);
+       else
+               cmd_arg->uid = getuid();
+
+       if (opt[OPT_INSTANCE])
+               cmd_arg->instance_id = opt[OPT_INSTANCE];
+
+       return cmd_arg;
+}
+
 int main(int argc, char *argv[])
 {
        GOptionContext *context;
        GOptionGroup *opt_group;
        GError *error = NULL;
+       struct cmd_arg *cmd_arg;
 
        context = g_option_context_new(NULL);
        g_option_context_add_main_entries(context, cmd_entries, NULL);
@@ -356,7 +676,14 @@ int main(int argc, char *argv[])
        help = g_option_context_get_help(context, TRUE, NULL);
        g_option_context_free(context);
 
-       g_idle_add(__run_cmd, NULL);
+       cmd_arg = __create_cmd_arg(argc, argv);
+       if (!cmd_arg) {
+               printf("%s", help);
+               free(help);
+               return -1;
+       }
+
+       g_idle_add(__run_cmd, cmd_arg);
        loop = g_main_loop_new(NULL, FALSE);
        if (!loop) {
                printf("Failed to create glib main loop\n");
@@ -364,6 +691,7 @@ int main(int argc, char *argv[])
        }
        g_main_loop_run(loop);
        g_main_loop_unref(loop);
+       free(cmd_arg);
        free(help);
 
        return 0;