Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move duplicate conversion functions to Message Helper #3449

Original file line number Diff line number Diff line change
Expand Up @@ -1229,21 +1229,6 @@ class ApplicationManagerImpl
smart_objects::SmartObject& ttsName,
smart_objects::SmartObject& vrSynonym);

/**
* @brief Method transforms string to AppHMIType
* @param str contains string AppHMIType
* @return enum AppHMIType
*/
mobile_apis::AppHMIType::eType StringToAppHMIType(std::string str);

/**
* @brief Returns a string representation of AppHMIType
* @param type an enum value of AppHMIType
* @return string representation of the enum value
*/
const std::string AppHMITypeToString(
mobile_apis::AppHMIType::eType type) const;

/**
* @brief Method compares arrays of app HMI type
* @param from_policy contains app HMI type from policy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "interfaces/MOBILE_API.h"
#include "policy/policy_types.h"
#include "protocol_handler/session_observer.h"
#include "smart_objects/enum_schema_item.h"
#include "smart_objects/smart_object.h"
#include "transport_manager/common.h"
#include "utils/macro.h"
Expand Down Expand Up @@ -102,6 +103,35 @@ struct ResetGlobalPropertiesResult {
*/
typedef std::map<std::string, mobile_apis::VehicleDataType::eType> VehicleData;

/**
* @brief Converts stringified value to enum value
* @param str stringified value
* @return Enum value if succedeed, otherwise -
* INVALID_ENUM
*/
template <typename T>
T StringToEnum(const std::string& str) {
using namespace ns_smart_device_link::ns_smart_objects;
T enum_value;
EnumConversionHelper<T>::StringToEnum(str, &enum_value);
return enum_value;
}

/**
* @brief Converts enum value to string
* @param enum_value enum value
* @return stringified value for enum if succedeed, otherwise - empty string
*/
template <typename T>
std::string EnumToString(T enum_value) {
using namespace ns_smart_device_link::ns_smart_objects;
const char* str = 0;
if (EnumConversionHelper<T>::EnumToCString(enum_value, &str)) {
return str;
}
return std::string();
}

