[Verification] Code compiles without error.
TCT passrate didn't change.
Change-Id: I83deb2c0ce692ee67c86213d3a9552dadceb7bb9
Signed-off-by: Piotr Kosko <p.kosko@samsung.com>
/*
- * 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.
#include "notification/common_notification.h"
-#include <notification.h>
#include <notification_internal.h>
#include <app_control_internal.h>
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<double>(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
/*
- * 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.
#include <notification.h>
#include <app_control.h>
+#include <functional>
#include "common/picojson.h"
#include "common/platform_result.h"
typedef std::map<int, notification_text_type_e> InformationEnumMap;
typedef std::map<int, notification_image_type_e> ImageEnumMap;
+typedef std::function<common::PlatformResult(const picojson::object& args,
+ bool is_update,
+ notification_h *noti_handle)> GetHandleFromJsonFun;
+
class CommonNotification {
public:
XW_EXPORT static common::PlatformResult GetAppControl(notification_h noti_handle,
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();
'notification_manager.cc',
'status_notification.cc',
'status_notification.h',
+ 'user_notification.cc',
+ 'user_notification.h',
'common_notification.cc',
'common_notification.h'
],
#include "notification/notification_instance.h"
-#include <functional>
-
#include "common/logger.h"
#include "common/picojson.h"
#include "common/platform_result.h"
LoggerD("Enter");
picojson::value val{picojson::object{}};
- using namespace std::placeholders;
- std::function <PlatformResult(const picojson::object& args, picojson::object&)> impl {};
- if (args.contains("newImpl") && args.get("newImpl").get<bool>()) {
- 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<picojson::object>(), val.get<picojson::object>());
+ PlatformResult status = manager_->Get(
+ args.get<picojson::object>(), val.get<picojson::object>(),
+ args.contains("newImpl") && args.get("newImpl").get<bool>());
if (status.IsSuccess()) {
ReportSuccess(val, out);
LoggerD("Enter");
picojson::value val{picojson::array{}};
- using namespace std::placeholders;
- std::function <PlatformResult(picojson::array&)> impl {};
- if (args.contains("newImpl") && args.get("newImpl").get<bool>()) {
- 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<picojson::array>());
+ PlatformResult status = manager_->GetAll(
+ val.get<picojson::array>(),
+ args.contains("newImpl") && args.get("newImpl").get<bool>());
if (status.IsSuccess()) {
ReportSuccess(val, out);
#include "common/scope_exit.h"
#include "notification/status_notification.h"
+#include "notification/user_notification.h"
#include "notification/common_notification.h"
namespace extension {
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,
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) {
}
PlatformResult NotificationManager::Get(const picojson::object& args,
- picojson::object& out) {
+ picojson::object& out, bool is_new_impl) {
LoggerD("Enter");
int id;
try {
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");
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;
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;
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");
notification_free(noti_handle);
};
+ // TODO use UserNotification method
PlatformResult status = StatusNotification::GetNotiHandleFromJson(args, false, ¬i_handle);
if (status.IsError()){
notification_free(noti_handle);
};
+ // TODO use UserNotification method
PlatformResult status = StatusNotification::ToJson(0, noti_handle, nullptr, &out);
if (status.IsError())
{
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();
#include "notification/status_notification.h"
-#include <notification.h>
-#include <notification_internal.h>
-#include <app_control_internal.h>
-
#include "common/converter.h"
#include "common/logger.h"
#include "common/scope_exit.h"
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<double>(posted_time) * 1000.0);
- out["type"] = picojson::value("STATUS");
-
- return PlatformResult(ErrorCode::NO_ERROR);
+ return PostNotification(args, is_update, out_ptr, GetNotiHandleFromJson);
}
} // namespace notification
namespace extension {
namespace notification {
-typedef std::map<int, notification_text_type_e> InformationEnumMap;
-typedef std::map<int, notification_image_type_e> ImageEnumMap;
-
class StatusNotification : public CommonNotification {
public:
XW_EXPORT static common::PlatformResult ToJson(int id,
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:
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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_ */