TEST_F(DE, GetCurDataIdx)
{
- EXPECT_EQ(DE::element->SetCurDataIdx(1), 0);
- EXPECT_EQ(DE::element->GetCurDataIdx(), 1);
+ EXPECT_EQ(DE::element->SetCurDataIdx(0), 0);
+ EXPECT_EQ(DE::element->GetCurDataIdx(), 0);
}
TEST_F(DE, GetName)
static std::map<string, WatchComplicationProviderStub*> __providers;
extern "C" EXPORT_API int complication_provider_update_request_cb_add(
const char *provider_id, on_update_request cb, void *user_data) {
+ if (provider_id == NULL || cb == NULL)
+ return COMPLICATION_ERROR_INVALID_PARAMETER;
+
// TODO(?): Provider ID validation
// TODO(?): Get provider's support type from storage
int support_types = ShortText | Image;
extern "C" EXPORT_API int complication_provider_update_request_cb_del(
const char *provider_id, on_update_request cb, void *user_data) {
+ if (provider_id == NULL || cb == NULL)
+ return COMPLICATION_ERROR_INVALID_PARAMETER;
+
return 0;
}
extern "C" EXPORT_API int complication_provider_get_support_types(
const char *provider_id, int *types) {
+ if (provider_id == NULL || types == NULL)
+ return COMPLICATION_ERROR_INVALID_PARAMETER;
+
return 0;
}
#include <unistd.h>
#include <aul.h>
#include <appsvc.h>
+#include <stdexcept>
#include "watchface-complication/complication.h"
#include "watchface-complication/complication-implementation.h"
parent_->GetProviderList(static_cast<ComplicationType>(type));
for (auto& provider_id : provider_list) {
bundle* data = bundle_create();
+ if (data == NULL)
+ std::runtime_error("bundle create failed");
+
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());
candidates_list_.emplace_back(new Bundle(data));
const char* Complication::GetProviderId(Bundle& data) {
char* provider_id = NULL;
+
+ if (data.GetRaw() == nullptr)
+ return NULL;
+
bundle_get_str(data.GetRaw(), impl_->provider_id_key_.c_str(), &provider_id);
return provider_id;
int Complication::GetType(Bundle& data) {
char* type;
int ret = -1;
+
+ if (data.GetRaw() == nullptr)
+ return ret;
+
bundle_get_str(data.GetRaw(), impl_->provider_type_key_.c_str(), &type);
if (type)
}
void Complication::SetName(const std::string& name) {
+ if (name.empty())
+ return;
+
impl_->name_ = name;
}
std::string provider_appid = impl_->GetProviderAppId();
const char* context_data_raw = "";
bundle *arg_list = bundle_create();
+ if (arg_list == NULL)
+ std::runtime_error("bundle create failed");
appsvc_set_operation(arg_list, APPSVC_OPERATION_DEFAULT);
appsvc_set_appid(arg_list, provider_appid.c_str());
}
int DesignElement::SetCurDataIdx(int cur_data_idx) {
+ if (cur_data_idx < 0 || cur_data_idx >= (int)impl_->candidates_list_.size()) {
+ LOGE("Invalid index");
+ return -1;
+ }
+
LOGI("set cur data %d", cur_data_idx);
impl_->cur_data_idx_ = cur_data_idx;
return 0;
}
void DesignElement::SetName(const std::string& name) {
+ if (name.empty())
+ return;
+
impl_->name_ = name;
}
bundle_raw *str_raw = NULL;
std::unique_ptr<const char*[]> list_arr(new const char*[impl_->ed_list_.size()]);
+ if (editor_id.empty())
+ return -1;
+
for (auto& i : impl_->ed_list_) {
i.get()->SetState(IEditable::OnGoing);
bundle* ed = bundle_create();
+ if (ed == NULL) {
+ if (str_raw)
+ free(str_raw);
+ return -1;
+ }
+
bundle_add(ed, "EDITABLE_ID", std::to_string(i.get()->GetId()).c_str());
int cur_data_idx = i.get()->GetCurDataIdx();
}
bundle* container = bundle_create();
+ if (container == NULL) {
+ if (str_raw)
+ free(str_raw);
+ return -1;
+ }
+
bundle_add_str_array(container, "EDITABLE_LIST", list_arr.get(), list_idx);
bundle_encode(container, &str_raw, &str_len);
}
int EditablesContainer::Add(std::shared_ptr<IEditable> ed) {
+ if (ed == nullptr)
+ return -1;
+
impl_->ed_list_.push_back(ed);
return 0;
}
int EditablesContainer::Remove(std::shared_ptr<IEditable> ed) {
+ if (ed == nullptr)
+ return -1;
+
for (auto& i : impl_->ed_list_) {
if (i.get() == ed.get()) {
impl_->ed_list_.remove(i);
#endif
typedef enum _complication_type {
+ COMPLICATION_TYPE_NONE = 0x00,
COMPLICATION_SHORT_TEXT = 0x01,
COMPLICATION_LONG_TEXT = 0x02,
COMPLICATION_RANGED_VALUE = 0x04,
COMPLICATION_TIME = 0x08,
COMPLICATION_ICON = 0x10,
COMPLICATION_IMAGE = 0x20,
+ COMPLICATION_TYPE_MAX = COMPLICATION_SHORT_TEXT |
+ COMPLICATION_LONG_TEXT |
+ COMPLICATION_RANGED_VALUE |
+ COMPLICATION_TIME |
+ COMPLICATION_ICON |
+ COMPLICATION_IMAGE,
} complication_type;
typedef enum _complication_shape_type {
ReceivedEditable::~ReceivedEditable() = default;
ReceivedEditable::Impl::Impl(ReceivedEditable* parent, std::string raw)
: parent_(parent) {
+ if (raw.empty())
+ return;
bundle* data = bundle_decode(
reinterpret_cast<const bundle_raw*>(
}
int ReceivedEditable::SetCurDataIdx(int cur_data_idx) {
+ if (cur_data_idx < 0 || cur_data_idx >= (int)impl_->candidates_list_.size()) {
+ LOGE("Invalid index");
+ return -1;
+ }
+
impl_->cur_data_idx_ = cur_data_idx;
return 0;
}
const std::string& ReceivedEditable::GetName() {
return impl_->name_;
}
+
void ReceivedEditable::SetName(const std::string& name) {
+ if (name.empty())
+ return;
+
impl_->name_ = name;
}
-
/*
* Copyright (c) 2017 Samsung Electronics Co., Ltd.
*
extern "C" EXPORT_API int complication_update_cb_add(complication_h handle,
on_complication_update cb, void *user_data) {
+ if (handle == NULL || cb == NULL)
+ return COMPLICATION_ERROR_INVALID_PARAMETER;
auto sh = static_cast<SharedHandle<WatchComplicationStub>*>(handle);
auto ptr = SharedHandle<WatchComplicationStub>::Share(sh);
extern "C" EXPORT_API int complication_update_cb_del(complication_h handle,
on_complication_update cb) {
+ if (handle == NULL || cb == NULL)
+ return COMPLICATION_ERROR_INVALID_PARAMETER;
+
return 0;
}
extern "C" EXPORT_API int complication_set_provider(const char *provider_id) {
+ if (provider_id == NULL)
+ return COMPLICATION_ERROR_INVALID_PARAMETER;
+
return 0;
}
extern "C" EXPORT_API int complication_send_update_request(
complication_h handle) {
+ if (handle == NULL)
+ return COMPLICATION_ERROR_INVALID_PARAMETER;
+
LOGI("update call!!");
auto sh = static_cast<SharedHandle<WatchComplicationStub>*>(handle);
auto ptr = SharedHandle<WatchComplicationStub>::Share(sh);
}
extern "C" EXPORT_API int complication_get_id(complication_h handle) {
- return -1;
-}
+ if (handle == NULL)
+ return COMPLICATION_ERROR_INVALID_PARAMETER;
-int __get_complication_data(int complication_id, char **provider_id,
- complication_type *comp_type) {
- // TODO(?): return saved value
return -1;
}
const char *default_provider_id, complication_type default_type,
int support_types, complication_shape_type shape_type,
complication_h *created_handle) {
+ if (support_types <= COMPLICATION_TYPE_NONE ||
+ support_types > COMPLICATION_TYPE_MAX)
+ return COMPLICATION_ERROR_INVALID_PARAMETER;
+
// TODO(?) check default value and type is valid
auto ws = new WatchComplicationStub(
complication_id,
}
extern "C" EXPORT_API int complication_destroy(complication_h handle) {
+ if (handle == NULL)
+ return COMPLICATION_ERROR_INVALID_PARAMETER;
auto sh = static_cast<SharedHandle<WatchComplicationStub>*>(handle);
delete sh;
extern "C" EXPORT_API int complication_get_cur_provider_id(complication_h handle,
const char** cur_provider_id) {
+ if (handle == NULL || cur_provider_id == NULL)
+ return COMPLICATION_ERROR_INVALID_PARAMETER;
+
auto sh = static_cast<SharedHandle<WatchComplicationStub>*>(handle);
auto ptr = SharedHandle<WatchComplicationStub>::Share(sh);
*cur_provider_id = ptr.get()->GetCurProviderId();
extern "C" EXPORT_API int complication_get_cur_type(complication_h handle,
complication_type* cur_type) {
+ if (handle == NULL || cur_type == NULL)
+ return COMPLICATION_ERROR_INVALID_PARAMETER;
+
auto sh = static_cast<SharedHandle<WatchComplicationStub>*>(handle);
auto ptr = SharedHandle<WatchComplicationStub>::Share(sh);
int ret = ptr.get()->GetCurType();
extern "C" EXPORT_API int complication_get_provider_id(const bundle* candidate,
const char** provider_id) {
+ if (candidate == NULL || provider_id == NULL)
+ return COMPLICATION_ERROR_INVALID_PARAMETER;
+
char* val = NULL;
bundle_get_str(const_cast<bundle*>(candidate),
extern "C" EXPORT_API int complication_get_type(const bundle* candidate,
complication_type* cur_type) {
+ if (candidate == NULL || cur_type == NULL)
+ return COMPLICATION_ERROR_INVALID_PARAMETER;
+
char* val = NULL;
bundle_get_str(const_cast<bundle*>(candidate),
return -1;
return 0;
-}
\ No newline at end of file
+}
extern "C" EXPORT_API int editable_add_design_element(editable_container_h handle,
int edit_id, int cur_data_idx, GList* candiatelist, editable_geo geo,
const char* editable_name) {
+ if (handle == NULL || candiatelist == NULL || editable_name == NULL)
+ return COMPLICATION_ERROR_INVALID_PARAMETER;
+
EditablesContainerStub* ec = static_cast<EditablesContainerStub*>(handle);
bundle* data;
int str_len = 0;
extern "C" EXPORT_API int editable_add_complication(editable_container_h handle,
int edit_id, complication_h comp, editable_geo geo,
const char* editable_name) {
+ if (handle == NULL || comp == NULL || editable_name == NULL)
+ return COMPLICATION_ERROR_INVALID_PARAMETER;
+
EditablesContainerStub* ec = static_cast<EditablesContainerStub*>(handle);
SharedHandle<IEditable>* sh = static_cast<SharedHandle<IEditable>*>(comp);
extern "C" EXPORT_API int editable_request_edit(editable_container_h handle,
const char *editor_appid, on_editable_update cb, void *user_data) {
+ if (handle == NULL || editor_appid == NULL || cb == NULL)
+ return COMPLICATION_ERROR_INVALID_PARAMETER;
+
EditablesContainerStub* ec = static_cast<EditablesContainerStub*>(handle);
auto ci = new UpdateCallbackInfo(cb, user_data);
ec->ClearUpdateCallbackInfo();
extern "C" EXPORT_API int editable_on_edit_ready_cb_add(on_edit_ready cb,
void *user_data) {
+ if (cb == NULL)
+ return COMPLICATION_ERROR_INVALID_PARAMETER;
+
if (__container == NULL)
__container = new EditablesContainerStub();
}
extern "C" EXPORT_API int editable_on_edit_ready_cb_del(on_edit_ready cb) {
+ if (cb == NULL)
+ return COMPLICATION_ERROR_INVALID_PARAMETER;
+
return 0;
}
extern "C" EXPORT_API int editable_get_cur_data_idx(const editable_h handle,
int *idx) {
+ if (handle == NULL || idx == NULL)
+ return COMPLICATION_ERROR_INVALID_PARAMETER;
+
IEditable* ie = static_cast<IEditable*>(handle);
*idx = ie->GetCurDataIdx();
return 0;
extern "C" EXPORT_API int editable_set_cur_data_idx(const editable_h handle,
int idx) {
+ if (handle == NULL)
+ return COMPLICATION_ERROR_INVALID_PARAMETER;
+
IEditable* ie = static_cast<IEditable*>(handle);
ie->SetCurDataIdx(idx);
return 0;
extern "C" EXPORT_API int editable_get_cur_data(const editable_h handle,
bundle **cur_data) {
+ if (handle == NULL || cur_data == NULL)
+ return COMPLICATION_ERROR_INVALID_PARAMETER;
+
IEditable* ie = static_cast<IEditable*>(handle);
Bundle& data = ie->GetCurData();
*cur_data = data.GetRaw();
extern "C" EXPORT_API int editable_get_nth_data(const editable_h handle,
int nth, bundle **cur_data) {
+ if (handle == NULL || cur_data == NULL)
+ return COMPLICATION_ERROR_INVALID_PARAMETER;
+
IEditable* ie = static_cast<IEditable*>(handle);
Bundle& data = ie->GetNthData(nth);
*cur_data = data.GetRaw();
extern "C" EXPORT_API int editable_get_editable_id(const editable_h handle,
int *editable_id) {
+ if (handle == NULL || editable_id == NULL)
+ return COMPLICATION_ERROR_INVALID_PARAMETER;
+
IEditable* ie = static_cast<IEditable*>(handle);
*editable_id = ie->GetId();
}
extern "C" EXPORT_API int editable_get_geometry(const editable_h handle,
editable_geo *geo) {
+ if (handle == NULL || geo == NULL)
+ return COMPLICATION_ERROR_INVALID_PARAMETER;
+
return 0;
}
extern "C" EXPORT_API int editable_get_candidates_list(const editable_h handle,
GList **candiates_list) {
+ if (handle == NULL || candiates_list == NULL)
+ return COMPLICATION_ERROR_INVALID_PARAMETER;
+
return 0;
}
extern "C" EXPORT_API int editable_get_editable_name(const editable_h handle,
const char **editable_name) {
+ if (handle == NULL || editable_name == NULL)
+ return COMPLICATION_ERROR_INVALID_PARAMETER;
+
IEditable* ie = static_cast<IEditable*>(handle);
if (!ie->GetName().empty())
*editable_name = ie->GetName().c_str();
extern "C" EXPORT_API int editable_set_editable_name(const editable_h handle,
const char *editable_name) {
+ if (handle == NULL || editable_name == NULL)
+ return COMPLICATION_ERROR_INVALID_PARAMETER;
+
IEditable* ie = static_cast<IEditable*>(handle);
ie->SetName(std::string(editable_name));
return 0;
#include <glib.h>
#include <unistd.h>
#include <utility>
+#include <stdexcept>
#include "watchface-editor/editables-editor.h"
#include "watchface-editor/editables-editor-implementation.h"
const char **str_arr = NULL;
int len = 0;
+ if (data == NULL)
+ throw std::runtime_error("bundle decode failed");
+
str_arr = bundle_get_str_array(data, "EDITABLE_LIST", &len);
for (int i = 0; i < len; i++) {
e_list.emplace_back(std::unique_ptr<IEditable>(
}
int EditablesEditor::NotifyEditReady(std::string appid) {
+ if (appid.empty())
+ return -1;
+
ComplicationConnector::GetInst().EmitSignal(
ComplicationConnector::Editable,
appid,
static std::unique_ptr<EditablesEditorStub> __stub = nullptr;
extern "C" EXPORT_API int editor_on_request_edit_cb_add(on_request_edit cb,
void *user_data) {
+ if (cb == NULL)
+ return COMPLICATION_ERROR_INVALID_PARAMETER;
+
if (__stub == nullptr)
__stub = std::unique_ptr<EditablesEditorStub>(new EditablesEditorStub());
}
extern "C" EXPORT_API int editor_on_request_edit_cb_del(on_request_edit cb) {
+ if (cb == NULL)
+ return COMPLICATION_ERROR_INVALID_PARAMETER;
+
return 0;
}
extern "C" EXPORT_API int editor_edit_preview(const editable_h ed_h,
int cur_data_idx) {
+ if (ed_h == NULL)
+ return COMPLICATION_ERROR_INVALID_PARAMETER;
+
IEditable* ed = static_cast<IEditable*>(ed_h);
ed->SetCurDataIdx(cur_data_idx);
return __stub->EditPreview(*ed, cur_data_idx);
}
extern "C" EXPORT_API int editor_notify_edit_ready(const char *appid) {
+ if (appid == NULL)
+ return COMPLICATION_ERROR_INVALID_PARAMETER;
+
if (__stub == nullptr)
__stub = std::unique_ptr<EditablesEditorStub>(new EditablesEditorStub());
else
extern "C" EXPORT_API int editor_foreach_editable_list(editable_list_h list_h,
editable_list_foreach_cb cb, void *user_data) {
+ if (list_h == NULL || cb == NULL)
+ return COMPLICATION_ERROR_INVALID_PARAMETER;
+
GList *iter = list_h;
while (iter) {
cb((editable_h)iter->data, user_data);
extern "C" EXPORT_API editable_list_h editor_editable_list_dup(
editable_list_h source) {
+ if (source == NULL) {
+ LOGE("Invalid parameter");
+ return NULL;
+ }
+
GList* dest = NULL;
GList* iter = source;
while (iter) {
extern "C" EXPORT_API const editable_h editor_editable_list_nth(
editable_list_h list, int nth) {
+ if (list == NULL) {
+ LOGE("Invalid parameter");
+ return NULL;
+ }
+
GList* iter = list;
int idx = 0;
while (iter) {
extern "C" EXPORT_API int editor_editable_candidate_list_size(const editable_h ed_h) {
+ if (ed_h == NULL) {
+ LOGE("Invalid parameter");
+ return -1;
+ }
+
IEditable* ed = static_cast<IEditable*>(ed_h);
std::list<std::unique_ptr<Bundle>> const& list = ed->GetCandidates();
return list.size();
extern "C" EXPORT_API const bundle* editor_editable_candidate_list_nth(
const editable_h ed_h, int nth) {
+ if (ed_h == NULL) {
+ LOGE("Invalid parameter");
+ return NULL;
+ }
+
IEditable* ed = static_cast<IEditable*>(ed_h);
const std::list<std::unique_ptr<Bundle>>& list = ed->GetCandidates();
const std::list<std::unique_ptr<Bundle>>::const_iterator it