From 9f0f08d0cc34b7072d4568fd0a9fe9a650220eb8 Mon Sep 17 00:00:00 2001 From: Piotr Kosko Date: Wed, 5 Jul 2017 14:42:40 +0200 Subject: [PATCH] [Notification] added C++ stubs for UserNotification [Verification] Code compiles without error. TCT passrate didn't change. Change-Id: I83deb2c0ce692ee67c86213d3a9552dadceb7bb9 Signed-off-by: Piotr Kosko --- src/notification/common_notification.cc | 60 +++++++++++++++++++++++++++++- src/notification/common_notification.h | 14 ++++++- src/notification/notification.gyp | 2 + src/notification/notification_instance.cc | 30 +++------------ src/notification/notification_manager.cc | 44 ++++++++++------------ src/notification/notification_manager.h | 7 +--- src/notification/status_notification.cc | 53 +-------------------------- src/notification/status_notification.h | 5 +-- src/notification/user_notification.cc | 61 +++++++++++++++++++++++++++++++ src/notification/user_notification.h | 45 +++++++++++++++++++++++ 10 files changed, 210 insertions(+), 111 deletions(-) create mode 100644 src/notification/user_notification.cc create mode 100644 src/notification/user_notification.h diff --git a/src/notification/common_notification.cc b/src/notification/common_notification.cc index ccaa6c7..233d424 100644 --- a/src/notification/common_notification.cc +++ b/src/notification/common_notification.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2015-2017 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,6 @@ #include "notification/common_notification.h" -#include #include #include @@ -976,5 +975,62 @@ PlatformResult CommonNotification::SetAppControl(notification_h noti_handle, return PlatformResult(ErrorCode::NO_ERROR); } +common::PlatformResult CommonNotification::UpdateNotificationAfterPost( + notification_h noti_handle, int id, picojson::object* out_ptr) { + time_t posted_time; + PlatformResult status = GetPostedTime(noti_handle, &posted_time); + if (status.IsError()) { + return status; + } + + picojson::object& out = *out_ptr; + out["postedTime"] = + picojson::value(static_cast(posted_time) * 1000.0); + out["id"] = picojson::value(std::to_string(id)); + out["type"] = picojson::value("STATUS"); + + return PlatformResult(ErrorCode::NO_ERROR); +} + +PlatformResult CommonNotification::PostNotification(const picojson::object& args, + bool is_update, + picojson::object* out_ptr, + GetHandleFromJsonFun getHandle) { + LoggerD("Enter"); + notification_h noti_handle = nullptr; + int ret = NOTIFICATION_ERROR_NONE; + int id = NOTIFICATION_PRIV_ID_NONE; + + SCOPE_EXIT { + notification_free(noti_handle); + }; + + PlatformResult status = getHandle(args, is_update, ¬i_handle); + + if (status.IsError()){ + return status; + } + + if (is_update) { + ret = notification_update(noti_handle); + if (NOTIFICATION_ERROR_NONE != ret) { + return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, + "Update notification error", + ("Update notification error: %d", ret)); + } + return PlatformResult(ErrorCode::NO_ERROR); + } else { + ret = notification_insert(noti_handle, &id); + if (NOTIFICATION_ERROR_NONE != ret) { + return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, + "Cannot insert notification", + ("Cannot insert notification: %d", ret)); + } + } + + return UpdateNotificationAfterPost(noti_handle, id, out_ptr); +} + + } // namespace notification } // namespace extension diff --git a/src/notification/common_notification.h b/src/notification/common_notification.h index 591e998..69b7101 100644 --- a/src/notification/common_notification.h +++ b/src/notification/common_notification.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2015-2017 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ #include #include +#include #include "common/picojson.h" #include "common/platform_result.h" @@ -34,6 +35,10 @@ const std::string kProgressTypeByte = "BYTE"; typedef std::map InformationEnumMap; typedef std::map ImageEnumMap; +typedef std::function GetHandleFromJsonFun; + class CommonNotification { public: XW_EXPORT static common::PlatformResult GetAppControl(notification_h noti_handle, @@ -124,6 +129,13 @@ class CommonNotification { static common::PlatformResult CreateAppControl(app_control_h* app_control); static bool IsColorFormatNumberic(const std::string& color); + static common::PlatformResult UpdateNotificationAfterPost(notification_h noti_handle, int id, + picojson::object* out_ptr); + static common::PlatformResult PostNotification(const picojson::object& args, + bool is_update, + picojson::object* out_ptr, + GetHandleFromJsonFun getHandle); + protected: CommonNotification(); virtual ~CommonNotification(); diff --git a/src/notification/notification.gyp b/src/notification/notification.gyp index 6374a5d..32a8fd9 100755 --- a/src/notification/notification.gyp +++ b/src/notification/notification.gyp @@ -19,6 +19,8 @@ 'notification_manager.cc', 'status_notification.cc', 'status_notification.h', + 'user_notification.cc', + 'user_notification.h', 'common_notification.cc', 'common_notification.h' ], diff --git a/src/notification/notification_instance.cc b/src/notification/notification_instance.cc index a4ffee9..5447733 100644 --- a/src/notification/notification_instance.cc +++ b/src/notification/notification_instance.cc @@ -16,8 +16,6 @@ #include "notification/notification_instance.h" -#include - #include "common/logger.h" #include "common/picojson.h" #include "common/platform_result.h" @@ -155,17 +153,9 @@ void NotificationInstance::NotificationManagerGet(const picojson::value& args, LoggerD("Enter"); picojson::value val{picojson::object{}}; - using namespace std::placeholders; - std::function impl {}; - if (args.contains("newImpl") && args.get("newImpl").get()) { - LoggerD("New implementation"); - impl = std::bind(&NotificationManager::GetUserNoti, manager_, _1, _2); - } else { - LoggerW("Deprecated object used"); - impl = std::bind(&NotificationManager::Get, manager_, _1, _2); - } - - PlatformResult status = impl(args.get(), val.get()); + PlatformResult status = manager_->Get( + args.get(), val.get(), + args.contains("newImpl") && args.get("newImpl").get()); if (status.IsSuccess()) { ReportSuccess(val, out); @@ -180,17 +170,9 @@ void NotificationInstance::NotificationManagerGetAll( LoggerD("Enter"); picojson::value val{picojson::array{}}; - using namespace std::placeholders; - std::function impl {}; - if (args.contains("newImpl") && args.get("newImpl").get()) { - LoggerD("New implementation"); - impl = std::bind(&NotificationManager::GetAllUserNoti, manager_, _1); - } else { - LoggerW("Deprecated object used"); - impl = std::bind(&NotificationManager::GetAll, manager_, _1); - } - - PlatformResult status = impl(val.get()); + PlatformResult status = manager_->GetAll( + val.get(), + args.contains("newImpl") && args.get("newImpl").get()); if (status.IsSuccess()) { ReportSuccess(val, out); diff --git a/src/notification/notification_manager.cc b/src/notification/notification_manager.cc index 6079a9d..81e7b00 100644 --- a/src/notification/notification_manager.cc +++ b/src/notification/notification_manager.cc @@ -30,6 +30,7 @@ #include "common/scope_exit.h" #include "notification/status_notification.h" +#include "notification/user_notification.h" #include "notification/common_notification.h" namespace extension { @@ -54,7 +55,7 @@ NotificationManager* NotificationManager::GetInstance() { PlatformResult NotificationManager::Post(const picojson::object& args, picojson::object& out) { LoggerD("Enter"); - return StatusNotification::FromJson(args, false, &out); + return StatusNotification::PostStatusNotification(args, false, &out); } PlatformResult NotificationManager::PostUserNoti(const picojson::object& args, @@ -68,7 +69,7 @@ PlatformResult NotificationManager::PostUserNoti(const picojson::object& args, PlatformResult NotificationManager::Update(const picojson::object& args) { LoggerD("Enter"); - return StatusNotification::FromJson(args, true, NULL); + return StatusNotification::PostStatusNotification(args, true, NULL); } PlatformResult NotificationManager::UpdateUserNoti(const picojson::object& args) { @@ -114,7 +115,7 @@ PlatformResult NotificationManager::RemoveAll() { } PlatformResult NotificationManager::Get(const picojson::object& args, - picojson::object& out) { + picojson::object& out, bool is_new_impl) { LoggerD("Enter"); int id; try { @@ -147,7 +148,12 @@ PlatformResult NotificationManager::Get(const picojson::object& args, LoggerE("Failed: GetAppControl"); return status; } - status = StatusNotification::ToJson(id, noti_handle, app_control, &out); + + if (!is_new_impl) { + status = StatusNotification::ToJson(id, noti_handle, app_control, &out); + } else { + status = UserNotification::ToJson(id, noti_handle, app_control, &out); + } if (status.IsError()) { LoggerE("Failed: ToJson"); @@ -156,16 +162,7 @@ PlatformResult NotificationManager::Get(const picojson::object& args, return PlatformResult(ErrorCode::NO_ERROR); } -PlatformResult NotificationManager::GetUserNoti(const picojson::object& args, - picojson::object& out) { - LoggerD("Enter"); - // TODO implement - return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR, - "Not implemented yet", - ("Not implemented yet")); -} - -PlatformResult NotificationManager::GetAll(picojson::array& out) { +PlatformResult NotificationManager::GetAll(picojson::array& out, bool is_new_impl) { LoggerD("Enter"); notification_h noti = nullptr; notification_list_h noti_list = nullptr; @@ -219,8 +216,13 @@ PlatformResult NotificationManager::GetAll(picojson::array& out) { picojson::object noti_item = picojson::object(); - status = - StatusNotification::ToJson(noti_priv, noti, app_control, ¬i_item); + if (!is_new_impl) { + status = + StatusNotification::ToJson(noti_priv, noti, app_control, ¬i_item); + } else { + status = + UserNotification::ToJson(noti_priv, noti, app_control, ¬i_item); + } if (status.IsError()) return status; @@ -233,14 +235,6 @@ PlatformResult NotificationManager::GetAll(picojson::array& out) { return PlatformResult(ErrorCode::NO_ERROR); } -PlatformResult NotificationManager::GetAllUserNoti(picojson::array& out) { - LoggerD("Enter"); - // TODO implement - return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR, - "Not implemented yet", - ("Not implemented yet")); -} - PlatformResult NotificationManager::PlayLEDCustomEffect( const picojson::object& args) { LoggerD("Enter"); @@ -290,6 +284,7 @@ common::PlatformResult NotificationManager::SaveTemplate(const picojson::object& notification_free(noti_handle); }; + // TODO use UserNotification method PlatformResult status = StatusNotification::GetNotiHandleFromJson(args, false, ¬i_handle); if (status.IsError()){ @@ -331,6 +326,7 @@ common::PlatformResult NotificationManager::CreateFromTemplate(const picojson::o notification_free(noti_handle); }; + // TODO use UserNotification method PlatformResult status = StatusNotification::ToJson(0, noti_handle, nullptr, &out); if (status.IsError()) { diff --git a/src/notification/notification_manager.h b/src/notification/notification_manager.h index 770cc7e..6ba779d 100644 --- a/src/notification/notification_manager.h +++ b/src/notification/notification_manager.h @@ -38,11 +38,8 @@ class NotificationManager { common::PlatformResult Remove(const picojson::object& args); common::PlatformResult RemoveAll(); common::PlatformResult Get(const picojson::object& args, - picojson::object& out); - common::PlatformResult GetUserNoti(const picojson::object& args, - picojson::object& out); - common::PlatformResult GetAll(picojson::array& out); - common::PlatformResult GetAllUserNoti(picojson::array& out); + picojson::object& out, bool is_new_impl = false); + common::PlatformResult GetAll(picojson::array& out, bool is_new_impl = false); common::PlatformResult PlayLEDCustomEffect(const picojson::object& args); common::PlatformResult StopLEDCustomEffect(); diff --git a/src/notification/status_notification.cc b/src/notification/status_notification.cc index f2378ca..7b1d0e2 100644 --- a/src/notification/status_notification.cc +++ b/src/notification/status_notification.cc @@ -16,10 +16,6 @@ #include "notification/status_notification.h" -#include -#include -#include - #include "common/converter.h" #include "common/logger.h" #include "common/scope_exit.h" @@ -406,56 +402,11 @@ PlatformResult StatusNotification::GetNotiHandleFromJson(const picojson::object& return PlatformResult(ErrorCode::NO_ERROR); } -PlatformResult StatusNotification::FromJson(const picojson::object& args, +PlatformResult StatusNotification::PostStatusNotification(const picojson::object& args, bool is_update, picojson::object* out_ptr) { LoggerD("Enter"); - notification_h noti_handle = nullptr; - int ret; - int id = NOTIFICATION_PRIV_ID_NONE; - - SCOPE_EXIT { - notification_free(noti_handle); - }; - - PlatformResult status = GetNotiHandleFromJson(args, is_update, ¬i_handle); - - if (status.IsError()){ - return status; - } - - if (is_update) { - ret = notification_update(noti_handle); - } else { - ret = notification_insert(noti_handle, &id); - if (NOTIFICATION_ERROR_NONE != ret) { - return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, - "Cannot insert notification"); - } - } - if (ret != NOTIFICATION_ERROR_NONE) { - return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, - "Post/Update notification error", - ("Post/Update notification error: %d", ret)); - } - - time_t posted_time; - status = GetPostedTime(noti_handle, &posted_time); - if (status.IsError()) { - return status; - } - - if (is_update) { - return PlatformResult(ErrorCode::NO_ERROR); - } - - picojson::object& out = *out_ptr; - out["id"] = picojson::value(std::to_string(id)); - out["postedTime"] = - picojson::value(static_cast(posted_time) * 1000.0); - out["type"] = picojson::value("STATUS"); - - return PlatformResult(ErrorCode::NO_ERROR); + return PostNotification(args, is_update, out_ptr, GetNotiHandleFromJson); } } // namespace notification diff --git a/src/notification/status_notification.h b/src/notification/status_notification.h index fccf002..3360729 100644 --- a/src/notification/status_notification.h +++ b/src/notification/status_notification.h @@ -30,9 +30,6 @@ namespace extension { namespace notification { -typedef std::map InformationEnumMap; -typedef std::map ImageEnumMap; - class StatusNotification : public CommonNotification { public: XW_EXPORT static common::PlatformResult ToJson(int id, @@ -42,7 +39,7 @@ class StatusNotification : public CommonNotification { XW_EXPORT static common::PlatformResult GetNotiHandleFromJson(const picojson::object& args, bool is_update, notification_h *noti_handle); - static common::PlatformResult FromJson(const picojson::object& args, + static common::PlatformResult PostStatusNotification(const picojson::object& args, bool is_update, picojson::object* out_ptr); private: diff --git a/src/notification/user_notification.cc b/src/notification/user_notification.cc new file mode 100644 index 0000000..0d5cacd --- /dev/null +++ b/src/notification/user_notification.cc @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 "notification/user_notification.h" + +#include "common/logger.h" +#include "common/scope_exit.h" + +namespace extension { +namespace notification { + +using namespace common; + +UserNotification::UserNotification() { +} + +UserNotification::~UserNotification() { +} + +PlatformResult UserNotification::ToJson(int id, + notification_h noti_handle, + app_control_h app_handle, + picojson::object* out_ptr) { + LoggerD("Enter"); + return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR, + "Not implemented yet", + ("Not implemented yet")); +} + +PlatformResult UserNotification::GetNotiHandleFromJson(const picojson::object& args, + bool is_update, + notification_h *noti_handle){ + LoggerD("Enter"); + return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR, + "Not implemented yet", + ("Not implemented yet")); +} + +PlatformResult UserNotification::PostUserNotification(const picojson::object& args, + bool is_update, + picojson::object* out_ptr) { + LoggerD("Enter"); + return PostNotification(args, is_update, out_ptr, GetNotiHandleFromJson); +} + + +} // namespace notification +} // namespace extension diff --git a/src/notification/user_notification.h b/src/notification/user_notification.h new file mode 100644 index 0000000..a0fb44e --- /dev/null +++ b/src/notification/user_notification.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 NOTIFICATION_USER_NOTIFICATION_H_ +#define NOTIFICATION_USER_NOTIFICATION_H_ + +#include "notification/common_notification.h" + +namespace extension { +namespace notification { + +class UserNotification : public CommonNotification { + public: + XW_EXPORT static common::PlatformResult ToJson(int id, + notification_h noti_handle, + app_control_h app_handle, + picojson::object* out_ptr); + XW_EXPORT static common::PlatformResult GetNotiHandleFromJson(const picojson::object& args, + bool is_update, + notification_h *noti_handle); + static common::PlatformResult PostUserNotification(const picojson::object& args, + bool is_update, + picojson::object* out_ptr); + private: + UserNotification(); + virtual ~UserNotification(); +}; + +} // namespace notification +} // namespace extension + +#endif /* NOTIFICATION_USER_NOTIFICATION_H_ */ -- 2.7.4