From: Piotr Kosko Date: Fri, 28 Jul 2017 12:42:59 +0000 (+0200) Subject: [Notification] Set*FromJson methods implemented X-Git-Tag: submit/tizen/20170802.090121~1^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F63%2F140963%2F5;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Notification] Set*FromJson methods implemented [Feature] Implemented body of Set*FromJson methods of UserNotification and some refactoring of Status notification code. [Verification] Code compiles without errors. Passrate didn't change. Checked in console. User notification interface works correctly when testing manually. Change-Id: I7ef4b98120899a1b9000f26b97d39493e43dac88 Signed-off-by: Piotr Kosko --- diff --git a/src/notification/common_notification.cc b/src/notification/common_notification.cc index c415fe1e..71abbd34 100644 --- a/src/notification/common_notification.cc +++ b/src/notification/common_notification.cc @@ -49,17 +49,17 @@ const InformationEnumMap CommonNotification::buttons_texts_map_ = { {0, NOTIFICATION_TEXT_TYPE_BUTTON_1}, {1, NOTIFICATION_TEXT_TYPE_BUTTON_2}, {2, NOTIFICATION_TEXT_TYPE_BUTTON_3}, - {2, NOTIFICATION_TEXT_TYPE_BUTTON_4}, - {2, NOTIFICATION_TEXT_TYPE_BUTTON_5}, - {2, NOTIFICATION_TEXT_TYPE_BUTTON_6}}; + {3, NOTIFICATION_TEXT_TYPE_BUTTON_4}, + {4, NOTIFICATION_TEXT_TYPE_BUTTON_5}, + {5, NOTIFICATION_TEXT_TYPE_BUTTON_6}}; const ImageEnumMap CommonNotification::buttons_icon_paths_map_ = { {0, NOTIFICATION_IMAGE_TYPE_BUTTON_1}, {1, NOTIFICATION_IMAGE_TYPE_BUTTON_2}, {2, NOTIFICATION_IMAGE_TYPE_BUTTON_3}, {3, NOTIFICATION_IMAGE_TYPE_BUTTON_4}, - {3, NOTIFICATION_IMAGE_TYPE_BUTTON_5}, - {3, NOTIFICATION_IMAGE_TYPE_BUTTON_6}}; + {4, NOTIFICATION_IMAGE_TYPE_BUTTON_5}, + {5, NOTIFICATION_IMAGE_TYPE_BUTTON_6}}; CommonNotification::CommonNotification() { @@ -68,15 +68,15 @@ CommonNotification::CommonNotification() { CommonNotification::~CommonNotification() { } -bool CommonNotification::IsColorFormatNumberic(const std::string& color) { +bool CommonNotification::IsColorFormatNumeric(const std::string& color) { LoggerD("Enter"); std::string hexCode = "0123456789abcdef"; - if (color.length() != 7 || '#' != color[0]) { + if (7 != color.length() || '#' != color[0]) { return false; } for (size_t i = 1; i < color.length(); i++) { - if (std::string::npos == hexCode.find(color[i])) { + if (hexCode.find(color[i]) == std::string::npos) { return false; } } @@ -90,7 +90,7 @@ PlatformResult CommonNotification::SetLayout(notification_h noti_handle, LoggerD("Enter"); notification_ly_type_e noti_layout = NOTIFICATION_LY_NONE; - if (noti_type == "SIMPLE") { + if ("SIMPLE" == noti_type) { long number; PlatformResult status = GetNumber(noti_handle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, &number); @@ -103,12 +103,12 @@ PlatformResult CommonNotification::SetLayout(notification_h noti_handle, noti_layout = NOTIFICATION_LY_NOTI_EVENT_MULTIPLE; else noti_layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE; - } else if (noti_type == "THUMBNAIL") { + } else if ("THUMBNAIL" == noti_type) { noti_layout = NOTIFICATION_LY_NOTI_THUMBNAIL; } - if (noti_type == "ONGOING") { + if ("ONGOING" == noti_type) { noti_layout = NOTIFICATION_LY_ONGOING_EVENT; - } else if (noti_type == "PROGRESS") { + } else if ("PROGRESS" == noti_type) { noti_layout = NOTIFICATION_LY_ONGOING_PROGRESS; } int ret = notification_set_layout(noti_handle, noti_layout); @@ -133,7 +133,7 @@ static bool ServiceExtraDataCb(app_control_h service, picojson::array* control_data = static_cast(user_data); int length = 0; - char** value = NULL; + char** value = nullptr; SCOPE_EXIT { free(value); }; int ret = app_control_get_extra_data_array(service, key, &value, &length); @@ -190,17 +190,17 @@ PlatformResult CommonNotification::StatusTypeFromPlatform( notification_ly_type_e noti_layout, std::string* type) { LoggerD("Enter"); - if (noti_type == NOTIFICATION_TYPE_NOTI) { - if (noti_layout == NOTIFICATION_LY_NOTI_EVENT_SINGLE || - noti_layout == NOTIFICATION_LY_NOTI_EVENT_MULTIPLE) { + if (NOTIFICATION_TYPE_NOTI == noti_type) { + if (NOTIFICATION_LY_NOTI_EVENT_SINGLE == noti_layout || + NOTIFICATION_LY_NOTI_EVENT_MULTIPLE == noti_layout) { *type = "SIMPLE"; - } else if (noti_layout == NOTIFICATION_LY_NOTI_THUMBNAIL) { + } else if (NOTIFICATION_LY_NOTI_THUMBNAIL == noti_layout) { *type = "THUMBNAIL"; } - } else if (noti_type == NOTIFICATION_TYPE_ONGOING) { - if (noti_layout == NOTIFICATION_LY_ONGOING_EVENT) { + } else if (NOTIFICATION_TYPE_ONGOING == noti_type) { + if (NOTIFICATION_LY_ONGOING_EVENT == noti_layout) { *type = "ONGOING"; - } else if (noti_layout == NOTIFICATION_LY_ONGOING_PROGRESS) { + } else if (NOTIFICATION_LY_ONGOING_PROGRESS == noti_layout) { *type = "PROGRESS"; } } else { @@ -215,9 +215,9 @@ PlatformResult CommonNotification::StatusTypeToPlatform( const std::string& type, notification_type_e* noti_type) { LoggerD("Enter"); - if (type == "SIMPLE" || type == "THUMBNAIL") { + if ("SIMPLE" == type || "THUMBNAIL" == type) { *noti_type = NOTIFICATION_TYPE_NOTI; - } else if (type == "ONGOING" || type == "PROGRESS") { + } else if ("ONGOING" == type || "PROGRESS" == type) { *noti_type = NOTIFICATION_TYPE_ONGOING; } else { return LogAndCreateResult(ErrorCode::TYPE_MISMATCH_ERR, @@ -233,7 +233,7 @@ PlatformResult CommonNotification::GetImage( notification_image_type_e image_type, std::string* image_path) { LoggerD("Enter"); - char* path = NULL; + char* path = nullptr; *image_path = ""; @@ -269,7 +269,7 @@ PlatformResult CommonNotification::GetText(notification_h noti_handle, notification_text_type_e text_type, std::string* noti_text) { LoggerD("Enter"); - char* text = NULL; + char* text = nullptr; *noti_text = ""; @@ -292,7 +292,7 @@ PlatformResult CommonNotification::SetText(notification_h noti_handle, int ret = notification_set_text(noti_handle, text_type, noti_text.c_str(), - NULL, + nullptr, NOTIFICATION_VARIABLE_TYPE_NONE); if (NOTIFICATION_ERROR_NONE != ret) { return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, @@ -320,43 +320,6 @@ PlatformResult CommonNotification::GetNumber(notification_h noti_handle, return PlatformResult(ErrorCode::NO_ERROR); } -PlatformResult CommonNotification::SetDetailInfos( - notification_h noti_handle, - const picojson::array& value) { - LoggerD("Enter"); - size_t idx = 0; - - size_t info_map_size = info_map_.size(); - for (auto& item : value) { - const picojson::object& obj = JsonCast(item); - - PlatformResult status = - SetText(noti_handle, - info_map_.at(idx), - common::FromJson(obj, "mainText")); - if (status.IsError()) - return status; - - if (picojson::value(obj).contains("subText") && !IsNull(obj, "subText")) { - PlatformResult status = - SetText(noti_handle, - info_sub_map_.at(idx), - common::FromJson(obj, "subText")); - if (status.IsError()) - return status; - } - - ++idx; - - if (idx > info_map_size) { - return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, - "Too many values in notification detailInfo array"); - } - } - - return PlatformResult(ErrorCode::NO_ERROR); -} - PlatformResult CommonNotification::GetLedColor(notification_h noti_handle, std::string* led_color) { LoggerD("Enter"); @@ -389,43 +352,6 @@ PlatformResult CommonNotification::GetLedColor(notification_h noti_handle, return PlatformResult(ErrorCode::NO_ERROR); } -PlatformResult CommonNotification::SetLedColor(notification_h noti_handle, - const std::string& led_color) { - LoggerD("Enter"); - std::string color_str = led_color; - std::transform( - color_str.begin(), color_str.end(), color_str.begin(), ::tolower); - - if (!IsColorFormatNumberic(color_str)) { - return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, - "Led color is not numeric value", - ("Led color is not numeric value: %s", color_str.c_str())); - } - - std::stringstream stream; - unsigned int color = 0; - notification_led_op_e type = NOTIFICATION_LED_OP_ON; - std::string color_code = - color_str.substr(1, color_str.length()).insert(0, "ff"); - - stream << std::hex << color_code; - stream >> color; - - if (color != 0) - type = NOTIFICATION_LED_OP_ON_CUSTOM_COLOR; - else - type = NOTIFICATION_LED_OP_OFF; - - int ret = notification_set_led(noti_handle, type, static_cast(color)); - if (NOTIFICATION_ERROR_NONE != ret) { - return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, - "Set notification led color eror", - ("Set notification led color eror: %d", ret)); - } - - return PlatformResult(ErrorCode::NO_ERROR); -} - PlatformResult CommonNotification::GetLedPeriod(notification_h noti_handle, unsigned long* on_period, unsigned long* off_period) { @@ -446,76 +372,12 @@ PlatformResult CommonNotification::GetLedPeriod(notification_h noti_handle, return PlatformResult(ErrorCode::NO_ERROR); } -PlatformResult CommonNotification::SetLedOnPeriod(notification_h noti_handle, - unsigned long on_period) { - LoggerD("Enter"); - unsigned long off_period = 0; - PlatformResult status = GetLedPeriod(noti_handle, nullptr, &off_period); - if (status.IsError()) - return status; - - int ret = - notification_set_led_time_period(noti_handle, on_period, off_period); - if (NOTIFICATION_ERROR_NONE != ret) { - return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, - "Set notification led on period error", - ("Set notification led on period error: %d", ret)); - } - - return PlatformResult(ErrorCode::NO_ERROR); -} - -PlatformResult CommonNotification::SetLedOffPeriod(notification_h noti_handle, - unsigned long off_period) { - LoggerD("Enter"); - unsigned long on_period = 0; - PlatformResult status = GetLedPeriod(noti_handle, &on_period, nullptr); - if (status.IsError()) - return status; - - int ret = - notification_set_led_time_period(noti_handle, on_period, off_period); - if (NOTIFICATION_ERROR_NONE != ret) { - return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, - "Set notification led off period error", - ("Set notification led off period error: %d", ret)); - } - - return PlatformResult(ErrorCode::NO_ERROR); -} - -PlatformResult CommonNotification::SetThumbnails(notification_h noti_handle, - const picojson::array& value) { - LoggerD("Enter"); - size_t idx = 0; - - size_t thumbnails_map_size = thumbnails_map_.size(); - for (auto& item : value) { - const std::string& text = JsonCast(item); - std::string real_path = common::FilesystemProvider::Create().GetRealPath(text); - - PlatformResult status = - SetImage(noti_handle, thumbnails_map_.at(idx), real_path); - if (status.IsError()) - return status; - - ++idx; - - if (idx > thumbnails_map_size) { - return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, - "Too many values in notification thumbnail array"); - } - } - - return PlatformResult(ErrorCode::NO_ERROR); -} - PlatformResult CommonNotification::GetSoundPath(notification_h noti_handle, std::string* sound_path) { LoggerD("Enter"); *sound_path = ""; - const char* path = NULL; + const char* path = nullptr; notification_sound_type_e type = NOTIFICATION_SOUND_TYPE_NONE; if (NOTIFICATION_ERROR_NONE != notification_get_sound(noti_handle, &type, &path)) { @@ -525,7 +387,7 @@ PlatformResult CommonNotification::GetSoundPath(notification_h noti_handle, LoggerD("Sound type = %d", type); - if (path && (type == NOTIFICATION_SOUND_TYPE_USER_DATA)) { + if (path && (NOTIFICATION_SOUND_TYPE_USER_DATA == type)) { *sound_path = path; } @@ -555,7 +417,7 @@ PlatformResult CommonNotification::GetVibration(notification_h noti_handle, LoggerD("Enter"); notification_vibration_type_e vib_type = NOTIFICATION_VIBRATION_TYPE_NONE; - if (NOTIFICATION_ERROR_NONE != notification_get_vibration(noti_handle, &vib_type, NULL)) { + if (NOTIFICATION_ERROR_NONE != notification_get_vibration(noti_handle, &vib_type, nullptr)) { return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Get notification vibration error"); } @@ -570,42 +432,16 @@ PlatformResult CommonNotification::GetVibration(notification_h noti_handle, return PlatformResult(ErrorCode::NO_ERROR); } -PlatformResult CommonNotification::SetVibration(notification_h noti_handle, - bool vibration) { - LoggerD("Enter"); - bool platform_vibration; - PlatformResult status = GetVibration(noti_handle, &platform_vibration); - if (status.IsError()) - return status; - - if (platform_vibration != vibration) { - notification_vibration_type_e vib_type = NOTIFICATION_VIBRATION_TYPE_NONE; - - if (vibration) { - vib_type = NOTIFICATION_VIBRATION_TYPE_DEFAULT; - } - - int ret = notification_set_vibration(noti_handle, vib_type, NULL); - if (NOTIFICATION_ERROR_NONE != ret) { - return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, - "Set notification vibration error", - ("Set notification vibration error: %d", ret)); - } - } - - return PlatformResult(ErrorCode::NO_ERROR); -} - PlatformResult CommonNotification::GetApplicationControl( app_control_h app_handle, picojson::object* out_ptr) { LoggerD("Enter"); picojson::object& out = *out_ptr; - char* operation = NULL; - char* uri = NULL; - char* mime = NULL; - char* category = NULL; + char* operation = nullptr; + char* uri = nullptr; + char* mime = nullptr; + char* category = nullptr; SCOPE_EXIT { free(operation); free(uri); @@ -624,7 +460,7 @@ PlatformResult CommonNotification::GetApplicationControl( LoggerD("operation = %s", operation); } - if (app_control_get_uri(app_handle, &uri) != APP_CONTROL_ERROR_NONE) { + if (APP_CONTROL_ERROR_NONE != app_control_get_uri(app_handle, &uri)) { return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Get application control uri error"); } @@ -633,7 +469,7 @@ PlatformResult CommonNotification::GetApplicationControl( LoggerD("uri = %s", uri); } - if (app_control_get_mime(app_handle, &mime) != APP_CONTROL_ERROR_NONE) { + if (APP_CONTROL_ERROR_NONE != app_control_get_mime(app_handle, &mime)) { return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Get application control mime error"); } @@ -642,8 +478,7 @@ PlatformResult CommonNotification::GetApplicationControl( LoggerD("mime = %s", mime); } - if (app_control_get_category(app_handle, &category) != - APP_CONTROL_ERROR_NONE) { + if (APP_CONTROL_ERROR_NONE != app_control_get_category(app_handle, &category)) { return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Get application control category error"); } @@ -653,9 +488,8 @@ PlatformResult CommonNotification::GetApplicationControl( } picojson::array app_control_data = picojson::array(); - if (app_control_foreach_extra_data( - app_handle, ServiceExtraDataCb, (void*)&app_control_data) != - APP_CONTROL_ERROR_NONE) { + if (APP_CONTROL_ERROR_NONE != app_control_foreach_extra_data( + app_handle, ServiceExtraDataCb, (void*)&app_control_data)) { return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Get application control data error"); } @@ -670,7 +504,7 @@ PlatformResult CommonNotification::SetApplicationControl( LoggerD("Enter"); picojson::value val(app_ctrl); const std::string& operation = - common::FromJson(app_ctrl, "operation"); + FromJson(app_ctrl, "operation"); int ret; if (operation.length()) { @@ -685,7 +519,7 @@ PlatformResult CommonNotification::SetApplicationControl( } if (val.contains("uri") && !IsNull(app_ctrl, "uri")) { - const std::string& uri = common::FromJson(app_ctrl, "uri"); + const std::string& uri = FromJson(app_ctrl, "uri"); ret = app_control_set_uri(app_handle, uri.c_str()); if (APP_CONTROL_ERROR_NONE != ret) { return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, @@ -695,7 +529,7 @@ PlatformResult CommonNotification::SetApplicationControl( } if (val.contains("mime") && !IsNull(app_ctrl, "mime")) { - const std::string& mime = common::FromJson(app_ctrl, "mime"); + const std::string& mime = FromJson(app_ctrl, "mime"); ret = app_control_set_mime(app_handle, mime.c_str()); if (APP_CONTROL_ERROR_NONE != ret) { return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, @@ -706,7 +540,7 @@ PlatformResult CommonNotification::SetApplicationControl( if (val.contains("category") && !IsNull(app_ctrl, "category")) { const std::string& category = - common::FromJson(app_ctrl, "category"); + FromJson(app_ctrl, "category"); ret = app_control_set_category(app_handle, category.c_str()); if (APP_CONTROL_ERROR_NONE != ret) { return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, @@ -719,15 +553,15 @@ PlatformResult CommonNotification::SetApplicationControl( return PlatformResult(ErrorCode::NO_ERROR); } - auto& items = common::FromJson(app_ctrl, "data"); + auto& items = FromJson(app_ctrl, "data"); int idx = 0; for (auto item : items) { const picojson::object& obj = JsonCast(item); - const std::string key = common::FromJson(obj, "key"); + const std::string key = FromJson(obj, "key"); const picojson::array values = - common::FromJson(obj, "value"); + FromJson(obj, "value"); const char** arrayValue = (const char**)calloc(sizeof(char*), values.size()); SCOPE_EXIT { free(arrayValue); }; @@ -751,17 +585,16 @@ PlatformResult CommonNotification::SetApplicationControl( PlatformResult CommonNotification::GetApplicationId(app_control_h app_handle, std::string* app_id) { LoggerD("Enter"); - char* app_id_str = NULL; + char* app_id_str = nullptr; SCOPE_EXIT { free(app_id_str); }; *app_id = ""; - if (app_control_get_app_id(app_handle, &app_id_str) != - APP_CONTROL_ERROR_NONE) { + if (APP_CONTROL_ERROR_NONE != app_control_get_app_id(app_handle, &app_id_str)) { return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Get applicaiton ID failed"); } - if (app_id_str != NULL) { + if (nullptr != app_id_str) { *app_id = app_id_str; } @@ -786,17 +619,17 @@ PlatformResult CommonNotification::SetApplicationId(app_control_h app_handle, PlatformResult CommonNotification::GetProgressValue( notification_h noti_handle, - const std::string& progess_type, + const std::string& progress_type, double* progress_value) { LoggerD("Enter"); double tmp_progress_value = 0.0; - if (progess_type == kProgressTypeByte) { + if (kProgressTypeByte == progress_type) { if (NOTIFICATION_ERROR_NONE != notification_get_size(noti_handle, &tmp_progress_value)) { return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Get notification size error"); } - } else if (progess_type == kProgressTypePercentage) { + } else if (kProgressTypePercentage == progress_type) { if (NOTIFICATION_ERROR_NONE != notification_get_progress(noti_handle, &tmp_progress_value)) { return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Get notification progress error"); @@ -806,10 +639,10 @@ PlatformResult CommonNotification::GetProgressValue( } else { return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Unknown notification progress type", - ("Unknown notification progress type: %s ", progess_type.c_str())); + ("Unknown notification progress type: %s ", progress_type.c_str())); } - LOGGER(DEBUG) << "Progress " << progess_type << " = " << tmp_progress_value; + LoggerD("Progress %s = %lf", progress_type.c_str(), tmp_progress_value); *progress_value = tmp_progress_value; return PlatformResult(ErrorCode::NO_ERROR); @@ -823,14 +656,14 @@ PlatformResult CommonNotification::SetProgressValue( LoggerD("Enter"); int ret; - if (progress_type == kProgressTypeByte) { + if (kProgressTypeByte == progress_type) { ret = notification_set_size(noti_handle, progress_value); if (is_update) { ret = notification_update_size(noti_handle, NOTIFICATION_PRIV_ID_NONE, progress_value); } - } else if (progress_type == kProgressTypePercentage) { + } else if (kProgressTypePercentage == progress_type) { // native api uses range 0-1, but webapi expects 0-100, so we need to divide by 100 ret = notification_set_progress(noti_handle, progress_value/100); @@ -869,8 +702,8 @@ PlatformResult CommonNotification::GetPostedTime(notification_h noti_handle, PlatformResult CommonNotification::GetNotiHandle(int id, notification_h* noti_handle) { LoggerD("Enter"); - *noti_handle = notification_load(NULL, id); - if (NULL == *noti_handle) { + *noti_handle = notification_load(nullptr, id); + if (nullptr == *noti_handle) { return LogAndCreateResult(ErrorCode::NOT_FOUND_ERR, "Not found or removed notification id"); } @@ -923,7 +756,7 @@ PlatformResult CommonNotification::SetAppControl(notification_h noti_handle, return PlatformResult(ErrorCode::NO_ERROR); } -common::PlatformResult CommonNotification::UpdateNotificationAfterPost( +PlatformResult CommonNotification::UpdateNotificationAfterPost( notification_h noti_handle, int id, picojson::object* out_ptr) { time_t posted_time; PlatformResult status = GetPostedTime(noti_handle, &posted_time); @@ -1037,8 +870,8 @@ PlatformResult CommonNotification::AddTypeToJson(notification_h noti_handle, con } PlatformResult CommonNotification::AddProgressTypeAndValueToJson(notification_h noti_handle, - const std::string& noti_type_str, - picojson::object* out_ptr) { + const std::string& noti_type_str, + picojson::object* out_ptr) { LoggerD("Enter"); picojson::object& out = *out_ptr; @@ -1125,7 +958,7 @@ PlatformResult CommonNotification::AddPathToJson(notification_h noti_handle, PlatformResult status = GetImage(noti_handle, type, &value_str); CHECK_ERROR(status); if (value_str.length()) { - out[key] = picojson::value(common::FilesystemProvider::Create().GetVirtualPath(value_str)); + out[key] = picojson::value(FilesystemProvider::Create().GetVirtualPath(value_str)); } return PlatformResult(ErrorCode::NO_ERROR); } @@ -1178,7 +1011,7 @@ PlatformResult CommonNotification::AddPathsArrayToJson(notification_h noti_handl if (path.length()) { result_array.push_back( - picojson::value(common::FilesystemProvider::Create().GetVirtualPath(path))); + picojson::value(FilesystemProvider::Create().GetVirtualPath(path))); } } @@ -1237,7 +1070,7 @@ PlatformResult CommonNotification::AddSoundPathToJson(notification_h noti_handle PlatformResult status = GetSoundPath(noti_handle, &sound_path); CHECK_ERROR(status); if (sound_path.length()) { - out["soundPath"] = picojson::value(common::FilesystemProvider::Create().GetVirtualPath(sound_path)); + out["soundPath"] = picojson::value(FilesystemProvider::Create().GetVirtualPath(sound_path)); } return PlatformResult(ErrorCode::NO_ERROR); @@ -1281,20 +1114,21 @@ PlatformResult CommonNotification::AddAppControlInfoToJson(notification_h noti_h } PlatformResult CommonNotification::InitNotiFromJson(const picojson::object& noti_obj, + const std::string& type_key, bool is_update, notification_h* noti_handle) { LoggerD("Enter"); notification_h tmp_noti = nullptr; const std::string& status_type = - common::FromJson(noti_obj, "statusType"); + FromJson(noti_obj, type_key.c_str()); notification_type_e noti_type = NOTIFICATION_TYPE_NONE; PlatformResult status = StatusTypeToPlatform(status_type, ¬i_type); CHECK_ERROR(status); if (is_update) { - int id = std::stoi(common::FromJson(noti_obj, "id")); + int id = std::stoi(FromJson(noti_obj, "id")); status = GetNotiHandle(id, &tmp_noti); CHECK_ERROR(status); @@ -1319,18 +1153,321 @@ PlatformResult CommonNotification::SetCommonMembersFromJson(const picojson::valu const picojson::object& noti_obj = noti_value.get(); PlatformResult status = SetText(noti_handle, NOTIFICATION_TEXT_TYPE_TITLE, - common::FromJson(noti_obj, "title")); + FromJson(noti_obj, "title")); + CHECK_ERROR(status); + + SetTextFromJson(noti_value, NOTIFICATION_TEXT_TYPE_CONTENT, "content", noti_handle); CHECK_ERROR(status); + return PlatformResult(ErrorCode::NO_ERROR); +} - if (noti_value.contains("content") && !IsNull(noti_obj, "content")) { - status = SetText(noti_handle, - NOTIFICATION_TEXT_TYPE_CONTENT, - common::FromJson(noti_obj, "content")); +PlatformResult CommonNotification::SetPathFromJson(const picojson::value& noti_value, + notification_image_type_e type, + const std::string& key, + notification_h noti_handle) { + LoggerD("Enter"); + const picojson::object& noti_obj = noti_value.get(); + if (noti_value.contains(key) && !IsNull(noti_obj, key.c_str())) { + const std::string& value_str = FromJson(noti_obj, key.c_str()); + std::string real_path = FilesystemProvider::Create().GetRealPath(value_str); + + PlatformResult status = SetImage(noti_handle, type, real_path); CHECK_ERROR(status); } return PlatformResult(ErrorCode::NO_ERROR); } +PlatformResult CommonNotification::SetLedColorFromJson(const picojson::value& noti_value, + notification_h noti_handle) { + LoggerD("Enter"); + const picojson::object& noti_obj = noti_value.get(); + if (noti_value.contains("ledColor") && !IsNull(noti_obj, "ledColor")) { + std::string color_str = FromJson(noti_obj, "ledColor"); + std::transform( + color_str.begin(), color_str.end(), color_str.begin(), ::tolower); + + if (!IsColorFormatNumeric(color_str)) { + return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, + "Led color is not numeric value", + ("Led color is not numeric value: %s", color_str.c_str())); + } + + std::stringstream stream; + unsigned int color = 0; + notification_led_op_e type = NOTIFICATION_LED_OP_ON; + std::string color_code = + color_str.substr(1, color_str.length()).insert(0, "ff"); + + stream << std::hex << color_code; + stream >> color; + + if (0 != color) + type = NOTIFICATION_LED_OP_ON_CUSTOM_COLOR; + else + type = NOTIFICATION_LED_OP_OFF; + + int ret = notification_set_led(noti_handle, type, static_cast(color)); + if (NOTIFICATION_ERROR_NONE != ret) { + return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, + "Set notification led color eror", + ("Set notification led color eror: %d", ret)); + } + } + + return PlatformResult(ErrorCode::NO_ERROR); +} + +PlatformResult CommonNotification::SetLedOnPeriodFromJson(const picojson::value& noti_value, + notification_h noti_handle) { + LoggerD("Enter"); + const picojson::object& noti_obj = noti_value.get(); + unsigned long on_period = static_cast( + FromJson(noti_obj, "ledOnPeriod")); + + unsigned long off_period = 0; + PlatformResult status = GetLedPeriod(noti_handle, nullptr, &off_period); + CHECK_ERROR(status); + + int ret = notification_set_led_time_period(noti_handle, on_period, off_period); + if (NOTIFICATION_ERROR_NONE != ret) { + return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, + "Set notification led on period error", + ("Set notification led on period error: %d", ret)); + } + + return PlatformResult(ErrorCode::NO_ERROR); +} + +PlatformResult CommonNotification::SetLedOffPeriodFromJson(const picojson::value& noti_value, + notification_h noti_handle) { + LoggerD("Enter"); + const picojson::object& noti_obj = noti_value.get(); + unsigned long off_period = static_cast( + FromJson(noti_obj, "ledOffPeriod")); + unsigned long on_period = 0; + PlatformResult status = GetLedPeriod(noti_handle, &on_period, nullptr); + CHECK_ERROR(status); + + int ret = notification_set_led_time_period(noti_handle, on_period, off_period); + if (NOTIFICATION_ERROR_NONE != ret) { + return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, + "Set notification led off period error", + ("Set notification led off period error: %d", ret)); + } + + return PlatformResult(ErrorCode::NO_ERROR); +} + +PlatformResult CommonNotification::SetProgressTypeAndValueFromJson(const picojson::value& noti_value, + bool is_update, + notification_h noti_handle) { + LoggerD("Enter"); + const picojson::object& noti_obj = noti_value.get(); + + // progressType + // native code does not support progress_type value, we are using NOTIFICATION_IMAGE_TYPE_LIST_5 + // to store this field on native level + const std::string& progress_type = + FromJson(noti_obj, "progressType"); + PlatformResult status = SetImage(noti_handle, NOTIFICATION_IMAGE_TYPE_LIST_5, progress_type); + CHECK_ERROR(status); + + // progressValue + double progress_value = -1; + if (noti_value.contains("progressValue") && !IsNull(noti_obj, "progressValue")) { + progress_value = FromJson(noti_obj, "progressValue"); + } + status = SetProgressValue(noti_handle, progress_type, progress_value, is_update); + CHECK_ERROR(status); + return PlatformResult(ErrorCode::NO_ERROR); +} + +PlatformResult CommonNotification::SetAppControlInfoFromJson(const picojson::value& noti_value, + notification_h noti_handle) { + LoggerD("Enter"); + const picojson::object& noti_obj = noti_value.get(); + + app_control_h app_control = nullptr; + SCOPE_EXIT { + if (app_control) { + app_control_destroy(app_control); + } + }; + + PlatformResult status = CreateAppControl(&app_control); + CHECK_ERROR(status); + + if (noti_value.contains("appControl") && !IsNull(noti_obj, "appControl")) { + status = SetApplicationControl( + app_control, FromJson(noti_obj, "appControl")); + CHECK_ERROR(status); + } + + if (noti_value.contains("appId") && !IsNull(noti_obj, "appId")) { + status = SetApplicationId(app_control, + FromJson(noti_obj, "appId")); + CHECK_ERROR(status); + } + + status = SetAppControl(noti_handle, app_control); + CHECK_ERROR(status); + + return PlatformResult(ErrorCode::NO_ERROR); +} + +PlatformResult CommonNotification::SetEventsNumberFromJson(const picojson::value& noti_value, + const std::string& key, + notification_h noti_handle) { + LoggerD("Enter"); + const picojson::object& noti_obj = noti_value.get(); + + if (noti_value.contains(key) && !IsNull(noti_obj, key.c_str())) { + long number = (long)FromJson(noti_obj, key.c_str()); + PlatformResult status = SetText(noti_handle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, + std::to_string(number)); + CHECK_ERROR(status); + } + return PlatformResult(ErrorCode::NO_ERROR); +} + +PlatformResult CommonNotification::SetDetailInfosFromJson(const picojson::value& noti_value, + notification_h noti_handle) { + LoggerD("Enter"); + const picojson::object& noti_obj = noti_value.get(); + const picojson::array& array = FromJson(noti_obj, "detailInfo"); + + if (array.size() > info_map_.size()) { + return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, + "Too many values in notification detailInfo array"); + } + size_t idx = 0; + + for (auto& item : array) { + const picojson::object& obj = JsonCast(item); + + PlatformResult status = + SetText(noti_handle, + info_map_.at(idx), + FromJson(obj, "mainText")); + CHECK_ERROR(status); + + SetTextFromJson(picojson::value(obj), info_sub_map_.at(idx), "subText", noti_handle); + CHECK_ERROR(status); + ++idx; + } + return PlatformResult(ErrorCode::NO_ERROR); +} + +PlatformResult CommonNotification::SetVibrationFromJson(const picojson::value& noti_value, + notification_h noti_handle) { + LoggerD("Enter"); + const picojson::object& noti_obj = noti_value.get(); + bool vibration = FromJson(noti_obj, "vibration"); + + bool platform_vibration; + PlatformResult status = GetVibration(noti_handle, &platform_vibration); + CHECK_ERROR(status); + + if (platform_vibration != vibration) { + notification_vibration_type_e vib_type = NOTIFICATION_VIBRATION_TYPE_NONE; + + if (vibration) { + vib_type = NOTIFICATION_VIBRATION_TYPE_DEFAULT; + } + + int ret = notification_set_vibration(noti_handle, vib_type, nullptr); + if (NOTIFICATION_ERROR_NONE != ret) { + return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, + "Set notification vibration error", + ("Set notification vibration error: %d", ret)); + } + } + + return PlatformResult(ErrorCode::NO_ERROR); +} + +PlatformResult CommonNotification::SetSoundPathFromJson(const picojson::value& noti_value, + notification_h noti_handle) { + LoggerD("Enter"); + const picojson::object& noti_obj = noti_value.get(); + + if (noti_value.contains("soundPath") && !IsNull(noti_obj, "soundPath")) { + const std::string& value_str = FromJson(noti_obj, "soundPath"); + std::string real_path = FilesystemProvider::Create().GetRealPath(value_str); + + PlatformResult status = SetSoundPath(noti_handle, real_path); + CHECK_ERROR(status); + } + + return PlatformResult(ErrorCode::NO_ERROR); +} + +PlatformResult CommonNotification::SetPathsArrayFromJson(const picojson::value& noti_value, + ImageEnumMap map, + const std::string& key, + notification_h noti_handle) { + LoggerD("Enter"); + const picojson::object& noti_obj = noti_value.get(); + + if (noti_value.contains(key) && !IsNull(noti_obj, key.c_str())) { + const picojson::array& array = FromJson(noti_obj, key.c_str()); + if (array.size() > map.size()) { + return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, "Too many values in array"); + } + size_t idx = 0; + for (auto& item : array) { + const std::string& text = JsonCast(item); + std::string real_path = FilesystemProvider::Create().GetRealPath(text); + + PlatformResult status = SetImage(noti_handle, map.at(idx), real_path); + CHECK_ERROR(status); + + ++idx; + } + } + + return PlatformResult(ErrorCode::NO_ERROR); +} + +PlatformResult CommonNotification::SetTextsArrayFromJson(const picojson::value& noti_value, + InformationEnumMap map, + const std::string& key, + notification_h noti_handle) { + LoggerD("Enter"); + const picojson::object& noti_obj = noti_value.get(); + + if (noti_value.contains(key) && !IsNull(noti_obj, key.c_str())) { + const picojson::array& array = FromJson(noti_obj, key.c_str()); + if (array.size() > map.size()) { + return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, "Too many values in array"); + } + + size_t idx = 0; + for (auto& item : array) { + const std::string& text = JsonCast(item); + PlatformResult status = SetText(noti_handle, map.at(idx), text); + CHECK_ERROR(status); + + ++idx; + } + } + + return PlatformResult(ErrorCode::NO_ERROR); +} + +PlatformResult CommonNotification::SetTextFromJson(const picojson::value& noti_value, + notification_text_type_e type, + const std::string& key, + notification_h noti_handle) { + LoggerD("Entered"); + const picojson::object& noti_obj = noti_value.get(); + + if (noti_value.contains(key) && !IsNull(noti_obj, key.c_str())) { + PlatformResult status = SetText(noti_handle, type, FromJson(noti_obj, key.c_str())); + CHECK_ERROR(status); + } + return PlatformResult(ErrorCode::NO_ERROR); +} } // namespace notification } // namespace extension diff --git a/src/notification/common_notification.h b/src/notification/common_notification.h index c00acc06..ba23662b 100644 --- a/src/notification/common_notification.h +++ b/src/notification/common_notification.h @@ -83,29 +83,17 @@ class CommonNotification { static common::PlatformResult GetNumber(notification_h noti_handle, notification_text_type_e text_type, long* number); - static common::PlatformResult SetDetailInfos(notification_h noti_handle, - const picojson::array& value); static common::PlatformResult GetLedColor(notification_h noti_handle, std::string* led_color); - static common::PlatformResult SetLedColor(notification_h noti_handle, - const std::string& led_color); static common::PlatformResult GetLedPeriod(notification_h noti_handle, unsigned long* on_period, unsigned long* off_period); - static common::PlatformResult SetLedOnPeriod(notification_h noti_handle, - unsigned long on_period); - static common::PlatformResult SetLedOffPeriod(notification_h noti_handle, - unsigned long off_period); - static common::PlatformResult SetThumbnails(notification_h noti_handle, - const picojson::array& value); static common::PlatformResult GetSoundPath(notification_h noti_handle, std::string* sound_path); static common::PlatformResult SetSoundPath(notification_h noti_handle, const std::string& sound_path); static common::PlatformResult GetVibration(notification_h noti_handle, bool* vibration); - static common::PlatformResult SetVibration(notification_h noti_handle, - bool vibration); static common::PlatformResult GetApplicationControl( app_control_h app_handle, picojson::object* out_ptr); @@ -131,7 +119,7 @@ class CommonNotification { const std::string& noti_type); static common::PlatformResult CreateAppControl(app_control_h* app_control); - static bool IsColorFormatNumberic(const std::string& color); + static bool IsColorFormatNumeric(const std::string& color); static common::PlatformResult UpdateNotificationAfterPost(notification_h noti_handle, int id, picojson::object* out_ptr); @@ -141,8 +129,8 @@ class CommonNotification { static common::PlatformResult AddTypeToJson(notification_h noti_handle, const std::string& key, picojson::object* out_ptr, std::string* noti_type_str); static common::PlatformResult AddProgressTypeAndValueToJson(notification_h noti_handle, - const std::string& noti_type_str, - picojson::object* out_ptr); + const std::string& noti_type_str, + picojson::object* out_ptr); static common::PlatformResult AddEventsNumberToJson(notification_h noti_handle, const std::string& key, picojson::object* out_ptr); static common::PlatformResult AddDetailInfosToJson(notification_h noti_handle, @@ -178,11 +166,48 @@ class CommonNotification { picojson::object* out_ptr); // FromJson section - static common::PlatformResult InitNotiFromJson(const picojson::object& args, bool is_update, + static common::PlatformResult InitNotiFromJson(const picojson::object& args, + const std::string& type_key, + bool is_update, notification_h* noti_handle); static common::PlatformResult SetCommonMembersFromJson(const picojson::value& noti_val, notification_h noti_handle); - + static common::PlatformResult SetPathFromJson(const picojson::value& noti_value, + notification_image_type_e type, + const std::string& key, + notification_h noti_handle); + static common::PlatformResult SetLedColorFromJson(const picojson::value& noti_value, + notification_h noti_handle); + static common::PlatformResult SetLedOnPeriodFromJson(const picojson::value& noti_value, + notification_h noti_handle); + static common::PlatformResult SetLedOffPeriodFromJson(const picojson::value& noti_value, + notification_h noti_handle); + static common::PlatformResult SetProgressTypeAndValueFromJson(const picojson::value& noti_value, + bool is_update, + notification_h noti_handle); + static common::PlatformResult SetAppControlInfoFromJson(const picojson::value& noti_value, + notification_h noti_handle); + static common::PlatformResult SetEventsNumberFromJson(const picojson::value& noti_value, + const std::string& key, + notification_h noti_handle); + static common::PlatformResult SetDetailInfosFromJson(const picojson::value& noti_value, + notification_h noti_handle); + static common::PlatformResult SetVibrationFromJson(const picojson::value& noti_value, + notification_h noti_handle); + static common::PlatformResult SetSoundPathFromJson(const picojson::value& noti_value, + notification_h noti_handle); + static common::PlatformResult SetPathsArrayFromJson(const picojson::value& noti_value, + ImageEnumMap map, + const std::string& key, + notification_h noti_handle); + static common::PlatformResult SetTextsArrayFromJson(const picojson::value& noti_value, + InformationEnumMap map, + const std::string& key, + notification_h noti_handle); + static common::PlatformResult SetTextFromJson(const picojson::value& noti_value, + notification_text_type_e type, + const std::string& key, + notification_h noti_handle); static common::PlatformResult PostNotification(const picojson::object& args, bool is_update, diff --git a/src/notification/notification_api.js b/src/notification/notification_api.js index 2b800b16..6fc32b0d 100644 --- a/src/notification/notification_api.js +++ b/src/notification/notification_api.js @@ -219,7 +219,7 @@ NotificationManager.prototype.getNotification = function(id) { var n = native_.getResultObject(result); _edit.allow(); - var returnObject = new UserNotification(n.statusType, n.title, n); + var returnObject = new UserNotification(n.userType, n.title, n); _edit.disallow(); return returnObject; @@ -259,7 +259,7 @@ NotificationManager.prototype.getAllNotifications = function() { _edit.allow(); for (var i = 0; i < n.length; i++) { - notifications.push(new UserNotification(n[i].statusType, n[i].title, n[i])); + notifications.push(new UserNotification(n[i].userType, n[i].title, n[i])); } _edit.disallow(); @@ -694,7 +694,7 @@ function NotificationDetailInfo(mainText, subText) { }); } -function UserNotification(statusType, title, notificationGropedInitDict) { +function UserNotification(userType, title, notificationGropedInitDict) { validator_.isConstructorCall(this, UserNotification); type_.isObject(notificationGropedInitDict) ? notificationGropedInitDict.title = title : @@ -702,17 +702,17 @@ function UserNotification(statusType, title, notificationGropedInitDict) { UserNotificationInitDict.call(this, notificationGropedInitDict); Notification.call(this, notificationGropedInitDict); - var _statusType = (Object.keys(UserNotificationType)).indexOf(statusType) >= 0 - ? statusType : StatusNotificationType.SIMPLE; + var _userType = (Object.keys(UserNotificationType)).indexOf(userType) >= 0 + ? userType : StatusNotificationType.SIMPLE; Object.defineProperties(this, { - statusType: { + userType: { get: function() { - return _statusType; + return _userType; }, set: function(v) { - _statusType = (Object.keys(StatusNotificationType)).indexOf(v) >= 0 && _edit.canEdit - ? v : _statusType; + _userType = (Object.keys(StatusNotificationType)).indexOf(v) >= 0 && _edit.canEdit + ? v : _userType; }, enumerable: true } @@ -736,6 +736,7 @@ function UserNotificationInitDict(data) { return _textContents; }, set: function(v) { + // TODO additional validation of members is needed _textContents = type_.isObject(v) || type_.isNull(v) ? v : _textContents; }, enumerable: true @@ -745,6 +746,7 @@ function UserNotificationInitDict(data) { return _images; }, set: function(v) { + // TODO additional validation of members is needed _images = type_.isObject(v) || type_.isNull(v) ? v : _images; }, enumerable: true @@ -754,6 +756,7 @@ function UserNotificationInitDict(data) { return _thumbnails; }, set: function(v) { + // TODO additional validation of members is needed _thumbnails = type_.isObject(v) || type_.isNull(v) ? v : _thumbnails; }, enumerable: true @@ -763,6 +766,7 @@ function UserNotificationInitDict(data) { return _actions; }, set: function(v) { + // TODO additional validation of members is needed _actions = type_.isObject(v) || type_.isNull(v) ? v : _actions; }, enumerable: true @@ -772,6 +776,7 @@ function UserNotificationInitDict(data) { return _groupContents; }, set: function(v) { + // TODO additional validation of members is needed _groupContents = type_.isObject(v) || type_.isNull(v) ? v : _groupContents; }, enumerable: true @@ -781,6 +786,7 @@ function UserNotificationInitDict(data) { return _leds; }, set: function(v) { + // TODO additional validation of members is needed _leds = type_.isObject(v) || type_.isNull(v) ? v : _leds; }, enumerable: true diff --git a/src/notification/notification_manager.cc b/src/notification/notification_manager.cc index c702fb73..b3cc6ee7 100644 --- a/src/notification/notification_manager.cc +++ b/src/notification/notification_manager.cc @@ -61,23 +61,17 @@ PlatformResult NotificationManager::Post(const picojson::object& args, PlatformResult NotificationManager::PostUserNoti(const picojson::object& args, picojson::object& out) { LoggerD("Enter"); - // TODO implement - return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR, - "Not implemented yet", - ("Not implemented yet")); + return UserNotification::PostUserNotification(args, false, &out); } PlatformResult NotificationManager::Update(const picojson::object& args) { LoggerD("Enter"); - return StatusNotification::PostStatusNotification(args, true, NULL); + return StatusNotification::PostStatusNotification(args, true, nullptr); } PlatformResult NotificationManager::UpdateUserNoti(const picojson::object& args) { LoggerD("Enter"); - // TODO implement - return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR, - "Not implemented yet", - ("Not implemented yet")); + return UserNotification::PostUserNotification(args, true, nullptr); } @@ -85,7 +79,7 @@ PlatformResult NotificationManager::Remove(const picojson::object& args) { LoggerD("Enter"); int id = std::stoi(FromJson(args, "id")); - int ret = notification_delete_by_priv_id(NULL, NOTIFICATION_TYPE_NONE, id); + int ret = notification_delete_by_priv_id(nullptr, NOTIFICATION_TYPE_NONE, id); if (NOTIFICATION_ERROR_NONE != ret) { return LogAndCreateResult(ErrorCode::NOT_FOUND_ERR, "Cannot remove notification error", @@ -194,7 +188,7 @@ PlatformResult NotificationManager::GetAll(picojson::array& out, bool is_new_imp noti = notification_list_get_data(noti_list_iter); if (nullptr != noti) { int noti_priv = -1; - ret = notification_get_id(noti, NULL, ¬i_priv); + ret = notification_get_id(noti, nullptr, ¬i_priv); if (NOTIFICATION_ERROR_NONE != ret) { return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Cannot get notification id error", @@ -247,9 +241,9 @@ PlatformResult NotificationManager::PlayLEDCustomEffect( unsigned int platformFlags = 0; for (auto flag : flags) { std::string flagStr = JsonCast(flag); - if (flagStr == "LED_CUSTOM_DEFAULT") + if ("LED_CUSTOM_DEFAULT" == flagStr) platformFlags |= LED_CUSTOM_DEFAULT; - else if (flagStr == "LED_CUSTOM_DUTY_ON") + else if ("LED_CUSTOM_DUTY_ON" == flagStr) platformFlags |= LED_CUSTOM_DUTY_ON; } @@ -319,7 +313,7 @@ common::PlatformResult NotificationManager::CreateFromTemplate(const picojson::o if (!noti_handle) { return LogAndCreateResult(ErrorCode::NOT_FOUND_ERR, "The template with given name not found", - ("The template with given name not found, handle is NULL")); + ("The template with given name not found, handle is nullptr")); } SCOPE_EXIT { diff --git a/src/notification/status_notification.cc b/src/notification/status_notification.cc index a3f1fe6a..40be3a0c 100644 --- a/src/notification/status_notification.cc +++ b/src/notification/status_notification.cc @@ -48,7 +48,7 @@ PlatformResult StatusNotification::ToJson(int id, // iconPath status = AddPathToJson(noti_handle, NOTIFICATION_IMAGE_TYPE_ICON, - "iconPath", out_ptr); + "iconPath", out_ptr); CHECK_ERROR(status); // subIconPath @@ -108,164 +108,68 @@ PlatformResult StatusNotification::GetNotiHandleFromJson(const picojson::object& common::FromJson(args, "notification"); picojson::value noti_val(noti_obj); - app_control_h app_control = nullptr; - - SCOPE_EXIT { - if (app_control) { - app_control_destroy(app_control); - } - }; - notification_h tmp_noti = nullptr; // statusType, id - PlatformResult status = InitNotiFromJson(noti_obj, is_update, &tmp_noti); + PlatformResult status = InitNotiFromJson(noti_obj, "statusType", is_update, &tmp_noti); CHECK_ERROR(status); std::unique_ptr::type, int(*)(notification_h)> - tmp_noti_ptr(tmp_noti, ¬ification_free); // automatically release the memory + tmp_noti_ptr(tmp_noti, ¬ification_free); // automatically release the memory // title, content status = SetCommonMembersFromJson(noti_val, tmp_noti); CHECK_ERROR(status); + // iconPath + status = SetPathFromJson(noti_val, NOTIFICATION_IMAGE_TYPE_ICON, "iconPath", tmp_noti); + CHECK_ERROR(status); + + // subIconPath + status = SetPathFromJson(noti_val, NOTIFICATION_IMAGE_TYPE_ICON_SUB, "subIconPath", tmp_noti); + CHECK_ERROR(status); + + // number + status = SetEventsNumberFromJson(noti_val, "number", tmp_noti); + CHECK_ERROR(status); + + // detailInfo + status = SetDetailInfosFromJson(noti_val, tmp_noti); + CHECK_ERROR(status); - if (noti_val.contains("iconPath") && !IsNull(noti_obj, "iconPath")) { - const std::string& value_str = common::FromJson(noti_obj, "iconPath"); - std::string real_path = common::FilesystemProvider::Create().GetRealPath(value_str); - - status = SetImage(tmp_noti, NOTIFICATION_IMAGE_TYPE_ICON, real_path); - if (status.IsError()) { - return status; - } - } - - if (noti_val.contains("subIconPath") && !IsNull(noti_obj, "subIconPath")) { - const std::string& value_str = - common::FromJson(noti_obj, "subIconPath"); - std::string real_path = common::FilesystemProvider::Create().GetRealPath(value_str); - - status = SetImage(tmp_noti, NOTIFICATION_IMAGE_TYPE_ICON_SUB, real_path); - if (status.IsError()) { - return status; - } - } - - if (noti_val.contains("number") && !IsNull(noti_obj, "number")) { - long number = (long)common::FromJson(noti_obj, "number"); - status = SetText(tmp_noti, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, std::to_string(number)); - if (status.IsError()) { - return status; - } - } - - if (noti_val.contains("detailInfo") && !IsNull(noti_obj, "detailInfo")) { - status = SetDetailInfos( - tmp_noti, common::FromJson(noti_obj, "detailInfo")); - if (status.IsError()) { - return status; - } - } - - if (noti_val.contains("ledColor") && !IsNull(noti_obj, "ledColor")) { - status = SetLedColor(tmp_noti, - common::FromJson(noti_obj, "ledColor")); - if (status.IsError()) { - return status; - } - } - - status = SetLedOnPeriod(tmp_noti, - static_cast(common::FromJson( - noti_obj, "ledOnPeriod"))); - if (status.IsError()) { - return status; - } - - status = SetLedOffPeriod(tmp_noti, - static_cast(common::FromJson( - noti_obj, "ledOffPeriod"))); - if (status.IsError()) { - return status; - } - - if (noti_val.contains("backgroundImagePath") - && !IsNull(noti_obj, "backgroundImagePath")) { - const std::string& value_str = common::FromJson(noti_obj, "backgroundImagePath"); - std::string real_path = common::FilesystemProvider::Create().GetRealPath(value_str); - - status = SetImage(tmp_noti, NOTIFICATION_IMAGE_TYPE_BACKGROUND, real_path); - if (status.IsError()) { - return status; - } - } - - if (noti_val.contains("thumbnails") && !IsNull(noti_obj, "thumbnails")) { - status = SetThumbnails( - tmp_noti, common::FromJson(noti_obj, "thumbnails")); - if (status.IsError()) { - return status; - } - } - - if (noti_val.contains("soundPath") && !IsNull(noti_obj, "soundPath")) { - const std::string& value_str = common::FromJson(noti_obj, "soundPath"); - std::string real_path = common::FilesystemProvider::Create().GetRealPath(value_str); - - status = SetSoundPath(tmp_noti, real_path); - if (status.IsError()) { - return status; - } - } - - status = SetVibration(tmp_noti, common::FromJson(noti_obj, "vibration")); - if (status.IsError()) { - return status; - } - - status = CreateAppControl(&app_control); - if (status.IsError()) { - return status; - } - - if (noti_val.contains("appControl") && !IsNull(noti_obj, "appControl")) { - status = SetApplicationControl( - app_control, - common::FromJson(noti_obj, "appControl")); - if (status.IsError()) { - return status; - } - } - - if (noti_val.contains("appId") && !IsNull(noti_obj, "appId")) { - status = SetApplicationId(app_control, - common::FromJson(noti_obj, "appId")); - if (status.IsError()) { - return status; - } - } - - const std::string& progress_type = - common::FromJson(noti_obj, "progressType"); - status = SetImage(tmp_noti, NOTIFICATION_IMAGE_TYPE_LIST_5, progress_type); - if (status.IsError()) { - return status; - } - - double progressValue; - if (noti_val.contains("progressValue") && !IsNull(noti_obj, "progressValue")) { - progressValue = common::FromJson(noti_obj, "progressValue"); - } - else { - progressValue = -1; - } - - status = SetProgressValue(tmp_noti, progress_type, progressValue, - is_update); - - if (status.IsError()) { - return status; - } - - status = SetAppControl(tmp_noti, app_control); + // ledColor + status = SetLedColorFromJson(noti_val, tmp_noti); + CHECK_ERROR(status); + + // ledOnPeriod + status = SetLedOnPeriodFromJson(noti_val, tmp_noti); + CHECK_ERROR(status); + + // ledOffPeriod + status = SetLedOffPeriodFromJson(noti_val, tmp_noti); + CHECK_ERROR(status); + + // backgroundImagePath + status = SetPathFromJson(noti_val, NOTIFICATION_IMAGE_TYPE_BACKGROUND, + "backgroundImagePath", tmp_noti); + CHECK_ERROR(status); + + // thumbnails + status = SetPathsArrayFromJson(noti_val, thumbnails_map_, "thumbnails", tmp_noti); + CHECK_ERROR(status); + + // soundPath + status = SetSoundPathFromJson(noti_val, tmp_noti); + CHECK_ERROR(status); + + // vibration + status = SetVibrationFromJson(noti_val, tmp_noti); + CHECK_ERROR(status); + + // appControl, appId + status = SetAppControlInfoFromJson(noti_val, tmp_noti); + CHECK_ERROR(status); + + // progressType, progressValue + status = SetProgressTypeAndValueFromJson(noti_val, is_update, tmp_noti); CHECK_ERROR(status); *noti_handle = tmp_noti_ptr.release(); @@ -274,8 +178,8 @@ PlatformResult StatusNotification::GetNotiHandleFromJson(const picojson::object& } PlatformResult StatusNotification::PostStatusNotification(const picojson::object& args, - bool is_update, - picojson::object* out_ptr) { + bool is_update, + picojson::object* out_ptr) { LoggerD("Enter"); return PostNotification(args, is_update, out_ptr, GetNotiHandleFromJson); } diff --git a/src/notification/status_notification.h b/src/notification/status_notification.h index 33607298..9c573e00 100644 --- a/src/notification/status_notification.h +++ b/src/notification/status_notification.h @@ -33,15 +33,15 @@ namespace notification { class StatusNotification : public CommonNotification { public: XW_EXPORT static common::PlatformResult ToJson(int id, - notification_h noti_handle, - app_control_h app_handle, - picojson::object* out_ptr); + 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); + bool is_update, + notification_h *noti_handle); static common::PlatformResult PostStatusNotification(const picojson::object& args, - bool is_update, - picojson::object* out_ptr); + bool is_update, + picojson::object* out_ptr); private: StatusNotification(); virtual ~StatusNotification(); diff --git a/src/notification/user_notification.cc b/src/notification/user_notification.cc index b863b6fe..7185d98c 100644 --- a/src/notification/user_notification.cc +++ b/src/notification/user_notification.cc @@ -68,12 +68,14 @@ PlatformResult UserNotification::GetNotiHandleFromJson(const picojson::object& a 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(args, "notification"); picojson::value noti_val(noti_obj); notification_h tmp_noti = nullptr; - PlatformResult status = InitNotiFromJson(noti_obj, is_update, &tmp_noti); + PlatformResult status = InitNotiFromJson(noti_obj, "userType", is_update, &tmp_noti); CHECK_ERROR(status); std::unique_ptr::type, int(*)(notification_h)> tmp_noti_ptr(tmp_noti, ¬ification_free); // automatically release the memory @@ -81,7 +83,7 @@ PlatformResult UserNotification::GetNotiHandleFromJson(const picojson::object& a status = SetCommonMembersFromJson(noti_val, tmp_noti); CHECK_ERROR(status); - status = SetTextContentsFromJson(noti_val, tmp_noti); + status = SetTextContentsFromJson(noti_val, is_update, tmp_noti); CHECK_ERROR(status); status = SetImagesFromJson(noti_val, tmp_noti); @@ -120,7 +122,8 @@ PlatformResult UserNotification::AddTextContentsToJson(notification_h noti_handl picojson::object& text_contents_obj = text_contents.get(); // progressType, progressValue - PlatformResult status = AddProgressTypeAndValueToJson(noti_handle, noti_type_str, &text_contents_obj); + PlatformResult status = AddProgressTypeAndValueToJson(noti_handle, noti_type_str, + &text_contents_obj); CHECK_ERROR(status); // eventsNumber @@ -132,12 +135,12 @@ PlatformResult UserNotification::AddTextContentsToJson(notification_h noti_handl CHECK_ERROR(status); // buttonsTexts - status = AddTextsArrayToJson(noti_handle, buttons_texts_map_, "buttonsTexts", out_ptr); + status = AddTextsArrayToJson(noti_handle, buttons_texts_map_, "buttonsTexts", &text_contents_obj); CHECK_ERROR(status); // contentForOff status = AddTextToJson(noti_handle, NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF, - "contentForOff", out_ptr); + "contentForOff", &text_contents_obj); CHECK_ERROR(status); (*out_ptr)["textContents"] = text_contents; @@ -172,7 +175,8 @@ PlatformResult UserNotification::AddImagesToJson(notification_h noti_handle, CHECK_ERROR(status); // buttonIconPaths - status = AddPathsArrayToJson(noti_handle, buttons_icon_paths_map_, "buttonIconPaths", out_ptr); + status = AddPathsArrayToJson(noti_handle, buttons_icon_paths_map_, "buttonIconPaths", + &images_contents_obj); CHECK_ERROR(status); // backgroundImagePath @@ -193,16 +197,16 @@ PlatformResult UserNotification::AddThumbnailsToJson(notification_h noti_handle, // lockScreenThumbnailIconPath PlatformResult status = AddPathToJson(noti_handle, NOTIFICATION_IMAGE_TYPE_THUMBNAIL_FOR_LOCK, - "lockScreenThumbnailIconPath", out_ptr); + "lockScreenThumbnailIconPath", &thumbnails_contents_obj); CHECK_ERROR(status); // thumbnailIconPath status = AddPathToJson(noti_handle, NOTIFICATION_IMAGE_TYPE_THUMBNAIL, - "thumbnailIconPath", out_ptr); + "thumbnailIconPath", &thumbnails_contents_obj); CHECK_ERROR(status); // thumbnails - status = AddPathsArrayToJson(noti_handle, thumbnails_map_, "thumbnails", out_ptr); + status = AddPathsArrayToJson(noti_handle, thumbnails_map_, "thumbnails", &thumbnails_contents_obj); CHECK_ERROR(status); (*out_ptr)["thumbnails"] = thumbnails_contents; @@ -279,57 +283,180 @@ PlatformResult UserNotification::AddLedsToJson(notification_h noti_handle, } PlatformResult UserNotification::SetTextContentsFromJson(const picojson::value& noti_value, + bool is_update, notification_h noti_handle) { LoggerD("Enter"); - - return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR, - "Not implemented yet", - ("Not implemented yet")); + if (noti_value.contains("textContents") && + noti_value.get("textContents").is()) { + LoggerD("nullable member textContents is present - parsing it"); + const picojson::value& text_contents_value = noti_value.get("textContents"); + + // progressType, progressValue + PlatformResult status = SetProgressTypeAndValueFromJson(text_contents_value, is_update, + noti_handle); + CHECK_ERROR(status); + + // eventsNumber + status = SetEventsNumberFromJson(text_contents_value, "eventsNumber", noti_handle); + CHECK_ERROR(status); + + // detailInfo + status = SetDetailInfosFromJson(text_contents_value, noti_handle); + CHECK_ERROR(status); + + // buttonsTexts + status = SetTextsArrayFromJson(text_contents_value, buttons_texts_map_, + "buttonsTexts", noti_handle); + CHECK_ERROR(status); + + // contentForOff + status = SetTextFromJson(text_contents_value, + NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF, + "contentForOff", noti_handle); + CHECK_ERROR(status); + } + return PlatformResult(ErrorCode::NO_ERROR); } PlatformResult UserNotification::SetImagesFromJson(const picojson::value& noti_value, notification_h noti_handle) { LoggerD("Enter"); - - return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR, - "Not implemented yet", - ("Not implemented yet")); + if (noti_value.contains("images") && + noti_value.get("images").is()) { + LoggerD("nullable member images is present - parsing it"); + const picojson::value& images_value = noti_value.get("images"); + + // iconPath + PlatformResult status = SetPathFromJson(images_value, NOTIFICATION_IMAGE_TYPE_ICON, + "iconPath", noti_handle); + CHECK_ERROR(status); + + // subIconPath + status = SetPathFromJson(images_value, NOTIFICATION_IMAGE_TYPE_ICON_SUB, + "subIconPath", noti_handle); + CHECK_ERROR(status); + + // indicatorIconPath + status = SetPathFromJson(images_value, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, + "indicatorIconPath", noti_handle); + CHECK_ERROR(status); + + // lockScreenIconPath + status = SetPathFromJson(images_value, NOTIFICATION_IMAGE_TYPE_ICON_FOR_LOCK, + "lockScreenIconPath", noti_handle); + CHECK_ERROR(status); + + // buttonIconPaths + status = SetPathsArrayFromJson(images_value, buttons_icon_paths_map_, + "buttonIconPaths", noti_handle); + CHECK_ERROR(status); + + // backgroundImagePath + status = SetPathFromJson(images_value, NOTIFICATION_IMAGE_TYPE_BACKGROUND, + "backgroundImagePath", noti_handle); + CHECK_ERROR(status); + } + return PlatformResult(ErrorCode::NO_ERROR); } PlatformResult UserNotification::SetThumbnailsFromJson(const picojson::value& noti_value, notification_h noti_handle) { LoggerD("Enter"); - return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR, - "Not implemented yet", - ("Not implemented yet")); + if (noti_value.contains("thumbnails") && noti_value.get("thumbnails").is()) { + LoggerD("nullable member thumbnails is present - parsing it"); + const picojson::value& thumbnails_value = noti_value.get("thumbnails"); + + // lockScreenThumbnailIconPath + PlatformResult status = SetPathFromJson(thumbnails_value, + NOTIFICATION_IMAGE_TYPE_THUMBNAIL_FOR_LOCK, + "lockScreenThumbnailIconPath", noti_handle); + CHECK_ERROR(status); + + // thumbnailIconPath + status = SetPathFromJson(thumbnails_value, NOTIFICATION_IMAGE_TYPE_THUMBNAIL, + "thumbnailIconPath", noti_handle); + CHECK_ERROR(status); + + // thumbnails + status = SetPathsArrayFromJson(thumbnails_value, thumbnails_map_, "thumbnails", noti_handle); + CHECK_ERROR(status); + } + return PlatformResult(ErrorCode::NO_ERROR); } PlatformResult UserNotification::SetActionsFromJson(const picojson::value& noti_value, notification_h noti_handle) { LoggerD("Enter"); - return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR, - "Not implemented yet", - ("Not implemented yet")); + if (noti_value.contains("actions") && noti_value.get("actions").is()) { + LoggerD("nullable member actions is present - parsing it"); + const picojson::value& actions_value = noti_value.get("actions"); + + // soundPath + PlatformResult status = SetSoundPathFromJson(actions_value, noti_handle); + CHECK_ERROR(status); + + // vibration + status = SetVibrationFromJson(actions_value, noti_handle); + CHECK_ERROR(status); + + // appControl, appId + status = SetAppControlInfoFromJson(actions_value, noti_handle); + CHECK_ERROR(status); + } + return PlatformResult(ErrorCode::NO_ERROR); } PlatformResult UserNotification::SetGroupContentsFromJson(const picojson::value& noti_value, notification_h noti_handle) { LoggerD("Enter"); - return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR, - "Not implemented yet", - ("Not implemented yet")); + if (noti_value.contains("groupContents") && + noti_value.get("groupContents").is()) { + LoggerD("nullable member groupContents is present - parsing it"); + const picojson::value& group_contents_value = noti_value.get("groupContents"); + + // groupTitle + PlatformResult status = SetTextFromJson(group_contents_value, NOTIFICATION_TEXT_TYPE_GROUP_TITLE, + "groupTitle", noti_handle); + CHECK_ERROR(status); + + // groupContent + status = SetTextFromJson(group_contents_value, NOTIFICATION_TEXT_TYPE_GROUP_CONTENT, + "groupContent", noti_handle); + CHECK_ERROR(status); + + // groupContentForOff + status = SetTextFromJson(group_contents_value, + NOTIFICATION_TEXT_TYPE_GROUP_CONTENT_FOR_DISPLAY_OPTION_IS_OFF, + "groupContentForOff", noti_handle); + CHECK_ERROR(status); + } + return PlatformResult(ErrorCode::NO_ERROR); } PlatformResult UserNotification::SetLedsFromJson(const picojson::value& noti_value, notification_h noti_handle) { LoggerD("Enter"); - return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR, - "Not implemented yet", - ("Not implemented yet")); + if (noti_value.contains("leds") && noti_value.get("leds").is()) { + LoggerD("nullable member leds is present - parsing it"); + const picojson::value& leds_value = noti_value.get("leds"); + + // ledColor + PlatformResult status = SetLedColorFromJson(leds_value, noti_handle); + CHECK_ERROR(status); + + // ledOnPeriod + status = SetLedOnPeriodFromJson(leds_value, noti_handle); + CHECK_ERROR(status); + + // ledOffPeriod + status = SetLedOffPeriodFromJson(leds_value, noti_handle); + CHECK_ERROR(status); + } + return PlatformResult(ErrorCode::NO_ERROR); } } // namespace notification diff --git a/src/notification/user_notification.h b/src/notification/user_notification.h index 849e1e13..47f5b7fe 100644 --- a/src/notification/user_notification.h +++ b/src/notification/user_notification.h @@ -51,6 +51,7 @@ class UserNotification : public CommonNotification { picojson::object* out_ptr); static common::PlatformResult SetTextContentsFromJson(const picojson::value& noti_val, + bool is_update, notification_h noti_handle); static common::PlatformResult SetImagesFromJson(const picojson::value& noti_val, notification_h noti_handle);