Add APIs to send/receive edit done 76/224676/14
authorhyunho <hhstark.kang@samsung.com>
Wed, 12 Feb 2020 07:54:53 +0000 (16:54 +0900)
committerHyunho Kang <hhstark.kang@samsung.com>
Wed, 19 Feb 2020 00:51:39 +0000 (00:51 +0000)
int watchface_editor_edit_preview_with_result(const watchface_editable_h handle,
        int cur_data_idx, watchface_editor_edit_result_cb result_cb,
int timeout, bool auto, void *user_data);

typedef void (*watchface_editor_edit_result_cb)(const watchface_editable_h handle,
        watchface_complication_error_e result, void *user_data);

int watchface_editable_edit_done(watchface_editable_h handle);
int watchface_editable_dup(const watchface_editable_h handle,
watchface_editable_h *dup_handle);
int watchface_editable_destroy(watchface_editable_h handle);

Change-Id: I5be804d33b9f38c28dc6fb11002d794d8ba2ea65
Signed-off-by: hyunho <hhstark.kang@samsung.com>
20 files changed:
unittest/src/test-editables-container.cc
unittest/src/test-editor.cc
unittest/src/test-watchface-editable.cc
unittest/src/test-watchface-editor.cc
watchface-common/shared-handle.h [moved from watchface-complication/shared-handle.h with 86% similarity]
watchface-common/watchface-util.cc
watchface-common/watchface-util.h
watchface-complication/editable-interface.h
watchface-complication/editables-container-event-interface.h
watchface-complication/editables-container.cc
watchface-complication/editables-container.h
watchface-complication/include/watchface-editable-internal.h
watchface-complication/watchface-complication.cc
watchface-complication/watchface-editable.cc
watchface-editor/editables-editor-event-interface.h
watchface-editor/editables-editor-implementation.h
watchface-editor/editables-editor.cc
watchface-editor/editables-editor.h
watchface-editor/include/watchface-editor.h
watchface-editor/watchface-editor.cc

