};
using namespace std::placeholders;
- std::function <PlatformResult(const picojson::object& args,
- bool is_update,
- notification_h *noti_handle)> impl {};
+ GetHandleFromJsonFun impl {};
if (args.contains("newImpl") && args.get("newImpl").is<bool>()
&& args.get("newImpl").get<bool>()) {
LoggerD("New implementation");
impl = std::bind(&StatusNotification::GetNotiHandleFromJson, _1, _2, _3);
}
- PlatformResult platform_result = impl(args.get<picojson::object>(),
- false, ¬ification_handle);
+ PlatformResult platform_result = impl(args.get("notification"), false, ¬ification_handle);
if (!platform_result) {
LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, platform_result.message().c_str()),
&out);
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;
- }
+ CHECK_ERROR(status);
picojson::object& out = *out_ptr;
out["postedTime"] =
notification_free(noti_handle);
};
- PlatformResult status = getHandle(args, is_update, ¬i_handle);
-
- if (status.IsError()) {
- return status;
+ const auto& noti_val_it = args.find("notification");
+ if (args.end() == noti_val_it) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Cannot post notification");
}
+ PlatformResult status = getHandle(noti_val_it->second, is_update, ¬i_handle);
+ CHECK_ERROR(status);
if (is_update) {
ret = notification_update(noti_handle);
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;
+XW_EXPORT typedef std::function<
+ common::PlatformResult(const picojson::value& noti_val,
+ bool is_update,
+ notification_h *noti_handle)> GetHandleFromJsonFun;
class CommonNotification {
public:
PlatformResult status = PlatformResult(ErrorCode::NO_ERROR);
const auto& new_impl_it = args.find("newImpl");
- if (args.end() != new_impl_it && new_impl_it->second.get<bool>()) {
- status = UserNotification::GetNotiHandleFromJson(args, false, ¬i_handle);
+ const auto& noti_val_it = args.find("notification");
+ if (args.end() != new_impl_it && args.end() != noti_val_it
+ && new_impl_it->second.get<bool>()) {
+ status = UserNotification::GetNotiHandleFromJson(noti_val_it->second, false, ¬i_handle);
} else {
- status = StatusNotification::GetNotiHandleFromJson(args, false, ¬i_handle);
+ status = StatusNotification::GetNotiHandleFromJson(noti_val_it->second, false, ¬i_handle);
}
if (status.IsError()) {
return PlatformResult(ErrorCode::NO_ERROR);
}
-PlatformResult StatusNotification::GetNotiHandleFromJson(const picojson::object& args,
+PlatformResult StatusNotification::GetNotiHandleFromJson(const picojson::value& noti_val,
bool is_update,
notification_h *noti_handle) {
LoggerD("Enter");
- picojson::object noti_obj =
- common::FromJson<picojson::object>(args, "notification");
- picojson::value noti_val(noti_obj);
+ picojson::object noti_obj = noti_val.get<picojson::object>();
notification_h tmp_noti = nullptr;
// statusType, id
notification_h noti_handle,
app_control_h app_handle,
picojson::object* out_ptr);
- XW_EXPORT static common::PlatformResult GetNotiHandleFromJson(const picojson::object& args,
+ XW_EXPORT static common::PlatformResult GetNotiHandleFromJson(const picojson::value& noti_val,
bool is_update,
notification_h *noti_handle);
static common::PlatformResult PostStatusNotification(const picojson::object& args,
return PlatformResult(ErrorCode::NO_ERROR);
}
-PlatformResult UserNotification::GetNotiHandleFromJson(const picojson::object& args,
+PlatformResult UserNotification::GetNotiHandleFromJson(const picojson::value& noti_val,
bool is_update,
notification_h *noti_handle) {
LoggerD("Enter");
- // TODO change this function to use const picojson::value& args
- // instead of object (no copying would be needed)
- picojson::object noti_obj =
- common::FromJson<picojson::object>(args, "notification");
- picojson::value noti_val(noti_obj);
+ picojson::object noti_obj = noti_val.get<picojson::object>();
notification_h tmp_noti = nullptr;
PlatformResult status = InitNotiFromJson(noti_obj, "userType", is_update, &tmp_noti);
notification_h noti_handle,
app_control_h app_handle,
picojson::object* out_ptr);
- XW_EXPORT static common::PlatformResult GetNotiHandleFromJson(const picojson::object& args,
+ XW_EXPORT static common::PlatformResult GetNotiHandleFromJson(const picojson::value& noti_val,
bool is_update,
notification_h *noti_handle);
static common::PlatformResult PostUserNotification(const picojson::object& args,