Add new functions for component-based application 10/201810/6
authorHwankyu Jhun <h.jhun@samsung.com>
Wed, 20 Mar 2019 00:01:24 +0000 (09:01 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Wed, 20 Mar 2019 04:19:33 +0000 (13:19 +0900)
Adds:
 - aul_comp_status_update()
 - aul_comp_notify_start()
 - aul_comp_notify_exit()

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

Change-Id: Iba57157ea5318ac4417b47b92f5dc7e357b1d16e
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
CMakeLists.txt
include/aul_cmd.h
include/aul_comp_status.h [new file with mode: 0644]
src/aul_cmd.c
src/aul_comp_status.c [new file with mode: 0644]

index ade9617..6e714b1 100755 (executable)
@@ -67,6 +67,7 @@ SET(HEADERS_LIB_AUL
        aul_watchdog.h
        aul_svc_internal.h
        aul_key.h
+       aul_comp_status.h
        )
 
 # Install headers, other files
index 7ade269..371d8bf 100755 (executable)
@@ -141,6 +141,10 @@ enum app_cmd {
        APP_SEND_LAUNCH_REQUEST = 109,
        APP_SEND_LAUNCH_REQUEST_SYNC = 110,
 
+       COMP_NOTIFY_START = 111,
+       COMP_NOTIFY_EXIT = 112,
+       COMP_STATUS_UPDATE = 113,
+
        APP_CMD_MAX
 };
 
diff --git a/include/aul_comp_status.h b/include/aul_comp_status.h
new file mode 100644 (file)
index 0000000..83dbaec
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2019 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.
+ */
+
+#pragma once
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief Updates a status of a component.
+ * @since_tizen 5.5
+ *
+ * @param[in]   instance_id     The instance ID
+ * @param[in]   status          The status
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_status_update(const char *instance_id, int status);
+
+/**
+ * @brief Notifies that a component is starting.
+ * @since_tizen 5.5
+ *
+ * @param[in]   instance_id     The instance ID
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_notify_start(const char *instance_id);
+
+/**
+ * @brief Notifies that a component is exiting.
+ * @since_tizen 5.5
+ *
+ * @param[in]   instance_id     The instance ID
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_notify_exit(const char *instance_id);
+
+#ifdef __cplusplus
+}
+#endif
index 66bff26..7ba1f22 100755 (executable)
@@ -246,6 +246,12 @@ API const char *aul_cmd_convert_to_string(int cmd)
                return "APP_SEND_LAUNCH_REQUEST";
        case APP_SEND_LAUNCH_REQUEST_SYNC:
                return "APP_SEND_LAUNCH_REQUEST_SYNC";
+       case COMP_NOTIFY_START:
+               return "COMP_NOTIFY_START";
+       case COMP_NOTIFY_EXIT:
+               return "COMP_NOTIFY_EXIT";
+       case COMP_STATUS_UPDATE:
+               return "COMP_STATUS_UPDATE";
        default:
                return "CUSTOM_COMMAND";
        }
diff --git a/src/aul_comp_status.c b/src/aul_comp_status.c
new file mode 100644 (file)
index 0000000..f0dbaf2
--- /dev/null
@@ -0,0 +1,120 @@
+/*
+ * Copyright (c) 2019 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 _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <bundle.h>
+#include <bundle_internal.h>
+
+#include "aul_util.h"
+#include "aul_sock.h"
+#include "aul_api.h"
+#include "aul.h"
+
+API int aul_comp_status_update(const char *instance_id, int status)
+{
+       char buf[32];
+       bundle *b;
+       int r;
+
+       if (!instance_id || status > STATUS_TERMINATE) {
+               _E("Invalid parameter");
+               return AUL_R_EINVAL;
+       }
+
+       b = bundle_create();
+       if (!b) {
+               _E("Failed to create bundle");
+               return AUL_R_ERROR;
+       }
+
+       bundle_add(b, AUL_K_INSTANCE_ID, instance_id);
+       snprintf(buf, sizeof(buf), "%d", status);
+       bundle_add(b, AUL_K_STATUS, buf);
+
+       r = aul_sock_send_bundle(AUL_UTIL_PID, getuid(),
+                       COMP_STATUS_UPDATE, b, AUL_SOCK_NOREPLY);
+       if (r < 0) {
+               _E("Failed to send the update request. error(%d)", r);
+               bundle_free(b);
+               return r;
+       }
+       bundle_free(b);
+
+       return AUL_R_OK;
+}
+
+API int aul_comp_notify_start(const char *instance_id)
+{
+       bundle *b;
+       int r;
+
+       if (!instance_id) {
+               _E("Invalid parameter");
+               return AUL_R_EINVAL;
+       }
+
+       b = bundle_create();
+       if (!b) {
+               _E("Failed to create bundle");
+               return AUL_R_ERROR;
+       }
+
+       bundle_add(b, AUL_K_INSTANCE_ID, instance_id);
+
+       r = aul_sock_send_bundle(AUL_UTIL_PID, getuid(),
+                       COMP_NOTIFY_START, b, AUL_SOCK_NOREPLY);
+       if (r < 0) {
+               _E("Failed to send the update request. error(%d)", r);
+               bundle_free(b);
+               return r;
+       }
+       bundle_free(b);
+
+       return AUL_R_OK;
+}
+
+API int aul_comp_notify_exit(const char *instance_id)
+{
+       bundle *b;
+       int r;
+
+       if (!instance_id) {
+               _E("Invalid parameter");
+               return AUL_R_EINVAL;
+       }
+
+       b = bundle_create();
+       if (!b) {
+               _E("Failed to create bundle");
+               return AUL_R_ERROR;
+       }
+
+       bundle_add(b, AUL_K_INSTANCE_ID, instance_id);
+
+       r = aul_sock_send_bundle(AUL_UTIL_PID, getuid(),
+                       COMP_NOTIFY_EXIT, b, AUL_SOCK_NOREPLY);
+       if (r < 0) {
+               _E("Failed to send the update request. error(%d)", r);
+               bundle_free(b);
+               return r;
+       }
+       bundle_free(b);
+
+       return AUL_R_OK;
+}