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>
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;
}
"__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",
"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",
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)
"__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",
"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",
}
+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;
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);
}
/*
- * 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.
* 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 {
} // namespace watchface_complication
-#endif // WATCHFACE_COMPLICATION_SHARED_HANDLE_H_
+#endif // WATCHFACE_COMMON_SHARED_HANDLE_H_
\ No newline at end of file
case ProviderReady :
ret = "__PROVIDER_READY__";
break;
+ case EditResult :
+ ret = "__EDIT_RESULT__";
+ break;
default :
break;
}
EditableEditCancel,
EditableEditReady,
SetupReply,
+ EditResult,
ProviderReady
};
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
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;
};
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);
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(
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) {
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);
}
}
}
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_,
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) {
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;
* @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
}
#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"
#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"
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) {
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;
}
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) {
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) {
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;
}
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;
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;
}
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;
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;
+}
+
+
#define WATCHFACE_EDITOR_EDITABLES_EDITOR_EVENT_INTERFACE_H_
#include <string>
+#include <memory>
#include "watchface-complication/complication.h"
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;
};
#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 {
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
#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"
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;
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");
}
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;
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());
}
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;
}
}
- 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() {
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;
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;
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
}
* @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.
#include <dlog.h>
#include <app_control.h>
#include <aul.h>
+#include <iostream>
#include <string>
#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
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() {
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());
}
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));
}
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;
}
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() {
int ret = __init_stub();
if (ret != WATCHFACE_COMPLICATION_ERROR_NONE)
return ret;
- __stub->ClearEditableList();
return __stub->NotifyEditReady(std::string(appid));
}
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;
return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
}
- g_list_free(list);
+ g_list_free_full(list, _delete_shared_editable);
return WATCHFACE_COMPLICATION_ERROR_NONE;
}
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;
}
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();
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;
}
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));
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;
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, };