/**
* @brief MessageHelper class
**/
Expand Down Expand Up @@ -184,42 +214,9 @@ class MessageHelper {
*/
static const VehicleData& vehicle_data();

/**
* @brief Converts HMI Result enum value to string
* @param hmi_result HMI Result enum value
* @return stringified value for enum if succedeed, otherwise - empty string
*/
static std::string HMIResultToString(
hmi_apis::Common_Result::eType hmi_result);

/**
* @brief Converts string to HMI Result enum value
* @param hmi_result stringified value
* @return HMI Result enum value if succedeed, otherwise - INVALID_ENUM
* value
*/
static hmi_apis::Common_Result::eType HMIResultFromString(
const std::string& hmi_result);

/**
* @brief Converts mobile Result enum value to string
* @param mobile_result mobile Result enum value
* @return stringified value for enum if succedeed, otherwise - empty string
*/
static std::string MobileResultToString(
mobile_apis::Result::eType mobile_result);

static std::string GetDeviceMacAddressForHandle(
const transport_manager::DeviceHandle device_handle,
const ApplicationManager& app_mngr);
/**
* @brief Converts string to mobile Result enum value
* @param mobile_result stringified value
* @return mobile Result enum value if succedeed, otherwise - INVALID_ENUM
* value
*/
static mobile_api::Result::eType MobileResultFromString(
const std::string& mobile_result);

/**
* @brief Converts HMI Result enum value to mobile Result enum value
Expand All @@ -238,23 +235,6 @@ class MessageHelper {
static hmi_apis::Common_Result::eType MobileToHMIResult(
const mobile_api::Result::eType mobile_result);

/**
* @brief Convert string to HMI level, if possible
* @param hmi_level Stringified HMI level
* @return Appropriate enum from HMI level, or INVALID_ENUM, if conversiion
* is not possible
*/
static mobile_api::HMILevel::eType StringToHMILevel(
const std::string& hmi_level);

/**
* @brief Used to obtain string representation of app's
* HMI Level.
* @param hmi_level Desired HMI Level
*/
static std::string StringifiedHMILevel(
const mobile_apis::HMILevel::eType hmi_level);

/**
* @brief Used to obtain function name by its id
* @param function_id Function ID
Expand Down Expand Up @@ -888,29 +868,6 @@ class MessageHelper {
}

static const uint32_t GetPriorityCode(const std::string& priority);
/**
* @brief Convert common language to string representation
* @param language Common language
* @return Common language string representation
*/
static std::string CommonLanguageToString(
hmi_apis::Common_Language::eType language);

/**
* @brief Converts mobile language to string representation
* @param language Mobile UI language
* @return Mobile language string representation
*/
static std::string MobileLanguageToString(
mobile_apis::Language::eType language);

/**
* @brief Converts string to mobile language enum value
* @param language language as string
* @return Mobile language enum value
*/
static mobile_apis::Language::eType MobileLanguageFromString(
const std::string& language);

/**
* @brief Converts mobile language enum to HMI language enum
Expand Down Expand Up @@ -963,17 +920,6 @@ class MessageHelper {
const std::string& icon_path,
ApplicationManager& application_manager);

static hmi_apis::Common_Language::eType CommonLanguageFromString(
const std::string& language);

/**
* @brief CommonLightNameFromString convert string to LightName enum value
* @param lightName string to convert
* @return value LightName enum value
*/
static hmi_apis::Common_LightName::eType CommonLightNameFromString(
const std::string& lightName);

static smart_objects::SmartObjectSPtr
GetOnAppInterfaceUnregisteredNotificationToMobile(
int32_t connection_key,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@ const SystemInfo GetSystemInfoResponse::GetSystemInfo() const {
info.wers_country_code =
(*message_)[strings::msg_params]["wersCountryCode"].asString();

const auto lang_code = static_cast<hmi_apis::Common_Language::eType>(
(*message_)[strings::msg_params]["language"].asUInt());
info.language = MessageHelper::CommonLanguageToString(lang_code);
const uint32_t lang_code =
(*message_)[strings::msg_params]["language"].asUInt();
info.language = application_manager::EnumToString(
static_cast<hmi_apis::Common_Language::eType>(lang_code));

return info;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ struct OnDriverDistractionProcessor {
if (is_lock_screen_dismissal_exists &&
msg_params[mobile_notification::lock_screen_dismissal_enabled]
.asBool()) {
const auto language =
MessageHelper::MobileLanguageToString(application->ui_language());
const auto language = EnumToString(application->ui_language());

const auto warning_message =
application_manager_.GetPolicyHandler()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@ void OnSystemInfoChangedNotification::Run() {
SDL_LOG_AUTO_TRACE();
uint32_t lang_code =
(*message_)[strings::msg_params][strings::language].asUInt();
const std::string language =
application_manager::MessageHelper::CommonLanguageToString(
static_cast<hmi_apis::Common_Language::eType>(lang_code));
const std::string language = application_manager::EnumToString(
static_cast<hmi_apis::Common_Language::eType>(lang_code));

policy_handler_.OnSystemInfoChanged(language);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,13 @@ void SDLGetUserFriendlyMessageRequest::Run() {
if ((*message_)[strings::msg_params].keyExists(strings::language)) {
uint32_t lang_code =
(*message_)[strings::msg_params][strings::language].asUInt();
required_language =
application_manager::MessageHelper::CommonLanguageToString(
static_cast<hmi_apis::Common_Language::eType>(lang_code));
required_language = application_manager::EnumToString(
static_cast<hmi_apis::Common_Language::eType>(lang_code));
} else {
hmi_apis::Common_Language::eType ui_language =
hmi_capabilities_.active_ui_language();

required_language =
application_manager::MessageHelper::CommonLanguageToString(ui_language);
required_language = application_manager::EnumToString(ui_language);
}

policy_handler_.OnGetUserFriendlyMessage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ void DeleteCommandRequest::on_event(const event_engine::Event& event) {
ui_result_ = static_cast<hmi_apis::Common_Result::eType>(
message[strings::params][hmi_response::code].asInt());
SDL_LOG_DEBUG("Received UI_DeleteCommand event with result "
<< MessageHelper::HMIResultToString(ui_result_));
<< EnumToString(ui_result_));
GetInfo(message, ui_info_);
break;
}
Expand All @@ -165,7 +165,7 @@ void DeleteCommandRequest::on_event(const event_engine::Event& event) {
vr_result_ = static_cast<hmi_apis::Common_Result::eType>(
message[strings::params][hmi_response::code].asInt());
SDL_LOG_DEBUG("Received VR_DeleteCommand event with result "
<< MessageHelper::HMIResultToString(vr_result_));
<< EnumToString(vr_result_));
GetInfo(message, vr_info_);
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,66 +56,14 @@
namespace {
namespace custom_str = utils::custom_string;

mobile_apis::AppHMIType::eType StringToAppHMIType(const std::string& str) {
if ("DEFAULT" == str) {
return mobile_apis::AppHMIType::DEFAULT;
} else if ("COMMUNICATION" == str) {
return mobile_apis::AppHMIType::COMMUNICATION;
} else if ("MEDIA" == str) {
return mobile_apis::AppHMIType::MEDIA;
} else if ("MESSAGING" == str) {
return mobile_apis::AppHMIType::MESSAGING;
} else if ("NAVIGATION" == str) {
return mobile_apis::AppHMIType::NAVIGATION;
} else if ("INFORMATION" == str) {
return mobile_apis::AppHMIType::INFORMATION;
} else if ("SOCIAL" == str) {
return mobile_apis::AppHMIType::SOCIAL;
} else if ("BACKGROUND_PROCESS" == str) {
return mobile_apis::AppHMIType::BACKGROUND_PROCESS;
} else if ("TESTING" == str) {
return mobile_apis::AppHMIType::TESTING;
} else if ("SYSTEM" == str) {
return mobile_apis::AppHMIType::SYSTEM;
} else if ("PROJECTION" == str) {
return mobile_apis::AppHMIType::PROJECTION;
} else if ("REMOTE_CONTROL" == str) {
return mobile_apis::AppHMIType::REMOTE_CONTROL;
} else if ("WEB_VIEW" == str) {
return mobile_apis::AppHMIType::WEB_VIEW;
} else {
return mobile_apis::AppHMIType::INVALID_ENUM;
}
}

std::string AppHMITypeToString(mobile_apis::AppHMIType::eType type) {
const std::map<mobile_apis::AppHMIType::eType, std::string> app_hmi_type_map =
{{mobile_apis::AppHMIType::DEFAULT, "DEFAULT"},
{mobile_apis::AppHMIType::REMOTE_CONTROL, "REMOTE_CONTROL"},
{mobile_apis::AppHMIType::COMMUNICATION, "COMMUNICATION"},
{mobile_apis::AppHMIType::MEDIA, "MEDIA"},
{mobile_apis::AppHMIType::MESSAGING, "MESSAGING"},
{mobile_apis::AppHMIType::NAVIGATION, "NAVIGATION"},
{mobile_apis::AppHMIType::INFORMATION, "INFORMATION"},
{mobile_apis::AppHMIType::SOCIAL, "SOCIAL"},
{mobile_apis::AppHMIType::BACKGROUND_PROCESS, "BACKGROUND_PROCESS"},
{mobile_apis::AppHMIType::TESTING, "TESTING"},
{mobile_apis::AppHMIType::SYSTEM, "SYSTEM"},
{mobile_apis::AppHMIType::PROJECTION, "PROJECTION"},
{mobile_apis::AppHMIType::WEB_VIEW, "WEB_VIEW"}};

std::map<mobile_apis::AppHMIType::eType, std::string>::const_iterator iter =
app_hmi_type_map.find(type);

return app_hmi_type_map.end() != iter ? iter->second : std::string("");
}

struct AppHMITypeInserter {
explicit AppHMITypeInserter(smart_objects::SmartObject& so_array)
: index_(0), so_array_(so_array) {}

bool operator()(const std::string& app_hmi_type) {
so_array_[index_] = StringToAppHMIType(app_hmi_type);
so_array_[index_] =
application_manager::StringToEnum<mobile_apis::AppHMIType::eType>(
app_hmi_type);
++index_;
return true;
}
Expand All @@ -131,7 +79,7 @@ struct CheckMissedTypes {
: policy_app_types_(policy_app_types), log_(log) {}

bool operator()(const smart_objects::SmartArray::value_type& value) {
std::string app_type_str = AppHMITypeToString(
std::string app_type_str = application_manager::EnumToString(
static_cast<mobile_apis::AppHMIType::eType>(value.asInt()));
if (!app_type_str.empty()) {
policy::StringArray::const_iterator it = policy_app_types_.begin();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ namespace {
const uint32_t kConnectionKey = 2u;
const std::string ccpu_version("4.1.3.B_EB355B");
const std::string wers_country_code("WAEGB");
const uint32_t lang_code = 0u;
const std::string kLanguage = "";
const std::string lang_code("EN-US");
} // namespace

class GetSystemInfoResponseTest
Expand Down Expand Up @@ -99,15 +98,8 @@ TEST_F(GetSystemInfoResponseTest, GetSystemInfo_SUCCESS) {

ResponseFromHMIPtr command(CreateCommand<GetSystemInfoResponse>(command_msg));

std::string language;
EXPECT_CALL(mock_message_helper_,
CommonLanguageToString(
static_cast<hmi_apis::Common_Language::eType>(lang_code)))
.WillOnce(Return(language));
EXPECT_EQ(kLanguage, language);

EXPECT_CALL(mock_policy_handler_,
OnGetSystemInfo(ccpu_version, wers_country_code, kLanguage));
OnGetSystemInfo(ccpu_version, wers_country_code, lang_code));

command->Run();
}
Expand All @@ -121,11 +113,6 @@ TEST_F(GetSystemInfoResponseTest, GetSystemInfo_UNSUCCESS) {

ResponseFromHMIPtr command(CreateCommand<GetSystemInfoResponse>(command_msg));

EXPECT_CALL(mock_message_helper_,
CommonLanguageToString(
static_cast<hmi_apis::Common_Language::eType>(lang_code)))
.Times(0);

EXPECT_CALL(mock_hmi_capabilities_, UpdateCachedCapabilities());
EXPECT_CALL(mock_policy_handler_, SetPreloadedPtFlag(false));

Expand Down
Loading