noti_layout = NOTIFICATION_LY_ONGOING_PROGRESS;
}
int ret = notification_set_layout(noti_handle, noti_layout);
- if (ret != NOTIFICATION_ERROR_NONE) {
+ if (NOTIFICATION_ERROR_NONE != ret) {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
- "Set notification layout error",
- ("Set notification layout error: %d", ret));
+ "Set notification layout error",
+ ("Set notification layout error: %d", ret));
}
return PlatformResult(ErrorCode::NO_ERROR);
SCOPE_EXIT { free(value); };
int ret = app_control_get_extra_data_array(service, key, &value, &length);
- if (ret != APP_CONTROL_ERROR_NONE) {
+ if (APP_CONTROL_ERROR_NONE != ret) {
LoggerE("Get app control extra data error: %d", ret);
return true;
}
*noti_handle = notification_create(noti_type);
if (!*noti_handle) {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
- "Cannot make new notification object");
+ "Cannot make new notification object");
}
if (NOTIFICATION_TYPE_ONGOING == noti_type) {
int ret = notification_set_display_applist(
*noti_handle,
NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY |
- NOTIFICATION_DISPLAY_APP_INDICATOR);
- if (ret != NOTIFICATION_ERROR_NONE) {
+ NOTIFICATION_DISPLAY_APP_INDICATOR);
+ if (NOTIFICATION_ERROR_NONE != ret) {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
- "Cannot set notification display applist",
- ("Cannot make new notification object: %d", ret));
+ "Cannot set notification display applist",
+ ("Cannot make new notification object: %d", ret));
}
}
}
} else {
return LogAndCreateResult(ErrorCode::NOT_FOUND_ERR,
- "Notification type not found");
+ "Notification type not found");
}
return PlatformResult(ErrorCode::NO_ERROR);
*noti_type = NOTIFICATION_TYPE_ONGOING;
} else {
return LogAndCreateResult(ErrorCode::TYPE_MISMATCH_ERR,
- "Invalide notification type",
- ("Invalide noti type: %s", type.c_str()));
+ "Invalide notification type",
+ ("Invalide noti type: %s", type.c_str()));
}
return PlatformResult(ErrorCode::NO_ERROR);
*image_path = "";
- if (notification_get_image(noti_handle, image_type, &path) !=
- NOTIFICATION_ERROR_NONE) {
+ if (NOTIFICATION_ERROR_NONE != notification_get_image(noti_handle, image_type, &path)) {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
- "Get notification image error",
- ("Get notification image error, image_type: %d", image_type));
+ "Get notification image error",
+ ("Get notification image error, image_type: %d", image_type));
}
if (path) {
*image_path = path;
const std::string& image_path) {
LoggerD("Enter");
int ret = notification_set_image(noti_handle, image_type, image_path.c_str());
- if (ret != NOTIFICATION_ERROR_NONE) {
+ if (NOTIFICATION_ERROR_NONE != ret) {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
- "Set notification image error",
- ("Set notification image error, image_type: %d, error: %d",
- image_type, ret));
+ "Set notification image error",
+ ("Set notification image error, image_type: %d, error: %d",
+ image_type, ret));
}
return PlatformResult(ErrorCode::NO_ERROR);
*noti_text = "";
- if (notification_get_text(noti_handle, text_type, &text) !=
- NOTIFICATION_ERROR_NONE) {
+ if (NOTIFICATION_ERROR_NONE != notification_get_text(noti_handle, text_type, &text)) {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
- "Get notification text error",
- ("Get notification text error, text_type: %d", text_type));
+ "Get notification text error",
+ ("Get notification text error, text_type: %d", text_type));
}
if (text)
noti_text.c_str(),
NULL,
NOTIFICATION_VARIABLE_TYPE_NONE);
- if (ret != NOTIFICATION_ERROR_NONE) {
+ if (NOTIFICATION_ERROR_NONE != ret) {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
- "Set notification text error",
- ("Set notification text error, text_type: %d, error: %d",
- text_type, ret));
+ "Set notification text error",
+ ("Set notification text error, text_type: %d, error: %d",
+ text_type, ret));
}
return PlatformResult(ErrorCode::NO_ERROR);
if (idx > info_map_size) {
return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR,
- "Too many values in notification detailInfo array");
+ "Too many values in notification detailInfo array");
}
}
unsigned int color = 0;
notification_led_op_e type = NOTIFICATION_LED_OP_ON;
- if (notification_get_led(noti_handle, &type, (int*)&color) !=
- NOTIFICATION_ERROR_NONE) {
+ if (NOTIFICATION_ERROR_NONE != notification_get_led(noti_handle, &type, (int*)&color)) {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
- "Get notification led displaying option error");
+ "Get notification led displaying option error");
}
*led_color = "";
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()));
+ "Led color is not numeric value",
+ ("Led color is not numeric value: %s", color_str.c_str()));
}
std::stringstream stream;
type = NOTIFICATION_LED_OP_OFF;
int ret = notification_set_led(noti_handle, type, static_cast<int>(color));
- if (ret != NOTIFICATION_ERROR_NONE) {
+ if (NOTIFICATION_ERROR_NONE != ret) {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
- "Set notification led color eror",
- ("Set notification led color eror: %d", ret));
+ "Set notification led color eror",
+ ("Set notification led color eror: %d", ret));
}
return PlatformResult(ErrorCode::NO_ERROR);
int on_time = 0;
int off_time = 0;
- if (notification_get_led_time_period(noti_handle, &on_time, &off_time) !=
- NOTIFICATION_ERROR_NONE) {
+ if (NOTIFICATION_ERROR_NONE != notification_get_led_time_period(noti_handle, &on_time, &off_time)) {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
- "Get notification led on/off period error");
+ "Get notification led on/off period error");
}
if (on_period)
int ret =
notification_set_led_time_period(noti_handle, on_period, off_period);
- if (ret != NOTIFICATION_ERROR_NONE) {
+ if (NOTIFICATION_ERROR_NONE != ret) {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
- "Set notification led on period error",
- ("Set notification led on period error: %d", ret));
+ "Set notification led on period error",
+ ("Set notification led on period error: %d", ret));
}
return PlatformResult(ErrorCode::NO_ERROR);
int ret =
notification_set_led_time_period(noti_handle, on_period, off_period);
- if (ret != NOTIFICATION_ERROR_NONE) {
+ if (NOTIFICATION_ERROR_NONE != ret) {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
- "Set notification led off period error",
- ("Set notification led off period error: %d", ret));
+ "Set notification led off period error",
+ ("Set notification led off period error: %d", ret));
}
return PlatformResult(ErrorCode::NO_ERROR);
if (idx > thumbnails_map_size) {
return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR,
- "Too many values in notification thumbnail array");
+ "Too many values in notification thumbnail array");
}
}
const char* path = NULL;
notification_sound_type_e type = NOTIFICATION_SOUND_TYPE_NONE;
- if (notification_get_sound(noti_handle, &type, &path) !=
- NOTIFICATION_ERROR_NONE) {
+ if (NOTIFICATION_ERROR_NONE != notification_get_sound(noti_handle, &type, &path)) {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
- "Get notification sound error");
+ "Get notification sound error");
}
LoggerD("Sound type = %d", type);
LoggerD("Enter");
int ret = notification_set_sound(
noti_handle, NOTIFICATION_SOUND_TYPE_USER_DATA, sound_path.c_str());
- if (ret != NOTIFICATION_ERROR_NONE) {
+ if (NOTIFICATION_ERROR_NONE != ret) {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
- "Set notification sound error",
- ("Set notification sound error: %d", ret));
+ "Set notification sound error",
+ ("Set notification sound error: %d", ret));
}
LoggerD("Sound path = %s", sound_path.c_str());
LoggerD("Enter");
notification_vibration_type_e vib_type = NOTIFICATION_VIBRATION_TYPE_NONE;
- if (notification_get_vibration(noti_handle, &vib_type, NULL) !=
- NOTIFICATION_ERROR_NONE) {
+ if (NOTIFICATION_ERROR_NONE != notification_get_vibration(noti_handle, &vib_type, NULL)) {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
- "Get notification vibration error");
+ "Get notification vibration error");
}
if (NOTIFICATION_VIBRATION_TYPE_DEFAULT == vib_type ||
}
int ret = notification_set_vibration(noti_handle, vib_type, NULL);
- if (ret != NOTIFICATION_ERROR_NONE) {
+ if (NOTIFICATION_ERROR_NONE != ret) {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
- "Set notification vibration error",
- ("Set notification vibration error: %d", ret));
+ "Set notification vibration error",
+ ("Set notification vibration error: %d", ret));
}
}
};
int ret = app_control_get_operation(app_handle, &operation);
- if (ret != APP_CONTROL_ERROR_NONE) {
+ if (APP_CONTROL_ERROR_NONE != ret) {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
- "Get application control operation error",
- ("Get application control operation error: %d", ret));
+ "Get application control operation error",
+ ("Get application control operation error: %d", ret));
}
if (operation) {
out["operation"] = picojson::value(operation);
if (app_control_get_uri(app_handle, &uri) != APP_CONTROL_ERROR_NONE) {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
- "Get application control uri error");
+ "Get application control uri error");
}
if (uri) {
out["uri"] = picojson::value(uri);
if (app_control_get_mime(app_handle, &mime) != APP_CONTROL_ERROR_NONE) {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
- "Get application control mime error");
+ "Get application control mime error");
}
if (mime) {
out["mime"] = picojson::value(mime);
if (app_control_get_category(app_handle, &category) !=
APP_CONTROL_ERROR_NONE) {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
- "Get application control category error");
+ "Get application control category error");
}
if (category) {
out["category"] = picojson::value(category);
picojson::array app_control_data = picojson::array();
if (app_control_foreach_extra_data(
- app_handle, ServiceExtraDataCb, (void*)&app_control_data) !=
- APP_CONTROL_ERROR_NONE) {
+ app_handle, ServiceExtraDataCb, (void*)&app_control_data) !=
+ APP_CONTROL_ERROR_NONE) {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
- "Get application control data error");
+ "Get application control data error");
}
out["data"] = picojson::value(app_control_data);
} else {
ret = app_control_set_operation(app_handle, APP_CONTROL_OPERATION_DEFAULT);
}
- if (ret != APP_CONTROL_ERROR_NONE) {
+ if (APP_CONTROL_ERROR_NONE != ret) {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
- "Set application control operation error",
- ("Set application control operation error: %d", ret));
+ "Set application control operation error",
+ ("Set application control operation error: %d", ret));
}
if (val.contains("uri") && !IsNull(app_ctrl, "uri")) {
const std::string& uri = common::FromJson<std::string>(app_ctrl, "uri");
ret = app_control_set_uri(app_handle, uri.c_str());
- if (ret != APP_CONTROL_ERROR_NONE) {
+ if (APP_CONTROL_ERROR_NONE != ret) {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
- "Set application control uri error",
- ("Set application control uri error: %d", ret));
+ "Set application control uri error",
+ ("Set application control uri error: %d", ret));
}
}
if (val.contains("mime") && !IsNull(app_ctrl, "mime")) {
const std::string& mime = common::FromJson<std::string>(app_ctrl, "mime");
ret = app_control_set_mime(app_handle, mime.c_str());
- if (ret != APP_CONTROL_ERROR_NONE) {
+ if (APP_CONTROL_ERROR_NONE != ret) {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
- "Set application control mime error",
- ("Set application control mime error: %d", ret));
+ "Set application control mime error",
+ ("Set application control mime error: %d", ret));
}
}
const std::string& category =
common::FromJson<std::string>(app_ctrl, "category");
ret = app_control_set_category(app_handle, category.c_str());
- if (ret != APP_CONTROL_ERROR_NONE) {
+ if (APP_CONTROL_ERROR_NONE != ret) {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
- "Set application control category error",
- ("Set application control category error: %d", ret));
+ "Set application control category error",
+ ("Set application control category error: %d", ret));
}
}
}
ret = app_control_add_extra_data_array(
app_handle, key.c_str(), arrayValue, values.size());
- if (ret != APP_CONTROL_ERROR_NONE) {
+ if (APP_CONTROL_ERROR_NONE != ret) {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
- "Set application control extra data error",
- ("Set application control extra data error: %d", ret));
+ "Set application control extra data error",
+ ("Set application control extra data error: %d", ret));
}
}
const std::string& app_id) {
LoggerD("Enter");
int ret = app_control_set_app_id(app_handle, app_id.c_str());
- if (ret != APP_CONTROL_ERROR_NONE) {
+ if (APP_CONTROL_ERROR_NONE != ret) {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Set applicaiton ID error",
("Set applicaiton ID error: %d", ret));
}
double tmp_progress_value = 0.0;
if (progess_type == kProgressTypeByte) {
- if (notification_get_size(noti_handle, &tmp_progress_value) !=
- NOTIFICATION_ERROR_NONE) {
+ if (NOTIFICATION_ERROR_NONE != notification_get_size(noti_handle, &tmp_progress_value)) {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
- "Get notification size error");
+ "Get notification size error");
}
} else if (progess_type == kProgressTypePercentage) {
- if (notification_get_progress(noti_handle, &tmp_progress_value) !=
- NOTIFICATION_ERROR_NONE) {
+ if (NOTIFICATION_ERROR_NONE != notification_get_progress(noti_handle, &tmp_progress_value)) {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
- "Get notification progress error");
+ "Get notification progress error");
}
// native api uses range 0-1, but webapi expects 0-100, so we need to multiply result with 100
tmp_progress_value *= 100;
} else {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
- "Unknown notification progress type",
- ("Unknown notification progress type: %s ", progess_type.c_str()));
+ "Unknown notification progress type",
+ ("Unknown notification progress type: %s ", progess_type.c_str()));
}
LOGGER(DEBUG) << "Progress " << progess_type << " = " << tmp_progress_value;
if (is_update) {
ret = notification_update_size(noti_handle, NOTIFICATION_PRIV_ID_NONE,
- progress_value);
+ progress_value);
}
} else if (progress_type == kProgressTypePercentage) {
// native api uses range 0-1, but webapi expects 0-100, so we need to divide by 100
if (is_update) {
ret = notification_update_progress(noti_handle, NOTIFICATION_PRIV_ID_NONE,
- progress_value);
+ progress_value);
}
} else {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
- "Unknown notification progress type",
- ("Unknown notification progress type: %s ", progress_type.c_str()));
+ "Unknown notification progress type",
+ ("Unknown notification progress type: %s ", progress_type.c_str()));
}
- if (ret != NOTIFICATION_ERROR_NONE) {
+ if (NOTIFICATION_ERROR_NONE != ret) {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
- "Set notification progress/size error",
- ("Set notification progress/size error: %d", ret));
+ "Set notification progress/size error",
+ ("Set notification progress/size error: %d", ret));
}
return PlatformResult(ErrorCode::NO_ERROR);
LoggerD("Enter");
*posted_time = 0;
- if (notification_get_insert_time(noti_handle, posted_time) !=
- NOTIFICATION_ERROR_NONE) {
+ if (NOTIFICATION_ERROR_NONE != notification_get_insert_time(noti_handle, posted_time)) {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
- "Get notification posted time error");
+ "Get notification posted time error");
}
return PlatformResult(ErrorCode::NO_ERROR);
*noti_handle = notification_load(NULL, id);
if (NULL == *noti_handle) {
return LogAndCreateResult(ErrorCode::NOT_FOUND_ERR,
- "Not found or removed notification id");
+ "Not found or removed notification id");
}
return PlatformResult(ErrorCode::NO_ERROR);
notification_get_launch_option(noti_handle,
NOTIFICATION_LAUNCH_OPTION_APP_CONTROL,
static_cast<void*>(app_control));
- if (ret != NOTIFICATION_ERROR_NONE) {
+ if (NOTIFICATION_ERROR_NONE != ret) {
return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR,
- "Notification get launch option error",
- ("Notification get launch option error: %d", ret));
+ "Notification get launch option error",
+ ("Notification get launch option error: %d", ret));
}
return PlatformResult(ErrorCode::NO_ERROR);
app_control_h* app_control) {
LoggerD("Enter");
int ret = app_control_create(app_control);
- if (ret != APP_CONTROL_ERROR_NONE) {
+ if (APP_CONTROL_ERROR_NONE != ret) {
return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR,
- "Application create error",
- ("Application create error: %d", ret));
+ "Application create error",
+ ("Application create error: %d", ret));
}
return PlatformResult(ErrorCode::NO_ERROR);
notification_set_launch_option(noti_handle,
NOTIFICATION_LAUNCH_OPTION_APP_CONTROL,
static_cast<void*>(app_control));
- if (ret != APP_CONTROL_ERROR_NONE) {
+ if (APP_CONTROL_ERROR_NONE != ret) {
return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR,
- "Notification set launch option error",
- ("Notification set launch option error: %d", ret));
+ "Notification set launch option error",
+ ("Notification set launch option error: %d", ret));
}
return PlatformResult(ErrorCode::NO_ERROR);
}
PlatformResult CommonNotification::PostNotification(const picojson::object& args,
- bool is_update,
- picojson::object* out_ptr,
- GetHandleFromJsonFun getHandle) {
+ bool is_update,
+ picojson::object* out_ptr,
+ GetHandleFromJsonFun getHandle) {
LoggerD("Enter");
notification_h noti_handle = nullptr;
int ret = NOTIFICATION_ERROR_NONE;
PlatformResult status = getHandle(args, is_update, ¬i_handle);
- if (status.IsError()){
+ if (status.IsError()) {
return status;
}
}
+PlatformResult CommonNotification::AddCommonMembersToJson(int id, notification_h noti_handle,
+ picojson::object* out_ptr) {
+ LoggerD("Enter");
+ picojson::object& out = *out_ptr;
+
+ out["id"] = picojson::value(std::to_string(id));
+ out["type"] = picojson::value("STATUS");
+
+ time_t posted_time = 0;
+ PlatformResult ret = GetPostedTime(noti_handle, &posted_time);
+ CHECK_ERROR(ret);
+ out["postedTime"] =
+ picojson::value(static_cast<double>(posted_time) * 1000.0);
+
+ std::string value_str;
+ ret = GetText(noti_handle, NOTIFICATION_TEXT_TYPE_TITLE, &value_str);
+ CHECK_ERROR(ret);
+ out["title"] = picojson::value(value_str);
+
+ ret = GetText(noti_handle, NOTIFICATION_TEXT_TYPE_CONTENT, &value_str);
+ CHECK_ERROR(ret);
+ if (value_str.length()) {
+ out["content"] = picojson::value(value_str);
+ }
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult CommonNotification::AddTypeToJson(notification_h noti_handle, const std::string& key,
+ picojson::object* out_ptr, std::string* noti_type_str) {
+ LoggerD("Enter");
+ picojson::object& out = *out_ptr;
+ // Notification type
+ notification_type_e noti_type = NOTIFICATION_TYPE_NONE;
+ int ret = notification_get_type(noti_handle, ¬i_type);
+ if (NOTIFICATION_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
+ "Notification get type error",
+ ("Notification get type error: %d", ret));
+ }
+
+ notification_ly_type_e noti_layout = NOTIFICATION_LY_NONE;
+ ret = notification_get_layout(noti_handle, ¬i_layout);
+ if (NOTIFICATION_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
+ "Notification get layout error",
+ ("Notification get layout error: %d", ret));
+ }
+
+ PlatformResult status = StatusTypeFromPlatform(noti_type, noti_layout, noti_type_str);
+ CHECK_ERROR(status);
+ out[key] = picojson::value(*noti_type_str);
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult CommonNotification::InitNotiFromJson(const picojson::object& noti_obj,
+ bool is_update,
+ notification_h* noti_handle) {
+ LoggerD("Enter");
+ notification_h tmp_noti = nullptr;
+
+ const std::string& status_type =
+ common::FromJson<std::string>(noti_obj, "statusType");
+
+ 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<std::string>(noti_obj, "id"));
+
+ status = GetNotiHandle(id, &tmp_noti);
+ CHECK_ERROR(status);
+ } else {
+ status = Create(noti_type, &tmp_noti);
+ CHECK_ERROR(status);
+ }
+ std::unique_ptr<std::remove_pointer<notification_h>::type, int(*)(notification_h)>
+ tmp_noti_ptr(tmp_noti, ¬ification_free); // automatically release the memory
+
+ status = SetLayout(tmp_noti, status_type);
+ CHECK_ERROR(status);
+
+ *noti_handle = tmp_noti_ptr.release();
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+
+PlatformResult CommonNotification::SetCommonMembersFromJson(const picojson::value& noti_value,
+ notification_h noti_handle) {
+ LoggerD("Enter");
+ const picojson::object& noti_obj = noti_value.get<picojson::object>();
+ PlatformResult status = SetText(noti_handle,
+ NOTIFICATION_TEXT_TYPE_TITLE,
+ common::FromJson<std::string>(noti_obj, "title"));
+ CHECK_ERROR(status);
+
+ if (noti_value.contains("content") && !IsNull(noti_obj, "content")) {
+ status = SetText(noti_handle,
+ NOTIFICATION_TEXT_TYPE_CONTENT,
+ common::FromJson<std::string>(noti_obj, "content"));
+ CHECK_ERROR(status);
+ }
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+
} // namespace notification
} // namespace extension
LoggerD("Enter");
picojson::object& out = *out_ptr;
- out["id"] = picojson::value(std::to_string(id));
- out["type"] = picojson::value("STATUS");
-
- // Nitification type
- notification_type_e noti_type = NOTIFICATION_TYPE_NONE;
- int ret = notification_get_type(noti_handle, ¬i_type);
- if (ret != NOTIFICATION_ERROR_NONE) {
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
- "Notification get type error",
- ("Notification get type error: %d", ret));
- }
-
- notification_ly_type_e noti_layout = NOTIFICATION_LY_NONE;
- ret = notification_get_layout(noti_handle, ¬i_layout);
- if (ret != NOTIFICATION_ERROR_NONE) {
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
- "Notification get layout error",
- ("Notification get layout error: %d", ret));
- }
+ CHECK_ERROR(AddCommonMembersToJson(id, noti_handle, out_ptr));
std::string noti_type_str;
- PlatformResult status =
- StatusTypeFromPlatform(noti_type, noti_layout, ¬i_type_str);
- if (status.IsError())
- return status;
- out["statusType"] = picojson::value(noti_type_str);
+ CHECK_ERROR(AddTypeToJson(noti_handle, "statusType", out_ptr, ¬i_type_str));
std::string value_str;
- status = GetImage(noti_handle, NOTIFICATION_IMAGE_TYPE_ICON, &value_str);
+ PlatformResult status = GetImage(noti_handle, NOTIFICATION_IMAGE_TYPE_ICON, &value_str);
if (status.IsError())
return status;
if (value_str.length()) {
return status;
out["progressValue"] = picojson::value(progress_value);
- time_t posted_time;
- status = GetPostedTime(noti_handle, &posted_time);
- if (status.IsError())
- return status;
- out["postedTime"] =
- picojson::value(static_cast<double>(posted_time) * 1000.0);
-
- status = GetText(noti_handle, NOTIFICATION_TEXT_TYPE_TITLE, &value_str);
- if (status.IsError())
- return status;
- out["title"] = picojson::value(value_str);
-
- status = GetText(noti_handle, NOTIFICATION_TEXT_TYPE_CONTENT, &value_str);
- if (status.IsError())
- return status;
- if (value_str.length()) {
- out["content"] = picojson::value(value_str);
- }
-
return PlatformResult(ErrorCode::NO_ERROR);
}
PlatformResult StatusNotification::GetNotiHandleFromJson(const picojson::object& args,
bool is_update,
- notification_h *noti_handle){
+ notification_h *noti_handle) {
LoggerD("Enter");
picojson::object noti_obj =
common::FromJson<picojson::object>(args, "notification");
-
- const std::string& status_type =
- common::FromJson<std::string>(noti_obj, "statusType");
-
- notification_type_e noti_type;
- PlatformResult status = StatusTypeToPlatform(status_type, ¬i_type);
- if (status.IsError())
- return status;
-
- int id = NOTIFICATION_PRIV_ID_NONE;
+ picojson::value noti_val(noti_obj);
app_control_h app_control = nullptr;
}
};
- if (is_update) {
- id = std::stoi(common::FromJson<std::string>(noti_obj, "id"));
+ notification_h tmp_noti = nullptr;
+ PlatformResult status = InitNotiFromJson(noti_obj, is_update, &tmp_noti);
+ CHECK_ERROR(status);
+ std::unique_ptr<std::remove_pointer<notification_h>::type, int(*)(notification_h)>
+ tmp_noti_ptr(tmp_noti, ¬ification_free); // automatically release the memory
- PlatformResult status = GetNotiHandle(id, noti_handle);
- if (status.IsError())
- return status;
+ status = SetCommonMembersFromJson(noti_val, tmp_noti);
+ CHECK_ERROR(status);
- } else {
- status = Create(noti_type, noti_handle);
- if (status.IsError())
- return status;
- }
- status = SetLayout(*noti_handle, status_type);
- if (status.IsError()) {
- return status;
- }
-
- picojson::value val(noti_obj);
- if (val.contains("iconPath") && !IsNull(noti_obj, "iconPath")) {
+ if (noti_val.contains("iconPath") && !IsNull(noti_obj, "iconPath")) {
const std::string& value_str = common::FromJson<std::string>(noti_obj, "iconPath");
std::string real_path = common::FilesystemProvider::Create().GetRealPath(value_str);
- status = SetImage(*noti_handle, NOTIFICATION_IMAGE_TYPE_ICON, real_path);
+ status = SetImage(tmp_noti, NOTIFICATION_IMAGE_TYPE_ICON, real_path);
if (status.IsError()) {
return status;
}
}
- if (val.contains("subIconPath") && !IsNull(noti_obj, "subIconPath")) {
+ if (noti_val.contains("subIconPath") && !IsNull(noti_obj, "subIconPath")) {
const std::string& value_str =
common::FromJson<std::string>(noti_obj, "subIconPath");
std::string real_path = common::FilesystemProvider::Create().GetRealPath(value_str);
- status = SetImage(*noti_handle, NOTIFICATION_IMAGE_TYPE_ICON_SUB, real_path);
+ status = SetImage(tmp_noti, NOTIFICATION_IMAGE_TYPE_ICON_SUB, real_path);
if (status.IsError()) {
return status;
}
}
- if (val.contains("number") && !IsNull(noti_obj, "number")) {
+ if (noti_val.contains("number") && !IsNull(noti_obj, "number")) {
long number = (long)common::FromJson<double>(noti_obj, "number");
- status = SetText(*noti_handle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, std::to_string(number));
+ status = SetText(tmp_noti, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, std::to_string(number));
if (status.IsError()) {
return status;
}
}
- if (val.contains("detailInfo") && !IsNull(noti_obj, "detailInfo")) {
+ if (noti_val.contains("detailInfo") && !IsNull(noti_obj, "detailInfo")) {
status = SetDetailInfos(
- *noti_handle, common::FromJson<picojson::array>(noti_obj, "detailInfo"));
+ tmp_noti, common::FromJson<picojson::array>(noti_obj, "detailInfo"));
if (status.IsError()) {
return status;
}
}
- if (val.contains("ledColor") && !IsNull(noti_obj, "ledColor")) {
- status = SetLedColor(*noti_handle,
+ if (noti_val.contains("ledColor") && !IsNull(noti_obj, "ledColor")) {
+ status = SetLedColor(tmp_noti,
common::FromJson<std::string>(noti_obj, "ledColor"));
if (status.IsError()) {
return status;
}
}
- status = SetLedOnPeriod(*noti_handle,
+ status = SetLedOnPeriod(tmp_noti,
static_cast<unsigned long>(common::FromJson<double>(
noti_obj, "ledOnPeriod")));
if (status.IsError()) {
return status;
}
- status = SetLedOffPeriod(*noti_handle,
+ status = SetLedOffPeriod(tmp_noti,
static_cast<unsigned long>(common::FromJson<double>(
noti_obj, "ledOffPeriod")));
if (status.IsError()) {
return status;
}
- if (val.contains("backgroundImagePath")
+ if (noti_val.contains("backgroundImagePath")
&& !IsNull(noti_obj, "backgroundImagePath")) {
const std::string& value_str = common::FromJson<std::string>(noti_obj, "backgroundImagePath");
std::string real_path = common::FilesystemProvider::Create().GetRealPath(value_str);
- status = SetImage(*noti_handle, NOTIFICATION_IMAGE_TYPE_BACKGROUND, real_path);
+ status = SetImage(tmp_noti, NOTIFICATION_IMAGE_TYPE_BACKGROUND, real_path);
if (status.IsError()) {
return status;
}
}
- if (val.contains("thumbnails") && !IsNull(noti_obj, "thumbnails")) {
+ if (noti_val.contains("thumbnails") && !IsNull(noti_obj, "thumbnails")) {
status = SetThumbnails(
- *noti_handle, common::FromJson<picojson::array>(noti_obj, "thumbnails"));
+ tmp_noti, common::FromJson<picojson::array>(noti_obj, "thumbnails"));
if (status.IsError()) {
return status;
}
}
- if (val.contains("soundPath") && !IsNull(noti_obj, "soundPath")) {
+ if (noti_val.contains("soundPath") && !IsNull(noti_obj, "soundPath")) {
const std::string& value_str = common::FromJson<std::string>(noti_obj, "soundPath");
std::string real_path = common::FilesystemProvider::Create().GetRealPath(value_str);
- status = SetSoundPath(*noti_handle, real_path);
+ status = SetSoundPath(tmp_noti, real_path);
if (status.IsError()) {
return status;
}
}
- status = SetVibration(*noti_handle, common::FromJson<bool>(noti_obj, "vibration"));
+ status = SetVibration(tmp_noti, common::FromJson<bool>(noti_obj, "vibration"));
if (status.IsError()) {
return status;
}
return status;
}
- if (val.contains("appControl") && !IsNull(noti_obj, "appControl")) {
+ if (noti_val.contains("appControl") && !IsNull(noti_obj, "appControl")) {
status = SetApplicationControl(
app_control,
common::FromJson<picojson::object>(noti_obj, "appControl"));
}
}
- if (val.contains("appId") && !IsNull(noti_obj, "appId")) {
+ if (noti_val.contains("appId") && !IsNull(noti_obj, "appId")) {
status = SetApplicationId(app_control,
common::FromJson<std::string>(noti_obj, "appId"));
if (status.IsError()) {
const std::string& progress_type =
common::FromJson<std::string>(noti_obj, "progressType");
- status = SetImage(*noti_handle, NOTIFICATION_IMAGE_TYPE_LIST_5, progress_type);
+ status = SetImage(tmp_noti, NOTIFICATION_IMAGE_TYPE_LIST_5, progress_type);
if (status.IsError()) {
return status;
}
double progressValue;
- if (val.contains("progressValue") && !IsNull(noti_obj, "progressValue")) {
+ if (noti_val.contains("progressValue") && !IsNull(noti_obj, "progressValue")) {
progressValue = common::FromJson<double>(noti_obj, "progressValue");
}
else {
progressValue = -1;
}
- status = SetProgressValue(*noti_handle, progress_type, progressValue,
+ status = SetProgressValue(tmp_noti, progress_type, progressValue,
is_update);
if (status.IsError()) {
return status;
}
- status = SetText(*noti_handle,
- NOTIFICATION_TEXT_TYPE_TITLE,
- common::FromJson<std::string>(noti_obj, "title"));
- if (status.IsError()) {
- return status;
- }
-
- if (val.contains("content") && !IsNull(noti_obj, "content")) {
- status = SetText(*noti_handle,
- NOTIFICATION_TEXT_TYPE_CONTENT,
- common::FromJson<std::string>(noti_obj, "content"));
- if (status.IsError()) {
- return status;
- }
- }
+ status = SetAppControl(tmp_noti, app_control);
+ CHECK_ERROR(status);
- status = SetAppControl(*noti_handle, app_control);
+ *noti_handle = tmp_noti_ptr.release();
return PlatformResult(ErrorCode::NO_ERROR);
}
#include "notification/user_notification.h"
+#include "common/converter.h"
#include "common/logger.h"
#include "common/scope_exit.h"
app_control_h app_handle,
picojson::object* out_ptr) {
LoggerD("Enter");
+ PlatformResult ret = AddCommonMembersToJson(id, noti_handle, out_ptr);
+ CHECK_ERROR(ret);
+
+ std::string noti_type_str;
+ ret = AddTypeToJson(noti_handle, "userType", out_ptr, ¬i_type_str);
+ CHECK_ERROR(ret);
+
+ ret = AddTextContentsToJson(noti_handle, out_ptr);
+ CHECK_ERROR(ret);
+
+ ret = AddImagesToJson(noti_handle, out_ptr);
+ CHECK_ERROR(ret);
+
+ ret = AddThumbnailsToJson(noti_handle, out_ptr);
+ CHECK_ERROR(ret);
+
+ ret = AddActionsToJson(noti_handle, out_ptr);
+ CHECK_ERROR(ret);
+
+ ret = AddGroupContentsToJson(noti_handle, out_ptr);
+ CHECK_ERROR(ret);
+
+ ret = AddLedsToJson(noti_handle, out_ptr);
+ CHECK_ERROR(ret);
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult UserNotification::GetNotiHandleFromJson(const picojson::object& args,
+ 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);
+
+ notification_h tmp_noti = nullptr;
+ PlatformResult status = InitNotiFromJson(noti_obj, is_update, &tmp_noti);
+ CHECK_ERROR(status);
+ std::unique_ptr<std::remove_pointer<notification_h>::type, int(*)(notification_h)>
+ tmp_noti_ptr(tmp_noti, ¬ification_free); // automatically release the memory
+
+ status = SetCommonMembersFromJson(noti_val, tmp_noti);
+ CHECK_ERROR(status);
+
+ status = SetTextContentsFromJson(noti_val, tmp_noti);
+ CHECK_ERROR(status);
+
+ status = SetImagesFromJson(noti_val, tmp_noti);
+ CHECK_ERROR(status);
+
+ status = SetThumbnailsFromJson(noti_val, tmp_noti);
+ CHECK_ERROR(status);
+
+ status = SetActionsFromJson(noti_val, tmp_noti);
+ CHECK_ERROR(status);
+
+ status = SetGroupContentsFromJson(noti_val, tmp_noti);
+ CHECK_ERROR(status);
+
+ status = SetLedsFromJson(noti_val, tmp_noti);
+ CHECK_ERROR(status);
+
+ *noti_handle = tmp_noti_ptr.release();
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult UserNotification::PostUserNotification(const picojson::object& args,
+ bool is_update,
+ picojson::object* out_ptr) {
+ LoggerD("Enter");
+ return PostNotification(args, is_update, out_ptr, GetNotiHandleFromJson);
+}
+
+PlatformResult UserNotification::AddTextContentsToJson(notification_h noti_handle,
+ picojson::object* out_ptr) {
+ LoggerD("Enter");
+ picojson::object& out = *out_ptr;
+
+ picojson::value text_contents = picojson::value(picojson::object());
+ picojson::object& text_contents_obj = text_contents.get<picojson::object>();
+
+ out["textContents"] = text_contents;
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult UserNotification::AddImagesToJson(notification_h noti_handle,
+ picojson::object* out_ptr) {
+ LoggerD("Enter");
+ picojson::object& out = *out_ptr;
+
+ picojson::value text_contents = picojson::value(picojson::object());
+ picojson::object& text_contents_obj = text_contents.get<picojson::object>();
+
+ out["images"] = text_contents;
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult UserNotification::AddThumbnailsToJson(notification_h noti_handle,
+ picojson::object* out_ptr) {
+ LoggerD("Enter");
+ picojson::object& out = *out_ptr;
+
+ picojson::value text_contents = picojson::value(picojson::object());
+ picojson::object& text_contents_obj = text_contents.get<picojson::object>();
+
+ out["thumbnails"] = text_contents;
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult UserNotification::AddActionsToJson(notification_h noti_handle,
+ picojson::object* out_ptr) {
+ LoggerD("Enter");
+ picojson::object& out = *out_ptr;
+
+ picojson::value text_contents = picojson::value(picojson::object());
+ picojson::object& text_contents_obj = text_contents.get<picojson::object>();
+
+ out["actions"] = text_contents;
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult UserNotification::AddGroupContentsToJson(notification_h noti_handle,
+ picojson::object* out_ptr) {
+ LoggerD("Enter");
+ picojson::object& out = *out_ptr;
+
+ picojson::value text_contents = picojson::value(picojson::object());
+ picojson::object& text_contents_obj = text_contents.get<picojson::object>();
+
+ out["groupContents"] = text_contents;
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult UserNotification::AddLedsToJson(notification_h noti_handle,
+ picojson::object* out_ptr) {
+ LoggerD("Enter");
+ picojson::object& out = *out_ptr;
+
+ picojson::value text_contents = picojson::value(picojson::object());
+ picojson::object& text_contents_obj = text_contents.get<picojson::object>();
+
+ out["leds"] = text_contents;
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult UserNotification::SetTextContentsFromJson(const picojson::value& noti_value,
+ notification_h noti_handle) {
+ 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){
+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"));
}
-PlatformResult UserNotification::PostUserNotification(const picojson::object& args,
- bool is_update,
- picojson::object* out_ptr) {
+PlatformResult UserNotification::SetThumbnailsFromJson(const picojson::value& noti_value,
+ notification_h noti_handle) {
LoggerD("Enter");
- return PostNotification(args, is_update, out_ptr, GetNotiHandleFromJson);
+
+ return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR,
+ "Not implemented yet",
+ ("Not implemented yet"));
+}
+
+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"));
+}
+
+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"));
}
+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"));
+}
} // namespace notification
} // namespace extension