Remove unnecessary GetInst 08/206308/4
authorhyunho <hhstark.kang@samsung.com>
Thu, 16 May 2019 06:54:31 +0000 (15:54 +0900)
committerHyunho Kang <hhstark.kang@samsung.com>
Wed, 22 May 2019 00:32:33 +0000 (00:32 +0000)
Change-Id: Id834bfd109245a35ac432431fddf5b3038e0f25e
Signed-off-by: hyunho <hhstark.kang@samsung.com>
watchface-complication/complication-implementation.h
watchface-complication/complication.cc
watchface-complication/design-element-implementation.h
watchface-complication/design-element.cc

index c6aaf47e66c5d2b4fba879b910cde7d3e4ce0edc..7e90542ead1ecd60588193b36151a2f3816ead70 100644 (file)
@@ -122,6 +122,7 @@ class Complication::Impl : IGDBus::IGDBusEvent, IPackageManager::IPackageEvent {
   guint periodic_timer_ = 0;
   std::unique_ptr<IGDBus> gdbus_ = nullptr;
   std::unique_ptr<IPackageManager> package_ = nullptr;
+  EditablesManager& editables_manager_;
   bool mock_ = false;
 };
 
index e83f22106dc821d8b0248815c62bdb95fd7d7699..9bfcfadeb11147558389702f10ecbff709b76251 100644 (file)
@@ -59,13 +59,7 @@ int Complication::Impl::LoadCurProviderFromPrev() {
   string prev_provider_id;
   unique_ptr<Bundle> setting_data;
 
-  try {
-    setting_data = EditablesManager::GetInst(mock_).LoadSetting(complication_id_);
-  } catch (watchface_complication::Exception &ex) {
-    LOGE("%s %d", ex.what(), ex.GetErrorCode());
-    return ex.GetErrorCode();
-  }
-
+  setting_data = editables_manager_.LoadSetting(complication_id_);
   if (setting_data == nullptr) {
     LOGW("no prev setting info");
     return WATCHFACE_COMPLICATION_ERROR_PROVIDER_NOT_AVAILABLE;
@@ -135,6 +129,7 @@ Complication::Impl::Impl(Complication* parent, int id,
     cur_type_(default_type),
     gdbus_(std::unique_ptr<IGDBus>(ComplicationConnector::GetInst(mock).CreateGDBus(mock))),
     package_(std::unique_ptr<IPackageManager>(ComplicationConnector::GetInst(mock).CreatePackageManager(mock))),
+    editables_manager_(EditablesManager::GetInst(mock)),
     mock_(mock) {
   for (auto& i : complication_id_list_) {
     if (i == complication_id_) {
@@ -271,15 +266,10 @@ int Complication::Impl::StoreSetting(int comp_id, std::string& provider_id,
   Bundle setting_data;
   setting_data.Add(provider_id_key_, provider_id);
   setting_data.Add(provider_type_key_, to_string(type));
-  try {
-    int ret = EditablesManager::GetInst(mock_).StoreSetting(
-        comp_id, setting_data.ToRaw().first.get());
-    if (ret != WATCHFACE_COMPLICATION_ERROR_NONE)
-      return ret;
-  } catch (Exception &ex) {
-    LOGE("%s %d", ex.what(), ex.GetErrorCode());
-    return ex.GetErrorCode();
-  }
+  int ret = editables_manager_.StoreSetting(comp_id,
+      setting_data.ToRaw().first.get());
+  if (ret != WATCHFACE_COMPLICATION_ERROR_NONE)
+    return ret;
   return WATCHFACE_COMPLICATION_ERROR_NONE;
 }
 
@@ -355,7 +345,7 @@ int Complication::Impl::DeleteAppContext(const char* appid) {
   int ret = WATCHFACE_COMPLICATION_ERROR_NONE;
   std::list<std::string> list = DBManager::GetProviderListWithAppId(appid);
   for (std::string& info : list) {
-    ret = EditablesManager::GetInst(mock_).DeleteContext(editable_id_, info.c_str());
+    ret = editables_manager_.DeleteContext(editable_id_, info.c_str());
     if (ret != WATCHFACE_COMPLICATION_ERROR_NONE) {
       LOGE("delete editable context fail %d", ret);
       return ret;
@@ -761,18 +751,16 @@ int Complication::UpdateLastContext() {
     return WATCHFACE_COMPLICATION_ERROR_NONE;
   }
 
-  try {
-    int ret = EditablesManager::GetInst(impl_->mock_).StoreContext(
-        impl_->complication_id_, impl_->cur_provider_id_.c_str(),
-        impl_->context_data_.get());
-    if (ret != WATCHFACE_COMPLICATION_ERROR_NONE)
-      return ret;
-    impl_->last_context_data_.reset(
-        new Bundle((impl_->context_data_.get())->GetHandle()));
-  } catch (Exception &ex) {
-    LOGE("%s %d", ex.what(), ex.GetErrorCode());
-    return ex.GetErrorCode();
-  }
+  int ret = impl_->editables_manager_.StoreContext(
+      impl_->complication_id_, impl_->cur_provider_id_.c_str(),
+      impl_->context_data_.get());
+  if (ret != WATCHFACE_COMPLICATION_ERROR_NONE)
+    return ret;
+  Bundle* new_ctx = new (std::nothrow) Bundle(
+      (impl_->context_data_.get())->GetHandle());
+  if (new_ctx == nullptr)
+    return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY;
+  impl_->last_context_data_.reset(new_ctx);
 
   return WATCHFACE_COMPLICATION_ERROR_NONE;
 }
@@ -959,15 +947,16 @@ int Complication::Impl::MakeCandidatesList() {
 }
 
 int Complication::Impl::LoadContext() {
-  context_data_ = EditablesManager::GetInst(mock_).LoadContext(complication_id_,
+  context_data_ = editables_manager_.LoadContext(complication_id_,
       cur_provider_id_.c_str());
-  try {
-    if (context_data_ != nullptr)
-      last_context_data_.reset(new Bundle(context_data_.get()->GetHandle()));
-  } catch (...) {
+  if (context_data_ == nullptr)
+    return WATCHFACE_COMPLICATION_ERROR_NONE;
+  Bundle* ctx = new (std::nothrow) Bundle(context_data_.get()->GetHandle());
+  if (ctx == nullptr) {
     LOGE("Out of memory");
     return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY;
   }
+  last_context_data_.reset(ctx);
   return WATCHFACE_COMPLICATION_ERROR_NONE;
 }
 
index 1b532c3aa89cfacb6b2217610f8900b50c0f31e5..b160ad637582a28a5b80ce16051d7c85277f0dc1 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "watchface-complication/design-element.h"
 #include "watchface-complication/complication-connector.h"
+#include "watchface-complication/editables-manager.h"
 
 namespace watchface_complication {
 
@@ -53,6 +54,7 @@ class DesignElement::Impl {
   IEditable::EditableState ed_state_ = Complete;
   std::unique_ptr<tizen_base::Bundle> context_data_;
   std::unique_ptr<tizen_base::Bundle> last_context_data_ = nullptr;
+  EditablesManager& editables_manager_;
   bool mock_;
 };
 
index f7f57f34e514be101a223e9cadbe5da47e7a2d23..a1d30f9a7bfe889ae85b18a18a7902b16755be8e 100644 (file)
@@ -45,7 +45,8 @@ DesignElement::~DesignElement() {
 
 DesignElement::Impl::Impl(DesignElement* parent, int id,
                           int cur_data_idx, bool mock)
-  : parent_(parent), id_(id), cur_data_idx_(cur_data_idx), mock_(mock) {
+  : parent_(parent), id_(id), cur_data_idx_(cur_data_idx),
+    editables_manager_(EditablesManager::GetInst(mock)), mock_(mock) {
   last_data_idx_ = cur_data_idx_;
 }
 
@@ -110,15 +111,11 @@ int DesignElement::UpdateLastData() {
   shared_ptr<Bundle> cur_data = GetCurData();
   if (cur_data.get() == nullptr)
     return WATCHFACE_COMPLICATION_ERROR_NO_DATA;
-  try {
-    int ret = EditablesManager::GetInst(impl_->mock_)
-        .StoreSetting(impl_->id_, cur_data->ToRaw().first.get());
-    if (ret != WATCHFACE_COMPLICATION_ERROR_NONE)
-      return ret;
-  } catch (Exception &ex) {
-    LOGE("%s %d", ex.what(), ex.GetErrorCode());
-    return ex.GetErrorCode();
-  }
+
+  int ret = impl_->editables_manager_.StoreSetting(
+      impl_->id_, cur_data->ToRaw().first.get());
+  if (ret != WATCHFACE_COMPLICATION_ERROR_NONE)
+    return ret;
 
   impl_->last_data_idx_ = impl_->cur_data_idx_;
   return WATCHFACE_COMPLICATION_ERROR_NONE;