Implement provider classes
authorSangyoon Jang <jeremy.jang@samsung.com>
Wed, 29 Apr 2020 07:45:29 +0000 (16:45 +0900)
committerSangyoon Jang <jeremy.jang@samsung.com>
Mon, 25 May 2020 04:28:15 +0000 (13:28 +0900)
Change-Id: I86e625a65c40612e4c6573b9133c1ced52929ab9
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
src/theme_provider/control_request_handler.cc
src/theme_provider/db_manager.cc
src/theme_provider/package_event_request_handler.cc
src/theme_provider/package_event_request_handler.h
src/theme_provider/selection_request_handler.cc
src/theme_provider/theme_info_proxy.cc
src/theme_provider/theme_info_proxy.h

index 2bf4db5..6011962 100644 (file)
@@ -6,12 +6,22 @@
 
 #include <bundle_cpp.h>
 
+#include "theme_provider/theme_info_proxy.h"
+
 namespace ttm {
 namespace provider {
 
 tizen_base::Bundle ControlRequestHandler::OnRequest(dbus::Command cmd,
     const tizen_base::Bundle& args) {
-  return {};
+  tizen_base::Bundle b;
+  if (cmd != dbus::Command::SET_ID) {
+    // this temporary return value should be fixed.
+    b.Add("result", "error");
+    return b;
+  }
+  bool r = proxy_->SetCurrentTheme(args.GetString("id"));
+  b.Add("result", r ? "ok" : "error");
+  return b;
 }
 
 }  // namespace provider
index 54af7f8..606fdc4 100644 (file)
@@ -40,6 +40,12 @@ const char kDeleteQuery[] =
 const char kSelectQuery[] =
     "SELECT id, version, tool_version, title, description, preview, resolution,"
     "  details WHERE id = ?";
+const char kCreateThemeSettingTableQuery[] =
+    "CREATE TABLE IF NOT EXISTS theme_setting (\n"
+    "  current TEXT,\n"
+    "  PRIMARY KEY (current))";
+const char kSetThemeQuery[] =
+    "INSERT OR REPLACE INTO theme_setting (current) VALUES (?)";
 
 }  // namespace
 
@@ -169,6 +175,25 @@ tizen_base::Bundle DbManager::Select(const std::string& id) {
 }
 
 bool DbManager::UpdateCurrentId(const std::string& id) {
+  std::unique_ptr<SQLiteStatement> stmt =
+      conn_.PrepareStatement(kSetThemeQuery);
+  if (!stmt) {
+    LOG(ERROR) << "Failed to prepare statement";
+    return false;
+  }
+
+  if (!stmt->BindString(1, id))
+    return false;
+
+  if (stmt->Step() != SQLiteStatement::StepResult::DONE) {
+    LOG(ERROR) << "Failed to set current theme as " << id;
+    return false;
+  }
+
+  // should notify to listeners that current theme was changed.
+  for (const auto& listener : listeners_)
+    listener->OnThemePackageChanged(id);
+
   return true;
 }
 
index b885904..690f319 100644 (file)
@@ -6,12 +6,52 @@
 
 #include <bundle_cpp.h>
 
+#include "theme/loader/theme_info.h"
+#include "theme/utils/logging.h"
+#include "theme_provider/theme_info_proxy.h"
+
 namespace ttm {
 namespace provider {
 
 tizen_base::Bundle PackageEventRequestHandler::OnRequest(dbus::Command cmd,
     const tizen_base::Bundle& args) {
-  return {};
+  bool result = false;
+  switch (cmd) {
+    case dbus::Command::ADD:
+      result = InstallTheme(args);
+      break;
+    case dbus::Command::REMOVE:
+      result = UninstallTheme(args);
+      break;
+    case dbus::Command::UPDATE:
+      result = UpdateTheme(args);
+      break;
+    default:
+      LOG(ERROR) << "Invalid command type";
+      break;
+  }
+
+  tizen_base::Bundle b;
+  // this temporary return value should be fixed.
+  if (result)
+    b.Add("result", "ok");
+  else
+    b.Add("result", "error");
+
+  return b;
+}
+
+bool PackageEventRequestHandler::InstallTheme(const tizen_base::Bundle& args) {
+  return proxy_->SaveTheme(loader::ThemeInfo(args));
+}
+
+bool PackageEventRequestHandler::UpdateTheme(const tizen_base::Bundle& args) {
+  return proxy_->UpdateTheme(loader::ThemeInfo(args));
+}
+
+bool PackageEventRequestHandler::UninstallTheme(
+    const tizen_base::Bundle& args) {
+  return proxy_->RemoveTheme(args.GetString("id"));
 }
 
 }  // namespace provider
index 9eae04a..fd72ac1 100644 (file)
@@ -25,6 +25,10 @@ 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 tizen_base::Bundle& args);
+
   std::shared_ptr<ThemeInfoProxy> proxy_;
 };
 
index aa790e4..e11ea43 100644 (file)
@@ -8,14 +8,17 @@
 
 #include <string>
 
+#include "theme/loader/theme_info.h"
+#include "theme_provider/theme_info_proxy.h"
+
 namespace ttm {
 namespace provider {
 
 tizen_base::Bundle SelectionRequestHandler::OnRequest(dbus::Command cmd,
     const tizen_base::Bundle& args) {
   std::string id = args.GetString("id");
-  
-  return {};
+  std::shared_ptr<loader::ThemeInfo> themeinfo = proxy_->LoadTheme(id);
+  return themeinfo->Serialize();
 }
 
 }  // namespace provider
index fb756a7..3ad7915 100644 (file)
@@ -21,15 +21,24 @@ bool ThemeInfoProxy::SaveTheme(const loader::ThemeInfo& info) {
   return db_manager_.Insert(info.GetId(), info.Serialize());
 }
 
+bool ThemeInfoProxy::UpdateTheme(const loader::ThemeInfo& info) {
+  return db_manager_.Update(info.GetId(), info.Serialize());
+}
+
+bool ThemeInfoProxy::RemoveTheme(const std::string& id) {
+  return db_manager_.Delete(id);
+}
+
 std::shared_ptr<loader::ThemeInfo> ThemeInfoProxy::GetLoadedTheme() {
-  return nullptr;
+  return cur_theme_;
 }
 
 bool ThemeInfoProxy::SetCurrentTheme(const std::string& id) {
-  return true;
+  return db_manager_.UpdateCurrentId(id);
 }
 
 void ThemeInfoProxy::OnThemePackageChanged(const std::string& id) {
+  cur_theme_ = std::make_shared<loader::ThemeInfo>(db_manager_.Select(id));
 }
 
 }  // namespace provider
index acc9afa..01db64f 100644 (file)
@@ -18,12 +18,15 @@ class ThemeInfoProxy : public IThemePackageEvent {
  public:
   std::shared_ptr<loader::ThemeInfo> LoadTheme(const std::string& id);
   bool SaveTheme(const loader::ThemeInfo& info);
+  bool UpdateTheme(const loader::ThemeInfo& info);
+  bool RemoveTheme(const std::string& id);
   std::shared_ptr<loader::ThemeInfo> GetLoadedTheme();
   bool SetCurrentTheme(const std::string& id);
   void OnThemePackageChanged(const std::string& id) override;
 
  private:
   DbManager db_manager_;
+  std::shared_ptr<loader::ThemeInfo> cur_theme_;
 };
 
 }  // namespace provider