Fix App Com 07/238907/1
authorHwankyu Jhun <h.jhun@samsung.com>
Mon, 20 Jul 2020 06:54:34 +0000 (15:54 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Mon, 20 Jul 2020 06:54:34 +0000 (15:54 +0900)
- Changes return values
- Initializes aul launch to communicate

Change-Id: I44120e19a01515be8bc7b0175b2b65d259621cac
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/app_com.c

index 0465d3c..7c8c619 100644 (file)
@@ -124,30 +124,42 @@ static aul_app_com_connection_h __add_handler(const char *endpoint, app_com_cb c
        return h;
 }
 
-API int aul_app_com_create(const char *endpoint, aul_app_com_permission_h permission, app_com_cb callback, void *user_data, aul_app_com_connection_h *connection)
+API int aul_app_com_create(const char *endpoint,
+               aul_app_com_permission_h permission, app_com_cb callback,
+               void *user_data, aul_app_com_connection_h *connection)
 {
-       bundle *b = NULL;
-       int ret = 0;
+       bundle *b;
+       int ret;
 
-       if (endpoint == NULL || callback == NULL || connection == NULL)
-               return -1;
+       if (endpoint == NULL || callback == NULL || connection == NULL) {
+               _E("Invalid parameter");
+               return AUL_R_EINVAL;
+       }
 
-       b = bundle_create();
+       if (!aul_is_initialized()) {
+                if (aul_launch_init(NULL, NULL) < 0)
+                        return AUL_R_ENOINIT;
+        }
 
+       b = bundle_create();
        if (!b) {
                _E("out of memory");
-               return -1;
+               return AUL_R_ENOMEM;
        }
 
        bundle_add_str(b, AUL_K_COM_ENDPOINT, endpoint);
 
        if (permission) {
-               if (permission->propagation)
+               if (permission->propagation) {
                        bundle_add_byte(b, AUL_K_COM_PROPAGATE,
-                               (void *)(GUINT_TO_POINTER(permission->propagation)), sizeof(unsigned int));
+                               (GUINT_TO_POINTER(permission->propagation)),
+                               sizeof(unsigned int));
+               }
 
-               if (permission->privilege)
-                       bundle_add_str(b, AUL_K_COM_PRIVILEGE, permission->privilege);
+               if (permission->privilege) {
+                       bundle_add_str(b, AUL_K_COM_PRIVILEGE,
+                                       permission->privilege);
+               }
        }
 
        ret = app_send_cmd(AUL_UTIL_PID, APP_COM_CREATE, b);
@@ -159,19 +171,27 @@ API int aul_app_com_create(const char *endpoint, aul_app_com_permission_h permis
        return ret;
 }
 
-API int aul_app_com_join(const char *endpoint, const char *filter, app_com_cb callback, void *user_data, aul_app_com_connection_h *connection)
+API int aul_app_com_join(const char *endpoint, const char *filter,
+               app_com_cb callback, void *user_data,
+               aul_app_com_connection_h *connection)
 {
-       bundle *b = NULL;
-       int ret = 0;
+       bundle *b;
+       int ret;
 
-       if (endpoint == NULL || callback == NULL || connection == NULL)
-               return -1;
+       if (endpoint == NULL || callback == NULL || connection == NULL) {
+               _E("Invalid parameter");
+               return AUL_R_EINVAL;
+       }
 
-       b = bundle_create();
+       if (!aul_is_initialized()) {
+               if (aul_launch_init(NULL, NULL) < 0)
+                       return AUL_R_ENOINIT;
+       }
 
+       b = bundle_create();
        if (!b) {
                _E("out of memory");
-               return -1;
+               return AUL_R_ENOMEM;
        }
 
        bundle_add_str(b, AUL_K_COM_ENDPOINT, endpoint);