Refactor complication API 56/279356/2
authorHwankyu Jhun <h.jhun@samsung.com>
Mon, 8 Aug 2022 00:09:12 +0000 (09:09 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Mon, 8 Aug 2022 03:21:38 +0000 (12:21 +0900)
The complication API is implemented using C++ language.

Change-Id: I33ab66b7283c6f70a75bc984348462f1b2205c96
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
include/aul_complication.h
include/aul_key.h
src/aul_complication.c [deleted file]
src/aul_complication.cc [new file with mode: 0644]
test/unit_tests/test_complication.cc

index bc99737..d25a414 100644 (file)
 #ifndef __AUL_COMPLICATION_H__
 #define __AUL_COMPLICATION_H__
 
+#include <sys/types.h>
+#include <aul.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-#define AUL_K_COMPLICATION_MODE                "__AUL_COMPLICATION_MODE__"
-
-#define UPDATE_REQUEST         "__UPDATE_REQUEST__"
-
-#define LAUNCH_REQUEST         "__LAUNCH_REQUEST__"
-
 int aul_complication_update_request(const char *appid,
                const char *provider_appid, uid_t uid);
 
index b9ace58..dfff008 100644 (file)
  * @since_tizen 7.0
  */
 #define AUL_K_ENABLED_LIGHT_USER      "__AUL_ENABLED_LIGHT_USER__"
+
+/**
+ * @brief Definition for AUL: The complication mode.
+ * @since_tizen 5.0
+ */
+#define AUL_K_COMPLICATION_MODE         "__AUL_COMPLICATION_MODE__"
diff --git a/src/aul_complication.c b/src/aul_complication.c
deleted file mode 100644 (file)
index 8d799b6..0000000
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * Copyright (c) 2018 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 <sys/types.h>
-#include <unistd.h>
-#include <bundle_internal.h>
-
-#include "aul_api.h"
-#include "aul_util.h"
-#include "aul_sock.h"
-#include "aul_complication.h"
-#include "aul.h"
-
-#define MAX_UID_STR_BUFSZ 20
-
-API int aul_complication_update_request(const char *appid, const char *provider_appid, uid_t uid)
-{
-       bundle *b;
-       int r;
-       char buf[MAX_UID_STR_BUFSZ];
-
-       if (!appid || !provider_appid) {
-               _E("Invalid parameter");
-               return AUL_R_EINVAL;
-       }
-
-       b = bundle_create();
-       if (!b) {
-               _E("Out of memory");
-               return AUL_R_ERROR;
-       }
-
-       r = bundle_add(b, AUL_K_CALLER_APPID, appid);
-       if (r != BUNDLE_ERROR_NONE) {
-               _E("Failed to add appid(%s)", appid);
-               bundle_free(b);
-               return AUL_R_ERROR;
-       }
-
-       r = bundle_add(b, AUL_K_APPID, provider_appid);
-       if (r != BUNDLE_ERROR_NONE) {
-               _E("Failed to add provider_appid(%s)", provider_appid);
-               bundle_free(b);
-               return AUL_R_ERROR;
-       }
-
-       r = bundle_add(b, AUL_K_COMPLICATION_MODE, UPDATE_REQUEST);
-       if (r != BUNDLE_ERROR_NONE) {
-               _E("Failed to add appid(%s)", appid);
-               bundle_free(b);
-               return AUL_R_ERROR;
-       }
-
-       snprintf(buf, sizeof(buf), "%d", uid);
-       r = bundle_add(b, AUL_K_TARGET_UID, buf);
-       if (r != BUNDLE_ERROR_NONE) {
-               _E("Failed to add uid(%d)", uid);
-               bundle_free(b);
-               return AUL_R_ERROR;
-       }
-
-       r = aul_sock_send_bundle(AUL_UTIL_PID, getuid(),
-               COMPLICATION_UPDATE_REQUEST, b, AUL_SOCK_QUEUE);
-       if (r < 0) {
-               _E("Failed to send request(%d:%s)",
-                               COMPLICATION_UPDATE_REQUEST, appid);
-               bundle_free(b);
-               return r;
-       }
-       bundle_free(b);
-
-       return AUL_R_OK;
-}
-
-API int aul_complication_launch_with_extra_data(const char *appid,
-               const char *provider_appid, uid_t uid, const char *key, const char *value)
-{
-       bundle *b;
-       int r;
-       char buf[MAX_UID_STR_BUFSZ];
-
-       if (!appid || !provider_appid || !key || !value) {
-               _E("Invalid parameter");
-               return AUL_R_EINVAL;
-       }
-
-       b = bundle_create();
-       if (!b) {
-               _E("Out of memory");
-               return AUL_R_ERROR;
-       }
-
-       r = bundle_add(b, AUL_K_CALLER_APPID, appid);
-       if (r != BUNDLE_ERROR_NONE) {
-               _E("Failed to add appid(%s)", appid);
-               bundle_free(b);
-               return AUL_R_ERROR;
-       }
-
-       r = bundle_add(b, AUL_K_APPID, provider_appid);
-       if (r != BUNDLE_ERROR_NONE) {
-               _E("Failed to add provider_appid(%s)", provider_appid);
-               bundle_free(b);
-               return AUL_R_ERROR;
-       }
-
-       r = bundle_add(b, AUL_K_COMPLICATION_MODE, LAUNCH_REQUEST);
-       if (r != BUNDLE_ERROR_NONE) {
-               _E("Failed to add appid(%s)", appid);
-               bundle_free(b);
-               return AUL_R_ERROR;
-       }
-
-       snprintf(buf, sizeof(buf), "%d", uid);
-       r = bundle_add(b, AUL_K_TARGET_UID, buf);
-       if (r != BUNDLE_ERROR_NONE) {
-               _E("Failed to add uid(%d)", uid);
-               bundle_free(b);
-               return AUL_R_ERROR;
-       }
-
-       if (key && value) {
-               r = bundle_add(b, key, value);
-               if (r != BUNDLE_ERROR_NONE) {
-                       _E("Failed to add key value data (%s)", key);
-                       bundle_free(b);
-                       return AUL_R_ERROR;
-               }
-       }
-
-       r = aul_sock_send_bundle(AUL_UTIL_PID, getuid(),
-               COMPLICATION_UPDATE_REQUEST, b, AUL_SOCK_QUEUE);
-       if (r < 0) {
-               _E("Failed to send request(%d:%s)",
-                               COMPLICATION_UPDATE_REQUEST, appid);
-               bundle_free(b);
-               return r;
-       }
-       bundle_free(b);
-
-       return AUL_R_OK;
-}
diff --git a/src/aul_complication.cc b/src/aul_complication.cc
new file mode 100644 (file)
index 0000000..cfbd26a
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2018 - 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_complication.h"
+
+#include <bundle_cpp.h>
+
+#include <string>
+
+#include "app_request.h"
+#include "aul_api.h"
+#include "aul_util.h"
+#include "include/aul.h"
+#include "include/aul_sock.h"
+
+using namespace aul::internal;
+
+namespace {
+
+constexpr const char kUpdateRequest[] = "__UPDATE_REQUEST__";
+constexpr const char kLaunchRequest[] = "__LAUNCH_REQUEST__";
+
+}  // namespace
+
+extern "C" API int aul_complication_update_request(const char* appid,
+    const char* provider_appid, uid_t uid) {
+  if (appid == nullptr || provider_appid == nullptr) {
+    _E("Invalid parameter");
+    return AUL_R_EINVAL;
+  }
+
+  tizen_base::Bundle b {
+    { AUL_K_CALLER_APPID, appid },
+    { AUL_K_COMPLICATION_MODE, kUpdateRequest}
+  };
+
+  return AppRequest(COMPLICATION_UPDATE_REQUEST, uid)
+      .With(std::move(b))
+      .SetAppId(provider_appid)
+      .Send();
+}
+
+extern "C" API int aul_complication_launch_with_extra_data(const char* appid,
+    const char* provider_appid, uid_t uid, const char* key, const char* value) {
+  if (appid == nullptr ||
+      provider_appid == nullptr ||
+      key == nullptr ||
+      value == nullptr) {
+    _E("Invalid parameter");
+    return AUL_R_EINVAL;
+  }
+
+  tizen_base::Bundle b {
+    { AUL_K_CALLER_APPID, appid },
+    { AUL_K_COMPLICATION_MODE, kLaunchRequest },
+    { key, value }
+  };
+
+  return AppRequest(COMPLICATION_UPDATE_REQUEST, uid)
+      .With(std::move(b))
+      .SetAppId(provider_appid)
+      .Send();
+}
index 4d4c27e..43491c9 100644 (file)
@@ -39,6 +39,8 @@ namespace {
 
 constexpr const char kAppId[] = "org.tizen.complication";
 constexpr const char kProviderAppId[] = "org.tizen.complication-provider";
+constexpr const char kUpdateRequest[] = "__UPDATE_REQUEST__";
+constexpr const char kLaunchRequest[] = "__LAUNCH_REQUEST__";
 
 class Mocks : virtual public ::testing::NiceMock<SocketMock> {};
 
@@ -92,7 +94,7 @@ TEST_F(ComplicationTest, aul_complication_update_request_P) {
   EXPECT_EQ(opt, (AUL_SOCK_BUNDLE | AUL_SOCK_QUEUE));
   EXPECT_EQ(b.GetString(AUL_K_CALLER_APPID), kAppId);
   EXPECT_EQ(b.GetString(AUL_K_APPID), kProviderAppId);
-  EXPECT_EQ(b.GetString(AUL_K_COMPLICATION_MODE), UPDATE_REQUEST);
+  EXPECT_EQ(b.GetString(AUL_K_COMPLICATION_MODE), kUpdateRequest);
 }
 
 TEST_F(ComplicationTest, aul_complication_update_request_N) {
@@ -136,7 +138,7 @@ TEST_F(ComplicationTest, aul_complication_launch_with_extra_data_P) {
   EXPECT_EQ(opt, (AUL_SOCK_BUNDLE | AUL_SOCK_QUEUE));
   EXPECT_EQ(b.GetString(AUL_K_CALLER_APPID), kAppId);
   EXPECT_EQ(b.GetString(AUL_K_APPID), kProviderAppId);
-  EXPECT_EQ(b.GetString(AUL_K_COMPLICATION_MODE), LAUNCH_REQUEST);
+  EXPECT_EQ(b.GetString(AUL_K_COMPLICATION_MODE), kLaunchRequest);
   EXPECT_EQ(b.GetString("KEY"), "VALUE");
 }