index 1e38c89..c80189a 100644 (file)
@@ -67,7 +67,7 @@ class MyContainer : public EditablesContainer {
   MyContainer() : EditablesContainer() {
   }
 
-  void OnUpdate(const IEditable& ed, int selected_idx,
+  void OnUpdate(std::shared_ptr<IEditable> ed, int selected_idx,
       IEditable::EditableState state) override {
     is_updated_ = true;
   }
@@ -190,7 +190,7 @@ guint __fake_signal_subscribe_on_update(GDBusConnection* connection,
                         "__EDITABLE_EDIT_READY__",
                         parameters);
 
-    parameters = g_variant_new("(iis)", 0, 0, b.ToRaw().first.get());
+    parameters = g_variant_new("(iisii)", 0, 0, b.ToRaw().first.get(), 0, 0);
     rs->OnSignal(nullptr, "org.tizen.editor",
                         "test path",
                         "test interface",
@@ -201,7 +201,7 @@ guint __fake_signal_subscribe_on_update(GDBusConnection* connection,
                         "test interface",
                         "__EDITABLE_EDIT_CANCEL__",
                         parameters);
-    parameters = g_variant_new("(iis)", 0, 0, b.ToRaw().first.get());
+    parameters = g_variant_new("(iisii)", 0, 0, b.ToRaw().first.get(), 0, 0);
     rs->OnSignal(nullptr, "org.tizen.editor",
                         "test path",
                         "test interface",
index 9f60f5f..d467afc 100644 (file)
@@ -101,10 +101,8 @@ TEST_F(WE, EditPreview)
       reinterpret_cast<char*>(candidate2.ToRaw().first.get()));
   data.Add("CANDIDATES_LIST", candidates_list);
 
-  received = new ReceivedEditable(
-      reinterpret_cast<char*>(data.ToRaw().first.get()));
-  IEditable* ed = static_cast<IEditable*>(received);
-  EXPECT_EQ(WE::editor->EditPreview(*ed, cur_data_idx), WATCHFACE_COMPLICATION_ERROR_EDIT_NOT_READY);
+  EXPECT_EQ(WE::editor->EditPreview(shared_ptr<IEditable>(new ReceivedEditable(
+      reinterpret_cast<char*>(data.ToRaw().first.get()))), cur_data_idx, 0, false), WATCHFACE_COMPLICATION_ERROR_EDIT_NOT_READY);
 }
 
 TEST_F(WE, NotifyEditReady)
index aa6330c..889dc34 100644 (file)
@@ -67,7 +67,7 @@ guint __fake_signal_subscribe_on_update(GDBusConnection* connection,
                         "__EDITABLE_EDIT_READY__",
                         parameters);
 
-    parameters = g_variant_new("(iis)", 0, 0, b.ToRaw().first.get());
+    parameters = g_variant_new("(iisii)", 0, 0, b.ToRaw().first.get(), 0, 0);
     rs->OnSignal(nullptr, "org.tizen.editor",
                         "test path",
                         "test interface",
@@ -78,7 +78,7 @@ guint __fake_signal_subscribe_on_update(GDBusConnection* connection,
                         "test interface",
                         "__EDITABLE_EDIT_CANCEL__",
                         parameters);
-    parameters = g_variant_new("(iis)", 0, 0, b.ToRaw().first.get());
+    parameters = g_variant_new("(iisii)", 0, 0, b.ToRaw().first.get(), 0, 0);
     rs->OnSignal(nullptr, "org.tizen.editor",
                         "test path",
                         "test interface",
index ab3a042..d28adf1 100644 (file)
@@ -164,6 +164,10 @@ void _setup_result_cb(int editable_id,
 
 }
 
+void _edit_result_cb(const watchface_editable_h handle,
+        watchface_complication_error_e result, void *user_data) {
+}
+
 void _editor_request_edit_cb(const char* appid,
       editable_list_h list, void* user_data) {
   int size;
@@ -229,10 +233,10 @@ void _editor_request_edit_cb(const char* appid,
     watchface_editor_set_context(handle, c_context);
     bundle_free(c_context);
     watchface_editor_edit_preview(handle, 0);
+    watchface_editor_edit_preview_with_result(handle, 0, _edit_result_cb, 0, true, nullptr);
   }
   watchface_editor_edit_cancel();
   watchface_editor_edit_complete();
-
   watchface_editor_editable_list_destroy(dup_list);
 }
 
similarity index 86%
rename from watchface-complication/shared-handle.h
rename to watchface-common/shared-handle.h
index ff681b2..c8402ee 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * 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.
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef WATCHFACE_COMPLICATION_SHARED_HANDLE_H_
-#define WATCHFACE_COMPLICATION_SHARED_HANDLE_H_
+#ifndef WATCHFACE_COMMON_SHARED_HANDLE_H_
+#define WATCHFACE_COMMON_SHARED_HANDLE_H_
 
 namespace watchface_complication {
 
@@ -56,4 +56,4 @@ class SharedHandle {
 
 }  // namespace watchface_complication
 
-#endif  // WATCHFACE_COMPLICATION_SHARED_HANDLE_H_
+#endif  // WATCHFACE_COMMON_SHARED_HANDLE_H_
\ No newline at end of file
index ba2ea79..d1e3861 100644 (file)
@@ -375,6 +375,9 @@ out:
     case ProviderReady :
       ret = "__PROVIDER_READY__";
       break;
+    case EditResult :
+      ret = "__EDIT_RESULT__";
+      break;
     default :
       break;
     }
index 7a65414..a45c729 100644 (file)
@@ -48,6 +48,7 @@ namespace util {
     EditableEditCancel,
     EditableEditReady,
     SetupReply,
+    EditResult,
     ProviderReady
   };
 
index 861c2f2..1162567 100644 (file)
@@ -324,6 +324,16 @@ class IEditable {
   virtual std::unique_ptr<tizen_base::Bundle>& GetLastContext() const = 0;
   virtual std::shared_ptr<Highlight> GetHighlight() const = 0;
   virtual int SetHighlight(std::shared_ptr<Highlight> highlight) = 0;
+  void SetEditSequence(int seq) {
+    edit_sequence_ = seq;
+  }
+
+  int GetEditSequence() {
+    return edit_sequence_;
+  }
+
+ private:
+  int edit_sequence_ = 0;
 };
 
 }  // namespace watchface_complication
index 9f12837..779f1f4 100644 (file)
@@ -28,8 +28,9 @@ namespace watchface_complication {
 
 class EXPORT_API IEditablesContainerEvent {
  public:
+  virtual void OnEditResult(std::shared_ptr<IEditable> editable, int result) = 0;
   virtual void OnRequestEdit(const std::string& appid,
-                             std::list<std::unique_ptr<IEditable>> e_list) = 0;
+                             std::list<std::shared_ptr<IEditable>> e_list) = 0;
   virtual void OnSetupReply(const std::string& appid, int editable_id,
                              std::unique_ptr<tizen_base::Bundle> context) = 0;
 };
index 8c59efd..6a6cee7 100644 (file)
@@ -97,13 +97,16 @@ void EditablesContainer::Impl::OnSignal(GDBusConnection* connection,
     int editable_id;
     int selected_idx;
     char* context = nullptr;
+    int edit_seq;
+    int auto_reply;
 
     if (sender_name_.compare(sender_name) != 0) {
       LOGE("invalid sender_name %s", sender_name.c_str());
       return;
     }
 
-    g_variant_get(parameters, "(iis)", &selected_idx, &editable_id, &context);
+    g_variant_get(parameters, "(iisii)",
+        &selected_idx, &editable_id, &context, &edit_seq, &auto_reply);
     LOGI("preview selected_idx, editable_id, state: %d, %d", selected_idx,
         editable_id);
 
@@ -126,7 +129,12 @@ void EditablesContainer::Impl::OnSignal(GDBusConnection* connection,
           i.get()->SetContext(move(ctx_ptr));
 
         i.get()->OnEditableUpdated(i.get()->GetCurDataIdx(), IEditable::OnGoing);
-        parent_->OnUpdate(*i.get(), i.get()->GetCurDataIdx(), IEditable::OnGoing);
+        i.get()->SetEditSequence(edit_seq);
+        parent_->OnUpdate(i, i.get()->GetCurDataIdx(), IEditable::OnGoing);
+        if (auto_reply) {
+          parent_->SendEditResult(
+              editable_id, edit_seq, WATCHFACE_COMPLICATION_ERROR_NONE);
+        }
       }
     }
   } else if (signal_name.compare(
@@ -140,7 +148,7 @@ void EditablesContainer::Impl::OnSignal(GDBusConnection* connection,
       i.get()->UpdateLastData();
       i.get()->UpdateLastContext();
       i.get()->OnEditableUpdated(i.get()->GetCurDataIdx(), IEditable::Complete);
-      parent_->OnUpdate(*i.get(), i.get()->GetCurDataIdx(), IEditable::Complete);
+      parent_->OnUpdate(i, i.get()->GetCurDataIdx(), IEditable::Complete);
     }
   } else if (signal_name.compare(util::GetCmdStr(
           util::EditableEditCancel)) == 0) {
@@ -165,7 +173,7 @@ void EditablesContainer::Impl::CancelEditing() {
         i.get()->SetContext(std::unique_ptr<Bundle>{});
       }
       i.get()->OnEditableUpdated(i.get()->GetCurDataIdx(), IEditable::Cancel);
-      parent_->OnUpdate(*i.get(), i.get()->GetCurDataIdx(), IEditable::Cancel);
+      parent_->OnUpdate(i, i.get()->GetCurDataIdx(), IEditable::Cancel);
     }
   }
 }
@@ -233,16 +241,10 @@ int EditablesContainer::RequestEdit() {
     if (ret != BUNDLE_ERROR_NONE)
       return WATCHFACE_COMPLICATION_ERROR_IO_ERROR;
 
-    bool emit_ret = impl_->gdbus_.get()->EmitSignal(
-      IGDBus::SigType::Editable,
-      impl_->editor_id_,
-      impl_->editor_id_,
-      -1,
-      util::GetCmdStr(util::EditableEditRequest),
-      g_variant_new("(ss)",
-          util::GetAppId().c_str(), container.ToRaw().first.get()));
-
-    if (!emit_ret)
+    if (!SendEventToEditor(
+            util::GetCmdStr(util::EditableEditRequest),
+            g_variant_new("(ss)",
+                util::GetAppId().c_str(), container.ToRaw().first.get())))
       return WATCHFACE_COMPLICATION_ERROR_IO_ERROR;
 
     impl_->watcher_id_ = impl_->gdbus_.get()->Watch(impl_->editor_id_,
@@ -255,8 +257,26 @@ int EditablesContainer::RequestEdit() {
   return WATCHFACE_COMPLICATION_ERROR_NONE;
 }
 
+bool EditablesContainer::SendEventToEditor(string cmd, GVariant* data) {
+  return impl_->gdbus_.get()->EmitSignal(
+      IGDBus::SigType::Editable,
+      impl_->editor_id_,
+      impl_->editor_id_,
+      -1,
+      cmd,
+      data);
+}
+
+bool EditablesContainer::SendEditResult(
+    int editable_id, int edit_seq, int result) {
+  return SendEventToEditor(
+    util::GetCmdStr(util::EditResult),
+    g_variant_new("(iii)", editable_id, edit_seq, result)
+  );
+}
+
 /* LCOV_EXCL_START */
-void EditablesContainer::OnUpdate(const IEditable& ed, int selected_idx,
+void EditablesContainer::OnUpdate(std::shared_ptr<IEditable> ed, int selected_idx,
                                         IEditable::EditableState state) {
 }
 void EditablesContainer::OnEditReady(const std::string& editor_id) {
index f3afa3c..bb0b1a8 100644 (file)
@@ -34,10 +34,14 @@ class EXPORT_API EditablesContainer : IEditablesEditorEvent {
   int Add(std::shared_ptr<IEditable> ed, int editable_id);
   int Remove(std::shared_ptr<IEditable> ed);
   int RequestEdit();
-  void OnUpdate(const IEditable& ed, int selected_idx,
+  void OnUpdate(std::shared_ptr<IEditable> ed, int selected_idx,
       IEditable::EditableState state) override;
   void OnEditReady(const std::string& editor_id) override;
   bool IsExist(int editable_id);
+  bool SendEditResult(int editable_id, int edit_seq, int result);
+
+ private:
+  bool SendEventToEditor(std::string cmd, GVariant* data);
 
  private:
   class Impl;
index defaae6..45846d2 100644 (file)
@@ -66,6 +66,10 @@ int watchface_editable_highlight_get_normalized_geometry(
  * @endcode
  */
 int watchface_editable_container_get(watchface_editable_container_h *container);
+int watchface_editable_edit_done(watchface_editable_h handle);
+int watchface_editable_dup(const watchface_editable_h handle,
+    watchface_editable_h *dup_handle);
+int watchface_editable_destroy(watchface_editable_h handle);
 
 #ifdef __cplusplus
 }
index eeb3f7e..83ae20e 100644 (file)
@@ -30,7 +30,7 @@
 #include "watchface-complication/include/watchface-complication-internal.h"
 #include "watchface-complication/complication-internal.h"
 #include "watchface-complication/complication.h"
-#include "watchface-complication/shared-handle.h"
+#include "watchface-common/shared-handle.h"
 #include "watchface-common/watchface-util.h"
 #include "watchface-common/watchface-common-internal.h"
 
index ca9d4e4..a5ef650 100644 (file)
@@ -24,7 +24,7 @@
 #include "watchface-complication/include/watchface-editable-internal.h"
 #include "watchface-complication/editables-container.h"
 #include "watchface-complication/design-element.h"
-#include "watchface-complication/shared-handle.h"
+#include "watchface-common/shared-handle.h"
 #include "watchface-complication/editables-manager.h"
 #include "watchface-common/watchface-util.h"
 #include "watchface-common/watchface-exception.h"
@@ -119,12 +119,14 @@ class EditablesContainerStub : public EditablesContainer {
     LOGI("On edit call!! ready !!");
   }
 
-  void OnUpdate(const IEditable& ed, int selected_idx,
+  void OnUpdate(shared_ptr<IEditable> ed, int selected_idx,
                 IEditable::EditableState state) override {
+    SharedHandle<IEditable>* ptr = SharedHandle<IEditable>::Make(ed);
     for (auto& i : update_cb_list_) {
-      i->Invoke(static_cast<const void*>(&ed), selected_idx,
+      i->Invoke(static_cast<const void*>(ptr), selected_idx,
                 static_cast<const watchface_editable_edit_state_e>(state));
     }
+    delete ptr;
   }
 
   int AddReadyCallbackInfo(unique_ptr<ReadyCallbackInfo> ci) {
@@ -346,8 +348,8 @@ extern "C" EXPORT_API int watchface_editable_get_current_data_idx(
   if (handle == nullptr || idx == nullptr)
     return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
 
-  IEditable* ie = static_cast<IEditable*>(handle);
-  *idx = ie->GetCurDataIdx();
+  SharedHandle<IEditable>* ie = static_cast<SharedHandle<IEditable>*>(handle);
+  *idx = ie->GetPtr()->GetCurDataIdx();
   return WATCHFACE_COMPLICATION_ERROR_NONE;
 }
 
@@ -359,8 +361,8 @@ extern "C" EXPORT_API int watchface_editable_get_current_data(
   if (handle == nullptr || cur_data == nullptr)
     return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
 
-  IEditable* ie = static_cast<IEditable*>(handle);
-  shared_ptr<Bundle> data = ie->GetCurData();
+  SharedHandle<IEditable>* ie = static_cast<SharedHandle<IEditable>*>(handle);
+  shared_ptr<Bundle> data = ie->GetPtr()->GetCurData();
   if (data.get() == nullptr)
     return WATCHFACE_COMPLICATION_ERROR_NO_DATA;
   if (data->GetHandle() != nullptr) {
@@ -381,8 +383,8 @@ extern "C" EXPORT_API int watchface_editable_get_nth_data(
   if (handle == nullptr || nth_data == nullptr)
     return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
 
-  IEditable* ie = static_cast<IEditable*>(handle);
-  shared_ptr<Bundle> data = ie->GetNthData(nth);
+  SharedHandle<IEditable>* ie = static_cast<SharedHandle<IEditable>*>(handle);
+  shared_ptr<Bundle> data = ie->GetPtr()->GetNthData(nth);
   if (data.get() == nullptr)
     return WATCHFACE_COMPLICATION_ERROR_NO_DATA;
   if (data->GetHandle() != nullptr) {
@@ -403,8 +405,8 @@ extern "C" EXPORT_API int watchface_editable_get_editable_id(
   if (handle == nullptr || editable_id == nullptr)
     return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
 
-  IEditable* ie = static_cast<IEditable*>(handle);
-  *editable_id = ie->GetEditableId();
+  SharedHandle<IEditable>* ie = static_cast<SharedHandle<IEditable>*>(handle);
+  *editable_id = ie->GetPtr()->GetEditableId();
 
   return WATCHFACE_COMPLICATION_ERROR_NONE;
 }
@@ -417,9 +419,9 @@ extern "C" EXPORT_API int watchface_editable_get_editable_name(
   if (handle == nullptr || editable_name == nullptr)
     return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
 
-  IEditable* ie = static_cast<IEditable*>(handle);
-  if (!ie->GetLabel().empty()) {
-    *editable_name = strdup(ie->GetLabel().c_str());
+  SharedHandle<IEditable>* ie = static_cast<SharedHandle<IEditable>*>(handle);
+  if (!ie->GetPtr()->GetLabel().empty()) {
+    *editable_name = strdup(ie->GetPtr()->GetLabel().c_str());
     if (*editable_name == nullptr) {
       LOGE("Out of memory");
       return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY;
@@ -438,8 +440,8 @@ extern "C" EXPORT_API int watchface_editable_set_editable_name(
   if (handle == nullptr || editable_name == nullptr)
     return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
 
-  IEditable* ie = static_cast<IEditable*>(handle);
-  ie->SetLabel(std::string(editable_name));
+  SharedHandle<IEditable>* ie = static_cast<SharedHandle<IEditable>*>(handle);
+  ie->GetPtr()->SetLabel(std::string(editable_name));
   return WATCHFACE_COMPLICATION_ERROR_NONE;
 }
 
@@ -889,8 +891,8 @@ extern "C" EXPORT_API int watchface_editable_get_highlight(
     return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
   }
 
-  IEditable* ie = static_cast<IEditable*>(handle);
-  shared_ptr<IEditable::Highlight> info = ie->GetHighlight();
+  SharedHandle<IEditable>* ie = static_cast<SharedHandle<IEditable>*>(handle);
+  shared_ptr<IEditable::Highlight> info = ie->GetPtr()->GetHighlight();
   if (info == nullptr) {
     LOGE("editor do not have highlight data");
     return WATCHFACE_COMPLICATION_ERROR_NO_DATA;
@@ -900,3 +902,54 @@ extern "C" EXPORT_API int watchface_editable_get_highlight(
 
   return WATCHFACE_COMPLICATION_ERROR_NONE;
 }
+
+extern "C" EXPORT_API int watchface_editable_edit_done(
+    watchface_editable_h handle) {
+  if (!watchface_complication::util::CheckWatchFeatureEnabled())
+    return WATCHFACE_COMPLICATION_ERROR_NOT_SUPPORTED;
+
+  if (handle == nullptr) {
+    LOGE("Invalid param");
+    return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
+  }
+
+  SharedHandle<IEditable>* ie = static_cast<SharedHandle<IEditable>*>(handle);
+  shared_ptr<IEditable> ptr = ie->GetPtr();
+  if (!__container->SendEditResult(
+          ptr->GetEditableId(), ptr->GetEditSequence(),
+          WATCHFACE_COMPLICATION_ERROR_NONE)) {
+    LOGE("Fail to send edit result");
+    return WATCHFACE_COMPLICATION_ERROR_IO_ERROR;
+  }
+
+  return WATCHFACE_COMPLICATION_ERROR_NONE;
+}
+
+extern "C" EXPORT_API int watchface_editable_dup(
+    const watchface_editable_h handle, watchface_editable_h *dup_handle) {
+  if (!watchface_complication::util::CheckWatchFeatureEnabled())
+    return WATCHFACE_COMPLICATION_ERROR_NOT_SUPPORTED;
+
+  if (handle == nullptr || dup_handle == nullptr) {
+    LOGE("Invalid param");
+    return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
+  }
+  SharedHandle<IEditable>* ie = static_cast<SharedHandle<IEditable>*>(handle);
+  *dup_handle = SharedHandle<IEditable>::Make(ie->GetPtr());
+  return WATCHFACE_COMPLICATION_ERROR_NONE;
+}
+
+extern "C" EXPORT_API int watchface_editable_destroy(watchface_editable_h handle) {
+  if (!watchface_complication::util::CheckWatchFeatureEnabled())
+    return WATCHFACE_COMPLICATION_ERROR_NOT_SUPPORTED;
+
+  if (handle == nullptr) {
+    LOGE("Invalid param");
+    return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
+  }
+  SharedHandle<IEditable>* ie = static_cast<SharedHandle<IEditable>*>(handle);
+  delete ie;
+  return WATCHFACE_COMPLICATION_ERROR_NONE;
+}
+
+
index 5b545b8..1e826d0 100644 (file)
@@ -18,6 +18,7 @@
 #define WATCHFACE_EDITOR_EDITABLES_EDITOR_EVENT_INTERFACE_H_
 
 #include <string>
+#include <memory>
 
 #include "watchface-complication/complication.h"
 
@@ -26,7 +27,7 @@ namespace watchface_complication {
 class EXPORT_API IEditablesEditorEvent {
  public:
   virtual void OnEditReady(const std::string& editor_id) = 0;
-  virtual void OnUpdate(const IEditable& ed, int selected_idx,
+  virtual void OnUpdate(std::shared_ptr<IEditable> ed, int selected_idx,
       IEditable::EditableState state) = 0;
 };
 
index 13cf066..08055be 100644 (file)
@@ -27,6 +27,7 @@
 #include "watchface-complication/complication-connector.h"
 #include "watchface-complication/gdbus-interface.h"
 #include "watchface-common/watchface-util.h"
+#include "watchface-common/shared-handle.h"
 
 namespace watchface_complication {
 
@@ -57,6 +58,9 @@ class EditablesEditor::Impl : IGDBus::IGDBusEvent {
   int subscribe_id_;
   std::string edit_appid_;
   std::unique_ptr<IGDBus> gdbus_;
+  std::list<std::shared_ptr<IEditable>> editable_list_;
+  std::list<SharedHandle<EditablesEditor::EditInfo>*> edit_info_list_;
+  int edit_sequence_ = 0;
 };
 
 }  // namespace watchface_complication
index 21d325c..7ea4e80 100644 (file)
@@ -24,6 +24,7 @@
 #include "watchface-editor/editables-editor-implementation.h"
 #include "watchface-complication/received-editable.h"
 #include "watchface-common/watchface-util.h"
+#include "watchface-common/shared-handle.h"
 
 #include "watchface-complication/gdbus-interface.h"
 
@@ -73,7 +74,7 @@ void EditablesEditor::Impl::OnSignal(GDBusConnection* connection,
                                      GVariant* parameters) {
   char* appid = NULL;
   bundle_raw* raw = NULL;
-  std::list<std::unique_ptr<IEditable>> e_list;
+  std::list<std::shared_ptr<IEditable>> e_list;
   std::string sender_appid = util::GetSenderAppid(connection, sender_name);
   if (sender_appid.empty())
     return;
@@ -95,7 +96,7 @@ void EditablesEditor::Impl::OnSignal(GDBusConnection* connection,
       Bundle data(reinterpret_cast<char*>(raw));
       vector<string> raw_arr = data.GetStringArray("EDITABLE_LIST");
       for (auto& i : raw_arr) {
-        std::unique_ptr<IEditable> received = std::unique_ptr<IEditable>(
+        std::shared_ptr<IEditable> received = std::shared_ptr<IEditable>(
             new ReceivedEditable(i));
         if (received.get() == nullptr) {
           LOGE("Out of memory");
@@ -103,7 +104,8 @@ void EditablesEditor::Impl::OnSignal(GDBusConnection* connection,
         }
         e_list.emplace_back(move(received));
       }
-      parent_->OnRequestEdit(std::string(appid), std::move(e_list));
+      editable_list_ = e_list;
+      parent_->OnRequestEdit(std::string(appid), editable_list_);
     } else if (signal_name.compare(
         util::GetCmdStr(util::CmdType::SetupReply)) == 0) {
       int edit_id;
@@ -112,6 +114,16 @@ void EditablesEditor::Impl::OnSignal(GDBusConnection* connection,
       unique_ptr<Bundle> reply_data =
           unique_ptr<Bundle>(new Bundle(std::string(raw_str)));
       parent_->OnSetupReply(sender_appid, edit_id, move(reply_data));
+    } else if (signal_name.compare(
+        util::GetCmdStr(util::CmdType::EditResult)) == 0) {
+      int edit_id, edit_seq, result;
+      g_variant_get(parameters, "(iii)", &edit_id, &edit_seq, &result);
+      LOGI("edit result : id(%d), seq(%d), res(%d)", edit_id, edit_seq, result);
+      shared_ptr<EditablesEditor::EditInfo> ptr = parent_->FindEditInfo(edit_id, edit_seq);
+      if (ptr != nullptr) {
+        ptr->GetEditor()->OnEditResult(ptr->GetEditable(), result);
+        parent_->RemoveEditInfo(*ptr->GetEditable().get());
+      }
     }
   } catch (const std::bad_alloc &e) {
     LOGE("Exception (%s)", e.what());
@@ -125,23 +137,25 @@ void EditablesEditor::OnSetupReply(const std::string& appid,
 }
 
 void EditablesEditor::OnRequestEdit(const std::string& appid,
-                            std::list<std::unique_ptr<IEditable>> e_list) {
+                            std::list<std::shared_ptr<IEditable>> e_list) {
+}
+
+void EditablesEditor::OnEditResult(shared_ptr<IEditable> editable, int result) {
 }
 /* LCOV_EXCL_STOP */
 
-int EditablesEditor::EditPreview(IEditable& ed, int cur_data_idx) {
-  bool emit_result;
-  int ret;
+int EditablesEditor::EditPreview(shared_ptr<IEditable> ed, int cur_data_idx,
+      int reply_timeout, bool auto_reply) {
   if (impl_->edit_appid_.empty()) {
     LOGE("Editing is not ready");
     return WATCHFACE_COMPLICATION_ERROR_EDIT_NOT_READY;
   }
 
-  ret = impl_->CheckPrivilege();
+  int ret = impl_->CheckPrivilege();
   if (ret != WATCHFACE_COMPLICATION_ERROR_NONE)
     return ret;
 
-  ReceivedEditable& re = static_cast<ReceivedEditable&>(ed);
+  ReceivedEditable& re = static_cast<ReceivedEditable&>(*ed.get());
   ret = re.SetCurDataIdx(cur_data_idx);
   if (ret != WATCHFACE_COMPLICATION_ERROR_NONE)
     return ret;
@@ -157,18 +171,62 @@ int EditablesEditor::EditPreview(IEditable& ed, int cur_data_idx) {
     }
   }
 
-  emit_result = impl_->gdbus_.get()->EmitSignal(
-    IGDBus::Editable,
-    impl_->edit_appid_.c_str(),
-    impl_->edit_appid_.c_str(),
-    -1,
-    util::GetCmdStr(util::CmdType::EditableEditPreview),
-    g_variant_new("(iis)", cur_data_idx, ed.GetEditableId(), ctx_str.c_str()));
-
-  if (emit_result)
-    return WATCHFACE_COMPLICATION_ERROR_NONE;
-  else
+  if (!impl_->gdbus_.get()->EmitSignal(
+      IGDBus::Editable,
+      impl_->edit_appid_.c_str(),
+      impl_->edit_appid_.c_str(),
+      -1,
+      util::GetCmdStr(util::CmdType::EditableEditPreview),
+      g_variant_new("(iisii)", cur_data_idx, ed->GetEditableId(),
+          ctx_str.c_str(), ++impl_->edit_sequence_, (int)auto_reply)))
     return WATCHFACE_COMPLICATION_ERROR_IO_ERROR;
+
+  re.SetEditSequence(impl_->edit_sequence_);
+  SharedHandle<EditablesEditor::EditInfo>* info =
+      SharedHandle<EditablesEditor::EditInfo>::Make(
+          make_shared<EditablesEditor::EditInfo>(this, impl_->edit_sequence_, ed));
+
+  if (reply_timeout > 0) {
+    LOGI("Add edit timer");
+    int timer = g_timeout_add(reply_timeout, [](gpointer user_data)->gboolean {
+      SharedHandle<EditablesEditor::EditInfo>* einfo =
+          static_cast<SharedHandle<EditablesEditor::EditInfo>*>(user_data);
+      shared_ptr<EditablesEditor::EditInfo> ptr = einfo->GetPtr();
+      LOGW("Edit timeout called");
+      ptr->GetEditor()->OnEditResult(ptr->GetEditable(),
+          WATCHFACE_COMPLICATION_ERROR_IO_ERROR);
+      ptr->GetEditor()->RemoveEditInfo(*ptr->GetEditable().get());
+      return G_SOURCE_REMOVE;
+    }, reinterpret_cast<gpointer>(info));
+    info->GetPtr()->SetTimer(timer);
+  }
+  impl_->edit_info_list_.push_back(info);
+  return WATCHFACE_COMPLICATION_ERROR_NONE;
+}
+
+shared_ptr<EditablesEditor::EditInfo> EditablesEditor::FindEditInfo(int edit_id, int edit_seq) {
+  for (SharedHandle<EditablesEditor::EditInfo>* i : impl_->edit_info_list_) {
+        shared_ptr<EditablesEditor::EditInfo> ptr = i->GetPtr();
+        if (ptr->GetSequence() == edit_seq &&
+            ptr->GetEditable()->GetEditableId() == edit_id)
+          return ptr;
+  }
+  return nullptr;
+}
+
+void EditablesEditor::RemoveEditInfo(IEditable& ed) {
+  std::list<SharedHandle<EditablesEditor::EditInfo>*>::iterator iter =
+      impl_->edit_info_list_.begin();
+  while (iter != impl_->edit_info_list_.end()) {
+    SharedHandle<EditablesEditor::EditInfo>* info = *iter;
+    shared_ptr<EditInfo> ptr = info->GetPtr();
+    if (ptr->GetSequence() == ed.GetEditSequence()) {
+      if (ptr->GetTimer() > 0)
+        g_source_remove(ptr->GetTimer());
+      impl_->edit_info_list_.erase(iter++);
+      delete info;
+    }
+  }
 }
 
 int EditablesEditor::EditComplete() {
@@ -226,6 +284,8 @@ int EditablesEditor::NotifyEditReady(std::string appid) {
   if (appid.empty())
     return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
 
+  impl_->editable_list_.clear();
+  impl_->edit_sequence_ = 0;
   ret = impl_->CheckPrivilege();
   if (ret != WATCHFACE_COMPLICATION_ERROR_NONE)
     return ret;
index ae28bc7..bba638e 100644 (file)
@@ -30,16 +30,83 @@ namespace watchface_complication {
 
 class EXPORT_API EditablesEditor : IEditablesContainerEvent {
  public:
+  class EditInfo {
+   public:
+    EditInfo(EditablesEditor* editor, int edit_seq, std::shared_ptr<IEditable> editable)
+        : editor_(editor), edit_seq_(edit_seq), edit_timer_(0), editable_(editable) {
+    }
+
+    EditInfo(EditInfo&& info)
+        : editor_(info.GetEditor()), edit_seq_(info.GetSequence()),
+          edit_timer_(info.GetTimer()), editable_(info.GetEditable()) {
+    }
+
+    EditInfo(const EditInfo& info)
+        : editor_(info.GetEditor()), edit_seq_(info.GetSequence()),
+          edit_timer_(info.GetTimer()), editable_(info.GetEditable()) {
+    }
+
+    EditInfo& operator = (const EditInfo& info) {
+      if (this != &info) {
+        editor_ = info.GetEditor();
+        edit_seq_ = info.GetSequence();
+        editable_ = info.GetEditable();
+        edit_timer_ = info.GetTimer();
+      }
+      return *this;
+    }
+
+    EditInfo& operator = (EditInfo&& info) noexcept {
+      if (this != &info) {
+        editor_ = info.GetEditor();
+        edit_seq_ = info.GetSequence();
+        editable_ = info.GetEditable();
+        edit_timer_ = info.GetTimer();
+      }
+      return *this;
+    }
+
+    EditablesEditor* GetEditor() const {
+      return editor_;
+    }
+
+    int GetSequence() const {
+      return edit_seq_;
+    }
+
+    int GetTimer() const {
+      return edit_timer_;
+    }
+
+    void SetTimer(int timer) {
+      edit_timer_ = timer;
+    }
+
+    std::shared_ptr<IEditable> GetEditable() const {
+      return editable_;
+    }
+
+   private:
+    EditablesEditor* editor_;
+    int edit_seq_;
+    int edit_timer_;
+    std::shared_ptr<IEditable> editable_;
+  };
+
   EditablesEditor();
   virtual ~EditablesEditor();
+  void OnEditResult(std::shared_ptr<IEditable> editable, int result) override;
   void OnRequestEdit(const std::string& appid,
-                     std::list<std::unique_ptr<IEditable>> e_list) override;
+                     std::list<std::shared_ptr<IEditable>> e_list) override;
   void OnSetupReply(const std::string& appid,
                      int editable_id, std::unique_ptr<tizen_base::Bundle> context) override;
-  int EditPreview(IEditable& ed, int cur_data_idx);
+  int EditPreview(std::shared_ptr<IEditable> ed, int cur_data_idx,
+                     int reply_timeout, bool auto_reply);
   int EditComplete();
   int EditCancel();
   int NotifyEditReady(std::string appid);
+  void RemoveEditInfo(IEditable& ed);
+  std::shared_ptr<EditInfo> FindEditInfo(int edit_id, int edit_seq);
 
  private:
   class Impl;
index fcffbff..b637b4e 100644 (file)
@@ -67,6 +67,9 @@ typedef void (*watchface_editor_setup_result_cb)(int editable_id,
 typedef void (*watchface_editor_request_edit_cb)(const char *appid,
                        editable_list_h list, void *user_data);
 
+typedef void (*watchface_editor_edit_result_cb)(const watchface_editable_h handle,
+        watchface_complication_error_e result, void *user_data);
+
 /**
  * @brief Adds the callback function to edit.
  * @since_tizen 5.0
@@ -152,7 +155,12 @@ int watchface_editor_edit_complete(void);
 }
  * @endcode
  */
-int watchface_editor_edit_preview(const watchface_editable_h handle, int cur_data_idx);
+int watchface_editor_edit_preview(const watchface_editable_h handle,
+        int cur_data_idx);
+
+int watchface_editor_edit_preview_with_result(const watchface_editable_h handle,
+        int cur_data_idx, watchface_editor_edit_result_cb result_cb,
+       int timeout, bool auto_reply, void *user_data);
 
 /**
  * @brief Cancels without making any changes in edit mode.
index 1d75d09..ab1a005 100644 (file)
@@ -20,6 +20,7 @@
 #include <dlog.h>
 #include <app_control.h>
 #include <aul.h>
+#include <iostream>
 
 #include <string>
 
@@ -27,6 +28,7 @@
 #include "watchface-complication/complication.h"
 #include "watchface-editor/editables-editor.h"
 #include "watchface-common/watchface-util.h"
+#include "watchface-common/shared-handle.h"
 
 #ifdef LOG_TAG
 #undef LOG_TAG
@@ -99,6 +101,45 @@ class SetupCallbackInfo {
   void* user_data_;
 };
 
+class EditResultCallbackInfo {
+ public:
+  EditResultCallbackInfo(watchface_editor_edit_result_cb cb,
+      int editable_id, int sequence, void* user_data)
+    : cb_(cb), editable_id_(editable_id), sequence_(sequence), user_data_(user_data) {
+  }
+
+  EditResultCallbackInfo(EditResultCallbackInfo&& info) noexcept {
+    cb_ = info.cb_;
+    editable_id_ = info.editable_id_;
+    sequence_ = info.sequence_;
+    user_data_ = info.user_data_;
+  }
+
+  void Invoke(const watchface_editable_h handle, int result) {
+    cb_(handle, (watchface_complication_error_e)result, user_data_);
+  }
+
+  bool CompareInfo(int sequence, int editable_id) {
+    if (editable_id == editable_id_ && sequence == sequence_)
+      return true;
+
+    return false;
+  }
+
+ private:
+  watchface_editor_edit_result_cb cb_;
+  int editable_id_;
+  int sequence_;
+  void* user_data_;
+};
+
+static void _delete_shared_editable(gpointer data)
+{
+  SharedHandle<IEditable>* ptr = (SharedHandle<IEditable>*)data;
+  shared_ptr<IEditable> ed = ptr->GetPtr();
+  delete ptr;
+}
+
 class EditablesEditorStub : public EditablesEditor {
  public:
   EditablesEditorStub() : EditablesEditor() {
@@ -106,18 +147,16 @@ class EditablesEditorStub : public EditablesEditor {
 
   virtual ~EditablesEditorStub() = default;
   void OnRequestEdit(const std::string& appid,
-                     std::list<std::unique_ptr<IEditable>> e_list) override {
-    e_list_ = std::move(e_list);
-
-    GList* list = NULL;
-    for (auto& i : e_list_) {
+                     std::list<std::shared_ptr<IEditable>> e_list) override {
+    GList* list = nullptr;
+    for (auto& i : e_list) {
       LOGI("edit item %d", i.get()->GetEditableId());
-      list = g_list_append(list, i.get());
+      list = g_list_append(list, SharedHandle<IEditable>::Make(i));
     }
     for (auto& i : cb_list_) {
       i->Invoke(appid, list);
     }
-    g_list_free(list);
+    g_list_free_full(list, _delete_shared_editable);
     LOGI("request edit!! %s", appid.c_str());
   }
 
@@ -134,6 +173,17 @@ class EditablesEditorStub : public EditablesEditor {
     LOGE("Not exist callback info");
   }
 
+  void OnEditResult(shared_ptr<IEditable> editable, int result) override {
+    for (auto& i : edit_cb_list_) {
+      if (i.get()->CompareInfo(editable->GetEditSequence(),
+          editable->GetEditableId())) {
+        SharedHandle<IEditable>* share = SharedHandle<IEditable>::Make(editable);
+        i.get()->Invoke((void*)share, result);
+        delete share;
+      }
+    }
+  }
+
   void AddSetupCallbackInfo(unique_ptr<SetupCallbackInfo> ci) {
     setup_cb_list_.emplace_back(move(ci));
   }
@@ -169,14 +219,34 @@ class EditablesEditorStub : public EditablesEditor {
     return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
   }
 
-  void ClearEditableList() {
-    e_list_.clear();
+  int AddEditResultCallbackInfo(watchface_editor_edit_result_cb cb,
+      int editable_id, int sequence, void* user_data) {
+    for (auto& i : edit_cb_list_) {
+      if (i.get()->CompareInfo(editable_id, sequence)) {
+        LOGI("already registered callback");
+        return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
+      }
+    }
+
+    edit_cb_list_.emplace_back(unique_ptr<EditResultCallbackInfo>(
+      new EditResultCallbackInfo(cb, editable_id, sequence, user_data)));
+    return WATCHFACE_COMPLICATION_ERROR_NONE;
+  }
+
+  int RemoveEditResultCallbackInfo(int editable_id, int sequence) {
+    for (auto& i : edit_cb_list_) {
+      if (i.get()->CompareInfo(editable_id, sequence)) {
+        edit_cb_list_.remove(i);
+        return WATCHFACE_COMPLICATION_ERROR_NONE;
+      }
+    }
+    return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
   }
 
  private:
-  std::list<std::unique_ptr<IEditable>> e_list_;
   std::list<std::unique_ptr<CallbackInfo>> cb_list_;
   std::list<std::unique_ptr<SetupCallbackInfo>> setup_cb_list_;
+  std::list<std::unique_ptr<EditResultCallbackInfo>> edit_cb_list_;
 };
 
 static std::unique_ptr<EditablesEditorStub> __stub = nullptr;
@@ -222,24 +292,55 @@ extern "C" EXPORT_API int watchface_editor_remove_request_edit_cb(
 }
 
 extern "C" EXPORT_API int watchface_editor_edit_preview(
-    watchface_editable_h handle,
-    int cur_data_idx) {
+    const watchface_editable_h handle, int cur_data_idx) {
   int ret;
 
   if (!watchface_complication::util::CheckWatchFeatureEnabled())
     return WATCHFACE_COMPLICATION_ERROR_NOT_SUPPORTED;
 
-  if (handle == NULL) {
+  if (handle == nullptr) {
+    LOGE("Invalid parameter");
+    return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
+  }
+
+  SharedHandle<IEditable>* ptr = static_cast<SharedHandle<IEditable>*>(handle);
+  shared_ptr<IEditable> ed = ptr->GetPtr();
+  ret = ed->SetCurDataIdx(cur_data_idx);
+  if (ret != WATCHFACE_COMPLICATION_ERROR_NONE)
+    return ret;
+
+  __stub->EditPreview(ed, cur_data_idx, 0, true);
+
+  return WATCHFACE_COMPLICATION_ERROR_NONE;
+}
+
+
+extern "C" EXPORT_API int watchface_editor_edit_preview_with_result(
+    const watchface_editable_h handle,
+    int cur_data_idx, watchface_editor_edit_result_cb result_cb,
+    int timeout, bool auto_reply, void *user_data) {
+  int ret;
+
+  if (!watchface_complication::util::CheckWatchFeatureEnabled())
+    return WATCHFACE_COMPLICATION_ERROR_NOT_SUPPORTED;
+
+  if (handle == nullptr || result_cb == nullptr || (auto_reply && timeout <= 0)
+      || timeout < 0) {
     LOGE("Invalid parameter");
     return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
   }
 
-  IEditable* ed = static_cast<IEditable*>(handle);
+  SharedHandle<IEditable>* ptr = static_cast<SharedHandle<IEditable>*>(handle);
+  shared_ptr<IEditable> ed = ptr->GetPtr();
   ret = ed->SetCurDataIdx(cur_data_idx);
   if (ret != WATCHFACE_COMPLICATION_ERROR_NONE)
     return ret;
 
-  return __stub->EditPreview(*ed, cur_data_idx);
+  __stub->EditPreview(ed, cur_data_idx, timeout, auto_reply);
+  __stub->AddEditResultCallbackInfo(result_cb,
+      ed->GetEditableId(), ed->GetEditSequence(), user_data);
+
+  return WATCHFACE_COMPLICATION_ERROR_NONE;
 }
 
 static int __init_stub() {
@@ -289,7 +390,6 @@ extern "C" EXPORT_API int watchface_editor_notify_edit_ready(
   int ret = __init_stub();
   if (ret != WATCHFACE_COMPLICATION_ERROR_NONE)
     return ret;
-  __stub->ClearEditableList();
   return __stub->NotifyEditReady(std::string(appid));
 }
 
@@ -305,7 +405,9 @@ extern "C" EXPORT_API int watchface_editor_editable_list_dup(
 
   GList* iter = source;
   while (iter) {
-    *dest = g_list_append(*dest, iter->data);
+    SharedHandle<IEditable>* ptr =
+        static_cast<SharedHandle<IEditable>*>(iter->data);
+    *dest = g_list_append(*dest, SharedHandle<IEditable>::Make(ptr->GetPtr()));
     iter = iter->next;
   }
   return WATCHFACE_COMPLICATION_ERROR_NONE;
@@ -322,7 +424,7 @@ extern "C" EXPORT_API int watchface_editor_editable_list_destroy(
     return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
   }
 
-  g_list_free(list);
+  g_list_free_full(list, _delete_shared_editable);
   return WATCHFACE_COMPLICATION_ERROR_NONE;
 }
 
@@ -374,7 +476,8 @@ extern "C" EXPORT_API int watchface_editor_editable_candidate_list_get_size(
     return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
   }
 
-  IEditable* ed = static_cast<IEditable*>(handle);
+  SharedHandle<IEditable>* ptr = static_cast<SharedHandle<IEditable>*>(handle);
+  shared_ptr<IEditable> ed = ptr->GetPtr();
   std::list<std::shared_ptr<Bundle>> const& list = ed->GetCandidates();
   *size = list.size();
   return WATCHFACE_COMPLICATION_ERROR_NONE;
@@ -391,7 +494,8 @@ extern "C" EXPORT_API int watchface_editor_editable_candidate_list_get_nth(
   }
 
   bundle* tmp;
-  IEditable* ed = static_cast<IEditable*>(handle);
+  SharedHandle<IEditable>* ptr = static_cast<SharedHandle<IEditable>*>(handle);
+  shared_ptr<IEditable> ed = ptr->GetPtr();
   const std::list<std::shared_ptr<Bundle>>& list = ed->GetCandidates();
   const std::list<std::shared_ptr<Bundle>>::const_iterator it
                                   = list.begin();
@@ -413,7 +517,8 @@ extern "C" EXPORT_API int watchface_editor_get_setup_appid(
     return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
 
   char* tmp;
-  IEditable* ed = static_cast<IEditable*>(handle);
+  SharedHandle<IEditable>* ptr = static_cast<SharedHandle<IEditable>*>(handle);
+  shared_ptr<IEditable> ed = ptr->GetPtr();
   std::string appid = ed->GetSetupAppId();
   if (appid.empty())
     return WATCHFACE_COMPLICATION_ERROR_NO_DATA;
@@ -437,7 +542,8 @@ extern "C" EXPORT_API int watchface_editor_set_context(
   }
 
   int re = WATCHFACE_COMPLICATION_ERROR_NONE;
-  IEditable* ed = static_cast<IEditable*>(handle);
+  SharedHandle<IEditable>* ptr = static_cast<SharedHandle<IEditable>*>(handle);
+  shared_ptr<IEditable> ed = ptr->GetPtr();
   if (new_context) {
     try {
       std::unique_ptr<Bundle> b(new Bundle(new_context));
@@ -461,7 +567,8 @@ extern "C" EXPORT_API int watchface_editor_is_setup_app_exist(
     LOGE("Invalid parameter");
     return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
   }
-  IEditable* ed = static_cast<IEditable*>(handle);
+  SharedHandle<IEditable>* ptr = static_cast<SharedHandle<IEditable>*>(handle);
+  shared_ptr<IEditable> ed = ptr->GetPtr();
   std::string appid = ed->GetSetupAppId();
   if (appid.empty())
     *exist = false;
@@ -494,7 +601,8 @@ extern "C" EXPORT_API int watchface_editor_launch_setup_app(
     return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
   }
 
-  IEditable* ed = static_cast<IEditable*>(handle);
+  SharedHandle<IEditable>* share = static_cast<SharedHandle<IEditable>*>(handle);
+  shared_ptr<IEditable> ed = share->GetPtr();
   std::string appid = ed->GetSetupAppId();
   Bundle* context_data;
   char ed_id[256] = {0, };