Fix the constants of bundle key 77/236877/3
authorSangyoon Jang <jeremy.jang@samsung.com>
Tue, 23 Jun 2020 05:13:16 +0000 (14:13 +0900)
committerSangyoon Jang <jeremy.jang@samsung.com>
Tue, 23 Jun 2020 11:59:20 +0000 (20:59 +0900)
We don't need to add command at bundle, because it is already passed by
dbus message.
Use constants as extern, instead of macro.

Change-Id: I7a4534af84c7ec244f7749c824b4c3599a1674f7
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
13 files changed:
src/theme/dbus/command.cc [new file with mode: 0644]
src/theme/dbus/command.h [new file with mode: 0644]
src/theme/dbus/request_broker.cc
src/theme/dbus/request_handler.h
src/theme/loader/theme_info_loader.cc
src/theme_plugin/theme_parser.cc
src/theme_provider/control_request_handler.cc
src/theme_provider/package_event_request_handler.cc
src/theme_provider/package_event_request_handler.h
src/theme_provider/selection_request_handler.cc
test/unit_tests/test_request_broker.cc
test/unit_tests/test_request_handlers.cc
test/unit_tests/test_theme_info_loader.cc

diff --git a/src/theme/dbus/command.cc b/src/theme/dbus/command.cc
new file mode 100644 (file)
index 0000000..eae435c
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * 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 "theme/dbus/command.h"
+
+namespace ttm {
+namespace dbus {
+
+const char kCmdDataKey[] = "__DATA__";
+const char kCmdResultKey[] = "__RESULT__";
+
+}  // namespace dbus
+}  // namespace ttm
diff --git a/src/theme/dbus/command.h b/src/theme/dbus/command.h
new file mode 100644 (file)
index 0000000..3e79b70
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+
+#ifndef THEME_DBUS_COMMAND_H_
+#define THEME_DBUS_COMMAND_H_
+
+namespace ttm {
+namespace dbus {
+
+enum class Command : int {
+  GET_IDS,
+  SET_ID,
+  GET,
+  RESULT,
+  ADD,
+  UPDATE,
+  REMOVE,
+  CHANGED,
+  REMOVED
+};
+
+extern const char kCmdDataKey[];
+extern const char kCmdResultKey[];
+
+}  // namespace dbus
+}  // namespace ttm
+
+#endif  // THEME_DBUS_COMMAND_H_
index 8175a51..d47eebc 100644 (file)
@@ -36,7 +36,7 @@ namespace dbus {
 
 static tizen_base::Bundle ErrorResultBundle() {
   tizen_base::Bundle b;
-  b.Add(CMD_RESULT_KEY, "error");
+  b.Add(dbus::kCmdResultKey, "error");
   return b;
 }
 
index 4ec09e8..9c2ec6d 100644 (file)
 
 #include <bundle_cpp.h>
 
+#include "theme/dbus/command.h"
+
 namespace ttm {
 namespace dbus {
 
-#define CMD_GET_IDS_KEY "__GET_IDS__"
-#define CMD_SET_ID_KEY "__SET_ID__"
-#define CMD_GET_KEY "__GET__"
-#define CMD_RESULT_KEY "__RESULT__"
-#define CMD_ADD_KEY "__ADD__"
-#define CMD_UPDATE_KEY "__UPDATE__"
-#define CMD_REMOVE_KEY "__REMOVE__"
-#define CMD_CHANGED_KEY "__CHANGED__"
-#define CMD_REMOVED_KEY "__REMOVED__"
-
-enum class Command : int {
-  GET_IDS,
-  SET_ID,
-  GET,
-  RESULT,
-  ADD,
-  UPDATE,
-  REMOVE,
-  CHANGED,
-  REMOVED
-};
-
 class IRequestHandler {
  public:
   virtual ~IRequestHandler() = default;
index 365ae1c..502318e 100644 (file)
@@ -18,6 +18,7 @@
 
 #include "theme/loader/theme_info.h"
 #include "theme/loader/theme_info_loader.h"
+#include "theme/dbus/command.h"
 #include "theme/dbus/request_broker.h"
 
 #include "theme/utils/logging.h"
@@ -29,7 +30,7 @@ tizen_base::Bundle ThemeInfoLoader::OnRequest(dbus::Command cmd,
     const tizen_base::Bundle& args) {
   switch (cmd) {
     case dbus::Command::CHANGED: {
-      tizen_base::Bundle b(args.GetString(CMD_CHANGED_KEY));
+      tizen_base::Bundle b(args.GetString(dbus::kCmdDataKey));
       const ThemeInfo* info = new ThemeInfo(b);
       for (auto& listener : listeners_) {
         std::shared_ptr<IThemeEvent> ev = listener.second;
@@ -39,7 +40,7 @@ tizen_base::Bundle ThemeInfoLoader::OnRequest(dbus::Command cmd,
       break;
     }
     case dbus::Command::REMOVED: {
-      std::string id = args.GetString(CMD_REMOVE_KEY);
+      std::string id = args.GetString(dbus::kCmdDataKey);
       for (auto& listener : listeners_) {
         std::shared_ptr<IThemeEvent> ev = listener.second;
         ev->OnThemeUnloaded(id);
@@ -96,15 +97,15 @@ std::vector<std::string> ThemeInfoLoader::QueryThemeId() {
   tizen_base::Bundle b;
   tizen_base::Bundle reply =
     dbus::RequestBroker::GetInst().SendData(dbus::Command::GET_IDS, b);
-  if (reply.GetString(CMD_RESULT_KEY) == "error")
+  if (reply.GetString(dbus::kCmdResultKey) == "error")
     return {};
 
-  return reply.GetStringArray(CMD_GET_IDS_KEY);
+  return reply.GetStringArray(dbus::kCmdDataKey);
 }
 
 void ThemeInfoLoader::SetCurrent(const std::string& id) {
   tizen_base::Bundle b;
-  b.Add(CMD_SET_ID_KEY, id);
+  b.Add(dbus::kCmdDataKey, id);
 
   tizen_base::Bundle reply =
     dbus::RequestBroker::GetInst().SendData(dbus::Command::SET_ID, b);
@@ -115,11 +116,11 @@ std::shared_ptr<ThemeInfo> ThemeInfoLoader::LoadCurrent() {
     return cache_;
 
   tizen_base::Bundle b;
-  b.Add(CMD_GET_KEY, "");
+  b.Add(dbus::kCmdDataKey, "");
 
   tizen_base::Bundle reply =
     dbus::RequestBroker::GetInst().SendData(dbus::Command::GET, b);
-  std::string str = reply.GetString(CMD_GET_KEY);
+  std::string str = reply.GetString(dbus::kCmdDataKey);
   tizen_base::Bundle serialized(str);
 
   cache_ = std::make_shared<ThemeInfo>(serialized);
@@ -132,14 +133,14 @@ std::shared_ptr<ThemeInfo> ThemeInfoLoader::Load(const std::string& id) const {
     return cache_;
 
   tizen_base::Bundle b;
-  b.Add(CMD_GET_KEY, id);
+  b.Add(dbus::kCmdDataKey, id);
 
   tizen_base::Bundle reply =
     dbus::RequestBroker::GetInst().SendData(dbus::Command::GET, b);
-  tizen_base::Bundle serialized(
-      reply.GetString(CMD_GET_KEY));
+  tizen_base::Bundle serialized(reply.GetString(dbus::kCmdDataKey));
 
-  std::shared_ptr<ThemeInfo> info = std::make_shared<ThemeInfo>(serialized);
+  std::shared_ptr<ThemeInfo> info =
+      std::make_shared<ThemeInfo>(serialized);
 
   return info;
 }
index 403ee45..b735705 100644 (file)
@@ -34,7 +34,7 @@ loader::ThemeInfo ThemeParser::Inflate(const std::string id,
   }
 
   // FIXME: this parser should parse more theme information.
-  ThemeInfoBuilder builder("testid");
+  ThemeInfoBuilder builder(id);
   builder.PutString("pkgid", pkgid).
       PutString("uid", std::to_string(uid)).
       PutString("version", root["version"].asString()).
@@ -67,6 +67,8 @@ bool ThemeParser::Commit(ThemeOperation operation,
     default:
       return false;
   }
+  if (reply.GetString(dbus::kCmdResultKey) != "ok")
+    return false;
   return true;
 }
 
index 0522459..7b3c7fd 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <bundle_cpp.h>
 
+#include "theme/dbus/command.h"
 #include "theme_provider/theme_info_proxy.h"
 
 namespace ttm {
@@ -16,11 +17,11 @@ tizen_base::Bundle ControlRequestHandler::OnRequest(dbus::Command cmd,
   tizen_base::Bundle b;
   if (cmd != dbus::Command::SET_ID) {
     // this temporary return value should be fixed.
-    b.Add(CMD_RESULT_KEY, "error");
+    b.Add(dbus::kCmdResultKey, "error");
     return b;
   }
-  bool r = proxy_->SetCurrentTheme(args.GetString(CMD_SET_ID_KEY));
-  b.Add(CMD_RESULT_KEY, r ? "ok" : "error");
+  bool r = proxy_->SetCurrentTheme(args.GetString(dbus::kCmdDataKey));
+  b.Add(dbus::kCmdResultKey, r ? "ok" : "error");
   return b;
 }
 
index 963467b..dee1be9 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <bundle_cpp.h>
 
+#include "theme/dbus/command.h"
 #include "theme/loader/theme_info.h"
 #include "theme/utils/logging.h"
 #include "theme_provider/theme_info_proxy.h"
@@ -15,20 +16,25 @@ namespace provider {
 
 tizen_base::Bundle PackageEventRequestHandler::OnRequest(dbus::Command cmd,
     const tizen_base::Bundle& args) {
+  tizen_base::Bundle b;
   bool result = false;
+  if (args.IsEmpty()) {
+    b.Add(dbus::kCmdResultKey, "error");
+    return b;
+  }
+
+  loader::ThemeInfo theme(args);
   switch (cmd) {
     case dbus::Command::ADD: {
-      tizen_base::Bundle b(args.GetString(CMD_ADD_KEY));
-      result = InstallTheme(b);
+      result = InstallTheme(theme);
       break;
     }
     case dbus::Command::REMOVE: {
-      result = UninstallTheme(args.GetString(CMD_REMOVE_KEY));
+      result = UninstallTheme(theme);
       break;
     }
     case dbus::Command::UPDATE: {
-      tizen_base::Bundle b(args.GetString(CMD_UPDATE_KEY));
-      result = UpdateTheme(b);
+      result = UpdateTheme(theme);
       break;
     }
     default: {
@@ -37,24 +43,23 @@ tizen_base::Bundle PackageEventRequestHandler::OnRequest(dbus::Command cmd,
     }
   }
 
-  tizen_base::Bundle b;
   // this temporary return value should be fixed.
-  b.Add(CMD_RESULT_KEY, result ? "ok" : "error");
+  b.Add(dbus::kCmdResultKey, result ? "ok" : "error");
 
   return b;
 }
 
-bool PackageEventRequestHandler::InstallTheme(const tizen_base::Bundle& args) {
-  return proxy_->SaveTheme(loader::ThemeInfo(args));
+bool PackageEventRequestHandler::InstallTheme(const loader::ThemeInfo& theme) {
+  return proxy_->SaveTheme(theme);
 }
 
-bool PackageEventRequestHandler::UpdateTheme(const tizen_base::Bundle& args) {
-  return proxy_->UpdateTheme(loader::ThemeInfo(args));
+bool PackageEventRequestHandler::UpdateTheme(const loader::ThemeInfo& theme) {
+  return proxy_->UpdateTheme(theme);
 }
 
 bool PackageEventRequestHandler::UninstallTheme(
-    const std::string& id) {
-  return proxy_->RemoveTheme(id);
+    const loader::ThemeInfo& theme) {
+  return proxy_->RemoveTheme(theme.GetId());
 }
 
 }  // namespace provider
index 9dfe457..f84d6e9 100644 (file)
@@ -10,7 +10,9 @@
 #include <memory>
 #include <string>
 
+#include "theme/dbus/command.h"
 #include "theme/dbus/request_handler.h"
+#include "theme/loader/theme_info.h"
 
 namespace ttm {
 namespace provider {
@@ -25,9 +27,9 @@ class PackageEventRequestHandler : public dbus::IRequestHandler {
       const tizen_base::Bundle& args);
 
  private:
-  bool InstallTheme(const tizen_base::Bundle& args);
-  bool UpdateTheme(const tizen_base::Bundle& args);
-  bool UninstallTheme(const std::string& id);
+  bool InstallTheme(const loader::ThemeInfo& theme);
+  bool UpdateTheme(const loader::ThemeInfo& theme);
+  bool UninstallTheme(const loader::ThemeInfo& theme);
 
   std::shared_ptr<ThemeInfoProxy> proxy_;
 };
index a15c731..8ce0774 100644 (file)
@@ -8,6 +8,7 @@
 
 #include <string>
 
+#include "theme/dbus/command.h"
 #include "theme/loader/theme_info.h"
 #include "theme_provider/theme_info_proxy.h"
 
@@ -19,26 +20,26 @@ tizen_base::Bundle SelectionRequestHandler::OnRequest(dbus::Command cmd,
   tizen_base::Bundle b;
   switch (cmd) {
     case dbus::Command::GET: {
-      std::string id = args.GetString(CMD_GET_KEY);
+      std::string id = args.GetString(dbus::kCmdDataKey);
       std::shared_ptr<loader::ThemeInfo> themeinfo = proxy_->LoadTheme(id);
       if (themeinfo == nullptr) {
-        b.Add(CMD_RESULT_KEY, "error");
+        b.Add(dbus::kCmdResultKey, "error");
         return b;
       }
-      b.Add(CMD_RESULT_KEY, "ok");
-      b.Add(CMD_GET_KEY,
+      b.Add(dbus::kCmdResultKey, "ok");
+      b.Add(dbus::kCmdDataKey,
           reinterpret_cast<char*>(themeinfo->Serialize().ToRaw().first.get()));
       return b;
     }
     case dbus::Command::GET_IDS: {
       std::vector<std::string> ids = proxy_->GetThemeIds();
-      b.Add(CMD_RESULT_KEY, "ok");
-      b.Add(CMD_GET_IDS_KEY, ids);
+      b.Add(dbus::kCmdResultKey, "ok");
+      b.Add(dbus::kCmdDataKey, ids);
       return b;
     }
     default: {
       // this temporary return value should be fixed.
-      b.Add(CMD_RESULT_KEY, "error");
+      b.Add(dbus::kCmdResultKey, "error");
       return b;
     }
   }
index 013e63d..45e525f 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <cstdio>
 
+#include "theme/dbus/command.h"
 #include "theme/dbus/request_broker.h"
 #include "theme/dbus/request_handler.h"
 #include "theme/loader/theme_info.h"
@@ -195,7 +196,7 @@ TEST_F(RequestBrokerTest, SendData_N1) {
       g_dbus_message_new_method_call(_, _, _, _)).WillOnce(Return(nullptr));
   tizen_base::Bundle b;
   b = broker_.SendData(ttm::dbus::Command::ADD, b);
-  std::string result = b.GetString(CMD_RESULT_KEY);
+  std::string result = b.GetString(ttm::dbus::kCmdResultKey);
   EXPECT_EQ(result, "error");
 }
 
@@ -211,7 +212,7 @@ TEST_F(RequestBrokerTest, SendData_N2) {
           WillOnce(DoAll(SetArgPointee<6>(error), Return(nullptr)));
   tizen_base::Bundle b;
   b = broker_.SendData(ttm::dbus::Command::ADD, b);
-  std::string result = b.GetString(CMD_RESULT_KEY);
+  std::string result = b.GetString(ttm::dbus::kCmdResultKey);
   EXPECT_EQ(result, "error");
 }
 
@@ -228,7 +229,7 @@ TEST_F(RequestBrokerTest, SendData_N3) {
       g_dbus_message_get_body(_)).WillOnce(Return(nullptr));
   tizen_base::Bundle b;
   b = broker_.SendData(ttm::dbus::Command::ADD, b);
-  std::string result = b.GetString(CMD_RESULT_KEY);
+  std::string result = b.GetString(ttm::dbus::kCmdResultKey);
   EXPECT_EQ(result, "error");
 }
 
@@ -253,10 +254,10 @@ TEST_F(RequestBrokerTest, OnResultReceivedCb) {
           WillOnce(Return(msg));
   tizen_base::Bundle b;
   ttm::loader::ThemeInfo ti;
-  b.Add(CMD_RESULT_KEY, "ok");
-  b.Add(CMD_GET_KEY,
+  b.Add(ttm::dbus::kCmdResultKey, "ok");
+  b.Add(ttm::dbus::kCmdDataKey,
       reinterpret_cast<char*>(ti.Serialize().ToRaw().first.get()));
-  b.Add(CMD_GET_IDS_KEY, std::vector<std::string>());
+  b.Add(ttm::dbus::kCmdDataKey, std::vector<std::string>());
   GVariant *gv = g_variant_new("(s)", b.ToRaw().first.get());
   EXPECT_CALL(GetMock<GioMock>(),
       g_dbus_message_get_body(_)).WillOnce(Return(gv));
index 8e23668..8cd687d 100644 (file)
@@ -20,6 +20,7 @@
 #include <cstdio>
 #include <memory>
 
+#include "theme/dbus/command.h"
 #include "theme/dbus/request_handler.h"
 #include "theme_provider/control_request_handler.h"
 #include "theme_provider/package_event_request_handler.h"
@@ -67,7 +68,7 @@ TEST_F(RequestHandlersTest, ControlRequestHandler_OnRequest) {
   proxy_->SaveTheme(info);
 
   tizen_base::Bundle b;
-  b.Add(CMD_SET_ID_KEY, "testid");
+  b.Add(ttm::dbus::kCmdDataKey, "testid");
   handler.OnRequest(ttm::dbus::Command::SET_ID, b);
 
   auto cur = proxy_->GetLoadedTheme();
@@ -80,10 +81,7 @@ TEST_F(RequestHandlersTest, PackageRequestHandler_OnRequest) {
   PackageEventRequestHandler handler(proxy_);
 
   ThemeInfo info(b_);
-  tizen_base::Bundle b;
-  b.Add(CMD_ADD_KEY,
-      reinterpret_cast<char*>(info.Serialize().ToRaw().first.get()));
-  handler.OnRequest(ttm::dbus::Command::ADD, b);
+  handler.OnRequest(ttm::dbus::Command::ADD, info.Serialize());
 
   auto theme = proxy_->LoadTheme("testid");
   EXPECT_NE(theme, nullptr);
@@ -100,18 +98,14 @@ TEST_F(RequestHandlersTest, PackageRequestHandler_OnRequest) {
   v2.Add("description", "test_v2");
 
   ThemeInfo info2(v2);
-  b = info2.Serialize();
-  b.Add(CMD_UPDATE_KEY,
-      reinterpret_cast<char*>(info2.Serialize().ToRaw().first.get()));
-  handler.OnRequest(ttm::dbus::Command::UPDATE, b);
+  handler.OnRequest(ttm::dbus::Command::UPDATE, info2.Serialize());
 
   theme = proxy_->LoadTheme("testid");
   EXPECT_NE(theme, nullptr);
   EXPECT_EQ(theme->GetId(), "testid");
   EXPECT_EQ(theme->GetVersion(), "2.0");
 
-  b.Add(CMD_REMOVE_KEY, "testid");
-  handler.OnRequest(ttm::dbus::Command::REMOVE, b);
+  handler.OnRequest(ttm::dbus::Command::REMOVE, info2.Serialize());
   theme = proxy_->LoadTheme("testid");
   EXPECT_EQ(theme, nullptr);
 }
@@ -136,14 +130,14 @@ TEST_F(RequestHandlersTest, SelectionRequestHandler_OnRequest) {
   proxy_->SaveTheme(info2);
 
   tizen_base::Bundle b;
-  b.Add(CMD_GET_KEY, "testid");
+  b.Add(ttm::dbus::kCmdDataKey, "testid");
 
   auto rb = handler.OnRequest(ttm::dbus::Command::GET, b);
-  tizen_base::Bundle result(rb.GetString(CMD_GET_KEY));
+  tizen_base::Bundle result(rb.GetString(ttm::dbus::kCmdDataKey));
   ThemeInfo theme(result);
   EXPECT_EQ(theme.GetId(), "testid");
 
   rb = handler.OnRequest(ttm::dbus::Command::GET_IDS, {});
-  std::vector<std::string> ids = rb.GetStringArray(CMD_GET_IDS_KEY);
+  std::vector<std::string> ids = rb.GetStringArray(ttm::dbus::kCmdDataKey);
   EXPECT_EQ(ids.size(), 2);
 }
index 2477a29..5c8d5e1 100644 (file)
@@ -21,6 +21,7 @@
 #include <memory>
 #include <string>
 
+#include "theme/dbus/command.h"
 #include "theme/loader/theme_event.h"
 #include "theme/loader/theme_info.h"
 #include "theme/loader/theme_info_loader.h"
@@ -75,8 +76,8 @@ TEST_F(ThemeInfoLoaderTest, QueryThemeId_N) {
           WillOnce(Return(msg));
   tizen_base::Bundle b;
   std::vector<std::string> ids_vec;
-  b.Add(CMD_RESULT_KEY, "ok");
-  b.Add(CMD_GET_IDS_KEY, ids_vec);
+  b.Add(ttm::dbus::kCmdResultKey, "ok");
+  b.Add(ttm::dbus::kCmdDataKey, ids_vec);
   auto br = b.ToRaw();
   char* b_raw = reinterpret_cast<char*>(br.first.get());
   EXPECT_CALL(GetMock<GioMock>(),
@@ -102,8 +103,8 @@ TEST_F(ThemeInfoLoaderTest, LoadCurrent) {
           WillOnce(Return(msg));
   tizen_base::Bundle b;
   ThemeInfo ti;
-  b.Add(CMD_RESULT_KEY, "ok");
-  b.Add(CMD_GET_KEY,
+  b.Add(ttm::dbus::kCmdResultKey, "ok");
+  b.Add(ttm::dbus::kCmdDataKey,
       reinterpret_cast<char*>(ti.Serialize().ToRaw().first.get()));
   auto br = b.ToRaw();
   char* b_raw = reinterpret_cast<char*>(br.first.get());
@@ -128,8 +129,8 @@ TEST_F(ThemeInfoLoaderTest, Load) {
           WillOnce(Return(msg));
   tizen_base::Bundle b;
   ThemeInfo ti;
-  b.Add(CMD_RESULT_KEY, "ok");
-  b.Add(CMD_GET_KEY,
+  b.Add(ttm::dbus::kCmdResultKey, "ok");
+  b.Add(ttm::dbus::kCmdDataKey,
       reinterpret_cast<char*>(ti.Serialize().ToRaw().first.get()));
   auto br = b.ToRaw();
   char* b_raw = reinterpret_cast<char*>(br.first.get());