From 2b4ca822c4a3e23ca397b3a704a2968af8ec9746 Mon Sep 17 00:00:00 2001 From: hyunho Date: Wed, 15 May 2019 15:36:09 +0900 Subject: [PATCH] Replace internal Bundle with tizen_base::Bundle Change-Id: I1f8a40f503ce2881a11f9a61e2effbac530475f3 Signed-off-by: hyunho --- parser/complication_parser_plugin.cc | 128 +++++-------- unittest/src/test-complication-bundle.cc | 137 ------------- unittest/src/test-complication-provider.cc | 2 +- unittest/src/test-complication.cc | 62 +++--- unittest/src/test-design-element.cc | 54 +++--- unittest/src/test-editables-container.cc | 104 +++------- unittest/src/test-editables-manager.cc | 8 +- unittest/src/test-editor.cc | 102 ++++------ unittest/src/test-received-editable.cc | 93 ++++----- .../src/test-watchface-complication-provider.cc | 5 +- unittest/src/test-watchface-complication.cc | 50 ++--- unittest/src/test-watchface-editable.cc | 5 +- unittest/src/test-watchface-editor.cc | 61 +++--- watchface-common/watchface-util.cc | 68 +++++++ watchface-common/watchface-util.h | 3 + .../complication-provider-event-interface.h | 5 +- .../complication-provider.cc | 105 ++++------ .../complication-provider.h | 4 +- .../watchface-complication-provider.cc | 86 ++------- watchface-complication/complication-bundle.cc | 110 ----------- watchface-complication/complication-bundle.h | 50 ----- .../complication-event-interface.h | 6 +- .../complication-implementation.h | 11 +- watchface-complication/complication.cc | 212 +++++++-------------- watchface-complication/complication.h | 23 +-- watchface-complication/db-manager.cc | 4 +- watchface-complication/db-manager.h | 7 +- .../design-element-implementation.h | 7 +- watchface-complication/design-element.cc | 54 ++---- watchface-complication/design-element.h | 15 +- watchface-complication/editable-interface.h | 16 +- .../editables-container-event-interface.h | 4 +- .../editables-container-implementation.h | 7 - watchface-complication/editables-container.cc | 87 +++------ watchface-complication/editables-manager.cc | 5 +- watchface-complication/editables-manager.h | 11 +- .../received-editable-implementation.h | 9 +- watchface-complication/received-editable.cc | 119 +++++------- watchface-complication/received-editable.h | 15 +- watchface-complication/watchface-complication.cc | 9 +- watchface-complication/watchface-editable.cc | 28 +-- .../editables-editor-event-interface.h | 1 - watchface-editor/editables-editor.cc | 7 +- watchface-editor/editables-editor.h | 3 +- watchface-editor/watchface-editor.cc | 13 +- 45 files changed, 665 insertions(+), 1250 deletions(-) delete mode 100644 unittest/src/test-complication-bundle.cc delete mode 100644 watchface-complication/complication-bundle.cc delete mode 100644 watchface-complication/complication-bundle.h diff --git a/parser/complication_parser_plugin.cc b/parser/complication_parser_plugin.cc index 10b73ef..68af55e 100644 --- a/parser/complication_parser_plugin.cc +++ b/parser/complication_parser_plugin.cc @@ -28,6 +28,7 @@ #include #include #include +#include #include "watchface-complication/include/watchface-complication-internal.h" #include "watchface-complication/include/watchface-complication.h" @@ -48,6 +49,8 @@ #define DEFAULT_IMAGE "default-image" #define DEFAULT_EXTRA_DATA "default-extra-data" +using namespace std; +using namespace tizen_base; struct support_event_tag_map { const char* name; @@ -247,7 +250,7 @@ static bool _is_valid_element(int type, char* element_name) { } static int _get_time_value(const char* time_type, const char* time_val, - char* prev_value, char** default_value) { + string prev_value, char** default_value) { time_t rawtime; struct tm timeinfo; @@ -256,10 +259,10 @@ static int _get_time_value(const char* time_type, const char* time_val, return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER; } - if (prev_value == NULL) + if (prev_value.empty()) time(&rawtime); else - rawtime = strtol(prev_value, NULL, 10); + rawtime = stoi(prev_value); localtime_r(&rawtime, &timeinfo); if (strcmp(DEFAULT_HOUR, time_type) == 0) { @@ -306,20 +309,7 @@ static int _get_time_value(const char* time_type, const char* time_val, static int _parse_support_type(xmlNode* node, sqlite3* db, const char* pkgid, const char* appid, const char* providerid, int period, bool trusted) { int ret; - int idx; - int support_type = 0; - - xmlNode* tmp; - xmlNode* tmpdata; - sqlite3_stmt* stmt = NULL; - - bundle* default_data = NULL; - bundle_raw* raw = NULL; - int len = 0; - const char* bundle_key; - char* default_value = NULL; - char* dup_val = NULL; - char* prev_value; + sqlite3_stmt* stmt = nullptr; static const char query[] = "INSERT INTO complication_provider ( " @@ -336,70 +326,62 @@ static int _parse_support_type(xmlNode* node, sqlite3* db, const char* pkgid, goto out; } + xmlNode* tmp; for (tmp = node->children; tmp; tmp = tmp->next) { if (tmp->children == NULL || tmp->children->content == NULL) continue; - support_type = _get_support_type_tag(tmp); + int support_type = _get_support_type_tag(tmp); if (!support_type) { LOGE("not supported type"); goto out; } - default_data = bundle_create(); - if (default_data == NULL) { - LOGE("bundle create error"); - goto out; - } - + xmlNode* tmpdata; + Bundle default_data; for (tmpdata = tmp->children; tmpdata; tmpdata = tmpdata->next) { - if (tmpdata->children != NULL - && tmpdata->children->content != NULL) { - if (!_is_valid_element(support_type, (char*)tmpdata->name)) - goto out; + if (tmpdata->children == nullptr || tmpdata->children->content == nullptr) + continue; + if (!_is_valid_element(support_type, (char*)tmpdata->name)) + goto out; + + const char* bundle_key = _get_bundle_key((const char*)tmpdata->name); + if (bundle_key == nullptr) { + LOGE("wrong element name (%s)", (const char*)tmpdata->name); + goto out; + } - bundle_key = _get_bundle_key((const char*)tmpdata->name); - if (bundle_key == NULL) { - LOGE("wrong element name (%s)", (const char*)tmpdata->name); + string default_value; + if (strcmp(bundle_key, TIME_KEY) == 0) { + string prev_value = default_data.GetString(TIME_KEY); + + char* dup_val = nullptr; + ret = _get_time_value( + (const char*)tmpdata->name, + (const char*)tmpdata->children->content, + prev_value, &dup_val); + if (ret != WATCHFACE_COMPLICATION_ERROR_NONE) goto out; - } - - if (strcmp(bundle_key, TIME_KEY) == 0) { - prev_value = NULL; - bundle_get_str(default_data, TIME_KEY, &prev_value); - ret = _get_time_value( - (const char*)tmpdata->name, - (const char*)tmpdata->children->content, - prev_value, &dup_val); - if (ret != WATCHFACE_COMPLICATION_ERROR_NONE) - goto out; - - default_value = dup_val; - if (prev_value) - bundle_del(default_data, TIME_KEY); - } else { - default_value = reinterpret_cast(tmpdata->children->content); - } - - ret = bundle_add_str(default_data, bundle_key, default_value); + + default_value = string(dup_val); free(dup_val); - dup_val = NULL; - if (ret != BUNDLE_ERROR_NONE) { - LOGE("bundle add error : %d", ret); - goto out; - } + + if (!prev_value.empty()) + default_data.Delete(TIME_KEY); + } else { + default_value = + string(reinterpret_cast(tmpdata->children->content)); } - } - ret = bundle_encode(default_data, &raw, &len); - if (ret != BUNDLE_ERROR_NONE) { - LOGE("bundle encode error %d", ret); - goto out; + ret = default_data.Add(bundle_key, default_value); + if (ret != BUNDLE_ERROR_NONE) { + LOGE("bundle add error : %d", ret); + goto out; + } } - idx = 1; - + int idx = 1; ret = sqlite3_bind_text(stmt, idx++, pkgid, -1, SQLITE_TRANSIENT); if (ret != SQLITE_OK) { LOGE("sqlite3_bind_text() error: %d(%s)", ret, sqlite3_errmsg(db)); @@ -436,7 +418,9 @@ static int _parse_support_type(xmlNode* node, sqlite3* db, const char* pkgid, goto out; } - ret = sqlite3_bind_text(stmt, idx, (char*)raw, -1, SQLITE_TRANSIENT); + ret = sqlite3_bind_text(stmt, idx, + reinterpret_cast(default_data.ToRaw().first.get()), + -1, SQLITE_TRANSIENT); if (ret != SQLITE_OK) { LOGE("sqlite3_bind_text() error: %d(%s)", ret, sqlite3_errmsg(db)); goto out; @@ -455,26 +439,10 @@ static int _parse_support_type(xmlNode* node, sqlite3* db, const char* pkgid, } sqlite3_clear_bindings(stmt); - - if (raw) { - free(raw); - raw = NULL; - } - - if (default_data) { - bundle_free(default_data); - default_data = NULL; - } } ret = 0; out: - if (default_data) - bundle_free(default_data); - - if (raw) - free(raw); - if (stmt) sqlite3_finalize(stmt); diff --git a/unittest/src/test-complication-bundle.cc b/unittest/src/test-complication-bundle.cc deleted file mode 100644 index dc8352e..0000000 --- a/unittest/src/test-complication-bundle.cc +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright (c) 2018 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include - -#include "watchface-complication/complication-bundle.h" -#include "watchface-complication/complication-connector.h" - -using namespace std; -using namespace watchface_complication; - -class BUNDLE : public ::testing::Test { - public: - Bundle *b = nullptr; - virtual void SetUp() { - b = new Bundle(); - } - virtual void TearDown() { - delete b; - } -}; - -TEST_F(BUNDLE, Create1) -{ - EXPECT_NE(BUNDLE::b, nullptr); -} - -TEST_F(BUNDLE, Create2) -{ - int len = 0; - bundle *data; - bundle_raw *raw_data; - - data = bundle_create(); - bundle_encode(data, &raw_data, &len); - - Bundle *b = new Bundle(std::string(reinterpret_cast(raw_data))); - EXPECT_NE(b, nullptr); - - bundle_free(data); - free(raw_data); - delete b; -} - -TEST_F(BUNDLE, Create3) -{ - bundle *data; - - data = bundle_create(); - - Bundle *b = new Bundle(data); - EXPECT_NE(b, nullptr); - - bundle_free(data); - delete b; -} - -TEST_F(BUNDLE, GetRaw) -{ - EXPECT_NE(BUNDLE::b->GetConstRaw(), nullptr); - EXPECT_NE(BUNDLE::b->GetRaw(), nullptr); -} - -TEST_F(BUNDLE, ToString) -{ - EXPECT_NE(BUNDLE::b->ToString(), ""); -} - -TEST_F(BUNDLE, Copy) -{ - Bundle b; - bundle_add_str(b.GetRaw(), "TEST_KEY", "TEST_VALUE"); - - char* value; - Bundle b2 = b; - bundle_get_str(b2.GetRaw(), "TEST_KEY", &value); - EXPECT_STREQ(value, "TEST_VALUE"); -} - -TEST_F(BUNDLE, Copy2) -{ - Bundle b; - bundle_add_str(b.GetRaw(), "TEST_KEY", "TEST_VALUE"); - - char* value; - Bundle b2; - b2 = b; - bundle_get_str(b2.GetRaw(), "TEST_KEY", &value); - EXPECT_STREQ(value, "TEST_VALUE"); -} - -TEST_F(BUNDLE, Move) -{ - Bundle b; - bundle_add_str(b.GetRaw(), "TEST_KEY", "TEST_VALUE"); - - char* value; - Bundle b2 = std::move(b); - bundle_get_str(b2.GetRaw(), "TEST_KEY", &value); - EXPECT_STREQ(value, "TEST_VALUE"); -} - -TEST_F(BUNDLE, Move2) -{ - Bundle b; - bundle_add_str(b.GetRaw(), "TEST_KEY", "TEST_VALUE"); - - char* value; - Bundle b2; - b2 = std::move(b); - bundle_get_str(b2.GetRaw(), "TEST_KEY", &value); - EXPECT_STREQ(value, "TEST_VALUE"); -} \ No newline at end of file diff --git a/unittest/src/test-complication-provider.cc b/unittest/src/test-complication-provider.cc index 615d4a2..aba3f92 100644 --- a/unittest/src/test-complication-provider.cc +++ b/unittest/src/test-complication-provider.cc @@ -58,7 +58,7 @@ TEST_F(WCP, Create) TEST_F(WCP, GetProviderId) { - EXPECT_EQ(WCP::provider->GetProviderId(), providerId.c_str()); + EXPECT_STREQ(WCP::provider->GetProviderId().c_str(), providerId.c_str()); } diff --git a/unittest/src/test-complication.cc b/unittest/src/test-complication.cc index 8cc6217..cb51b72 100644 --- a/unittest/src/test-complication.cc +++ b/unittest/src/test-complication.cc @@ -38,6 +38,7 @@ using namespace std; +using namespace tizen_base; using namespace watchface_complication; namespace { GMainLoop* loop_ = NULL; @@ -309,7 +310,7 @@ guint __fake_signal_subscribe_on_data_updated(GDBusConnection* connection, GVariant* parameters = g_variant_new("(siis)", "org.tizen.gmock_comp_provider2/test", ShortText, 4, - b.ToString()); + b.ToRaw().first.get()); callback(nullptr, "org.tizen.gmock_comp_provider2", "test path", "test interface", @@ -409,21 +410,21 @@ TEST_F(WC, SetCandidates) WatchComplication* comp = new WatchComplication(1, default_type, EventTap, providerId2.c_str(), ShortText); comp->Init(); - std::list> candidates_list; - EXPECT_EQ(comp->SetCandidates(std::move(candidates_list)), 0); + std::list> candidates_list; + EXPECT_EQ(comp->SetCandidates(candidates_list), 0); delete comp; } TEST_F(WC, GetCurData) { - const Bundle* data = WC::complication->GetCurData(); - EXPECT_NE(data, nullptr); + shared_ptr data = WC::complication->GetCurData(); + EXPECT_NE(data.get(), nullptr); } TEST_F(WC, GetNthData) { - const Bundle* data = WC::complication->GetNthData(0); - EXPECT_NE(data, nullptr); + shared_ptr data = WC::complication->GetNthData(0); + EXPECT_NE(data.get(), nullptr); } int __fake_pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h, @@ -483,10 +484,10 @@ TEST_F(WC, Disabled) WatchComplication* comp = new WatchComplication(1, default_type, EventTap, providerId2.c_str(), ShortText); comp->Init(); - std::list> const& list = comp->GetCandidates(); + std::list> const& list = comp->GetCandidates(); for (unsigned int i = 0; i < list.size(); i++) { comp->SetCurDataIdx(i); - if (strcmp(comp->GetCurProviderId(), "org.tizen.gmock_comp_provider2/test") == 0) + if (comp->GetCurProviderId() == "org.tizen.gmock_comp_provider2/test") break; } comp->not_available_ = false; @@ -506,10 +507,10 @@ TEST_F(WC, DisabledRecovery) WatchComplication* comp = new WatchComplication(4, default_type, EventTap, providerId3.c_str(), ShortText); comp->Init(); - std::list> const& list = comp->GetCandidates(); + std::list> const& list = comp->GetCandidates(); for (unsigned int i = 0; i < list.size(); i++) { comp->SetCurDataIdx(i); - if (strcmp(comp->GetCurProviderId(), WC::providerId2.c_str()) == 0) + if (comp->GetCurProviderId() == WC::providerId2) break; } @@ -519,23 +520,22 @@ TEST_F(WC, DisabledRecovery) comp->SetTestType(WatchComplication::Error); comp1->SetTestType(WatchComplication::Error); RunLoop(); - EXPECT_EQ(strcmp(comp->GetCurProviderId(), WC::providerId3.c_str()), 0); + EXPECT_STREQ(comp->GetCurProviderId().c_str(), WC::providerId3.c_str()); delete comp; delete comp1; } TEST_F(WC, GetProviderId) { - const Bundle* data = WC::complication->GetCurData(); - const char* provider_id = WC::complication->GetProviderId(data); - EXPECT_EQ(strcmp(complication->GetCurProviderId(), provider_id), 0); + shared_ptr data = WC::complication->GetCurData(); + string provider_id = WC::complication->GetProviderId(*data); + EXPECT_STREQ(complication->GetCurProviderId().c_str(), provider_id.c_str()); } TEST_F(WC, GetProviderType) { - const Bundle* data = WC::complication->GetCurData(); - - EXPECT_EQ(WC::complication->GetProviderType(data), WC::complication->GetCurType()); + shared_ptr data = WC::complication->GetCurData(); + EXPECT_EQ(WC::complication->GetProviderType(*data), WC::complication->GetCurType()); } TEST_F(WC, GetSetupAppId) @@ -556,33 +556,27 @@ TEST_F(WC, GetPrivilegeErrorKey) TEST_F(WC, SetContext) { - bundle* b = bundle_create(); - bundle_add_str(b, "TEST_KEY", "TEST_VALUE"); + Bundle* bundle = new Bundle(); + bundle->Add("TEST_KEY", "TEST_VALUE"); - Bundle* bundle = new Bundle(b); - bundle_free(b); WC::complication->SetContext(std::unique_ptr(bundle)); std::unique_ptr& ctx = WC::complication->GetContext(); - char* value; - bundle_get_str(ctx.get()->GetRaw(), "TEST_KEY", &value); - EXPECT_STREQ(value, "TEST_VALUE"); + string value = ctx.get()->GetString("TEST_KEY"); + EXPECT_STREQ(value.c_str(), "TEST_VALUE"); } TEST_F(WC, GetLastContext) { - bundle* b = bundle_create(); - bundle_add_str(b, "TEST_KEY", "TEST_VALUE"); + Bundle* bundle = new Bundle(); + bundle->Add("TEST_KEY", "TEST_VALUE"); - Bundle* bundle = new Bundle(b); - bundle_free(b); WC::complication->SetContext(std::unique_ptr(bundle)); WC::complication->UpdateLastContext(); std::unique_ptr& ctx = WC::complication->GetLastContext(); - char* value; - bundle_get_str(ctx.get()->GetRaw(), "TEST_KEY", &value); - EXPECT_STREQ(value, "TEST_VALUE"); + string value = ctx.get()->GetString("TEST_KEY"); + EXPECT_STREQ(value.c_str(), "TEST_VALUE"); } TEST_F(WC, DuplicateID) @@ -607,7 +601,7 @@ TEST_F(WC, ApplyAllowedList) int ret = WC::complication->ApplyAllowedList(std::move(allowed_list)); EXPECT_EQ(ret, WATCHFACE_COMPLICATION_ERROR_NONE); - std::list> const& list = complication->GetCandidates(); + std::list> const& list = complication->GetCandidates(); EXPECT_EQ(1, list.size()); } @@ -620,7 +614,7 @@ TEST_F(WC, ClearAllowedList) int ret = WC::complication->ClearAllowedList(); EXPECT_EQ(ret, WATCHFACE_COMPLICATION_ERROR_NONE); - std::list> const& list = complication->GetCandidates(); + std::list> const& list = complication->GetCandidates(); EXPECT_EQ(true, list.size() > 0); } diff --git a/unittest/src/test-design-element.cc b/unittest/src/test-design-element.cc index 1454107..bad826a 100644 --- a/unittest/src/test-design-element.cc +++ b/unittest/src/test-design-element.cc @@ -13,24 +13,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -#include +#include +#include +#include #include #include + +#include #include #include - -#include -#include -#include +#include #include #include #include "watchface-complication/design-element.h" -#include "watchface-complication/complication-bundle.h" using namespace std; +using namespace tizen_base; using namespace watchface_complication; class Element : public DesignElement { @@ -50,13 +50,13 @@ class Element : public DesignElement { class DE : public ::testing::Test { public: Element* element = NULL; - std::list> candidatesList; + std::list> candidates; virtual void SetUp() { - candidatesList.emplace_back(std::unique_ptr(new Bundle())); + candidates.emplace_back(std::shared_ptr(new Bundle())); element = new Element(0, 0); - element->SetCandidates(std::move(candidatesList)); + element->SetCandidates(candidates); } virtual void TearDown() { delete element; @@ -79,17 +79,17 @@ TEST_F(DE, GetGeo) TEST_F(DE, GetCandidates) { - std::list> const& list = DE::element->GetCandidates(); + std::list> const& list = DE::element->GetCandidates(); EXPECT_NE(list.empty(), true); } TEST_F(DE, GetData) { - const Bundle* curData = DE::element->GetCurData(); - const Bundle* nthData = DE::element->GetNthData(0); + shared_ptr curData = DE::element->GetCurData(); + shared_ptr nthData = DE::element->GetNthData(0); - EXPECT_NE(curData->GetConstRaw(), nullptr); - EXPECT_NE(nthData->GetConstRaw(), nullptr); + EXPECT_NE(curData->GetHandle(), nullptr); + EXPECT_NE(nthData->GetHandle(), nullptr); } TEST_F(DE, DataIdx) @@ -141,31 +141,23 @@ TEST_F(DE, GetSetupAppId) TEST_F(DE, SetContext) { - bundle* b = bundle_create(); - bundle_add_str(b, "TEST_KEY", "TEST_VALUE"); - - Bundle* bundle = new Bundle(b); - bundle_free(b); + Bundle* bundle = new Bundle(); + bundle->Add("TEST_KEY", "TEST_VALUE"); DE::element->SetContext(std::unique_ptr(bundle)); std::unique_ptr& ctx = DE::element->GetContext(); - char* value; - bundle_get_str(ctx.get()->GetRaw(), "TEST_KEY", &value); - EXPECT_STREQ(value, "TEST_VALUE"); + string value = ctx.get()->GetString("TEST_KEY"); + EXPECT_STREQ(value.c_str(), "TEST_VALUE"); } TEST_F(DE, GetLastContext) { - bundle* b = bundle_create(); - bundle_add_str(b, "TEST_KEY", "TEST_VALUE"); - - Bundle* bundle = new Bundle(b); - bundle_free(b); + Bundle* bundle = new Bundle(); + bundle->Add("TEST_KEY", "TEST_VALUE"); DE::element->SetContext(std::unique_ptr(bundle)); DE::element->UpdateLastContext(); std::unique_ptr& ctx = DE::element->GetLastContext(); - char* value; - bundle_get_str(ctx.get()->GetRaw(), "TEST_KEY", &value); - EXPECT_STREQ(value, "TEST_VALUE"); + string value = ctx.get()->GetString("TEST_KEY"); + EXPECT_STREQ(value.c_str(), "TEST_VALUE"); } \ No newline at end of file diff --git a/unittest/src/test-editables-container.cc b/unittest/src/test-editables-container.cc index fe3f31f..72341b9 100644 --- a/unittest/src/test-editables-container.cc +++ b/unittest/src/test-editables-container.cc @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -39,6 +40,7 @@ #include "unittest/mock/pkgmgr_mock.h" using namespace std; +using namespace tizen_base; using namespace watchface_complication; namespace { unsigned int event_timer__; @@ -103,53 +105,42 @@ guint __fake_g_dbus_connection_signal_subscribe(GDBusConnection* connection, class EC : public ::testing::Test { public: MyContainer* container; - ReceivedEditable* received; + shared_ptr received; virtual void SetUp() { g_dbus_connection_signal_subscribe_fake.custom_fake = __fake_g_dbus_connection_signal_subscribe; ec_loop_ = g_main_loop_new(nullptr, FALSE); - bundle* data; - bundle_raw* raw_data; pkgmgr_client_listen_status_fake.custom_fake = __fake_pkgmgr_client_listen_status; - Bundle* candidate1 = new Bundle(); - Bundle* candidate2 = new Bundle(); - std::unique_ptr array(new const char*[2]); - - data = bundle_create(); - bundle_add_str(data, "GEO_X", std::to_string(0).c_str()); - bundle_add_str(data, "GEO_Y", std::to_string(0).c_str()); - bundle_add_str(data, "GEO_W", std::to_string(100).c_str()); - bundle_add_str(data, "GEO_H", std::to_string(100).c_str()); - bundle_add_str(data, "SHAPE_TYPE", - std::to_string(IEditable::EditableShapeType::Circle).c_str()); - bundle_add_str(data, "CUR_DATA_IDX", std::to_string(0).c_str()); - bundle_add_str(data, "NAME", "sample"); - bundle_add_str(data, "EDITABLE_ID", std::to_string(0).c_str()); - bundle_add_str(data, "SETUP_APPID", ""); - - array.get()[0] = candidate1->ToString(); - array.get()[1] = candidate2->ToString(); - - bundle_add_str_array(data, "CANDIDATES_LIST", array.get(), 2); - - int len = 0; - bundle_encode(data, &raw_data, &len); - - received = new ReceivedEditable( - std::string(reinterpret_cast(raw_data))); + Bundle data; + data.Add("GEO_X", std::to_string(0)); + data.Add("GEO_Y", std::to_string(0)); + data.Add("GEO_W", std::to_string(100)); + data.Add("GEO_H", std::to_string(100)); + data.Add("SHAPE_TYPE", + std::to_string(IEditable::EditableShapeType::Circle)); + data.Add("CUR_DATA_IDX", std::to_string(0)); + data.Add("NAME", "sample"); + data.Add("EDITABLE_ID", std::to_string(0)); + data.Add("SETUP_APPID", ""); + + Bundle candidate1; + Bundle candidate2; + vector candidates_list; + candidates_list.push_back( + reinterpret_cast(candidate1.ToRaw().first.get())); + candidates_list.push_back( + reinterpret_cast(candidate2.ToRaw().first.get())); + data.Add("CANDIDATES_LIST", candidates_list); + + received = shared_ptr(new ReceivedEditable( + reinterpret_cast(data.ToRaw().first.get()))); container = new MyContainer(); - - delete candidate1; - delete candidate2; - bundle_free(data); - free(raw_data); } virtual void TearDown() { - delete received; delete container; if (event_timer__ != 0) { @@ -172,43 +163,8 @@ TEST_F(EC, Create) TEST_F(EC, AddRemove) { - int len = 0; - bundle* data; - bundle_raw* raw_data; - - Bundle* candidate1 = new Bundle(); - Bundle* candidate2 = new Bundle(); - std::unique_ptr array(new const char*[2]); - - data = bundle_create(); - bundle_add_str(data, "GEO_X", std::to_string(0).c_str()); - bundle_add_str(data, "GEO_Y", std::to_string(0).c_str()); - bundle_add_str(data, "GEO_W", std::to_string(100).c_str()); - bundle_add_str(data, "GEO_H", std::to_string(100).c_str()); - bundle_add_str(data, "SHAPE_TYPE", - std::to_string(IEditable::EditableShapeType::Circle).c_str()); - bundle_add_str(data, "CUR_DATA_IDX", std::to_string(0).c_str()); - bundle_add_str(data, "NAME", "sample"); - bundle_add_str(data, "EDITABLE_ID", std::to_string(0).c_str()); - bundle_add_str(data, "SETUP_APPID", ""); - - array.get()[0] = candidate1->ToString(); - array.get()[1] = candidate2->ToString(); - bundle_add_str_array(data, "CANDIDATES_LIST", array.get(), 2); - - bundle_encode(data, &raw_data, &len); - - ReceivedEditable* re = - new ReceivedEditable(std::string(reinterpret_cast(raw_data))); - std::shared_ptr ed = static_cast>(re); - - delete candidate1; - delete candidate2; - bundle_free(data); - free(raw_data); - - EXPECT_EQ(EC::container->Add(ed, 1), 0); - EXPECT_EQ(EC::container->Remove(ed), 0); + EXPECT_EQ(EC::container->Add(received, 1), 0); + EXPECT_EQ(EC::container->Remove(received), 0); } guint __fake_signal_subscribe_on_update(GDBusConnection* connection, @@ -235,7 +191,7 @@ guint __fake_signal_subscribe_on_update(GDBusConnection* connection, "__EDITABLE_EDIT_READY__", parameters); - parameters = g_variant_new("(iis)", 0, 0, b.ToString()); + parameters = g_variant_new("(iis)", 0, 0, b.ToRaw().first.get()); rs->OnSignal(nullptr, "org.tizen.editor", "test path", "test interface", @@ -246,7 +202,7 @@ guint __fake_signal_subscribe_on_update(GDBusConnection* connection, "test interface", "__EDITABLE_EDIT_CANCEL__", parameters); - parameters = g_variant_new("(iis)", 0, 0, b.ToString()); + parameters = g_variant_new("(iis)", 0, 0, b.ToRaw().first.get()); rs->OnSignal(nullptr, "org.tizen.editor", "test path", "test interface", diff --git a/unittest/src/test-editables-manager.cc b/unittest/src/test-editables-manager.cc index 3feccdf..1aca516 100644 --- a/unittest/src/test-editables-manager.cc +++ b/unittest/src/test-editables-manager.cc @@ -30,6 +30,7 @@ #include "watchface-complication/editables-manager.h" using namespace std; +using namespace tizen_base; using namespace watchface_complication; class EDITABLES_MANAGER : public ::testing::Test { @@ -42,11 +43,8 @@ class EDITABLES_MANAGER : public ::testing::Test { TEST_F(EDITABLES_MANAGER, StoreContext) { - bundle* b = bundle_create(); - bundle_add_str(b, "TEST_KEY", "TEST_VALUE"); - - Bundle bundle(b); - bundle_free(b); + Bundle* bundle = new Bundle(); + bundle->Add("TEST_KEY", "TEST_VALUE"); EditablesManager::GetInst(true).StoreContext(10, "org.tizen.mock_provider/test", bundle); int ret = EditablesManager::GetInst(true).DeleteContext( diff --git a/unittest/src/test-editor.cc b/unittest/src/test-editor.cc index 3a7f489..dcd77bb 100644 --- a/unittest/src/test-editor.cc +++ b/unittest/src/test-editor.cc @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -29,6 +30,7 @@ #include "unittest/mock/cynara_mock.h" using namespace std; +using namespace tizen_base; using namespace watchface_complication; int __cynara_initialize( @@ -50,17 +52,20 @@ int __cynara_check(cynara* c, const char* client, const char* client_session, class WE : public ::testing::Test { public: EditablesEditor* editor; - + ReceivedEditable* received; virtual void SetUp(){ cynara_initialize_fake.custom_fake = __cynara_initialize; cynara_finish_fake.custom_fake = __cynara_finish; cynara_check_fake.custom_fake = __cynara_check; - + received = nullptr; editor = new EditablesEditor(true); } virtual void TearDown(){ - delete editor; + if (received) + delete received; + if (editor) + delete editor; } }; @@ -75,75 +80,34 @@ TEST_F(WE, Create) TEST_F(WE, EditPreview) { int cur_data_idx = 1; - int len = 0; - bundle* data; - bundle_raw* raw_data; - - data = bundle_create(); - bundle_add_str(data, "GEO_X", std::to_string(0).c_str()); - bundle_add_str(data, "GEO_Y", std::to_string(0).c_str()); - bundle_add_str(data, "GEO_W", std::to_string(100).c_str()); - bundle_add_str(data, "GEO_H", std::to_string(100).c_str()); - bundle_add_str(data, "SHAPE_TYPE", std::to_string(IEditable::EditableShapeType::Circle).c_str()); - bundle_add_str(data, "CUR_DATA_IDX", std::to_string(0).c_str()); - bundle_add_str(data, "EDITABLE_ID", std::to_string(0).c_str()); - bundle_add_str(data, "NAME", "sample"); - bundle_add_str(data, "SETUP_APPID", ""); - bundle_encode(data, &raw_data, &len); - - ReceivedEditable* re = new ReceivedEditable(std::string(reinterpret_cast(raw_data))); - IEditable* ed = static_cast(re); + Bundle data; + data.Add("GEO_X", std::to_string(0)); + data.Add("GEO_Y", std::to_string(0)); + data.Add("GEO_W", std::to_string(100)); + data.Add("GEO_H", std::to_string(100)); + data.Add("SHAPE_TYPE", + std::to_string(IEditable::EditableShapeType::Circle)); + data.Add("CUR_DATA_IDX", std::to_string(0)); + data.Add("NAME", "sample"); + data.Add("EDITABLE_ID", std::to_string(0)); + data.Add("SETUP_APPID", ""); + + Bundle candidate1; + Bundle candidate2; + vector candidates_list; + candidates_list.push_back( + reinterpret_cast(candidate1.ToRaw().first.get())); + candidates_list.push_back( + reinterpret_cast(candidate2.ToRaw().first.get())); + data.Add("CANDIDATES_LIST", candidates_list); + + received = new ReceivedEditable( + reinterpret_cast(data.ToRaw().first.get())); + IEditable* ed = static_cast(received); EXPECT_EQ(WE::editor->EditPreview(*ed, cur_data_idx), WATCHFACE_COMPLICATION_ERROR_EDIT_NOT_READY); - - delete re; - bundle_free(data); - free(raw_data); } TEST_F(WE, NotifyEditReady) { EXPECT_EQ(WE::editor->NotifyEditReady("sample_provider"), 0); -} - -class WEL : public ::testing::Test { - public: - GList* editables = NULL; - ReceivedEditable* received; - bundle_raw* raw_data; - int len = 0; - - virtual void SetUp(){ - Bundle* candidate1 = new Bundle(); - Bundle* candidate2 = new Bundle(); - std::unique_ptr array(new const char*[2]); - - bundle* data = bundle_create(); - bundle_add_str(data, "GEO_X", std::to_string(0).c_str()); - bundle_add_str(data, "GEO_Y", std::to_string(0).c_str()); - bundle_add_str(data, "GEO_W", std::to_string(100).c_str()); - bundle_add_str(data, "GEO_H", std::to_string(100).c_str()); - bundle_add_str(data, "SHAPE_TYPE", std::to_string(IEditable::EditableShapeType::Circle).c_str()); - bundle_add_str(data, "CUR_DATA_IDX", std::to_string(0).c_str()); - bundle_add_str(data, "EDITABLE_ID", std::to_string(0).c_str()); - bundle_add_str(data, "NAME", "sample"); - bundle_add_str(data, "SETUP_APPID", ""); - - array.get()[0] = candidate1->ToString(); - array.get()[1] = candidate2->ToString(); - - bundle_add_str_array(data, "CANDIDATES_LIST", array.get(), 2); - - bundle_encode(data, &raw_data, &len); - received = new ReceivedEditable(std::string(reinterpret_cast(raw_data))); - editables = g_list_append(editables, received); - - delete candidate1; - delete candidate2; - bundle_free(data); - free(raw_data); - } - virtual void TearDown(){ - delete received; - g_list_free(editables); - } -}; \ No newline at end of file +} \ No newline at end of file diff --git a/unittest/src/test-received-editable.cc b/unittest/src/test-received-editable.cc index d37d01a..447852f 100644 --- a/unittest/src/test-received-editable.cc +++ b/unittest/src/test-received-editable.cc @@ -19,11 +19,12 @@ #include #include #include -#include +#include #include #include #include +#include #include #include @@ -31,43 +32,37 @@ #include "watchface-complication/received-editable.h" using namespace std; +using namespace tizen_base; using namespace watchface_complication; class RE : public ::testing::Test { public: ReceivedEditable* received; - bundle* data; - bundle_raw* raw_data; - int len = 0; virtual void SetUp() { - Bundle* candidate1 = new Bundle(); - Bundle* candidate2 = new Bundle(); - std::unique_ptr array(new const char*[2]); - - data = bundle_create(); - - bundle_add_str(data, "GEO_X", std::to_string(0).c_str()); - bundle_add_str(data, "GEO_Y", std::to_string(0).c_str()); - bundle_add_str(data, "GEO_W", std::to_string(100).c_str()); - bundle_add_str(data, "GEO_H", std::to_string(100).c_str()); - bundle_add_str(data, "SHAPE_TYPE", std::to_string(IEditable::EditableShapeType::Circle).c_str()); - bundle_add_str(data, "CUR_DATA_IDX", std::to_string(0).c_str()); - bundle_add_str(data, "EDITABLE_ID", std::to_string(0).c_str()); - bundle_add_str(data, "NAME", "sample"); - bundle_add_str(data, "SETUP_APPID", "org.tizen.setup"); - - array.get()[0] = candidate1->ToString(); - array.get()[1] = candidate2->ToString(); - - bundle_add_str_array(data, "CANDIDATES_LIST", array.get(), 2); - - bundle_encode(data, &raw_data, &len); - received = new ReceivedEditable(std::string(reinterpret_cast(raw_data))); - - delete candidate1; - delete candidate2; - free(raw_data); + Bundle data; + data.Add("GEO_X", std::to_string(0).c_str()); + data.Add("GEO_Y", std::to_string(0).c_str()); + data.Add("GEO_W", std::to_string(100).c_str()); + data.Add("GEO_H", std::to_string(100).c_str()); + data.Add("SHAPE_TYPE", + std::to_string(IEditable::EditableShapeType::Circle).c_str()); + data.Add("CUR_DATA_IDX", std::to_string(0).c_str()); + data.Add("NAME", "sample"); + data.Add("EDITABLE_ID", std::to_string(0).c_str()); + data.Add("SETUP_APPID", "org.tizen.setup"); + + Bundle candidate1; + Bundle candidate2; + vector candidates_list; + candidates_list.push_back( + reinterpret_cast(candidate1.ToRaw().first.get())); + candidates_list.push_back( + reinterpret_cast(candidate2.ToRaw().first.get())); + data.Add("CANDIDATES_LIST", candidates_list); + + received = new ReceivedEditable( + reinterpret_cast(data.ToRaw().first.get())); } virtual void TearDown() { delete received; @@ -90,17 +85,17 @@ TEST_F(RE, GetGeometry) TEST_F(RE, GetCandidates) { - std::list> const& list = RE::received->GetCandidates(); + std::list> const& list = RE::received->GetCandidates(); EXPECT_NE(list.empty(), true); } TEST_F(RE, GetData) { - const Bundle* curData = RE::received->GetCurData(); - const Bundle* nthData = RE::received->GetNthData(1); + shared_ptr curData = RE::received->GetCurData(); + shared_ptr nthData = RE::received->GetNthData(1); - EXPECT_NE(curData->GetConstRaw(), nullptr); - EXPECT_NE(nthData->GetConstRaw(), nullptr); + EXPECT_NE(curData->GetHandle(), nullptr); + EXPECT_NE(nthData->GetHandle(), nullptr); } TEST_F(RE, DataIdx) @@ -139,18 +134,14 @@ TEST_F(RE, OnEditableUpdated) TEST_F(RE, SetContext) { - bundle* b = bundle_create(); - bundle_add_str(b, "TEST_KEY", "TEST_VALUE"); - - Bundle* bundle = new Bundle(b); - bundle_free(b); + Bundle* bundle = new Bundle(); + bundle->Add("TEST_KEY", "TEST_VALUE"); RE::received->SetContext(std::unique_ptr(bundle)); std::unique_ptr& ctx = RE::received->GetContext(); RE::received->UpdateLastContext(); - char* value; - bundle_get_str(ctx.get()->GetRaw(), "TEST_KEY", &value); - EXPECT_STREQ(value, "TEST_VALUE"); + string value = ctx.get()->GetString("TEST_KEY"); + EXPECT_STREQ(value.c_str(), "TEST_VALUE"); } TEST_F(RE, SetHighlight) @@ -188,20 +179,14 @@ TEST_F(RE, GetSetupAppId) EXPECT_STREQ(RE::received->GetSetupAppId().c_str(), "org.tizen.setup"); } - TEST_F(RE, GetLastContext) { - bundle* b = bundle_create(); - bundle_add_str(b, "TEST_KEY", "TEST_VALUE"); - - Bundle* bundle = new Bundle(b); - bundle_free(b); + Bundle* bundle = new Bundle(); + bundle->Add("TEST_KEY", "TEST_VALUE"); RE::received->SetContext(std::unique_ptr(bundle)); RE::received->UpdateLastContext(); - char* value; - std::unique_ptr& last_ctx = RE::received->GetLastContext(); - bundle_get_str(last_ctx.get()->GetRaw(), "TEST_KEY", &value); - EXPECT_STREQ(value, "TEST_VALUE"); + string value = last_ctx.get()->GetString("TEST_KEY"); + EXPECT_STREQ(value.c_str(), "TEST_VALUE"); } diff --git a/unittest/src/test-watchface-complication-provider.cc b/unittest/src/test-watchface-complication-provider.cc index fccbf34..4336249 100644 --- a/unittest/src/test-watchface-complication-provider.cc +++ b/unittest/src/test-watchface-complication-provider.cc @@ -35,6 +35,7 @@ using namespace std; +using namespace tizen_base; using namespace watchface_complication; namespace { @@ -98,9 +99,9 @@ guint __fake_signal_subscribe_on_update(GDBusConnection* connection, IGDBus::IGDBusEvent* rs = static_cast(user_data); Bundle b; string sender_name = "org.tizen.gmock_comp_provider2"; - bundle_add_str(b.GetRaw(), "context", "test"); + b.Add("context", "test"); GVariant* parameters = g_variant_new("(siis)", - "org.tizen.gmock_comp_provider2", 1, Icon, b.ToString()); + "org.tizen.gmock_comp_provider2", 1, Icon, b.ToRaw().first.get()); rs->OnSignal(nullptr, sender_name, "test path", diff --git a/unittest/src/test-watchface-complication.cc b/unittest/src/test-watchface-complication.cc index 912317c..7b2ac34 100644 --- a/unittest/src/test-watchface-complication.cc +++ b/unittest/src/test-watchface-complication.cc @@ -29,6 +29,7 @@ #include "unittest/mock/aul_mock.h" using namespace std; +using namespace tizen_base; using namespace watchface_complication; namespace { @@ -295,21 +296,22 @@ guint __fake_signal_subscribe_on_data_updated(GDBusConnection* connection, Bundle b; char num_str[32] = {0, }; snprintf(num_str, sizeof(num_str), "%d", ShortText); - bundle_add_str(b.GetRaw(), "__DATA_TYPE_KEY__", num_str); - watchface_complication_provider_data_set_short_text(b.GetRaw(), "shorttext"); - watchface_complication_provider_data_set_title(b.GetRaw(), "title"); - watchface_complication_provider_data_set_icon_path(b.GetRaw(), "data/icon.png"); + b.Add("__DATA_TYPE_KEY__", num_str); + watchface_complication_provider_data_set_short_text(b.GetHandle(), "shorttext"); + watchface_complication_provider_data_set_title(b.GetHandle(), "title"); + watchface_complication_provider_data_set_icon_path(b.GetHandle(), "data/icon.png"); + Bundle extra; - bundle_add_str(extra.GetRaw(), "extra_key", "extra_data"); + extra.Add("extra_key", "extra_data"); watchface_complication_provider_data_set_extra_data( - b.GetRaw(), extra.ToString()); + b.GetHandle(), reinterpret_cast(extra.ToRaw().first.get())); watchface_complication_provider_data_set_screen_reader_text( - b.GetRaw(), "screen reader"); + b.GetHandle(), "screen reader"); GVariant* parameters = g_variant_new("(siis)", "org.tizen.gmock_comp_provider/test", ShortText, 777, - b.ToString()); + reinterpret_cast(b.ToRaw().first.get())); rs->OnSignal(nullptr, "org.tizen.gmock_comp_provider", "test path", @@ -317,59 +319,59 @@ guint __fake_signal_subscribe_on_data_updated(GDBusConnection* connection, "__COMP_UPDATED__", parameters); - bundle_del(b.GetRaw(), "__DATA_TYPE_KEY__"); + b.Delete("__DATA_TYPE_KEY__"); snprintf(num_str, sizeof(num_str), "%d", LongText); - bundle_add_str(b.GetRaw(), "__DATA_TYPE_KEY__", num_str); - watchface_complication_provider_data_set_long_text(b.GetRaw(), "longtext"); + b.Add("__DATA_TYPE_KEY__", num_str); + watchface_complication_provider_data_set_long_text(b.GetHandle(), "longtext"); parameters = g_variant_new("(siis)", "org.tizen.gmock_comp_provider/test", LongText, 777, - b.ToString()); + reinterpret_cast(b.ToRaw().first.get())); rs->OnSignal(nullptr, "org.tizen.gmock_comp_provider", "test path", "test interface", "__COMP_UPDATED__", parameters); - bundle_del(b.GetRaw(), "__DATA_TYPE_KEY__"); + b.Delete("__DATA_TYPE_KEY__"); snprintf(num_str, sizeof(num_str), "%d", RangedValue); - bundle_add_str(b.GetRaw(), "__DATA_TYPE_KEY__", num_str); + b.Add("__DATA_TYPE_KEY__", num_str); watchface_complication_provider_data_set_ranged_value( - b.GetRaw(), 10.0, 0.0, 100.0); + b.GetHandle(), 10.0, 0.0, 100.0); parameters = g_variant_new("(siis)", "org.tizen.gmock_comp_provider/test", RangedValue, 777, - b.ToString()); + reinterpret_cast(b.ToRaw().first.get())); rs->OnSignal(nullptr, "org.tizen.gmock_comp_provider", "test path", "test interface", "__COMP_UPDATED__", parameters); - bundle_del(b.GetRaw(), "__DATA_TYPE_KEY__"); + b.Delete("__DATA_TYPE_KEY__"); snprintf(num_str, sizeof(num_str), "%d", Time); - bundle_add_str(b.GetRaw(), "__DATA_TYPE_KEY__", num_str); + b.Add("__DATA_TYPE_KEY__", num_str); watchface_complication_provider_data_set_timestamp( - b.GetRaw(), 10); + b.GetHandle(), 10); parameters = g_variant_new("(siis)", "org.tizen.gmock_comp_provider/test", Time, 777, - b.ToString()); + reinterpret_cast(b.ToRaw().first.get())); rs->OnSignal(nullptr, "org.tizen.gmock_comp_provider", "test path", "test interface", "__COMP_UPDATED__", parameters); - bundle_del(b.GetRaw(), "__DATA_TYPE_KEY__"); + b.Delete("__DATA_TYPE_KEY__"); snprintf(num_str, sizeof(num_str), "%d", Image); - bundle_add_str(b.GetRaw(), "__DATA_TYPE_KEY__", num_str); + b.Add("__DATA_TYPE_KEY__", num_str); watchface_complication_provider_data_set_image_path( - b.GetRaw(), "data/img.png"); + b.GetHandle(), "data/img.png"); parameters = g_variant_new("(siis)", "org.tizen.gmock_comp_provider/test", Image, 777, - b.ToString()); + reinterpret_cast(b.ToRaw().first.get())); rs->OnSignal(nullptr, "org.tizen.gmock_comp_provider", "test path", "test interface", diff --git a/unittest/src/test-watchface-editable.cc b/unittest/src/test-watchface-editable.cc index 08c2e73..48980bf 100644 --- a/unittest/src/test-watchface-editable.cc +++ b/unittest/src/test-watchface-editable.cc @@ -32,6 +32,7 @@ #include "unittest/mock/aul_mock.h" using namespace std; +using namespace tizen_base; using namespace watchface_complication; namespace { @@ -66,7 +67,7 @@ guint __fake_signal_subscribe_on_update(GDBusConnection* connection, "__EDITABLE_EDIT_READY__", parameters); - parameters = g_variant_new("(iis)", 0, 0, b.ToString()); + parameters = g_variant_new("(iis)", 0, 0, b.ToRaw().first.get()); rs->OnSignal(nullptr, "org.tizen.editor", "test path", "test interface", @@ -77,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.ToString()); + parameters = g_variant_new("(iis)", 0, 0, b.ToRaw().first.get()); rs->OnSignal(nullptr, "org.tizen.editor", "test path", "test interface", diff --git a/unittest/src/test-watchface-editor.cc b/unittest/src/test-watchface-editor.cc index 7eddee8..72b6db4 100644 --- a/unittest/src/test-watchface-editor.cc +++ b/unittest/src/test-watchface-editor.cc @@ -17,6 +17,7 @@ #include #include #include +#include #include "watchface-complication/design-element.h" #include "watchface-complication/editables-container.h" @@ -32,6 +33,7 @@ #include "unittest/mock/app_control_mock.h" using namespace std; +using namespace tizen_base; using namespace watchface_complication; namespace { @@ -58,44 +60,45 @@ guint __fake_signal_subscribe_on_update(GDBusConnection* connection, event_timer__ = g_timeout_add(1000, [](gpointer user_data)->gboolean { IGDBus::IGDBusEvent* rs = static_cast(user_data); + Bundle data; + data.Add("GEO_X", std::to_string(0)); + data.Add("GEO_Y", std::to_string(0)); + data.Add("GEO_W", std::to_string(100)); + data.Add("GEO_H", std::to_string(100)); + data.Add("SHAPE_TYPE", + std::to_string(IEditable::EditableShapeType::Circle)); + data.Add("CUR_DATA_IDX", std::to_string(0)); + data.Add("NAME", "sample"); + data.Add("EDITABLE_ID", std::to_string(0)); + data.Add("SETUP_APPID", "org.tizen.setup"); + Bundle candidate1; Bundle candidate2; - std::unique_ptr array(new const char*[2]); - std::unique_ptr ed_array(new const char*[1]); - - Bundle data; - bundle_add_str(data.GetRaw(), "GEO_X", std::to_string(0).c_str()); - bundle_add_str(data.GetRaw(), "GEO_Y", std::to_string(0).c_str()); - bundle_add_str(data.GetRaw(), "GEO_W", std::to_string(100).c_str()); - bundle_add_str(data.GetRaw(), "GEO_H", std::to_string(100).c_str()); - bundle_add_str(data.GetRaw(), "SHAPE_TYPE", - std::to_string(IEditable::EditableShapeType::Circle).c_str()); - bundle_add_str(data.GetRaw(), "CUR_DATA_IDX", std::to_string(0).c_str()); - bundle_add_str(data.GetRaw(), "NAME", "sample"); - bundle_add_str(data.GetRaw(), "EDITABLE_ID", std::to_string(0).c_str()); - bundle_add_str(data.GetRaw(), "SETUP_APPID", "org.tizen.setup"); - - - bundle_add_str(candidate1.GetRaw(), "__PROVIDER_ID_KEY__", + candidate1.Add("__PROVIDER_ID_KEY__", "org.tizen.gmock_comp_provider2/test"); - bundle_add_str(candidate1.GetRaw(), "__PROVIDER_TYPE_KEY__", "2"); - bundle_add_str(candidate1.GetRaw(), "__PRIVILEGE_ERROR_KEY__", "err msg"); + candidate1.Add("__PROVIDER_TYPE_KEY__", "2"); + candidate1.Add("__PRIVILEGE_ERROR_KEY__", "err msg"); - bundle_add_str(candidate2.GetRaw(), "__PROVIDER_ID_KEY__", + candidate2.Add("__PROVIDER_ID_KEY__", "org.tizen.gmock_comp_provider/test"); - bundle_add_str(candidate2.GetRaw(), "__PROVIDER_TYPE_KEY__", "4"); - bundle_add_str(candidate2.GetRaw(), "__SUPPORTED_EVENTS_ERROR_KEY__", "4"); + candidate2.Add("__PROVIDER_TYPE_KEY__", "4"); + candidate2.Add("__SUPPORTED_EVENTS_ERROR_KEY__", "4"); - array.get()[0] = candidate1.ToString(); - array.get()[1] = candidate2.ToString(); - bundle_add_str_array(data.GetRaw(), "CANDIDATES_LIST", array.get(), 2); + vector candidates_list; + candidates_list.push_back( + reinterpret_cast(candidate1.ToRaw().first.get())); + candidates_list.push_back( + reinterpret_cast(candidate2.ToRaw().first.get())); + data.Add("CANDIDATES_LIST", candidates_list); Bundle list_data; - ed_array.get()[0] = data.ToString(); - bundle_add_str_array(list_data.GetRaw(), "EDITABLE_LIST", ed_array.get(), 1); + vector editable_list; + editable_list.push_back( + reinterpret_cast(data.ToRaw().first.get())); + list_data.Add("EDITABLE_LIST", editable_list); GVariant* parameters = g_variant_new("(ss)", - "org.tizen.watch", list_data.ToString()); + "org.tizen.watch", list_data.ToRaw().first.get()); rs->OnSignal(nullptr, "org.tizen.watch", "test path", @@ -104,7 +107,7 @@ guint __fake_signal_subscribe_on_update(GDBusConnection* connection, parameters); Bundle setup_ctx; parameters = g_variant_new("(is)", - "org.tizen.watch", setup_ctx.ToString()); + "org.tizen.watch", setup_ctx.ToRaw().first.get()); rs->OnSignal(nullptr, "org.tizen.watch", "test path", "test interface", diff --git a/watchface-common/watchface-util.cc b/watchface-common/watchface-util.cc index afe0f33..b925b87 100644 --- a/watchface-common/watchface-util.cc +++ b/watchface-common/watchface-util.cc @@ -28,6 +28,7 @@ #include #include +#include #include "watchface-common/watchface-util.h" #include "watchface-common/include/watchface-common.h" @@ -47,6 +48,8 @@ #define LOG_TAG "WATCHFACE_COMPLICATION" +using namespace std; +using namespace tizen_base; namespace watchface_complication { namespace util { static int __cynara_check(const char* client, const char* user, @@ -374,6 +377,71 @@ out: return appid; } + int GetDataType(Bundle shared_data) { + string shared_type = shared_data.GetString(DATA_TYPE_KEY); + if (shared_type.empty()) { + LOGE("failed to get data type"); + return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER; + } + + int comp_type = stoi(shared_type); + if (!CheckComplicationType(comp_type)) { + LOGE("Invalid param for type(%d)", comp_type); + return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER; + } + return comp_type; + } + + bool IsValidData(Bundle shared_data) { + int type = GetDataType(shared_data); + bool is_valid = true; + + switch(type) { + case WATCHFACE_COMPLICATION_TYPE_SHORT_TEXT : { + if (shared_data.GetString(SHORT_TEXT_KEY).empty()) + is_valid = false; + break; + } + case WATCHFACE_COMPLICATION_TYPE_LONG_TEXT : { + if (shared_data.GetString(LONG_TEXT_KEY).empty()) + is_valid = false; + break; + } + case WATCHFACE_COMPLICATION_TYPE_RANGED_VALUE : { + if (shared_data.GetString(RANGE_CUR_KEY).empty() || + shared_data.GetString(RANGE_MAX_KEY).empty() || + shared_data.GetString(RANGE_MIN_KEY).empty()) + is_valid = false; + break; + } + case WATCHFACE_COMPLICATION_TYPE_TIME : { + if (shared_data.GetString(TIME_KEY).empty()) + is_valid = false; + break; + } + case WATCHFACE_COMPLICATION_TYPE_ICON : { + if (shared_data.GetString(ICON_KEY).empty()) + is_valid = false; + break; + } + case WATCHFACE_COMPLICATION_TYPE_IMAGE : { + if (shared_data.GetString(IMAGE_KEY).empty()) + is_valid = false; + break; + } + case WATCHFACE_COMPLICATION_TYPE_NO_DATA : + is_valid = true; + break; + default : + is_valid = false; + break; + } + + if (!is_valid) + LOGE("Invalid data (%d)", type); + return is_valid; + } + std::string GetAppPath(const char* appid, char* path) { char* root_path; aul_get_app_shared_resource_path_by_appid(appid, &root_path); diff --git a/watchface-common/watchface-util.h b/watchface-common/watchface-util.h index 1aaf0a5..630d9de 100644 --- a/watchface-common/watchface-util.h +++ b/watchface-common/watchface-util.h @@ -19,6 +19,7 @@ #include #include +#include #include #include "watchface-common/include/watchface-common.h" @@ -72,6 +73,8 @@ namespace util { EXPORT_API bool CheckCertificate(const std::string& provider_app_id); EXPORT_API std::string GetAppPath(const char* appid, char* path); EXPORT_API int ConvertPathToAppPath(const char* appid, bundle* data); + EXPORT_API bool IsValidData(tizen_base::Bundle shared_data); + EXPORT_API int GetDataType(tizen_base::Bundle shared_data); } // namespace util } // namespace watchface_complication diff --git a/watchface-complication-provider/complication-provider-event-interface.h b/watchface-complication-provider/complication-provider-event-interface.h index df0b6f4..8c66a53 100644 --- a/watchface-complication-provider/complication-provider-event-interface.h +++ b/watchface-complication-provider/complication-provider-event-interface.h @@ -18,16 +18,17 @@ #define WATCHFACE_COMPLICATION_PROVIDER_COMPLICATION_PROVIDER_EVENT_INTERFACE_H_ #include +#include #include "watchface-complication/include/watchface-complication-internal.h" -#include "watchface-complication/complication-bundle.h" namespace watchface_complication { class EXPORT_API IComplicationProviderEvent { public: virtual void OnDataUpdated(const std::string& provider_id, - ComplicationType type, const std::unique_ptr& data) = 0; + ComplicationType type, + const std::unique_ptr& data) = 0; virtual void OnProviderError(const std::string& provider_id, ComplicationType type, int error) = 0; virtual void OnNotifyDataUpdate() = 0; diff --git a/watchface-complication-provider/complication-provider.cc b/watchface-complication-provider/complication-provider.cc index 417386a..57b63ab 100644 --- a/watchface-complication-provider/complication-provider.cc +++ b/watchface-complication-provider/complication-provider.cc @@ -32,6 +32,8 @@ #define LOG_TAG "WATCHFACE_COMPLICATION" #define PRIVILEGE_DATASHARING "http://tizen.org/privilege/datasharing" +using namespace std; +using namespace tizen_base; namespace watchface_complication { ComplicationProvider::ComplicationProvider(const std::string& provider_id, bool mock) @@ -218,15 +220,6 @@ void ComplicationProvider::Impl::OnSignal(GDBusConnection* connection, const std::string& signal_name, GVariant* parameters) { LOGI("%s, %s", sender_name.c_str(), signal_name.c_str()); - int complication_id; - char* context_raw = NULL; - int type; - bool ret; - bool is_valid; - char num_str[32] = {0, }; - char* shared_data_type; - char* sender_app_id = NULL; - SenderInfo* si = GetSenderInfo(sender_name, connection, parameters); if (si == NULL) return; @@ -255,6 +248,10 @@ void ComplicationProvider::Impl::OnSignal(GDBusConnection* connection, if (signal_name.compare(util::GetCmdStr( util::CmdType::CompUpdateRequest)) == 0) { + char* context_raw = nullptr; + int type; + int complication_id; + char* sender_app_id = nullptr; g_variant_get(parameters, "(&sii&s)", &sender_app_id, &complication_id, &type, &context_raw); @@ -274,69 +271,51 @@ void ComplicationProvider::Impl::OnSignal(GDBusConnection* connection, } LOGI("get : %s, %d, %d", sender_app_id, complication_id, type); - - Bundle* context_data = nullptr; - Bundle* shared_data = nullptr; try { - context_data = new Bundle(std::string(context_raw)); - shared_data = new Bundle(); + Bundle context_data(context_raw); + Bundle shared_data; + string received_type = std::to_string(type); + shared_data.Add(DATA_TYPE_KEY, received_type); + + /* Call update request callback and fill shared data */ + parent_->OnDataUpdateRequest(sender_app_id, (ComplicationType)type, + context_data, &shared_data); + string shared_type = shared_data.GetString(DATA_TYPE_KEY); + if (shared_type.empty() || shared_type != received_type) { + shared_data.Delete(DATA_TYPE_KEY); + shared_data.Add(DATA_TYPE_KEY, received_type); + LOGW("DATA_TYPE_KEY repaired : %s %s", + shared_type.c_str(), received_type.c_str()); + } + if (!util::IsValidData(shared_data)) { + LOGE("EmitSignal failed %s %s %d %d", sender_app_id, (provider_id_).c_str(), + complication_id, type); + return; + } + util::ConvertPathToAppPath(util::GetAppId().c_str(), shared_data.GetHandle()); + bool ret = gdbus_.get()->EmitSignal( + IGDBus::Complication, + std::string(sender_app_id), + provider_id_, -1, + util::GetCmdStr(util::CompUpdated), + g_variant_new("(siis)", + (provider_id_).c_str(), + type, + complication_id, + shared_data.ToRaw().first.get())); + if (ret == false) + LOGE("EmitSignal failed %s %s %d", sender_app_id, (provider_id_).c_str(), + complication_id); } catch (const std::bad_alloc &ba) { - LOGE("Bundle::Exception bad_alloc"); - if (context_data != nullptr) - delete context_data; - return; - } catch (Exception &ex) { - LOGE("%s %d", ex.what(), ex.GetErrorCode()); - if (context_data != nullptr) - delete context_data; - return; - } - - snprintf(num_str, sizeof(num_str), "%d", type); - bundle_add_str(shared_data->GetRaw(), DATA_TYPE_KEY, num_str); - - /* Call update request callback and fill shared data */ - parent_->OnDataUpdateRequest(sender_app_id, (ComplicationType)type, - context_data, shared_data); - delete context_data; - - shared_data_type = NULL; - bundle_get_str(shared_data->GetRaw(), DATA_TYPE_KEY, &shared_data_type); - if (shared_data_type == NULL || strcmp(shared_data_type, num_str) != 0) { - bundle_del(shared_data->GetRaw(), DATA_TYPE_KEY); - bundle_add_str(shared_data->GetRaw(), DATA_TYPE_KEY, num_str); - LOGI("DATA_TYPE_KEY repaired : %s %s", shared_data_type, num_str); - } - - is_valid = false; - watchface_complication_provider_data_is_valid(shared_data->GetRaw(), &is_valid); - if (is_valid == false) { - LOGE("EmitSignal failed %s %s %d %d", sender_app_id, (provider_id_).c_str(), - complication_id, type); - delete shared_data; + LOGE("Exception bad_alloc"); return; } - util::ConvertPathToAppPath(util::GetAppId().c_str(), shared_data->GetRaw()); - ret = gdbus_.get()->EmitSignal( - IGDBus::Complication, - std::string(sender_app_id), - provider_id_, -1, - util::GetCmdStr(util::CompUpdated), - g_variant_new("(siis)", - (provider_id_).c_str(), - type, - complication_id, - shared_data->ToString())); - delete shared_data; - if (ret == false) - LOGE("EmitSignal failed %s %s %d", sender_app_id, (provider_id_).c_str(), - complication_id); } } /* LCOV_EXCL_START */ void ComplicationProvider::OnDataUpdateRequest(const std::string& sender_appid, - ComplicationType type, const Bundle* context, Bundle* shared_data) { + ComplicationType type, const Bundle& context, Bundle* shared_data) { } /* LCOV_EXCL_STOP */ diff --git a/watchface-complication-provider/complication-provider.h b/watchface-complication-provider/complication-provider.h index faef2a1..fe195d3 100644 --- a/watchface-complication-provider/complication-provider.h +++ b/watchface-complication-provider/complication-provider.h @@ -34,8 +34,8 @@ class EXPORT_API ComplicationProvider : public IComplicationEvent { public: void OnDataUpdateRequest(const std::string& sender_appid, ComplicationType type, - const Bundle* context, - Bundle* shared_data) override; + const tizen_base::Bundle& context, + tizen_base::Bundle* shared_data) override; int NotifyDataUpdate(); const std::string& GetProviderId() const; diff --git a/watchface-complication-provider/watchface-complication-provider.cc b/watchface-complication-provider/watchface-complication-provider.cc index 3e92dd5..74f56f8 100644 --- a/watchface-complication-provider/watchface-complication-provider.cc +++ b/watchface-complication-provider/watchface-complication-provider.cc @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -40,11 +41,11 @@ #endif #define LOG_TAG "WATCHFACE_COMPLICATION" -#define MAX_MANDATORY_FIELDS 3 static int _add_bundle_data(bundle* shared_data, const char* key, const char* value); +using namespace tizen_base; using namespace watchface_complication; class CallbackInfo { public: @@ -53,13 +54,13 @@ class CallbackInfo { } void Invoke(const std::string& provider_id, const std::string& sender_appid, - ComplicationType type, const Bundle* context, + ComplicationType type, const Bundle& context, Bundle* shared_data) { - const bundle* context_data = context->GetConstRaw(); + const bundle* context_data = context.GetHandle(); cb_(provider_id.c_str(), sender_appid.c_str(), static_cast(type), context_data, - shared_data->GetRaw(), user_data_); + shared_data->GetHandle(), user_data_); } watchface_complication_provider_update_requested_cb GetCallback() { @@ -78,7 +79,7 @@ class WatchComplicationProviderStub : public ComplicationProvider { } void OnDataUpdateRequest(const std::string& sender_appid, - ComplicationType type, const Bundle* context, + ComplicationType type, const Bundle& context, Bundle* shared_data) override { for (auto& i : cb_list_) i->Invoke(GetProviderId(), sender_appid, type, context, shared_data); @@ -113,12 +114,6 @@ class WatchComplicationProviderStub : public ComplicationProvider { }; static std::map __providers; - -struct complication_mandatory_fields { - watchface_complication_type_e type; - const char* mandatory_fields[MAX_MANDATORY_FIELDS]; -}; - extern "C" EXPORT_API int watchface_complication_provider_add_update_requested_cb( const char* provider_id, watchface_complication_provider_update_requested_cb cb, @@ -357,26 +352,13 @@ static int _add_bundle_data(bundle* shared_data, const char* key, static int _get_data_type(bundle* shared_data, watchface_complication_type_e* type) { - int ret; - char* type_str = NULL; - - if (shared_data == NULL) { - LOGE("shared_data is NULL"); - return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER; - } - - ret = bundle_get_str(shared_data, DATA_TYPE_KEY, &type_str); - if (ret != BUNDLE_ERROR_NONE) { - LOGE("failed to get data type %d", ret); - return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER; - } - - int comp_type = strtol(type_str, NULL, 10); - if (!util::CheckComplicationType(comp_type)) { + Bundle b(shared_data); + int data_type = util::GetDataType(b); + if (!util::CheckComplicationType(data_type)) { LOGE("Invalid param"); return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER; } - *type = static_cast(comp_type); + *type = static_cast(data_type); return WATCHFACE_COMPLICATION_ERROR_NONE; } @@ -619,23 +601,8 @@ int watchface_complication_provider_data_set_screen_reader_text( return _add_bundle_data(shared_data, SCREEN_READER_TEXT_KEY, screen_reader_text); } -static struct complication_mandatory_fields _mandatory_fields[] { - {WATCHFACE_COMPLICATION_TYPE_SHORT_TEXT, {SHORT_TEXT_KEY, NULL, NULL}}, - {WATCHFACE_COMPLICATION_TYPE_LONG_TEXT, {LONG_TEXT_KEY, NULL, NULL}}, - {WATCHFACE_COMPLICATION_TYPE_RANGED_VALUE, - {RANGE_CUR_KEY, RANGE_MAX_KEY, RANGE_MIN_KEY}}, - {WATCHFACE_COMPLICATION_TYPE_TIME, {TIME_KEY, NULL, NULL}}, - {WATCHFACE_COMPLICATION_TYPE_ICON, {ICON_KEY, NULL, NULL}}, - {WATCHFACE_COMPLICATION_TYPE_IMAGE, {IMAGE_KEY, NULL, NULL}} -}; - extern "C" EXPORT_API int watchface_complication_provider_data_is_valid( - bundle* shared_data, bool*is_valid) { - int ret; - int type_count; - watchface_complication_type_e type; - char* value = NULL; - + bundle* shared_data, bool* is_valid) { if (!watchface_complication::util::CheckWatchFeatureEnabled()) return WATCHFACE_COMPLICATION_ERROR_NOT_SUPPORTED; @@ -644,32 +611,13 @@ extern "C" EXPORT_API int watchface_complication_provider_data_is_valid( return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER; } - ret = _get_data_type(shared_data, &type); - if (ret != WATCHFACE_COMPLICATION_ERROR_NONE) - return ret; - - type_count = sizeof(_mandatory_fields) / - sizeof(struct complication_mandatory_fields); - - for (int i = 0; i < type_count; i++) { - if (type == _mandatory_fields[i].type) { - for (int idx = 0; idx < MAX_MANDATORY_FIELDS - && _mandatory_fields[i].mandatory_fields[idx] != NULL; idx++) { - ret = bundle_get_str(shared_data, - _mandatory_fields[i].mandatory_fields[idx], &value); - if (ret != BUNDLE_ERROR_NONE) { - LOGE("Invalid data, missing field : %s", - _mandatory_fields[i].mandatory_fields[idx]); - *is_valid = false; - return WATCHFACE_COMPLICATION_ERROR_NONE; - } - } - *is_valid = true; - return WATCHFACE_COMPLICATION_ERROR_NONE; - } - } + Bundle b(shared_data, false, false); + int result = util::GetDataType(b); + if (!util::CheckComplicationType(result)) + return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER; + *is_valid = util::IsValidData(b); - return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER; + return WATCHFACE_COMPLICATION_ERROR_NONE; } static int _get_value_from_touch_launch_data(app_control_h handle, diff --git a/watchface-complication/complication-bundle.cc b/watchface-complication/complication-bundle.cc deleted file mode 100644 index d52a0d7..0000000 --- a/watchface-complication/complication-bundle.cc +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2018 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "watchface-complication/complication-bundle.h" -#include "watchface-common/watchface-exception.h" - -#ifdef LOG_TAG -#undef LOG_TAG -#endif - -#define LOG_TAG "WATCHFACE_COMPLICATION" -using std::string; -namespace watchface_complication { - -Bundle::Bundle() { - LOGE("create bundle !!"); - raw_ = bundle_create(); - if (raw_ == NULL) - THROW(WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY); -} - -Bundle::Bundle(std::string raw) { - if (!raw.empty()) { - raw_ = bundle_decode(reinterpret_cast(raw.c_str()), - raw.length()); - if (raw_ == NULL) { - int ret = get_last_result(); - if (ret == BUNDLE_ERROR_OUT_OF_MEMORY) - THROW(WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY); - else - THROW(WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER); - } - } else { - raw_ = bundle_create(); - if (raw_ == NULL) - THROW(WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY); - } -} - -Bundle::Bundle(bundle* raw) { - raw_ = bundle_dup(raw); - if (raw_ == NULL) - THROW(WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY); -} - -Bundle::Bundle(Bundle&& b) : raw_(b.raw_) { - b.raw_ = nullptr; -} - -Bundle& Bundle::operator = (Bundle&& b) { - raw_ = b.raw_; - b.raw_ = nullptr; - return *this; -} - -Bundle::Bundle(const Bundle& b) : raw_(bundle_dup(b.raw_)) {} -Bundle& Bundle::operator = (const Bundle& b) { - raw_ = bundle_dup(b.raw_); - if (raw_ == NULL) - THROW(WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY); - return *this; -} - -const bundle* Bundle::GetConstRaw() const { - return raw_; -} - -bundle* Bundle::GetRaw() { - return raw_; -} - -const char* Bundle::ToString() { - int str_len = 0; - bundle_raw* temp; - - if (str_raw_ != nullptr) { - free(str_raw_); - str_raw_ = nullptr; - } - - if (bundle_encode(raw_, &temp, &str_len) != BUNDLE_ERROR_NONE) - THROW(WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY); - - str_raw_ = reinterpret_cast(temp); - return str_raw_; -} - -Bundle::~Bundle() { - bundle_free(raw_); - free(str_raw_); - str_raw_ = nullptr; - raw_ = nullptr; -} - -} // namespace watchface_complication diff --git a/watchface-complication/complication-bundle.h b/watchface-complication/complication-bundle.h deleted file mode 100644 index de6f049..0000000 --- a/watchface-complication/complication-bundle.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2018 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef WATCHFACE_COMPLICATION_COMPLICATION_BUNDLE_H_ -#define WATCHFACE_COMPLICATION_COMPLICATION_BUNDLE_H_ - -#include - -#include - -#include - -namespace watchface_complication { - -class EXPORT_API Bundle { - public: - Bundle(); - explicit Bundle(std::string raw); - explicit Bundle(bundle* raw); - ~Bundle(); - Bundle(const Bundle&); - Bundle& operator=(const Bundle&); - - Bundle(Bundle && other); - Bundle& operator=(Bundle && other); - - const bundle* GetConstRaw() const; - bundle* GetRaw(); - const char* ToString(); - private: - bundle* raw_ = NULL; - char* str_raw_ = NULL; -}; - -} // namespace watchface_complication - -#endif // WATCHFACE_COMPLICATION_COMPLICATION_BUNDLE_H_ diff --git a/watchface-complication/complication-event-interface.h b/watchface-complication/complication-event-interface.h index 8376d3c..7868e05 100644 --- a/watchface-complication/complication-event-interface.h +++ b/watchface-complication/complication-event-interface.h @@ -18,9 +18,9 @@ #define WATCHFACE_COMPLICATION_COMPLICATION_EVENT_INTERFACE_H_ #include +#include #include "watchface-complication/include/watchface-complication-internal.h" -#include "watchface-complication/complication-bundle.h" namespace watchface_complication { @@ -28,8 +28,8 @@ class EXPORT_API IComplicationEvent { public: virtual void OnDataUpdateRequest(const std::string& sender_appid, ComplicationType type, - const Bundle* context, - Bundle* shared_data) = 0; + const tizen_base::Bundle& context, + tizen_base::Bundle* shared_data) = 0; }; } // namespace watchface_complication diff --git a/watchface-complication/complication-implementation.h b/watchface-complication/complication-implementation.h index 0305b03..c6aaf47 100644 --- a/watchface-complication/complication-implementation.h +++ b/watchface-complication/complication-implementation.h @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -60,7 +61,7 @@ class Complication::Impl : IGDBus::IGDBusEvent, IPackageManager::IPackageEvent { void RestoreStateOrSetDefault(); int StoreSetting(int comp_id, std::string& provider_id, ComplicationType type); - std::unique_ptr LoadSetting(); + std::unique_ptr LoadSetting(); int AddCandidate(std::string provider_id, int type); int AddCandidates(std::string provider_id, int types); int AddCandidates(int types); @@ -101,13 +102,13 @@ class Complication::Impl : IGDBus::IGDBusEvent, IPackageManager::IPackageEvent { ComplicationType cur_type_; std::string last_provider_id_; ComplicationType last_type_ = NoData; - std::list> candidates_list_; + std::list> candidates_list_; std::list> allowed_list_; std::list privilege_list_; int cur_data_idx_ = -1; - std::unique_ptr context_data_ = nullptr; - std::unique_ptr last_context_data_ = nullptr; - std::unique_ptr last_data_ = nullptr; + std::unique_ptr context_data_ = nullptr; + std::unique_ptr last_context_data_ = nullptr; + std::unique_ptr last_data_ = nullptr; int last_data_idx_ = -1; std::string name_; int subscribe_id_ = -1; diff --git a/watchface-complication/complication.cc b/watchface-complication/complication.cc index 48b088c..e83f221 100644 --- a/watchface-complication/complication.cc +++ b/watchface-complication/complication.cc @@ -28,6 +28,8 @@ #include "watchface-common/watchface-common-internal.h" #include "watchface-complication/include/watchface-complication-internal.h" +#include + #ifdef LOG_TAG #undef LOG_TAG #endif @@ -36,6 +38,8 @@ #define MAX_PACKAGE_STR_SIZE 512 #define QUERY_MAXLEN 4096 +using namespace std; +using namespace tizen_base; namespace watchface_complication { std::list Complication::Impl::complication_id_list_; const std::string Complication::Impl::provider_id_key_ = "__PROVIDER_ID_KEY__"; @@ -51,10 +55,9 @@ Complication::Complication(int id, int supported_types, int supported_event_type Complication::~Complication() = default; int Complication::Impl::LoadCurProviderFromPrev() { - char* prev_provider_id = NULL; - char* prev_provider_type = NULL; - std::string prev_provider_id_str; - std::unique_ptr setting_data; + string prev_provider_type; + string prev_provider_id; + unique_ptr setting_data; try { setting_data = EditablesManager::GetInst(mock_).LoadSetting(complication_id_); @@ -68,23 +71,17 @@ int Complication::Impl::LoadCurProviderFromPrev() { return WATCHFACE_COMPLICATION_ERROR_PROVIDER_NOT_AVAILABLE; } - bundle_get_str(setting_data.get()->GetRaw(), provider_id_key_.c_str(), - &prev_provider_id); - bundle_get_str(setting_data.get()->GetRaw(), provider_type_key_.c_str(), - &prev_provider_type); - - if (prev_provider_id == NULL) { + prev_provider_id = setting_data->GetString(provider_id_key_); + prev_provider_type = setting_data->GetString(provider_type_key_); + if (prev_provider_id.empty()) { LOGW("No prev provider id"); return WATCHFACE_COMPLICATION_ERROR_PROVIDER_NOT_AVAILABLE; } - if (prev_provider_id) - prev_provider_id_str = std::string(prev_provider_id); - - LOGI("get setting from bundle %s, %s", prev_provider_id, prev_provider_type); - - int ret = UpdateCurProvider(prev_provider_id_str, static_cast( - strtol((const char*)prev_provider_type, NULL, 10))); + LOGI("get setting from bundle %s, %s", + prev_provider_id.c_str(), prev_provider_type.c_str()); + int ret = UpdateCurProvider(prev_provider_id, static_cast( + stoi(prev_provider_type))); if (ret != WATCHFACE_COMPLICATION_ERROR_NONE) return ret; @@ -114,7 +111,6 @@ int Complication::Init() { ret = impl_->LoadPeriod(); if (ret != WATCHFACE_COMPLICATION_ERROR_NONE) return ret; - impl_->package_.get()->Watch(impl_.get()); impl_->default_provider_appid_ = @@ -269,40 +265,21 @@ void Complication::Impl::OnSignal(GDBusConnection* connection, int Complication::Impl::StoreSetting(int comp_id, std::string& provider_id, ComplicationType type) { - bundle* setting_data; - bundle_raw* raw_data = NULL; - int raw_len; - int ret; - char buf[32]; - if (provider_id.empty() && type != NoData) return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER; - setting_data = bundle_create(); - if (setting_data == NULL) { - LOGE("bundle_create failed"); - return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY; - } - - snprintf(buf, sizeof(buf), "%d", static_cast(type)); - bundle_add_str(setting_data, provider_id_key_.c_str(), provider_id.c_str()); - bundle_add_str(setting_data, provider_type_key_.c_str(), buf); - bundle_encode(setting_data, &raw_data, &raw_len); - bundle_free(setting_data); - + Bundle setting_data; + setting_data.Add(provider_id_key_, provider_id); + setting_data.Add(provider_type_key_, to_string(type)); try { - ret = EditablesManager::GetInst(mock_).StoreSetting(comp_id, raw_data); - if (ret != WATCHFACE_COMPLICATION_ERROR_NONE) { - free(raw_data); + int ret = EditablesManager::GetInst(mock_).StoreSetting( + comp_id, setting_data.ToRaw().first.get()); + if (ret != WATCHFACE_COMPLICATION_ERROR_NONE) return ret; - } } catch (Exception &ex) { LOGE("%s %d", ex.what(), ex.GetErrorCode()); - free(raw_data); return ex.GetErrorCode(); } - - free(raw_data); return WATCHFACE_COMPLICATION_ERROR_NONE; } @@ -332,40 +309,38 @@ IEditable::Highlight* Complication::GetHighlight() { Complication make candidates automatically, so we don't need it */ int Complication::SetCandidates( - std::list> candidates_list) { + std::list> candidates_list) { return WATCHFACE_COMPLICATION_ERROR_NONE; } -std::list> const& Complication::GetCandidates() const { +std::list> const& Complication::GetCandidates() const { return impl_->candidates_list_; } -const Bundle* Complication::GetCurData() { +shared_ptr Complication::GetCurData() { if (static_cast(impl_->candidates_list_.size()) < impl_->cur_data_idx_ + 1 || impl_->cur_data_idx_ < 0) { LOGE("No candidates"); - return NULL; + return shared_ptr({}); } - std::list>::iterator it + std::list>::iterator it = impl_->candidates_list_.begin(); LOGI("get cur data idx(%d), list_size(%zu)", impl_->cur_data_idx_, impl_->candidates_list_.size()); - auto nx = std::next(it, impl_->cur_data_idx_); - return nx->get(); + return *std::next(it, impl_->cur_data_idx_); } -const Bundle* Complication::GetNthData(int nth) { +shared_ptr Complication::GetNthData(int nth) { if (static_cast(impl_->candidates_list_.size()) <= nth || nth < 0) - return NULL; + return shared_ptr({}); - std::list>::iterator it + std::list>::iterator it = impl_->candidates_list_.begin(); LOGI("get nth data %d", nth); - auto nx = std::next(it, nth); - return nx->get(); + return *std::next(it, nth); } int Complication::GetCurDataIdx() { @@ -554,10 +529,7 @@ int Complication::UpdateLastData() { } int Complication::SetCurDataIdx(int cur_data_idx) { - char* provider_id = NULL; - char* type = NULL; int ret = WATCHFACE_COMPLICATION_ERROR_NONE; - if (impl_->cur_data_idx_ == cur_data_idx) { LOGI("Same with cur data idx skip setting process %d, %d", impl_->cur_data_idx_, cur_data_idx); @@ -571,22 +543,16 @@ int Complication::SetCurDataIdx(int cur_data_idx) { if (ret != WATCHFACE_COMPLICATION_ERROR_NONE) return ret; } else { - const Bundle* data = GetNthData(cur_data_idx); - if (data == NULL) { - LOGI("GetCurData failed"); - return WATCHFACE_COMPLICATION_ERROR_NO_DATA; - } - bundle_get_str(const_cast(data)->GetRaw(), - impl_->provider_id_key_.c_str(), &provider_id); - bundle_get_str(const_cast(data)->GetRaw(), - impl_->provider_type_key_.c_str(), &type); + shared_ptr data = GetNthData(cur_data_idx); + string provider_id = data->GetString(impl_->provider_id_key_); + string type = data->GetString(impl_->provider_type_key_); - if (provider_id == NULL || type == NULL) { + if (provider_id.empty() || type.empty()) { LOGI("GetCurData failed"); return WATCHFACE_COMPLICATION_ERROR_NO_DATA; } - ret = impl_->UpdateCurProvider(std::string(provider_id), - static_cast(strtol(type, NULL, 10))); + ret = impl_->UpdateCurProvider(provider_id, + static_cast(stoi(type))); if (ret != WATCHFACE_COMPLICATION_ERROR_NONE) return ret; impl_->cur_data_idx_ = cur_data_idx; @@ -597,39 +563,21 @@ int Complication::SetCurDataIdx(int cur_data_idx) { return impl_->UpdateProviderInfo(); } -const char* Complication::GetCurProviderId() { +const string Complication::GetCurProviderId() { if (!impl_->cur_provider_id_.empty()) return impl_->cur_provider_id_.c_str(); - - return NULL; + return ""; } -const char* Complication::GetProviderId(const Bundle* candidate_data) { - char* provider_id = NULL; - - if (candidate_data == NULL) - return NULL; - - bundle_get_str(const_cast(candidate_data)->GetRaw(), - impl_->provider_id_key_.c_str(), &provider_id); - - return provider_id; +const string Complication::GetProviderId(const Bundle& candidate_data) { + return candidate_data.GetString(impl_->provider_id_key_); } -int Complication::GetProviderType(const Bundle* candidate_data) { - char* provider_type = NULL; - int ret = 0; - - if (candidate_data == NULL) - return ret; - - bundle_get_str(const_cast(candidate_data)->GetRaw(), - impl_->provider_type_key_.c_str(), &provider_type); - - if (provider_type) - ret = strtol(provider_type, NULL, 10); - - return ret; +int Complication::GetProviderType(const Bundle& candidate_data) { + string type = candidate_data.GetString(impl_->provider_type_key_); + if (type.empty()) + return 0; + return stoi(type); } int Complication::GetCurType() { @@ -653,11 +601,9 @@ void Complication::OnEditableUpdated(int selected_idx, if (state == OnGoing) { LOGI("ongoing editing : %d", impl_->complication_id_); std::unique_ptr ptr = nullptr; - const char* provider_id = GetCurProviderId(); - std::string provider_id_str = - provider_id == NULL ? "" : std::string(provider_id); + std::string provider_id_str = GetCurProviderId(); int type = GetCurType(); - ptr = DBManager::GetDefaultData(provider_id, type); + ptr = DBManager::GetDefaultData(provider_id_str.c_str(), type); OnDataUpdated(provider_id_str, static_cast(type), ptr); } else if (state == Complete) { LOGI("complete editing : %d", impl_->complication_id_); @@ -750,7 +696,8 @@ int Complication::SendDataUpdateRequest(bool launch_option) { } if (impl_->context_data_ != nullptr) - context_data_raw = impl_->context_data_->ToString(); + context_data_raw = + reinterpret_cast(impl_->context_data_->ToRaw().first.get()); emit_ret = impl_->gdbus_.get()->EmitSignal( IGDBus::SigType::Complication, @@ -817,11 +764,11 @@ int Complication::UpdateLastContext() { try { int ret = EditablesManager::GetInst(impl_->mock_).StoreContext( impl_->complication_id_, impl_->cur_provider_id_.c_str(), - *impl_->context_data_.get()); + impl_->context_data_.get()); if (ret != WATCHFACE_COMPLICATION_ERROR_NONE) return ret; impl_->last_context_data_.reset( - new Bundle((impl_->context_data_.get())->GetRaw())); + new Bundle((impl_->context_data_.get())->GetHandle())); } catch (Exception &ex) { LOGE("%s %d", ex.what(), ex.GetErrorCode()); return ex.GetErrorCode(); @@ -835,8 +782,6 @@ std::unique_ptr& Complication::GetLastContext() const { } int Complication::TouchLaunch(watchface_complication_event_type_e event_type) { - const char* context_data_raw = NULL; - int ret; std::string provider_appid = DBManager::GetProviderAppId( impl_->cur_provider_id_.c_str()); if (provider_appid.empty()) { @@ -844,42 +789,18 @@ int Complication::TouchLaunch(watchface_complication_event_type_e event_type) { return WATCHFACE_COMPLICATION_ERROR_IO_ERROR; } - if (impl_->context_data_ != nullptr) - context_data_raw = impl_->context_data_->ToString(); - - bundle* launch_data = bundle_create(); - if (launch_data == NULL) { - LOGE("Out of memory"); - return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY; + Bundle launch_data; + launch_data.Add(TOUCH_LAUNCH_EVENT_KEY, to_string(event_type)); + launch_data.Add(TOUCH_LAUNCH_PROVIDER_ID_KEY, impl_->cur_provider_id_); + launch_data.Add(TOUCH_LAUNCH_TYPE_KEY, to_string(impl_->cur_type_)); + if (impl_->context_data_ != nullptr) { + launch_data.Add(TOUCH_LAUNCH_CONTEXT_KEY, + reinterpret_cast(impl_->context_data_->ToRaw().first.get())); } - - char event_str[32] = {0,}; - snprintf(event_str, sizeof(event_str), "%d", event_type); - bundle_add_str(launch_data, TOUCH_LAUNCH_EVENT_KEY, event_str); - - bundle_add_str(launch_data, TOUCH_LAUNCH_PROVIDER_ID_KEY, - impl_->cur_provider_id_.c_str()); - - char type_str[32] = {0, }; - snprintf(type_str, sizeof(type_str), "%d", impl_->cur_type_); - bundle_add_str(launch_data, TOUCH_LAUNCH_TYPE_KEY, type_str); - if (context_data_raw != NULL) - bundle_add_str(launch_data, TOUCH_LAUNCH_CONTEXT_KEY, context_data_raw); - - bundle_raw* raw_data = NULL; - int raw_len; - bundle_encode(launch_data, &raw_data, &raw_len); - bundle_free(launch_data); - if (raw_data == NULL) { - LOGE("Fail to encode bundle"); - return WATCHFACE_COMPLICATION_ERROR_IO_ERROR; - } - - ret = aul_complication_launch_with_extra_data( + int ret = aul_complication_launch_with_extra_data( util::GetAppId().c_str(), provider_appid.c_str(), getuid(), TOUCH_LAUNCH_DATA_KEY, - reinterpret_cast(raw_data)); - free(raw_data); + reinterpret_cast(launch_data.ToRaw().first.get())); LOGI("Touch launch the %s : %d", provider_appid.c_str(), ret); if (ret != AUL_R_OK) { @@ -1042,7 +963,7 @@ int Complication::Impl::LoadContext() { cur_provider_id_.c_str()); try { if (context_data_ != nullptr) - last_context_data_.reset(new Bundle(context_data_.get()->GetRaw())); + last_context_data_.reset(new Bundle(context_data_.get()->GetHandle())); } catch (...) { LOGE("Out of memory"); return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY; @@ -1057,14 +978,11 @@ int Complication::Impl::UpdateCandidatesInfo() { int idx = 0; for (auto& i : candidates_list_) { - char* temp_provider_id = NULL; - char* temp_type = NULL; Bundle& data = *(i.get()); - bundle_get_str(data.GetRaw(), provider_id_key_.c_str(), &temp_provider_id); - bundle_get_str(data.GetRaw(), provider_type_key_.c_str(), &temp_type); - if (temp_provider_id != NULL && temp_type != NULL) { - if (strcmp(temp_provider_id, cur_provider_id_.c_str()) == 0 - && strtol(temp_type, NULL, 10) == cur_type_) { + string provider_id = data.GetString(provider_id_key_); + string type = data.GetString(provider_type_key_); + if (!provider_id.empty() && !type.empty()) { + if (provider_id == cur_provider_id_ && stoi(type) == cur_type_) { cur_data_idx_ = idx; LOGI("find cur idx %d", idx); return WATCHFACE_COMPLICATION_ERROR_NONE; diff --git a/watchface-complication/complication.h b/watchface-complication/complication.h index 117e7bc..ed1c209 100644 --- a/watchface-complication/complication.h +++ b/watchface-complication/complication.h @@ -18,6 +18,7 @@ #define WATCHFACE_COMPLICATION_COMPLICATION_H_ #include +#include #include #include @@ -58,10 +59,10 @@ class EXPORT_API Complication : public IEditable }; int SetHighlight(std::unique_ptr highlight) override; IEditable::Highlight* GetHighlight() override; - std::list> const& GetCandidates() const override; - int SetCandidates(std::list> candidates_list) override; - const Bundle* GetCurData() override; - const Bundle* GetNthData(int nth) override; + std::list> const& GetCandidates() const override; + int SetCandidates(std::list> candidates_list) override; + std::shared_ptr GetCurData() override; + std::shared_ptr GetNthData(int nth) override; int GetCurDataIdx() override; int SetCurDataIdx(int cur_data_idx) override; int GetLastDataIdx() override; @@ -71,7 +72,7 @@ class EXPORT_API Complication : public IEditable IEditable::EditableState state) override; void OnDataUpdated(const std::string& provider_id, ComplicationType type, - const std::unique_ptr& data) override; + const std::unique_ptr& data) override; void OnProviderError(const std::string& provider_id, ComplicationType type, int error) override; void OnNotifyDataUpdate() override; @@ -81,16 +82,16 @@ class EXPORT_API Complication : public IEditable void SetLabel(const std::string& name) override; void SetState(IEditable::EditableState state) override; IEditable::EditableState GetState() override; - int SetContext(std::unique_ptr context) override; - std::unique_ptr& GetContext() const override; + int SetContext(std::unique_ptr context) override; + std::unique_ptr& GetContext() const override; int UpdateLastContext() override; - std::unique_ptr& GetLastContext() const override; + std::unique_ptr& GetLastContext() const override; const std::string GetSetupAppId() override; int SendDataUpdateRequest(bool launch_option = true); - const char* GetCurProviderId(); - const char* GetProviderId(const Bundle* candidate_data); - int GetProviderType(const Bundle* candidate_data); + const std::string GetCurProviderId(); + const std::string GetProviderId(const tizen_base::Bundle& candidate_data); + int GetProviderType(const tizen_base::Bundle& candidate_data); int GetCurType(); int TouchLaunch(watchface_complication_event_type_e event_type); int ApplyAllowedList( diff --git a/watchface-complication/db-manager.cc b/watchface-complication/db-manager.cc index 66e833f..b70a0b8 100644 --- a/watchface-complication/db-manager.cc +++ b/watchface-complication/db-manager.cc @@ -35,6 +35,7 @@ #define DEFAULT_LOCALE "No Locale" #define ROOT_USER 0 +using namespace tizen_base; namespace watchface_complication { DBManager::DBManager() = default; @@ -125,7 +126,8 @@ std::unique_ptr DBManager::GetDefaultData(const char* provider_id, goto out; } default_data = std::unique_ptr(new Bundle(std::string(raw_data))); - util::ConvertPathToAppPath(provider_app_id.c_str(), default_data->GetRaw()); + util::ConvertPathToAppPath( + provider_app_id.c_str(), default_data.get()->GetHandle()); } out: diff --git a/watchface-complication/db-manager.h b/watchface-complication/db-manager.h index 17b26a2..6ad36ad 100644 --- a/watchface-complication/db-manager.h +++ b/watchface-complication/db-manager.h @@ -20,13 +20,12 @@ #include #include #include +#include #include #include #include -#include "watchface-complication/complication-bundle.h" - namespace watchface_complication { class EXPORT_API DBManager { @@ -45,8 +44,8 @@ class EXPORT_API DBManager { return type_; } }; - static std::unique_ptr GetDefaultData(const char* provider_id, - int support_type); + static std::unique_ptr GetDefaultData( + const char* provider_id, int support_type); static std::string GetProviderAppId(const char* provider_id); static std::list GetRequiredPrivilegeList( std::string& provider_id); diff --git a/watchface-complication/design-element-implementation.h b/watchface-complication/design-element-implementation.h index 22e94af..1b532c3 100644 --- a/watchface-complication/design-element-implementation.h +++ b/watchface-complication/design-element-implementation.h @@ -18,6 +18,7 @@ #define WATCHFACE_COMPLICATION_DESIGN_ELEMENT_IMPLEMENTATION_H_ #include +#include #include #include @@ -45,13 +46,13 @@ class DesignElement::Impl { int id_ = -1; int cur_data_idx_; int last_data_idx_; - std::list> candidates_list_; + std::list> candidates_list_; std::unique_ptr highlight_; EditableShapeType shape_type_ = Circle; std::string name_; IEditable::EditableState ed_state_ = Complete; - std::unique_ptr context_data_; - std::unique_ptr last_context_data_ = nullptr; + std::unique_ptr context_data_; + std::unique_ptr last_context_data_ = nullptr; bool mock_; }; diff --git a/watchface-complication/design-element.cc b/watchface-complication/design-element.cc index fc5e821..f7f57f3 100644 --- a/watchface-complication/design-element.cc +++ b/watchface-complication/design-element.cc @@ -29,6 +29,8 @@ #define LOG_TAG "WATCHFACE_COMPLICATION" #define MAX_PACKAGE_STR_SIZE 512 +using namespace std; +using namespace tizen_base; namespace watchface_complication { DesignElement::DesignElement(int id, int cur_data_idx, bool mock) @@ -66,37 +68,33 @@ IEditable::Highlight* DesignElement::GetHighlight() { } int DesignElement::SetCandidates( - std::list> candidates_list) { - impl_->candidates_list_ = std::move(candidates_list); + std::list> candidates_list) { + impl_->candidates_list_ = candidates_list; return WATCHFACE_COMPLICATION_ERROR_NONE; } -std::list> const& DesignElement::GetCandidates() const { +std::list> const& DesignElement::GetCandidates() const { return impl_->candidates_list_; } -const Bundle* DesignElement::GetCurData() { +shared_ptr DesignElement::GetCurData() { if (static_cast(impl_->candidates_list_.size()) < impl_->cur_data_idx_ + 1 || impl_->cur_data_idx_ < 0) - return NULL; - std::list>::iterator it + return shared_ptr({}); + std::list>::iterator it = impl_->candidates_list_.begin(); - LOGI("get cur data %d", impl_->cur_data_idx_); - auto nx = std::next(it, impl_->cur_data_idx_); - return nx->get(); + return *std::next(it, impl_->cur_data_idx_); } -const Bundle* DesignElement::GetNthData(int nth) { +shared_ptr DesignElement::GetNthData(int nth) { if (static_cast(impl_->candidates_list_.size()) <= nth || nth < 0) - return NULL; + return shared_ptr({}); - std::list>::iterator it + std::list>::iterator it = impl_->candidates_list_.begin(); - LOGI("get nth data %d", nth); - auto nx = std::next(it, nth); - return nx->get(); + return *std::next(it, nth); } int DesignElement::GetCurDataIdx() { @@ -109,32 +107,16 @@ int DesignElement::GetLastDataIdx() { } int DesignElement::UpdateLastData() { - const Bundle* cur_data = GetCurData(); - if (cur_data == NULL) + shared_ptr cur_data = GetCurData(); + if (cur_data.get() == nullptr) return WATCHFACE_COMPLICATION_ERROR_NO_DATA; - - bundle_raw* raw_data = NULL; - int raw_len, ret; - ret = bundle_encode(const_cast(cur_data)->GetRaw(), - &raw_data, &raw_len); - if (ret != BUNDLE_ERROR_NONE) { - if (ret == BUNDLE_ERROR_OUT_OF_MEMORY) { - return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY; - } else { - LOGE("bundle encode fail"); - return WATCHFACE_COMPLICATION_ERROR_NO_DATA; - } - } try { - ret = EditablesManager::GetInst(impl_->mock_) - .StoreSetting(impl_->id_, raw_data); - free(raw_data); - + int ret = EditablesManager::GetInst(impl_->mock_) + .StoreSetting(impl_->id_, cur_data->ToRaw().first.get()); if (ret != WATCHFACE_COMPLICATION_ERROR_NONE) return ret; } catch (Exception &ex) { LOGE("%s %d", ex.what(), ex.GetErrorCode()); - free(raw_data); return ex.GetErrorCode(); } @@ -200,7 +182,7 @@ int DesignElement::UpdateLastContext() { try { impl_->last_context_data_.reset( - new Bundle((impl_->context_data_.get())->GetRaw())); + new Bundle((impl_->context_data_.get())->GetHandle())); } catch (Exception &ex) { LOGE("%s %d", ex.what(), ex.GetErrorCode()); return ex.GetErrorCode(); diff --git a/watchface-complication/design-element.h b/watchface-complication/design-element.h index 7924097..7255af6 100644 --- a/watchface-complication/design-element.h +++ b/watchface-complication/design-element.h @@ -18,6 +18,7 @@ #define WATCHFACE_COMPLICATION_DESIGN_ELEMENT_H_ #include +#include #include #include @@ -39,10 +40,10 @@ class EXPORT_API DesignElement : public IEditable { public: int SetHighlight(std::unique_ptr highlight) override; IEditable::Highlight* GetHighlight() override; - std::list> const& GetCandidates() const override; - int SetCandidates(std::list> candidates_list) override; - const Bundle* GetCurData() override; - const Bundle* GetNthData(int nth) override; + std::list> const& GetCandidates() const override; + int SetCandidates(std::list> candidates_list) override; + std::shared_ptr GetCurData() override; + std::shared_ptr GetNthData(int nth) override; int GetCurDataIdx() override; int SetCurDataIdx(int cur_data_idx) override; int GetLastDataIdx() override; @@ -55,10 +56,10 @@ class EXPORT_API DesignElement : public IEditable { void SetLabel(const std::string& name) override; void SetState(IEditable::EditableState state) override; IEditable::EditableState GetState() override; - int SetContext(std::unique_ptr context) override; - std::unique_ptr& GetContext() const override; + int SetContext(std::unique_ptr context) override; + std::unique_ptr& GetContext() const override; int UpdateLastContext() override; - std::unique_ptr& GetLastContext() const override; + std::unique_ptr& GetLastContext() const override; const std::string GetSetupAppId() override; private: diff --git a/watchface-complication/editable-interface.h b/watchface-complication/editable-interface.h index def9b9f..8641298 100644 --- a/watchface-complication/editable-interface.h +++ b/watchface-complication/editable-interface.h @@ -16,12 +16,12 @@ #ifndef WATCHFACE_COMPLICATION_EDITABLE_INTERFACE_H_ #define WATCHFACE_COMPLICATION_EDITABLE_INTERFACE_H_ +#include #include #include #include -#include "watchface-complication/complication-bundle.h" #include "watchface-complication/include/watchface-editable.h" namespace watchface_complication { @@ -125,10 +125,10 @@ class IEditable { virtual ~IEditable() = default; virtual int GetEditableId() = 0; virtual int SetEditableId(int id) = 0; - virtual std::list> const& GetCandidates() const = 0; - virtual int SetCandidates(std::list> candidates_list) = 0; - virtual const Bundle* GetCurData() = 0; - virtual const Bundle* GetNthData(int nth) = 0; + virtual std::list> const& GetCandidates() const = 0; + virtual int SetCandidates(std::list> candidates_list) = 0; + virtual std::shared_ptr GetCurData() = 0; + virtual std::shared_ptr GetNthData(int nth) = 0; virtual int GetCurDataIdx() = 0; virtual int SetCurDataIdx(int cur_data_idx) = 0; virtual int GetLastDataIdx() = 0; @@ -139,10 +139,10 @@ class IEditable { virtual void SetState(EditableState state) = 0; virtual EditableState GetState() = 0; virtual const std::string GetSetupAppId() = 0; - virtual int SetContext(std::unique_ptr context) = 0; - virtual std::unique_ptr& GetContext() const = 0; + virtual int SetContext(std::unique_ptr context) = 0; + virtual std::unique_ptr& GetContext() const = 0; virtual int UpdateLastContext() = 0; - virtual std::unique_ptr& GetLastContext() const = 0; + virtual std::unique_ptr& GetLastContext() const = 0; virtual Highlight* GetHighlight() = 0; virtual int SetHighlight(std::unique_ptr highlight) = 0; }; diff --git a/watchface-complication/editables-container-event-interface.h b/watchface-complication/editables-container-event-interface.h index 5567f46..9f12837 100644 --- a/watchface-complication/editables-container-event-interface.h +++ b/watchface-complication/editables-container-event-interface.h @@ -16,12 +16,12 @@ #ifndef WATCHFACE_COMPLICATION_EDITABLES_CONTAINER_EVENT_INTERFACE_H_ #define WATCHFACE_COMPLICATION_EDITABLES_CONTAINER_EVENT_INTERFACE_H_ +#include #include #include #include -#include "watchface-complication/complication-bundle.h" #include "watchface-complication/complication.h" namespace watchface_complication { @@ -31,7 +31,7 @@ class EXPORT_API IEditablesContainerEvent { virtual void OnRequestEdit(const std::string& appid, std::list> e_list) = 0; virtual void OnSetupReply(const std::string& appid, int editable_id, - std::unique_ptr context) = 0; + std::unique_ptr context) = 0; }; } // namespace watchface_complication diff --git a/watchface-complication/editables-container-implementation.h b/watchface-complication/editables-container-implementation.h index de79894..887ab8a 100644 --- a/watchface-complication/editables-container-implementation.h +++ b/watchface-complication/editables-container-implementation.h @@ -50,13 +50,6 @@ class EditablesContainer::Impl : IGDBus::IGDBusEvent { Impl(Impl && other) = default; Impl& operator=(Impl const& other) = default; Impl& operator=(Impl && other) = default; - static void FreeList(char** str_list, int size) { - for (int i = 0; i < size; i++) { - if (str_list[i]) - free(str_list[i]); - } - free(str_list); - } private: EditablesContainer* parent_; diff --git a/watchface-complication/editables-container.cc b/watchface-complication/editables-container.cc index 81914d1..cbe5d59 100644 --- a/watchface-complication/editables-container.cc +++ b/watchface-complication/editables-container.cc @@ -17,9 +17,11 @@ #include #include #include +#include #include #include +#include #include "watchface-complication/editables-container.h" #include "watchface-complication/editables-container-implementation.h" @@ -34,6 +36,8 @@ #define LOG_TAG "WATCHFACE_COMPLICATION" #define MAX_PACKAGE_STR_SIZE 512 +using namespace std; +using namespace tizen_base; namespace watchface_complication { EditablesContainer::EditablesContainer(bool mock) @@ -146,7 +150,7 @@ void EditablesContainer::Impl::CancelEditing() { i.get()->SetCurDataIdx(i.get()->GetLastDataIdx()); if (i.get()->GetLastContext().get() != NULL) { i.get()->SetContext(std::unique_ptr( - new Bundle(i.get()->GetLastContext().get()->GetRaw()))); + new Bundle(i.get()->GetLastContext().get()->GetHandle()))); } else { i.get()->SetContext(std::unique_ptr{}); } @@ -165,87 +169,55 @@ void EditablesContainer::Impl::OnAppear(const std::string& name, } int EditablesContainer::RequestEdit() { - int list_idx = 0; - int str_len = 0; - bundle_raw* str_raw = NULL; - char** list_arr; - bool emit_ret = false; - if (impl_->editor_id_.empty()) return -1; - list_arr = reinterpret_cast(calloc(impl_->ed_list_.size(), - sizeof(char*))); - if (list_arr == NULL) { - LOGE("Out of memory"); - return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY; - } - + vector encoded_list; for (auto& i : impl_->ed_list_) { i.get()->SetState(IEditable::OnGoing); - bundle* ed = bundle_create(); - if (ed == NULL) { - impl_->FreeList(list_arr, impl_->ed_list_.size()); - LOGE("Out of memory"); - return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY; - } - - bundle_add(ed, "SETUP_APPID", i.get()->GetSetupAppId().c_str()); - bundle_add(ed, "EDITABLE_ID", - std::to_string(i.get()->GetEditableId()).c_str()); + Bundle b; + b.Add("SETUP_APPID", i.get()->GetSetupAppId()); + b.Add("EDITABLE_ID", + std::to_string(i.get()->GetEditableId())); int cur_data_idx = i.get()->GetCurDataIdx(); - bundle_add(ed, "CUR_DATA_IDX", std::to_string(cur_data_idx).c_str()); + b.Add("CUR_DATA_IDX", std::to_string(cur_data_idx)); - std::unique_ptr arr( - new const char*[i->GetCandidates().size()]); - int idx = 0; + vector candidate_list; for (auto& data : i.get()->GetCandidates()) { - arr.get()[idx++] = data->ToString(); - LOGD("%s", arr.get()[idx - 1]); + candidate_list.push_back( + reinterpret_cast(data->ToRaw().first.get())); } - bundle_add_str_array(ed, "CANDIDATES_LIST", arr.get(), - i.get()->GetCandidates().size()); - bundle_add(ed, "CANDIDATES_LIST_SIZE", - std::to_string(i.get()->GetCandidates().size()).c_str()); + b.Add("CANDIDATES_LIST", candidate_list); + b.Add("CANDIDATES_LIST_SIZE", + std::to_string(i.get()->GetCandidates().size())); IEditable::Highlight* hi = i->GetHighlight(); if (hi) { if (hi->GetGeometry()) { - bundle_add(ed, "GEO_X", std::to_string(hi->GetGeometry()->GetX()).c_str()); - bundle_add(ed, "GEO_Y", std::to_string(hi->GetGeometry()->GetY()).c_str()); - bundle_add(ed, "GEO_W", std::to_string(hi->GetGeometry()->GetW()).c_str()); - bundle_add(ed, "GEO_H", std::to_string(hi->GetGeometry()->GetH()).c_str()); + b.Add("GEO_X", std::to_string(hi->GetGeometry()->GetX())); + b.Add("GEO_Y", std::to_string(hi->GetGeometry()->GetY())); + b.Add("GEO_W", std::to_string(hi->GetGeometry()->GetW())); + b.Add("GEO_H", std::to_string(hi->GetGeometry()->GetH())); LOGI("hi %d %d %d %d", hi->GetGeometry()->GetX(), hi->GetGeometry()->GetY(), hi->GetGeometry()->GetW(), hi->GetGeometry()->GetH()); } IEditable::EditableShapeType type = hi->GetShapeType(); - bundle_add(ed, "SHAPE_TYPE", std::to_string(type).c_str()); + b.Add("SHAPE_TYPE", std::to_string(type)); } else { LOGW("Null highlight info !!"); } if (!i.get()->GetLabel().empty()) - bundle_add(ed, "NAME", i.get()->GetLabel().c_str()); + b.Add("NAME", i.get()->GetLabel()); - bundle_encode(ed, &str_raw, &str_len); - list_arr[list_idx++] = reinterpret_cast(str_raw); - - bundle_free(ed); - } - - bundle* container = bundle_create(); - if (container == NULL) { - impl_->FreeList(list_arr, impl_->ed_list_.size()); - return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY; + encoded_list.push_back(reinterpret_cast(b.ToRaw().first.get())); } - bundle_add_str_array(container, "EDITABLE_LIST", - const_cast(list_arr), list_idx); - impl_->FreeList(list_arr, impl_->ed_list_.size()); - bundle_encode(container, &str_raw, &str_len); - emit_ret = impl_->gdbus_.get()->EmitSignal( + Bundle container; + container.Add("EDITABLE_LIST", encoded_list); + bool emit_ret = impl_->gdbus_.get()->EmitSignal( IGDBus::SigType::Editable, impl_->editor_id_, impl_->editor_id_, @@ -253,10 +225,7 @@ int EditablesContainer::RequestEdit() { util::GetCmdStr(util::EditableEditRequest), g_variant_new("(ss)", util::GetAppId().c_str(), - str_raw)); - - bundle_free_encoded_rawdata(&str_raw); - bundle_free(container); + container.ToRaw().first.get())); if (emit_ret == false) return WATCHFACE_COMPLICATION_ERROR_IO_ERROR; diff --git a/watchface-complication/editables-manager.cc b/watchface-complication/editables-manager.cc index 7a1a210..2d7703e 100644 --- a/watchface-complication/editables-manager.cc +++ b/watchface-complication/editables-manager.cc @@ -32,6 +32,7 @@ #define QUERY_MAXLEN 4096 +using namespace tizen_base; namespace watchface_complication { EditablesManager& EditablesManager::GetInst(bool mock) { @@ -166,7 +167,7 @@ std::unique_ptr EditablesManager::LoadSetting(int editable_id) { } int EditablesManager::StoreContext(int editable_id, const char* provider_id, - Bundle& context) { + Bundle* context) { char query[QUERY_MAXLEN] = {0, }; char* error = NULL; @@ -178,7 +179,7 @@ int EditablesManager::StoreContext(int editable_id, const char* provider_id, sqlite3_snprintf(QUERY_MAXLEN, query, "INSERT OR REPLACE INTO editable_context(editable_id, provider_id, " \ "context_data) VALUES (%d, %Q, %Q)", - editable_id, provider_id, context.ToString()); + editable_id, provider_id, context->ToRaw().first.get()); if (sqlite3_exec(impl_->context_db_, query, NULL, NULL, &error) != SQLITE_OK) { LOGE("sqlite3_exec error(editable_id : %d, provider_id : %s, error = %s)", editable_id, provider_id, error); diff --git a/watchface-complication/editables-manager.h b/watchface-complication/editables-manager.h index db3f66d..09d3ee5 100644 --- a/watchface-complication/editables-manager.h +++ b/watchface-complication/editables-manager.h @@ -19,21 +19,22 @@ #include #include +#include #include #include -#include "watchface-complication/complication-bundle.h" - namespace watchface_complication { class EXPORT_API EditablesManager { public: static EditablesManager& GetInst(bool mock = false); int StoreSetting(int editable_id, bundle_raw* raw_data); - std::unique_ptr LoadSetting(int editable_id); - int StoreContext(int editable_id, const char* provider_id, Bundle& context); - std::unique_ptr LoadContext(int editable_id, const char* provider_id); + std::unique_ptr LoadSetting(int editable_id); + int StoreContext(int editable_id, const char* provider_id, + tizen_base::Bundle* context); + std::unique_ptr LoadContext( + int editable_id, const char* provider_id); int DeleteContext(int editable_id, const char* provider_id); private: diff --git a/watchface-complication/received-editable-implementation.h b/watchface-complication/received-editable-implementation.h index be42d5f..24d449f 100644 --- a/watchface-complication/received-editable-implementation.h +++ b/watchface-complication/received-editable-implementation.h @@ -18,6 +18,7 @@ #define WATCHFACE_COMPLICATION_RECEIVED_EDITABLE_IMPLEMENTATION_H_ #include +#include #include #include @@ -42,8 +43,8 @@ class ReceivedEditable::Impl { private: ReceivedEditable* parent_; int id_ = -1; - Bundle* cur_data_ = nullptr; - std::list> candidates_list_; + tizen_base::Bundle* cur_data_ = nullptr; + std::list> candidates_list_; std::unique_ptr highlight_; EditableShapeType shape_type_ = Circle; std::string name_; @@ -51,8 +52,8 @@ class ReceivedEditable::Impl { int cur_data_idx_ = -1; int last_data_idx_ = -1; IEditable::EditableState ed_state_ = Complete; - std::unique_ptr context_data_; - std::unique_ptr last_context_data_ = nullptr; + std::unique_ptr context_data_; + std::unique_ptr last_context_data_ = nullptr; }; } // namespace watchface_complication diff --git a/watchface-complication/received-editable.cc b/watchface-complication/received-editable.cc index b751a02..1dccd84 100644 --- a/watchface-complication/received-editable.cc +++ b/watchface-complication/received-editable.cc @@ -17,6 +17,7 @@ #include #include #include +#include #include "watchface-complication/received-editable.h" #include "watchface-complication/received-editable-implementation.h" @@ -29,6 +30,8 @@ #define LOG_TAG "WATCHFACE_COMPLICATION" #define MAX_PACKAGE_STR_SIZE 512 +using namespace std; +using namespace tizen_base; namespace watchface_complication { ReceivedEditable::ReceivedEditable(std::string raw) @@ -40,92 +43,63 @@ ReceivedEditable::Impl::Impl(ReceivedEditable* parent, std::string raw) : parent_(parent) { if (raw.empty()) THROW(WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER); - - bundle* data = NULL; try { - data = bundle_decode( - reinterpret_cast( - raw.c_str()), raw.length()); - const char** str_arr = NULL; - int len = 0; - char* val = NULL; - - str_arr = bundle_get_str_array(data, "CANDIDATES_LIST", &len); - for (int i = 0; i < len; i++) { - LOGD("%s", str_arr[i]); - candidates_list_.emplace_back(new Bundle(str_arr[i])); + Bundle data(raw); + vector candidate_list = data.GetStringArray("CANDIDATES_LIST"); + for (auto& i : candidate_list) { + LOGD("%s", i.c_str()); + candidates_list_.emplace_back(new Bundle(i)); } - char* cur_data_idx_str = NULL; - int ret = bundle_get_str(data, "CUR_DATA_IDX", &cur_data_idx_str); - if (ret != BUNDLE_ERROR_NONE) - THROW(WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER); - cur_data_idx_ = atoi(cur_data_idx_str); - - char* setup_appid = NULL; - ret = bundle_get_str(data, "SETUP_APPID", &setup_appid); - if (ret == BUNDLE_ERROR_NONE) - setup_appid_ = std::string(setup_appid); - else - setup_appid_ = ""; - - char* editable_id_str = NULL; - ret = bundle_get_str(data, "EDITABLE_ID", &editable_id_str); - if (ret != BUNDLE_ERROR_NONE) + string cur_data_idx_str = data.GetString("CUR_DATA_IDX"); + if (cur_data_idx_str.empty()) THROW(WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER); - id_ = atoi(editable_id_str); + cur_data_idx_ = stoi(cur_data_idx_str); - ret = bundle_get_str(data, "GEO_X", &val); - if (ret == BUNDLE_ERROR_NONE) { - int x = atoi(val); + setup_appid_ = data.GetString("SETUP_APPID"); + string editable_id_str = data.GetString("EDITABLE_ID"); + if (editable_id_str.empty()) + THROW(WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER); + id_ = stoi(editable_id_str); - ret = bundle_get_str(data, "GEO_Y", &val); - if (ret != BUNDLE_ERROR_NONE) + string val = data.GetString("GEO_X"); + if (!val.empty()) { + int x = stoi(val); + val = data.GetString("GEO_Y"); + if (val.empty()) THROW(WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER); - int y = atoi(val); - - ret = bundle_get_str(data, "GEO_W", &val); - if (ret != BUNDLE_ERROR_NONE) + int y = stoi(val); + val = data.GetString("GEO_W"); + if (val.empty()) THROW(WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER); - int w = atoi(val); - - ret = bundle_get_str(data, "GEO_H", &val); - if (ret != BUNDLE_ERROR_NONE) + int w = stoi(val); + val = data.GetString("GEO_H"); + if (val.empty()) THROW(WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER); - int h = atoi(val); - + int h = stoi(val); Geometry geo(x, y, w, h); highlight_ = std::unique_ptr(new IEditable::Highlight()); highlight_->SetGeometry(geo); } - ret = bundle_get_str(data, "SHAPE_TYPE", &val); - if (ret == BUNDLE_ERROR_NONE) { - if (highlight_.get() == NULL) + val = data.GetString("SHAPE_TYPE"); + if (!val.empty()) { + if (highlight_.get() == nullptr) { highlight_ = std::unique_ptr( new IEditable::Highlight()); + } highlight_->SetShapeType( - static_cast(atoi(val))); + static_cast(stoi(val))); } - - ret = bundle_get_str(data, "NAME", &val); - if (ret != BUNDLE_ERROR_NONE) - name_ = ""; - else - name_ = std::string(val); - + name_ = data.GetString("NAME"); } catch (const std::bad_alloc &ba) { - if (data) - bundle_free(data); LOGE("ReceivedEditable::Exception bad_alloc"); THROW(WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY); } catch (Exception &ex) { - if (data) - bundle_free(data); LOGE("%s %d", ex.what(), ex.GetErrorCode()); THROW(ex.GetErrorCode()); } @@ -151,12 +125,12 @@ IEditable::Highlight* ReceivedEditable::GetHighlight() { /* LCOV_EXCL_START */ int ReceivedEditable::SetCandidates( - std::list> candidates_list) { + std::list> candidates_list) { return WATCHFACE_COMPLICATION_ERROR_NONE; } /* LCOV_EXCL_STOP */ -std::list> const& ReceivedEditable::GetCandidates() +std::list> const& ReceivedEditable::GetCandidates() const { return impl_->candidates_list_; } @@ -174,27 +148,24 @@ int ReceivedEditable::UpdateLastData() { return WATCHFACE_COMPLICATION_ERROR_NONE; } -const Bundle* ReceivedEditable::GetCurData() { +shared_ptr ReceivedEditable::GetCurData() { if (impl_->candidates_list_.size() == 0 || impl_->cur_data_idx_ < 0) - return NULL; - std::list>::iterator it + return shared_ptr({}); + std::list>::iterator it = impl_->candidates_list_.begin(); LOGI("get cur data %d", impl_->cur_data_idx_); - auto nx = std::next(it, impl_->cur_data_idx_); - return nx->get(); + return *std::next(it, impl_->cur_data_idx_); } -const Bundle* ReceivedEditable::GetNthData(int nth) { +shared_ptr ReceivedEditable::GetNthData(int nth) { if (static_cast(impl_->candidates_list_.size()) <= nth || nth < 0) - return NULL; + return shared_ptr({}); - std::list>::iterator it + std::list>::iterator it = impl_->candidates_list_.begin(); - LOGI("get nth data %d", nth); - auto nx = std::next(it, nth); - return nx->get(); + return *std::next(it, nth); } int ReceivedEditable::SetCurDataIdx(int cur_data_idx) { @@ -253,7 +224,7 @@ int ReceivedEditable::UpdateLastContext() { try { impl_->last_context_data_.reset( - new Bundle((impl_->context_data_.get())->GetRaw())); + new Bundle((impl_->context_data_.get())->GetHandle())); } catch (const std::bad_alloc &ba) { LOGE("Bundle::Exception bad_alloc"); return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY; diff --git a/watchface-complication/received-editable.h b/watchface-complication/received-editable.h index f96e878..f1c62c5 100644 --- a/watchface-complication/received-editable.h +++ b/watchface-complication/received-editable.h @@ -18,6 +18,7 @@ #define WATCHFACE_COMPLICATION_RECEIVED_EDITABLE_H_ #include +#include #include #include @@ -39,10 +40,10 @@ class EXPORT_API ReceivedEditable : public IEditable { public: int SetHighlight(std::unique_ptr highlight) override; IEditable::Highlight* GetHighlight() override; - std::list> const& GetCandidates() const override; - int SetCandidates(std::list> candidates_list) override; - const Bundle* GetCurData() override; - const Bundle* GetNthData(int nth) override; + std::list> const& GetCandidates() const override; + int SetCandidates(std::list> candidates_list) override; + std::shared_ptr GetCurData() override; + std::shared_ptr GetNthData(int nth) override; int GetCurDataIdx() override; int SetCurDataIdx(int cur_data_idx) override; int GetLastDataIdx() override; @@ -55,10 +56,10 @@ class EXPORT_API ReceivedEditable : public IEditable { void SetLabel(const std::string& name) override; void SetState(IEditable::EditableState state) override; IEditable::EditableState GetState() override; - int SetContext(std::unique_ptr context) override; - std::unique_ptr& GetContext() const override; + int SetContext(std::unique_ptr context) override; + std::unique_ptr& GetContext() const override; int UpdateLastContext() override; - std::unique_ptr& GetLastContext() const override; + std::unique_ptr& GetLastContext() const override; const std::string GetSetupAppId() override; private: diff --git a/watchface-complication/watchface-complication.cc b/watchface-complication/watchface-complication.cc index c892ea6..574b1bf 100644 --- a/watchface-complication/watchface-complication.cc +++ b/watchface-complication/watchface-complication.cc @@ -42,6 +42,7 @@ struct complication_allowed_list_ { GList* allowed_list; }; +using namespace tizen_base; using namespace watchface_complication; class CallbackInfo { public: @@ -55,7 +56,7 @@ class CallbackInfo { ComplicationType type, const std::unique_ptr& data) { cb_(complication_id, provider_id.c_str(), static_cast(type), - data.get() == NULL ? NULL : data.get()->GetConstRaw(), user_data_); + data.get() == NULL ? NULL : data.get()->GetHandle(), user_data_); } void InvokeErrorCallback(int complication_id, @@ -321,11 +322,11 @@ extern "C" EXPORT_API int watchface_complication_get_current_provider_id( char* tmp; auto sh = static_cast*>(handle); auto ptr = SharedHandle::Share(sh); - if (ptr.get()->GetCurProviderId() == NULL) + if (ptr.get()->GetCurProviderId().empty()) return WATCHFACE_COMPLICATION_ERROR_NO_DATA; - LOGI("provider id : %s", ptr.get()->GetCurProviderId()); - tmp = strdup(ptr.get()->GetCurProviderId()); + LOGI("provider id : %s", ptr.get()->GetCurProviderId().c_str()); + tmp = strdup(ptr.get()->GetCurProviderId().c_str()); if (tmp == NULL) return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY; diff --git a/watchface-complication/watchface-editable.cc b/watchface-complication/watchface-editable.cc index 57aad0b..248daa8 100644 --- a/watchface-complication/watchface-editable.cc +++ b/watchface-complication/watchface-editable.cc @@ -36,12 +36,12 @@ #define LOG_TAG "WATCHFACE_COMPLICATION" using watchface_complication::EditablesContainer; -using watchface_complication::Bundle; using watchface_complication::IEditable; using watchface_complication::DesignElement; using watchface_complication::SharedHandle; using watchface_complication::EditablesManager; - +using namespace std; +using namespace tizen_base; struct complication_candidates_list_ { GList* candidates_list; }; @@ -190,7 +190,7 @@ extern "C" EXPORT_API int watchface_editable_add_design_element( int ret; bundle_raw* str_raw = NULL; GList* iter = list_handle->candidates_list; - std::list> new_list; + std::list> new_list; for (; iter; iter = iter->next) { data = reinterpret_cast(iter->data); @@ -223,7 +223,7 @@ extern "C" EXPORT_API int watchface_editable_add_design_element( de.get()->SetHighlight(std::move(hi_ptr)); } de.get()->SetLabel(std::string(editable_name)); - ret = de.get()->SetCandidates(std::move(new_list)); + ret = de.get()->SetCandidates(new_list); if (ret != WATCHFACE_COMPLICATION_ERROR_NONE) return ret; @@ -251,7 +251,7 @@ extern "C" EXPORT_API int watchface_editable_add_complication( /* Update candidates */ ret = SharedHandle::Share(sh).get()->SetCandidates( - std::list>()); + std::list>()); if (ret != WATCHFACE_COMPLICATION_ERROR_NONE) return ret; @@ -399,11 +399,11 @@ extern "C" EXPORT_API int watchface_editable_get_current_data( return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER; IEditable* ie = static_cast(handle); - const Bundle* data = ie->GetCurData(); - if (data == NULL) + shared_ptr data = ie->GetCurData(); + if (data.get() == nullptr) return WATCHFACE_COMPLICATION_ERROR_NO_DATA; - if (data->GetConstRaw() != NULL) { - *cur_data = bundle_dup(const_cast(data->GetConstRaw())); + if (data->GetHandle() != NULL) { + *cur_data = bundle_dup(data->GetHandle()); if (*cur_data == NULL) return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY; } else { @@ -421,11 +421,11 @@ extern "C" EXPORT_API int watchface_editable_get_nth_data( return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER; IEditable* ie = static_cast(handle); - const Bundle* data = ie->GetNthData(nth); - if (data == NULL) + shared_ptr data = ie->GetNthData(nth); + if (data.get() == nullptr) return WATCHFACE_COMPLICATION_ERROR_NO_DATA; - if (data->GetConstRaw() != NULL) { - *nth_data = bundle_dup(const_cast(data->GetConstRaw())); + if (data->GetHandle() != NULL) { + *nth_data = bundle_dup(data->GetHandle()); if (*nth_data == NULL) return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY; } else { @@ -499,7 +499,7 @@ extern "C" EXPORT_API int watchface_editable_load_current_data( return ex.GetErrorCode(); } if (setting_data != nullptr) { - *selected_data = bundle_dup(setting_data.get()->GetRaw()); + *selected_data = bundle_dup(setting_data.get()->GetHandle()); if (*selected_data == NULL) return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY; } else { diff --git a/watchface-editor/editables-editor-event-interface.h b/watchface-editor/editables-editor-event-interface.h index 0d0b12c..5b545b8 100644 --- a/watchface-editor/editables-editor-event-interface.h +++ b/watchface-editor/editables-editor-event-interface.h @@ -19,7 +19,6 @@ #include -#include "watchface-complication/complication-bundle.h" #include "watchface-complication/complication.h" namespace watchface_complication { diff --git a/watchface-editor/editables-editor.cc b/watchface-editor/editables-editor.cc index b251ab4..76f8372 100644 --- a/watchface-editor/editables-editor.cc +++ b/watchface-editor/editables-editor.cc @@ -32,6 +32,7 @@ #define LOG_TAG "WATCHFACE_COMPLICATION" +using namespace tizen_base; namespace watchface_complication { EditablesEditor::EditablesEditor(bool mock) @@ -183,7 +184,11 @@ int EditablesEditor::EditPreview(IEditable& ed, int cur_data_idx) { -1, util::GetCmdStr(util::CmdType::EditableEditPreview), g_variant_new("(iis)", cur_data_idx, ed.GetEditableId(), - (context == nullptr) ? "" : context->ToString())); + (context == nullptr) ? "" : + reinterpret_cast(context->ToRaw().first.get() + ) + ) + ); if (emit_result) return WATCHFACE_COMPLICATION_ERROR_NONE; diff --git a/watchface-editor/editables-editor.h b/watchface-editor/editables-editor.h index ef66289..4b19441 100644 --- a/watchface-editor/editables-editor.h +++ b/watchface-editor/editables-editor.h @@ -18,6 +18,7 @@ #define WATCHFACE_EDITOR_EDITABLES_EDITOR_H_ #include +#include #include #include @@ -34,7 +35,7 @@ class EXPORT_API EditablesEditor : IEditablesContainerEvent { void OnRequestEdit(const std::string& appid, std::list> e_list) override; void OnSetupReply(const std::string& appid, - int editable_id, std::unique_ptr context) override; + int editable_id, std::unique_ptr context) override; int EditPreview(IEditable& ed, int cur_data_idx); int EditComplete(); int EditCancel(); diff --git a/watchface-editor/watchface-editor.cc b/watchface-editor/watchface-editor.cc index 32ea597..a612bb3 100644 --- a/watchface-editor/watchface-editor.cc +++ b/watchface-editor/watchface-editor.cc @@ -33,6 +33,7 @@ #define LOG_TAG "WATCHFACE_COMPLICATION" +using namespace tizen_base; using namespace watchface_complication; class CallbackInfo { @@ -108,7 +109,7 @@ class EditablesEditorStub : public EditablesEditor { LOGI("Setup reply!! %s, %d", appid.c_str(), editable_id); for (auto& i : setup_cb_list_) { if (i.get()->CompareInfo(appid, editable_id)) { - i.get()->Invoke(context.get()->GetRaw()); + i.get()->Invoke(context.get()->GetHandle()); setup_cb_list_.remove(i); return; } @@ -387,7 +388,7 @@ extern "C" EXPORT_API int watchface_editor_editable_candidate_list_get_size( } IEditable* ed = static_cast(handle); - std::list> const& list = ed->GetCandidates(); + std::list> const& list = ed->GetCandidates(); *size = list.size(); return WATCHFACE_COMPLICATION_ERROR_NONE; } @@ -404,11 +405,11 @@ extern "C" EXPORT_API int watchface_editor_editable_candidate_list_get_nth( bundle* tmp; IEditable* ed = static_cast(handle); - const std::list>& list = ed->GetCandidates(); - const std::list>::const_iterator it + const std::list>& list = ed->GetCandidates(); + const std::list>::const_iterator it = list.begin(); auto nx = std::next(it, nth); - tmp = bundle_dup(((*nx).get())->GetRaw()); + tmp = bundle_dup((*nx)->GetHandle()); if (tmp == NULL) return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY; @@ -547,7 +548,7 @@ extern "C" EXPORT_API int watchface_editor_launch_setup_app( context_data = (ed->GetContext()).get(); if (context_data != nullptr) { ret = _add_extra_data(service, SETUP_CONTEXT_DATA_KEY, - context_data->ToString()); + reinterpret_cast(context_data->ToRaw().first.get())); if (ret != WATCHFACE_COMPLICATION_ERROR_NONE) { LOGE("Fail to add setup_context_data %d", ret); app_control_destroy(service); -- 2.7.4