Refactor component status API 99/279299/1
authorHwankyu Jhun <h.jhun@samsung.com>
Fri, 5 Aug 2022 07:50:14 +0000 (16:50 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Fri, 5 Aug 2022 07:50:14 +0000 (16:50 +0900)
The comp status API is implemented using C++ language.

Change-Id: I9c84fa28d22815811aac4dee327d4c277a4b2a74
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/aul_comp_status.c [deleted file]
src/aul_comp_status.cc [new file with mode: 0644]

diff --git a/src/aul_comp_status.c b/src/aul_comp_status.c
deleted file mode 100644 (file)
index bff1de6..0000000
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
- * 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 <stdbool.h>
-
-#include <bundle.h>
-#include <bundle_internal.h>
-
-#include "aul_comp_status.h"
-#include "aul_util.h"
-#include "aul_sock.h"
-#include "aul_api.h"
-#include "aul_error.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;
-}
-
-static int __send_request(int cmd, int opt, const char *instance_id)
-{
-       bundle *b;
-       int ret;
-
-       b = bundle_create();
-       if (!b) {
-               _E("Failed to create bundle");
-               return AUL_R_ENOMEM;
-       }
-
-       ret = bundle_add(b, AUL_K_INSTANCE_ID, instance_id);
-       if (ret != BUNDLE_ERROR_NONE) {
-               bundle_free(b);
-               if (ret == BUNDLE_ERROR_OUT_OF_MEMORY)
-                       return AUL_R_ENOMEM;
-               else if (ret == BUNDLE_ERROR_INVALID_PARAMETER)
-                       return AUL_R_EINVAL;
-
-               return AUL_R_ERROR;
-       }
-
-       ret = aul_sock_send_bundle(AUL_UTIL_PID, getuid(), cmd, b, opt);
-       bundle_free(b);
-       if (ret < 0) {
-               _E("Failed to send command(%d). error(%d)", cmd, ret);
-               return aul_error_convert(ret);
-       }
-
-       return ret;
-}
-
-API int aul_comp_notify_start(const char *instance_id)
-{
-       int ret;
-
-       if (!instance_id) {
-               _E("Invalid parameter");
-               return AUL_R_EINVAL;
-       }
-
-       ret = __send_request(COMP_NOTIFY_START, AUL_SOCK_NOREPLY,
-                       instance_id);
-       if (ret < 0)
-               return ret;
-
-       return AUL_R_OK;
-}
-
-API int aul_comp_notify_exit(const char *instance_id)
-{
-       int ret;
-
-       if (!instance_id) {
-               _E("Invalid parameter");
-               return AUL_R_EINVAL;
-       }
-
-       ret = __send_request(COMP_NOTIFY_EXIT, AUL_SOCK_NOREPLY,
-                       instance_id);
-       if (ret < 0)
-               return ret;
-
-       return AUL_R_OK;
-}
-
-API int aul_comp_resume(const char *instance_id)
-{
-       int ret;
-
-       if (!instance_id) {
-               _E("Invalid parameter");
-               return AUL_R_EINVAL;
-       }
-
-       ret = __send_request(COMP_CONTEXT_RESUME, AUL_SOCK_NONE,
-                       instance_id);
-       if (ret < 0)
-               return ret;
-
-       return AUL_R_OK;
-}
-
-API int aul_comp_terminate(const char *instance_id)
-{
-       int ret;
-
-       if (!instance_id) {
-               _E("Invalid parameter");
-               return AUL_R_EINVAL;
-       }
-
-       ret = __send_request(COMP_CONTEXT_TERMINATE, AUL_SOCK_NONE,
-                       instance_id);
-       if (ret < 0)
-               return ret;
-
-       return AUL_R_OK;
-}
-
-API int aul_comp_is_running(const char *instance_id, bool *running)
-{
-       int ret;
-
-       if (!instance_id || !running) {
-               _E("Invalid parameter");
-               return AUL_R_EINVAL;
-       }
-
-       ret = __send_request(COMP_CONTEXT_IS_RUNNING, AUL_SOCK_NONE,
-                       instance_id);
-       if (ret < 0)
-               return ret;
-
-       *running = (bool)ret;
-
-       return AUL_R_OK;
-}
diff --git a/src/aul_comp_status.cc b/src/aul_comp_status.cc
new file mode 100644 (file)
index 0000000..c36b629
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+ * Copyright (c) 2019 - 2022 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.
+ */
+
+#include "include/aul_comp_status.h"
+
+#include <bundle_cpp.h>
+
+#include "include/aul.h"
+#include "include/aul_sock.h"
+#include "include/aul_error.h"
+#include "aul_util.h"
+#include "aul_api.h"
+
+#include "app_request.h"
+
+using namespace aul::internal;
+
+extern "C" API int aul_comp_status_update(const char* instance_id, int status) {
+  if (instance_id == nullptr ||
+      status < STATUS_LAUNCHING ||
+      status > STATUS_TERMINATE) {
+    _E("Invalid parameter");
+    return AUL_R_EINVAL;
+  }
+
+  tizen_base::Bundle b {
+    { AUL_K_INSTANCE_ID, instance_id },
+    { AUL_K_STATUS, std::to_string(status) },
+  };
+
+  return AppRequest(COMP_STATUS_UPDATE, getuid())
+      .With(std::move(b))
+      .SendSimply(AUL_SOCK_NOREPLY);
+}
+
+extern "C" API int aul_comp_notify_start(const char* instance_id) {
+  if (instance_id == nullptr) {
+    _E("Invalid parameter");
+    return AUL_R_EINVAL;
+  }
+
+  return AppRequest(COMP_NOTIFY_START, getuid())
+      .SetInstId(instance_id)
+      .SendSimply(AUL_SOCK_NOREPLY);
+}
+
+extern "C" API int aul_comp_notify_exit(const char* instance_id) {
+  if (instance_id == nullptr) {
+    _E("Invalid parameter");
+    return AUL_R_EINVAL;
+  }
+
+  return AppRequest(COMP_NOTIFY_EXIT, getuid())
+      .SetInstId(instance_id)
+      .SendSimply(AUL_SOCK_NOREPLY);
+}
+
+extern "C" API int aul_comp_resume(const char* instance_id) {
+  if (instance_id == nullptr) {
+    _E("Invalid parameter");
+    return AUL_R_EINVAL;
+  }
+
+  return AppRequest(COMP_CONTEXT_RESUME, getuid())
+      .SetInstId(instance_id)
+      .SendSimply();
+}
+
+extern "C" API int aul_comp_terminate(const char* instance_id) {
+  if (instance_id == nullptr) {
+    _E("Invalid parameter");
+    return AUL_R_EINVAL;
+  }
+
+  return AppRequest(COMP_CONTEXT_TERMINATE, getuid())
+      .SetInstId(instance_id)
+      .SendSimply();
+}
+
+extern "C" API int aul_comp_is_running(const char* instance_id, bool* running) {
+  if (instance_id == nullptr || running == nullptr) {
+    _E("Invalid parameter");
+    return AUL_R_EINVAL;
+  }
+
+  int ret = AppRequest(COMP_CONTEXT_IS_RUNNING, getuid())
+      .SetInstId(instance_id)
+      .SendSimply();
+  if (ret < 0)
+    return ret;
+
+  *running = (ret == 0) ? false : true;
+  return AUL_R_OK;
+}