Refactor Job scheduler API 11/279411/2
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 9 Aug 2022 03:51:52 +0000 (12:51 +0900)
committerHwanKyu Jhun <h.jhun@samsung.com>
Tue, 9 Aug 2022 04:42:07 +0000 (04:42 +0000)
The job scheduler API is implemented using C++ language.

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

diff --git a/src/aul_job_scheduler.c b/src/aul_job_scheduler.c
deleted file mode 100644 (file)
index ca8b23e..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright (c) 2017 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 <stdbool.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <glib.h>
-#include <bundle_internal.h>
-
-#include "aul_util.h"
-#include "aul_api.h"
-#include "aul_sock.h"
-#include "aul.h"
-#include "aul_job_scheduler.h"
-
-API int aul_job_scheduler_update_job_status(const char *job_id,
-               aul_job_status_e job_status)
-{
-       char buf[12];
-       bundle *b;
-       int r;
-
-       if (job_id == NULL || job_status > JOB_STATUS_FINISHED) {
-               _E("Invalid parameter");
-               return AUL_R_EINVAL;
-       }
-
-       b = bundle_create();
-       if (b == NULL) {
-               _E("Out of memory");
-               return AUL_R_ERROR;
-       }
-
-       r = bundle_add(b, AUL_K_JOB_ID, job_id);
-       if (r != BUNDLE_ERROR_NONE) {
-               _E("Failed to add job(%s)", job_id);
-               bundle_free(b);
-               return AUL_R_ERROR;
-       }
-
-       snprintf(buf, sizeof(buf), "%u", job_status);
-       r = bundle_add(b, AUL_K_JOB_STATUS, buf);
-       if (r != BUNDLE_ERROR_NONE) {
-               _E("Failed to add job status(%u)", job_status);
-               bundle_free(b);
-               return AUL_R_ERROR;
-       }
-
-       r = aul_sock_send_bundle(AUL_UTIL_PID, getuid(), JOB_STATUS_UPDATE,
-                       b, AUL_SOCK_NOREPLY);
-       if (r != 0) {
-               _E("Failed to update job status(%s:%u)", job_id, job_status);
-               bundle_free(b);
-               return r;
-       }
-       bundle_free(b);
-
-       return AUL_R_OK;
-}
diff --git a/src/aul_job_scheduler.cc b/src/aul_job_scheduler.cc
new file mode 100644 (file)
index 0000000..1b169de
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2017 - 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_job_scheduler.h"
+
+#include <bundle_cpp.h>
+
+#include "app_request.h"
+#include "aul_api.h"
+#include "aul_util.h"
+#include "include/aul.h"
+#include "include/aul_sock.h"
+
+extern "C" API int aul_job_scheduler_update_job_status(const char* job_id,
+    aul_job_status_e job_status) {
+  if (job_id == nullptr ||
+      job_status < JOB_STATUS_START ||
+      job_status > JOB_STATUS_FINISHED) {
+    _E("Invalid parameter");
+    return AUL_R_EINVAL;
+  }
+
+  tizen_base::Bundle b {
+    { AUL_K_JOB_ID, job_id },
+    { AUL_K_JOB_STATUS, std::to_string(job_status) }
+  };
+
+  return aul::internal::AppRequest(JOB_STATUS_UPDATE, getuid())
+      .With(std::move(b))
+      .SendSimply(AUL_SOCK_NOREPLY);
+}