std::string sender_name, GDBusConnection* connection, GVariant* parameters) {
auto iter = sender_info_.find(sender_name);
- SenderInfo* si;
- if (iter == sender_info_.end()) {
- char* sender_app_id = NULL;
- g_variant_get_child(parameters, 0, "&s", &sender_app_id);
- if (sender_app_id == NULL ||
- !util::CheckSender(sender_app_id, sender_name, connection)) {
- LOGE("invalid sender_app_id %s", sender_app_id);
- return NULL;
- }
+ if (iter != sender_info_.end())
+ return iter->second;
+
+ char* sender_app_id = nullptr;
+ g_variant_get_child(parameters, 0, "&s", &sender_app_id);
+ if (sender_app_id == nullptr ||
+ !util::CheckSender(sender_app_id, sender_name, connection)) {
+ LOGE("invalid sender_app_id %s", sender_app_id);
+ return nullptr;
+ }
- int watcher_id = 0;
- watcher_id = gdbus_.get()->Watch(std::string(sender_app_id), this);
- try {
- if (trusted_ && !util::CheckCertificate(sender_app_id)) {
- LOGE("Permission denied");
- return NULL;
- }
- std::string watch_name = util::EncodeStr(util::EncodeType::Name, sender_app_id);
- if (watch_name.empty()) {
- LOGE("fail to get watch name");
- return NULL;
- }
- si = new SenderInfo(sender_name, sender_app_id, watcher_id, watch_name);
- sender_info_[sender_name] = si;
- LOGI("sender_info added (%s) ", watch_name.c_str());
- } catch (const std::bad_alloc &ba) {
- LOGE("SenderInfo::Exception bad_alloc");
- return NULL;
- }
- LOGI("create new sender_info_ ");
- } else {
- si = iter->second;
+ int watcher_id = gdbus_.get()->Watch(std::string(sender_app_id), this);
+ if (trusted_ && !util::CheckCertificate(sender_app_id)) {
+ LOGE("Permission denied");
+ return nullptr;
+ }
+ std::string watch_name = util::EncodeStr(
+ util::EncodeType::Name, sender_app_id);
+ if (watch_name.empty()) {
+ LOGE("fail to get watch name");
+ return nullptr;
+ }
+ SenderInfo* si = new (std::nothrow) SenderInfo(
+ sender_name, sender_app_id, watcher_id, watch_name);
+ if (si == nullptr) {
+ LOGE("Out of memory");
+ return nullptr;
}
+ sender_info_[sender_name] = si;
+ LOGI("sender_info added (%s) ", watch_name.c_str());
return si;
}
static int _add_bundle_data(bundle* shared_data, const char* key,
const char* value);
+using namespace std;
using namespace tizen_base;
using namespace watchface_complication;
class CallbackInfo {
void* user_data) : cb_(cb), user_data_(user_data) {
}
+ CallbackInfo(CallbackInfo&& c) noexcept {
+ cb_ = c.cb_;
+ user_data_ = c.user_data_;
+ c.cb_ = nullptr;
+ c.user_data_ = nullptr;
+ }
+
+ CallbackInfo& operator = (CallbackInfo&& c) noexcept {
+ if (this != &c) {
+ cb_ = c.cb_;
+ user_data_ = c.user_data_;
+ c.cb_ = nullptr;
+ c.user_data_ = nullptr;
+ }
+ return *this;
+ }
+
void Invoke(const std::string& provider_id, const std::string& sender_appid,
ComplicationType type, const Bundle& context,
Bundle* shared_data) {
GetProviderId().c_str(), sender_appid.c_str());
}
- int AddCallbackInfo(CallbackInfo* ci) {
+ int AddCallbackInfo(unique_ptr<CallbackInfo> ci) {
for (auto& i : cb_list_) {
if (i.get()->GetCallback() == ci->GetCallback()) {
LOGI("already registered callback");
return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
}
}
- cb_list_.emplace_back(ci);
+ cb_list_.emplace_back(move(ci));
return WATCHFACE_COMPLICATION_ERROR_NONE;
}
return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
}
- int ret = WATCHFACE_COMPLICATION_ERROR_NONE;
auto cp = __providers.find(provider_id);
auto ws = cp->second;
LOGI("create new provider : %s", provider_id);
}
- auto ci = new CallbackInfo(cb, user_data);
- ret = ws->AddCallbackInfo(ci);
- if (ret != WATCHFACE_COMPLICATION_ERROR_NONE)
- delete ci;
+ auto ci = unique_ptr<CallbackInfo>(
+ new (std::nothrow) CallbackInfo(cb, user_data));
+ if (ci.get() == nullptr) {
+ LOGE("Out of memeory");
+ return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY;
+ }
- return ret;
+ return ws->AddCallbackInfo(move(ci));
}
extern "C" EXPORT_API int watchface_complication_provider_remove_update_requested_cb(
auto ws = cp->second;
if (cp == __providers.end()) {
- return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
+ LOGE("Cannot find callback");
+ return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
}
return ws->RemoveCallbackInfo(cb);
return;
}
- if (raw != NULL) {
- try {
- last_data_.reset(new Bundle(std::string(reinterpret_cast<char*>(raw))));
- LOGI("data: %s, %d, cur_type :%d",
- provider_id, complication_id, cur_type_);
- parent_->OnDataUpdated(std::string(provider_id), cur_type_, last_data_);
- } catch (Exception &ex) {
- LOGE("%s %d", ex.what(), ex.GetErrorCode());
- return;
- }
+ if (raw == nullptr) {
+ LOGW("Empty data !!");
+ return;
+ }
+
+ last_data_.reset(new (std::nothrow) Bundle(
+ string(reinterpret_cast<char*>(raw))));
+ if (last_data_.get() == nullptr) {
+ LOGE("Out of memmory, create bundle fail");
+ return;
}
+ LOGI("data: %s, %d, cur_type :%d", provider_id, complication_id, cur_type_);
+ parent_->OnDataUpdated(std::string(provider_id), cur_type_, last_data_);
}
void Complication::Impl::NotifyDataUpdateProcess(GVariant* parameters) {
}
int Complication::Impl::AddCandidate(std::string provider_id, int type) {
- bundle* data = bundle_create();
- if (data == NULL)
+ unique_ptr<Bundle> data = unique_ptr<Bundle>(new (std::nothrow) Bundle());
+ if (data.get() == nullptr) {
+ LOGE("Out of memory");
return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY;
- bundle_add_str(data, provider_id_key_.c_str(), provider_id.c_str());
- bundle_add_str(data, provider_type_key_.c_str(),
- std::to_string(type).c_str());
+ }
+ data->Add(provider_id_key_, provider_id);
+ data->Add(provider_type_key_, std::to_string(type));
std::string error_msg = GetNotSupportedPrivileges(provider_id);
if (!error_msg.empty())
- bundle_add_str(data, privilege_error_key_.c_str(), error_msg.c_str());
+ data->Add(privilege_error_key_, error_msg);
int not_supported_events = GetNotSupportedEvents(provider_id);
if (not_supported_events > 0) {
- bundle_add_str(data, supported_events_error_key_.c_str(),
- std::to_string(not_supported_events).c_str());
+ data->Add(supported_events_error_key_,
+ std::to_string(not_supported_events));
} else if (not_supported_events < 0) {
LOGE("fail to get required events");
- bundle_free(data);
return WATCHFACE_COMPLICATION_ERROR_DB;
}
-
- try {
- candidates_list_.emplace_back(new Bundle(data));
- } catch (const std::bad_alloc &ba) {
- LOGE("Bundle::Exception bad_alloc");
- bundle_free(data);
- return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY;
- } catch (Exception &ex) {
- LOGE("%s %d", ex.what(), ex.GetErrorCode());
- bundle_free(data);
- return ex.GetErrorCode();
- }
- bundle_free(data);
-
+ candidates_list_.emplace_back(move(data));
return WATCHFACE_COMPLICATION_ERROR_NONE;
}
}
int DesignElement::UpdateLastContext() {
- if (impl_->context_data_.get() == NULL) {
+ if (impl_->context_data_.get() == nullptr) {
LOGI("Empty context");
return WATCHFACE_COMPLICATION_ERROR_NONE;
}
-
- try {
- 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();
+ Bundle* ctx = new (std::nothrow) Bundle(
+ (impl_->context_data_.get())->GetHandle());
+ if (ctx == nullptr) {
+ LOGE("Out of memory");
+ return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY;
}
+ impl_->last_context_data_.reset(ctx);
return WATCHFACE_COMPLICATION_ERROR_NONE;
}
int EditablesManager::Init(bool mock) {
int ret;
int open_flags = (SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
- std::unique_ptr<Impl> tmp_impl;
-
- try {
- tmp_impl = std::unique_ptr<EditablesManager::Impl>(new Impl());
- } catch (const std::bad_alloc &ba) {
+ std::unique_ptr<Impl> tmp_impl
+ = std::unique_ptr<EditablesManager::Impl>(new (std::nothrow) Impl());
+ if (tmp_impl.get() == nullptr) {
LOGE("Out of memory");
return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY;
}
}
int ReceivedEditable::UpdateLastContext() {
- if (impl_->context_data_.get() == NULL) {
+ if (impl_->context_data_.get() == nullptr) {
LOGI("Empty context");
return WATCHFACE_COMPLICATION_ERROR_NONE;
}
- try {
- impl_->last_context_data_.reset(
- new Bundle((impl_->context_data_.get())->GetHandle()));
- } catch (const std::bad_alloc &ba) {
- LOGE("Bundle::Exception bad_alloc");
+ Bundle* ctx = new Bundle((impl_->context_data_.get())->GetHandle());
+ if (ctx == nullptr) {
+ LOGE("Out of memory");
return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY;
- } catch (Exception &ex) {
- LOGE("%s %d", ex.what(), ex.GetErrorCode());
- return ex.GetErrorCode();
}
+ impl_->last_context_data_.reset(ctx);
return WATCHFACE_COMPLICATION_ERROR_NONE;
}
GList* allowed_list;
};
+using namespace std;
using namespace tizen_base;
using namespace watchface_complication;
class CallbackInfo {
: cb_(cb), error_cb_(error_cb), user_data_(user_data) {
}
+ CallbackInfo(CallbackInfo&& c) noexcept {
+ cb_ = c.cb_;
+ error_cb_ = c.error_cb_;
+ user_data_ = c.user_data_;
+ c.cb_ = nullptr;
+ c.error_cb_ = nullptr;
+ c.user_data_ = nullptr;
+ }
+
+ CallbackInfo& operator = (CallbackInfo&& c) noexcept {
+ if (this != &c) {
+ cb_ = c.cb_;
+ error_cb_ = c.error_cb_;
+ user_data_ = c.user_data_;
+ c.cb_ = nullptr;
+ c.error_cb_ = nullptr;
+ c.user_data_ = nullptr;
+ }
+ return *this;
+ }
+
void Invoke(int complication_id,
const std::string& provider_id,
ComplicationType type, const std::unique_ptr<Bundle>& data) {
LOGI("update call!! done");
}
- int AddCallbackInfo(CallbackInfo* ci) {
+ int AddCallbackInfo(unique_ptr<CallbackInfo> ci) {
for (auto& i : cb_list_) {
if (i.get()->GetCallback() == ci->GetCallback()) {
LOGI("already registered callback");
return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
}
}
- cb_list_.emplace_back(ci);
+ cb_list_.emplace_back(move(ci));
return WATCHFACE_COMPLICATION_ERROR_NONE;
}
auto sh = static_cast<SharedHandle<WatchComplicationStub>*>(handle);
auto ptr = SharedHandle<WatchComplicationStub>::Share(sh);
-
- CallbackInfo* ci = nullptr;
- try {
- ci = new CallbackInfo(cb, error_cb, user_data);
- ret = ptr.get()->AddCallbackInfo(ci);
- if (ret != WATCHFACE_COMPLICATION_ERROR_NONE) {
- delete ci;
- return ret;
- }
- } catch (const std::bad_alloc &ba) {
- LOGE("WatchComplicationProviderStub::Exception bad_alloc");
- if (ci != nullptr)
- delete ci;
+ unique_ptr<CallbackInfo> ci = unique_ptr<CallbackInfo>(
+ new (std::nothrow) CallbackInfo(cb, error_cb, user_data));
+ if (ci.get() == nullptr) {
+ LOGE("Out of memory");
return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY;
- } catch (Exception &ex) {
- LOGE("%s %d", ex.what(), ex.GetErrorCode());
- delete ci;
- return ex.GetErrorCode();
}
+ ret = ptr.get()->AddCallbackInfo(move(ci));
+ if (ret != WATCHFACE_COMPLICATION_ERROR_NONE)
+ return ret;
return ret;
}
: cb_(cb), user_data_(user_data) {
}
+ ReadyCallbackInfo(ReadyCallbackInfo&& b) noexcept {
+ cb_ = b.cb_;
+ user_data_ = b.user_data_;
+ b.cb_ = nullptr;
+ b.user_data_ = nullptr;
+ }
+
void Invoke(void* stub, const std::string& editor_appid) {
cb_(stub, editor_appid.c_str(), user_data_);
}
: cb_(cb), user_data_(user_data) {
}
+ UpdateCallbackInfo(UpdateCallbackInfo&& b) noexcept {
+ cb_ = b.cb_;
+ user_data_ = b.user_data_;
+ b.cb_ = nullptr;
+ b.user_data_ = nullptr;
+ }
+
void Invoke(const void* handle, int selected_idx,
const watchface_editable_edit_state_e state) {
LOGI("call update");
}
}
- int AddReadyCallbackInfo(ReadyCallbackInfo* ci) {
+ int AddReadyCallbackInfo(unique_ptr<ReadyCallbackInfo> ci) {
for (auto& i : ready_cb_list_) {
if (i.get()->GetCallback() == ci->GetCallback()) {
LOGI("already registered callback");
}
}
- ready_cb_list_.emplace_back(ci);
+ ready_cb_list_.emplace_back(move(ci));
return WATCHFACE_COMPLICATION_ERROR_NONE;
}
update_cb_list_.clear();
}
- void AddUpdateCallbackInfo(UpdateCallbackInfo* ci) {
- update_cb_list_.emplace_back(ci);
+ void AddUpdateCallbackInfo(unique_ptr<UpdateCallbackInfo> ci) {
+ update_cb_list_.emplace_back(move(ci));
}
private:
cur_data_idx >= static_cast<int>(
g_list_length(list_handle->candidates_list)))
return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
+
EditablesContainerStub* ec = static_cast<EditablesContainerStub*>(handle);
- bundle* data;
- int str_len = 0;
- int ret;
- bundle_raw* str_raw = NULL;
GList* iter = list_handle->candidates_list;
std::list<std::shared_ptr<Bundle>> new_list;
for (; iter; iter = iter->next) {
- data = reinterpret_cast<bundle*>(iter->data);
- if (data != NULL) {
- ret = bundle_encode(data, &str_raw, &str_len);
- if (ret == BUNDLE_ERROR_NONE && str_raw) {
- new_list.emplace_back(
- new Bundle(std::string(reinterpret_cast<char*>(str_raw))));
- free(str_raw);
- str_raw = NULL;
- } else {
- return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY;
- }
+ bundle* data = reinterpret_cast<bundle*>(iter->data);
+ if (data == nullptr)
+ continue;
+
+ Bundle* new_data = new Bundle(data);
+ if (new_data == nullptr) {
+ LOGE("Out of memory");
+ return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY;
}
+ new_list.emplace_back(move(new_data));
}
if (ec->IsExist(edit_id)) {
de.get()->SetHighlight(std::move(hi_ptr));
}
de.get()->SetLabel(std::string(editable_name));
- ret = de.get()->SetCandidates(new_list);
+ int ret = de.get()->SetCandidates(new_list);
if (ret != WATCHFACE_COMPLICATION_ERROR_NONE)
return ret;
}
EditablesContainerStub* ec = static_cast<EditablesContainerStub*>(handle);
- UpdateCallbackInfo* ci = nullptr;
- try {
- ci = new UpdateCallbackInfo(cb, user_data);
- ec->ClearUpdateCallbackInfo();
- ec->AddUpdateCallbackInfo(ci);
- } catch (const std::bad_alloc &ba) {
- LOGE("UpdateCallbackInfo::Exception bad_alloc");
- if (ci != nullptr)
- delete ci;
+ unique_ptr<UpdateCallbackInfo> ci = unique_ptr<UpdateCallbackInfo>(
+ new (std::nothrow) UpdateCallbackInfo(cb, user_data));
+ if (ci.get() == nullptr) {
+ LOGE("Out of memory");
return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY;
- } catch (watchface_complication::Exception &ex) {
- LOGE("%s %d", ex.what(), ex.GetErrorCode());;
- delete ci;
- return ex.GetErrorCode();
}
+ ec->ClearUpdateCallbackInfo();
+ ec->AddUpdateCallbackInfo(move(ci));
ret = ec->RequestEdit();
return ret;
if (!watchface_complication::util::CheckWatchFeatureEnabled())
return WATCHFACE_COMPLICATION_ERROR_NOT_SUPPORTED;
- if (cb == NULL)
+ if (cb == nullptr)
return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
- try {
- if (__container == NULL)
- __container = new EditablesContainerStub();
- } catch (const std::bad_alloc &ba) {
- LOGE("EditablesContainerStub::Exception bad_alloc");
+ if (__container == nullptr)
+ __container = new (std::nothrow) EditablesContainerStub();
+ if (__container == nullptr) {
+ LOGE("Out of memory");
return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY;
- } catch (watchface_complication::Exception &ex) {
- LOGE("%s %d", ex.what(), ex.GetErrorCode());;
- return ex.GetErrorCode();
}
- ReadyCallbackInfo* ci = nullptr;
- try {
- ci = new ReadyCallbackInfo(cb, user_data);
- int ret = __container->AddReadyCallbackInfo(ci);
- if (ret != WATCHFACE_COMPLICATION_ERROR_NONE) {
- delete ci;
- return ret;
- }
- } catch (const std::bad_alloc &ba) {
- LOGE("UpdateCallbackInfo::Exception bad_alloc");
- if (ci != nullptr)
- delete ci;
+ unique_ptr<ReadyCallbackInfo> ci = unique_ptr<ReadyCallbackInfo>(
+ new (std::nothrow) ReadyCallbackInfo(cb, user_data));
+ if (ci.get() == nullptr) {
+ LOGE("Out of memory");
return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY;
- } catch (watchface_complication::Exception &ex) {
- LOGE("%s %d", ex.what(), ex.GetErrorCode());
- delete ci;
- return ex.GetErrorCode();
}
+ int ret = __container->AddReadyCallbackInfo(move(ci));
+ if (ret != WATCHFACE_COMPLICATION_ERROR_NONE)
+ return ret;
return WATCHFACE_COMPLICATION_ERROR_NONE;
}
return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
std::unique_ptr<Bundle> setting_data;
-
try {
setting_data = EditablesManager::GetInst().LoadSetting(editable_id);
} catch (watchface_complication::Exception &ex) {
LOGE("%s %d", ex.what(), ex.GetErrorCode());
return ex.GetErrorCode();
}
+
if (setting_data != nullptr) {
- *selected_data = bundle_dup(setting_data.get()->GetHandle());
- if (*selected_data == NULL)
+ bundle* dup_bundle = bundle_dup(setting_data.get()->GetHandle());
+ if (dup_bundle == nullptr)
return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY;
+ *selected_data = dup_bundle;
} else {
return WATCHFACE_COMPLICATION_ERROR_NO_DATA;
}
#define LOG_TAG "WATCHFACE_COMPLICATION"
+using namespace std;
using namespace tizen_base;
namespace watchface_complication {
return;
}
- bundle* data = bundle_decode(raw, strlen(reinterpret_cast<char*>(raw)));
- const char** str_arr = NULL;
- int len = 0;
-
- if (data == NULL) {
- LOGE("bundle decode failed %d", get_last_result());
- return;
- }
-
- str_arr = bundle_get_str_array(data, "EDITABLE_LIST", &len);
- for (int i = 0; i < len; i++) {
- try {
- e_list.emplace_back(std::unique_ptr<IEditable>(
- new ReceivedEditable(std::string(str_arr[i]))));
- } catch (const std::bad_alloc &ba) {
- LOGE("ReceivedEditable::Exception bad_alloc");
- return;
- } catch (Exception &ex) {
- LOGE("%s %d", ex.what(), ex.GetErrorCode());
+ 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>(
+ new ReceivedEditable(i));
+ if (received.get() == nullptr) {
+ LOGE("Out of memory");
return;
}
+ e_list.emplace_back(move(received));
}
parent_->OnRequestEdit(std::string(appid), std::move(e_list));
- bundle_free(data);
} else if (signal_name.compare(
util::GetCmdStr(util::CmdType::SetupReply)) == 0) {
int edit_id;
char* raw_str;
-
g_variant_get(parameters, "(i&s)", &edit_id, &raw_str);
- try {
- parent_->OnSetupReply(sender_appid, edit_id,
- std::unique_ptr<Bundle>(new Bundle(std::string(raw_str))));
- } catch (const std::bad_alloc &ba) {
- LOGE("Bundle::Exception bad_alloc");
- return;
- } catch (Exception &ex) {
- LOGE("%s %d", ex.what(), ex.GetErrorCode());
+ unique_ptr<Bundle> reply_data =
+ unique_ptr<Bundle>(new (std::nothrow) Bundle(std::string(raw_str)));
+ if (reply_data.get() == nullptr) {
+ LOGE("Out of memory");
return;
}
+ parent_->OnSetupReply(sender_appid, edit_id, move(reply_data));
}
}
}
int EditablesEditor::EditComplete() {
- bool emit_result;
- int ret;
-
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;
- emit_result = impl_->gdbus_.get()->EmitSignal(
+ bool emit_result = impl_->gdbus_.get()->EmitSignal(
IGDBus::Editable,
impl_->edit_appid_.c_str(),
impl_->edit_appid_.c_str(),
#define LOG_TAG "WATCHFACE_COMPLICATION"
+using namespace std;
using namespace tizen_base;
using namespace watchface_complication;
: cb_(cb), user_data_(user_data) {
}
+ CallbackInfo(CallbackInfo&& b) noexcept {
+ cb_ = b.cb_;
+ user_data_ = b.user_data_;
+ b.cb_ = nullptr;
+ b.user_data_ = nullptr;
+ }
+
void Invoke(const std::string& appid, editable_list_h list_h) {
cb_(appid.c_str(), list_h, user_data_);
}
cb_(cb), user_data_(user_data) {
}
+ SetupCallbackInfo(SetupCallbackInfo&& b) noexcept {
+ setup_appid_ = b.setup_appid_;
+ editable_id_ = b.editable_id_;
+ cb_ = b.cb_;
+ user_data_ = b.user_data_;
+ b.cb_ = nullptr;
+ b.user_data_ = nullptr;
+ }
+
void Invoke(bundle* new_context) {
cb_(editable_id_, new_context, user_data_);
}
LOGE("Not exist callback info");
}
- void AddSetupCallbackInfo(SetupCallbackInfo* ci) {
- setup_cb_list_.emplace_back(ci);
+ void AddSetupCallbackInfo(unique_ptr<SetupCallbackInfo> ci) {
+ setup_cb_list_.emplace_back(move(ci));
}
- void RemoveSetupCallbackInfo(SetupCallbackInfo* ci) {
+ void RemoveSetupCallbackInfo(unique_ptr<SetupCallbackInfo> ci) {
for (auto& i : setup_cb_list_) {
- if (i.get() == ci) {
+ if (i.get() == ci.get()) {
setup_cb_list_.remove(i);
break;
}
}
}
- int AddCallbackInfo(CallbackInfo* ci) {
+ int AddCallbackInfo(unique_ptr<CallbackInfo> ci) {
for (auto& i : cb_list_) {
if (i.get()->GetCallback() == ci->GetCallback()) {
LOGI("already registered callback");
}
}
- cb_list_.emplace_back(ci);
+ cb_list_.emplace_back(move(ci));
return WATCHFACE_COMPLICATION_ERROR_NONE;
}
static std::unique_ptr<EditablesEditorStub> __stub = nullptr;
extern "C" EXPORT_API int watchface_editor_add_request_edit_cb(
watchface_editor_request_edit_cb cb, void* user_data) {
- int ret;
-
if (!watchface_complication::util::CheckWatchFeatureEnabled())
return WATCHFACE_COMPLICATION_ERROR_NOT_SUPPORTED;
}
if (__stub == nullptr) {
- try {
- __stub = std::unique_ptr<EditablesEditorStub>(new EditablesEditorStub());
- } catch (const std::bad_alloc &ba) {
- LOGE("EditablesEditorStub::Exception bad_alloc");
- return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY;
- } catch (Exception &ex) {
- LOGE("%s %d", ex.what(), ex.GetErrorCode());
- return ex.GetErrorCode();
+ __stub = std::unique_ptr<EditablesEditorStub>(
+ new (std::nothrow) EditablesEditorStub());
+ if (__stub == nullptr) {
+ LOGE("Out of memory");
+ return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY;
}
}
- CallbackInfo* ci = nullptr;
- try {
- ci = new CallbackInfo(cb, user_data);
- ret = __stub->AddCallbackInfo(ci);
- if (ret != WATCHFACE_COMPLICATION_ERROR_NONE)
- delete ci;
- } catch (const std::bad_alloc &ba) {
- LOGE("CallbackInfo::Exception bad_alloc");
- if (ci != nullptr)
- delete ci;
+ unique_ptr<CallbackInfo> ci = unique_ptr<CallbackInfo>(
+ new (std::nothrow) CallbackInfo(cb, user_data));
+ if (ci.get() == nullptr) {
+ LOGE("Out of memory");
return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY;
- } catch (Exception &ex) {
- LOGE("%s %d", ex.what(), ex.GetErrorCode());
- delete ci;
- return ex.GetErrorCode();
}
-
- return ret;
+ return __stub->AddCallbackInfo(move(ci));
}
extern "C" EXPORT_API int watchface_editor_remove_request_edit_cb(
return __stub->EditPreview(*ed, cur_data_idx);
}
+static int __init_stub() {
+ if (__stub != nullptr)
+ return WATCHFACE_COMPLICATION_ERROR_NONE;
+ try {
+ __stub = std::unique_ptr<EditablesEditorStub>(new EditablesEditorStub());
+ } catch (const std::bad_alloc &ba) {
+ LOGE("EditablesEditorStub::Exception bad_alloc");
+ return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY;
+ } catch (Exception &ex) {
+ LOGE("%s %d", ex.what(), ex.GetErrorCode());
+ return ex.GetErrorCode();
+ }
+ return WATCHFACE_COMPLICATION_ERROR_NONE;
+}
+
extern "C" EXPORT_API int watchface_editor_edit_complete(void) {
if (!watchface_complication::util::CheckWatchFeatureEnabled())
return WATCHFACE_COMPLICATION_ERROR_NOT_SUPPORTED;
-
- if (__stub == nullptr) {
- try {
- __stub = std::unique_ptr<EditablesEditorStub>(new EditablesEditorStub());
- } catch (const std::bad_alloc &ba) {
- LOGE("EditablesEditorStub::Exception bad_alloc");
- return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY;
- } catch (Exception &ex) {
- LOGE("%s %d", ex.what(), ex.GetErrorCode());
- return ex.GetErrorCode();
- }
- }
-
+ int ret = __init_stub();
+ if (ret != WATCHFACE_COMPLICATION_ERROR_NONE)
+ return ret;
return __stub->EditComplete();
}
extern "C" EXPORT_API int watchface_editor_edit_cancel(void) {
if (!watchface_complication::util::CheckWatchFeatureEnabled())
return WATCHFACE_COMPLICATION_ERROR_NOT_SUPPORTED;
-
- if (__stub == nullptr) {
- try {
- __stub = std::unique_ptr<EditablesEditorStub>(new EditablesEditorStub());
- } catch (const std::bad_alloc &ba) {
- LOGE("EditablesEditorStub::Exception bad_alloc");
- return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY;
- } catch (Exception &ex) {
- LOGE("%s %d", ex.what(), ex.GetErrorCode());
- return ex.GetErrorCode();
- }
- }
+ int ret = __init_stub();
+ if (ret != WATCHFACE_COMPLICATION_ERROR_NONE)
+ return ret;
return __stub->EditCancel();
}
return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
}
- if (__stub == nullptr) {
- try {
- __stub = std::unique_ptr<EditablesEditorStub>(new EditablesEditorStub());
- } catch (const std::bad_alloc &ba) {
- LOGE("EditablesEditorStub::Exception bad_alloc");
- return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY;
- } catch (Exception &ex) {
- LOGE("%s %d", ex.what(), ex.GetErrorCode());
- return ex.GetErrorCode();
- }
- } else {
- __stub->ClearEditableList();
- }
-
+ int ret = __init_stub();
+ if (ret != WATCHFACE_COMPLICATION_ERROR_NONE)
+ return ret;
+ __stub->ClearEditableList();
return __stub->NotifyEditReady(std::string(appid));
}
int re = WATCHFACE_COMPLICATION_ERROR_NONE;
IEditable* ed = static_cast<IEditable*>(handle);
if (new_context) {
- try {
- std::unique_ptr<Bundle> b(new Bundle(new_context));
- re = ed->SetContext(std::move(b));
- } catch (const std::bad_alloc &ba) {
+ std::unique_ptr<Bundle> b(new (std::nothrow) Bundle(new_context));
+ if (b.get() == nullptr) {
LOGE("Out of memory");
return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY;
- } catch (Exception &ex) {
- LOGE("%s %d", ex.what(), ex.GetErrorCode());
- return ex.GetErrorCode();
}
+ re = ed->SetContext(std::move(b));
} else {
re = ed->SetContext(std::unique_ptr<Bundle>{});
}
}
app_control_destroy(service);
- SetupCallbackInfo* ci = nullptr;
- try {
- if (__stub == nullptr)
- __stub = std::unique_ptr<EditablesEditorStub>(new EditablesEditorStub());
+ unique_ptr<SetupCallbackInfo> ci = unique_ptr<SetupCallbackInfo>(
+ new (std::nothrow) SetupCallbackInfo(
+ appid, ed->GetEditableId(), cb, user_data));
- ci = new SetupCallbackInfo(appid, ed->GetEditableId(), cb, user_data);
- __stub->AddSetupCallbackInfo(ci);
- } catch (const std::bad_alloc &ba) {
- LOGE("Out of memory");
- if (ci != nullptr)
- delete ci;
- return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY;
- } catch (Exception &ex) {
- LOGE("%s %d", ex.what(), ex.GetErrorCode());
- delete ci;
- return ex.GetErrorCode();
- }
+ ret = __init_stub();
+ if (ret != WATCHFACE_COMPLICATION_ERROR_NONE)
+ return ret;
+ __stub->AddSetupCallbackInfo(move(ci));
return WATCHFACE_COMPLICATION_ERROR_NONE;
}