diff options
author | AGaliuzov <AGaliuzov@luxoft.com> | 2016-04-11 17:17:13 +0300 |
---|---|---|
committer | AGaliuzov <AGaliuzov@luxoft.com> | 2016-04-11 17:17:13 +0300 |
commit | 4f2c0330cc537fc1a6e4fb5d9a440cc627c4a846 (patch) | |
tree | 855894bec43bd03ad95a6c661df57faf2b7d86cd /src/components | |
parent | d4d40322cfb33783d0fb0e8aad10c4a8e3f18a20 (diff) | |
parent | 4439a2a9b1b5c78c08c712452fbca7ac5873ff76 (diff) | |
download | sdl_core-4f2c0330cc537fc1a6e4fb5d9a440cc627c4a846.tar.gz |
Merge pull request #439 from LuxoftAKutsan/feature/AddAdressAndDateTimeInSendLocation
Feature/Add address and date time in SendLocation RPC
Diffstat (limited to 'src/components')
6 files changed, 257 insertions, 67 deletions
diff --git a/src/components/application_manager/include/application_manager/commands/mobile/send_location_request.h b/src/components/application_manager/include/application_manager/commands/mobile/send_location_request.h index 581c779aa5..7178514bfe 100644 --- a/src/components/application_manager/include/application_manager/commands/mobile/send_location_request.h +++ b/src/components/application_manager/include/application_manager/commands/mobile/send_location_request.h @@ -34,6 +34,7 @@ #ifndef SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_COMMANDS_MOBILE_SEND_LOCATION_REQUEST_H_ #define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_COMMANDS_MOBILE_SEND_LOCATION_REQUEST_H_ +#include <list> #include "application_manager/commands/command_request_impl.h" namespace application_manager { @@ -70,6 +71,12 @@ class SendLocationRequest : public CommandRequestImpl { private: + /** + * @brief CheckFieldsCompatibility checks if fields are compatible with each other. + * @return true if compatible, otherwise return false + */ + bool CheckFieldsCompatibility(); + /** * @brief Checks sendlocation params(locationName, locationDescription, ...). * Checks string if it contains \t\n \\t \\n or whitespace diff --git a/src/components/application_manager/include/application_manager/smart_object_keys.h b/src/components/application_manager/include/application_manager/smart_object_keys.h index a6685534fa..0aaf21a8f5 100644 --- a/src/components/application_manager/include/application_manager/smart_object_keys.h +++ b/src/components/application_manager/include/application_manager/smart_object_keys.h @@ -277,12 +277,26 @@ const char time_stamp[] = "timeStamp"; const char manual_text_entry[] = "manualTextEntry"; const char image_type_supported[] = "imageTypeSupported"; const char unexpected_disconnect[] = "unexpectedDisconnect"; + +const char longitude_degrees[] = "longitudeDegrees"; +const char latitude_degrees[] = "latitudeDegrees"; const char location_name[] = "locationName"; const char location_description[] = "locationDescription"; const char address_lines[] = "addressLines"; const char phone_number[] = "phoneNumber"; const char number[] = "number"; const char location_image[] = "locationImage"; +const char address[] = "address"; +const char country_name[] = "countryName"; +const char country_code[] = "countryCode"; +const char postal_code[] = "postalCode"; +const char administrative_area[] = "administrativeArea"; +const char locality[] = "locality"; +const char sub_locality[] = "subLocality"; +const char thoroughfare[] = "thoroughfare"; +const char sub_thoroughfare[] = "subThoroughfare"; + + const char is_suscribed[] = "isSubscribed"; const char message_data[] = "messageData"; } // namespace strings diff --git a/src/components/application_manager/src/commands/command_request_impl.cc b/src/components/application_manager/src/commands/command_request_impl.cc index b83b646385..d42fb0e3f5 100644 --- a/src/components/application_manager/src/commands/command_request_impl.cc +++ b/src/components/application_manager/src/commands/command_request_impl.cc @@ -350,6 +350,10 @@ mobile_apis::Result::eType CommandRequestImpl::GetMobileResultCode( mobile_result = mobile_apis::Result::USER_DISALLOWED; break; } + case hmi_apis::Common_Result::SAVED: { + mobile_result = mobile_apis::Result::SAVED; + break; + } default: { LOG4CXX_ERROR(logger_, "Unknown HMI result code " << hmi_code); break; diff --git a/src/components/application_manager/src/commands/mobile/send_location_request.cc b/src/components/application_manager/src/commands/mobile/send_location_request.cc index 4a30b7c50c..9b91653984 100644 --- a/src/components/application_manager/src/commands/mobile/send_location_request.cc +++ b/src/components/application_manager/src/commands/mobile/send_location_request.cc @@ -33,6 +33,7 @@ #include "application_manager/commands/mobile/send_location_request.h" #include "application_manager/application_manager_impl.h" #include "application_manager/message_helper.h" +#include "utils/helpers.h" namespace application_manager { @@ -47,6 +48,7 @@ SendLocationRequest::~SendLocationRequest() { void SendLocationRequest::Run() { using namespace hmi_apis; + using smart_objects::SmartObject; LOG4CXX_AUTO_TRACE(logger_); ApplicationSharedPtr app = application_manager::ApplicationManagerImpl::instance() @@ -60,7 +62,7 @@ void SendLocationRequest::Run() { return; } - const smart_objects::SmartObject& msg_params = (*message_)[strings::msg_params]; + SmartObject& msg_params = (*message_)[strings::msg_params]; std::list<Common_TextFieldName::eType> fields_to_check; if (msg_params.keyExists(strings::location_name)) { @@ -81,17 +83,32 @@ void SendLocationRequest::Run() { return; } + if (IsWhiteSpaceExist()) { LOG4CXX_ERROR(logger_, "Strings contain invalid characters"); SendResponse(false, mobile_apis::Result::INVALID_DATA); return; } - if ((*message_)[strings::msg_params].keyExists(strings::location_image)) { + if (msg_params.keyExists(strings::address)) { + const custom_string::CustomString& address = + msg_params[strings::address].asCustomString(); + if (address.empty()) { + msg_params.erase(strings::address); + } + } + + if (!CheckFieldsCompatibility()){ + LOG4CXX_ERROR(logger_, "CheckFieldsCompatibility failed"); + SendResponse(false, mobile_apis::Result::INVALID_DATA); + return; + } + + if (msg_params.keyExists(strings::location_image)) { mobile_apis::Result::eType verification_result = mobile_apis::Result::SUCCESS; verification_result = MessageHelper::VerifyImage( - (*message_)[strings::msg_params][strings::location_image], app); + msg_params[strings::location_image], app); if (mobile_apis::Result::SUCCESS != verification_result) { LOG4CXX_ERROR(logger_, "VerifyImage INVALID_DATA!"); SendResponse(false, verification_result); @@ -99,61 +116,74 @@ void SendLocationRequest::Run() { } } - smart_objects::SmartObject request_msg_params = smart_objects::SmartObject( + + SmartObject request_msg_params = SmartObject( smart_objects::SmartType_Map); - request_msg_params = (*message_)[strings::msg_params]; + request_msg_params = msg_params; request_msg_params[strings::app_id] = app->hmi_app_id(); - SendHMIRequest(hmi_apis::FunctionID::Navigation_SendLocation, &request_msg_params, true); } void SendLocationRequest::on_event(const event_engine::Event& event) { LOG4CXX_AUTO_TRACE(logger_); + namespace Result = mobile_apis::Result; + using namespace helpers; const smart_objects::SmartObject& message = event.smart_object(); - switch (event.id()) { - case hmi_apis::FunctionID::Navigation_SendLocation: { - LOG4CXX_INFO(logger_, "Received Navigation_SendLocation event"); - mobile_apis::Result::eType result_code = GetMobileResultCode( - static_cast<hmi_apis::Common_Result::eType>( - message[strings::params][hmi_response::code].asUInt())); - bool result = - mobile_apis::Result::SUCCESS == result_code || - mobile_apis::Result::WARNINGS == result_code || - mobile_apis::Result::UNSUPPORTED_RESOURCE == result_code ; - SendResponse(result, result_code, NULL, &(message[strings::msg_params])); - break; - } - default: { - LOG4CXX_ERROR(logger_,"Received unknown event" << event.id()); - break; - } + if (hmi_apis::FunctionID::Navigation_SendLocation == event.id()) { + LOG4CXX_INFO(logger_, "Received Navigation_SendLocation event"); + mobile_apis::Result::eType result_code = + GetMobileResultCode(static_cast<hmi_apis::Common_Result::eType>( + message[strings::params][hmi_response::code].asUInt())); + const bool result = + Compare<Result::eType, EQ, ONE>(result_code, + Result::SAVED, + Result::SUCCESS, + Result::WARNINGS, + Result::UNSUPPORTED_RESOURCE); + SendResponse(result, result_code, NULL, &(message[strings::params])); + return; + } + LOG4CXX_ERROR(logger_, "Received unknown event" << event.id()); +} + +bool SendLocationRequest::CheckFieldsCompatibility() { + const smart_objects::SmartObject& msg_params = (*message_)[strings::msg_params]; + MessageHelper::PrintSmartObject(msg_params); + const bool longitude_degrees_exist = + msg_params.keyExists(strings::longitude_degrees); + const bool latitude_degrees_exist = + msg_params.keyExists(strings::latitude_degrees); + const bool address_exist = msg_params.keyExists(strings::address); + + if (latitude_degrees_exist ^ longitude_degrees_exist) { + LOG4CXX_DEBUG(logger_, "latitude and longitude should be provided only in pair"); + return false; + } + + if (!address_exist && !longitude_degrees_exist && !latitude_degrees_exist) { + LOG4CXX_DEBUG(logger_, "address or latitude/longtitude should should be provided"); + return false; } + return true; +} +void insert_if_contains(const smart_objects::SmartObject& msg_params, + const std::string& param_key, + std::vector<custom_string::CustomString>& output_vector) { + if (msg_params.keyExists(param_key)) { + output_vector.push_back(msg_params[param_key].asCustomString()); + } } bool SendLocationRequest::IsWhiteSpaceExist() { LOG4CXX_AUTO_TRACE(logger_); - const char* str; + std::vector<custom_string::CustomString> fields_to_check; const smart_objects::SmartObject& msg_params = (*message_)[strings::msg_params]; - - if (msg_params.keyExists(strings::location_name)) { - str = msg_params[strings::location_name].asCharArray(); - if (!CheckSyntax(str)) { - LOG4CXX_ERROR(logger_, - "parameter locationName contains invalid character"); - return true; - } - } - - if (msg_params.keyExists(strings::location_description)) { - str = msg_params[strings::location_description].asCharArray(); - if (!CheckSyntax(str)) { - LOG4CXX_ERROR(logger_, - "parameter locationDescription contains invalid character"); - return true; - } - } + insert_if_contains(msg_params, strings::location_name, fields_to_check); + insert_if_contains( + msg_params, strings::location_description, fields_to_check); + insert_if_contains(msg_params, strings::phone_number, fields_to_check); if (msg_params.keyExists(strings::address_lines)) { const smart_objects::SmartArray* al_array = @@ -161,33 +191,34 @@ bool SendLocationRequest::IsWhiteSpaceExist() { smart_objects::SmartArray::const_iterator it_al = al_array->begin(); smart_objects::SmartArray::const_iterator it_al_end = al_array->end(); for (; it_al != it_al_end; ++it_al) { - str = (*it_al).asCharArray(); - if(!CheckSyntax(str)) { - LOG4CXX_ERROR(logger_, - "parameter address_lines contains invalid character"); - return true; - } + const custom_string::CustomString& val = (*it_al).asCustomString(); + fields_to_check.push_back(val); } } - if (msg_params.keyExists(strings::phone_number)) { - str = msg_params[strings::phone_number].asCharArray(); - if (!CheckSyntax(str)) { - LOG4CXX_ERROR(logger_, - "parameter phoneNumber contains invalid character"); - return true; - } + if (msg_params.keyExists(strings::address)) { + const smart_objects::SmartObject& address_so = msg_params[strings::address]; + insert_if_contains(address_so, strings::country_name, fields_to_check); + insert_if_contains(address_so, strings::country_code, fields_to_check); + insert_if_contains(address_so, strings::postal_code, fields_to_check); + insert_if_contains( + address_so, strings::administrative_area, fields_to_check); + insert_if_contains(address_so, strings::locality, fields_to_check); + insert_if_contains(address_so, strings::sub_locality, fields_to_check); + insert_if_contains(address_so, strings::thoroughfare, fields_to_check); + insert_if_contains(address_so, strings::sub_thoroughfare, fields_to_check); } - if (msg_params.keyExists(strings::location_image)) { - str = msg_params[strings::location_image][strings::value].asCharArray(); - if (!CheckSyntax(str)) { + std::vector<custom_string::CustomString>::iterator it = + fields_to_check.begin(); + for (; it != fields_to_check.end(); ++it) { + const std::string& str = it->AsMBString(); + if (!CheckSyntax(str, false)) { LOG4CXX_ERROR(logger_, - "parameter value in locationImage contains invalid character"); + "string '" << str << "'' contains invalid characters"); return true; } } - return false; } diff --git a/src/components/interfaces/HMI_API.xml b/src/components/interfaces/HMI_API.xml index 6dbff0fcb8..09897f0f3f 100644 --- a/src/components/interfaces/HMI_API.xml +++ b/src/components/interfaces/HMI_API.xml @@ -34,7 +34,7 @@ <interfaces name="SmartDeviceLink HMI API"> -<interface name="Common" version="1.1" date="2013-10-02"> +<interface name="Common" version="1.3" date="2016-03-20"> <enum name="Result"> <element name="SUCCESS" value="0"/> @@ -62,6 +62,7 @@ <element name="GENERIC_ERROR" value="22"/> <element name="USER_DISALLOWED" value="23"/> <element name="TRUNCATED_DATA" value="24"/> + <element name="SAVED" value="25"/> </enum> <enum name="TransportType"> @@ -1656,9 +1657,9 @@ <!--IVI part--> <struct name="GPSData"> <description>Struct with the GPS data.</description> - <param name="longitudeDegrees" type="Float" minvalue="-180" maxvalue="180" mandatory="false"> + <param name="longitudeDegrees" type="Double" minvalue="-180" maxvalue="180" mandatory="false"> </param> - <param name="latitudeDegrees" type="Float" minvalue="-90" maxvalue="90" mandatory="false"> + <param name="latitudeDegrees" type="Double" minvalue="-90" maxvalue="90" mandatory="false"> </param> <param name="utcYear" type="Integer" minvalue="2010" maxvalue="2100" mandatory="false"> <description>The current UTC year.</description> @@ -1956,6 +1957,63 @@ </struct> <!--end of IVI part--> +<struct name="DateTime"> + <param name="second" type="Integer" minvalue="0" maxvalue="60" mandatory="true"> + <description>Seconds part of time</description> + </param> + <param name="minute" type="Integer" minvalue="0" maxvalue="59" mandatory="true"> + <description>Minutes part of time</description> + </param> + <param name="hour" type="Integer" minvalue="0" maxvalue="23" mandatory="true"> + <description>Hours part of time. Note that this structure accepts time only in 24 Hr format</description> + </param> + <param name="day" type="Integer" minvalue="1" maxvalue="31" mandatory="true"> + <description>Day of the month</description> + </param> + <param name="month" type="Integer" minvalue="1" maxvalue="12" mandatory="true"> + <description>Month of the year</description> + </param> + <param name="year" type="Integer" maxvalue="4095" mandatory="true"> + <description>The year in YYYY format</description> + </param> + <param name="tz_hour" type="Integer" minvalue="-12" maxvalue="14" defvalue="0" mandatory="true"> + <description>Time zone offset in Hours wrt UTC.</description> + </param> + <param name="tz_minute" type="Integer" minvalue="0" maxvalue="59" defvalue="0" mandatory="true"> + <description>Time zone offset in Min wrt UTC.</description> + </param> + </struct> + +<struct name="OASISAddress"> + <param name="countryName" minlength="0" maxlength="200" type="String" mandatory="false"> + <description>Name of the country (localized)</description> + </param> + <param name="countryCode" minlength="0" maxlength="50" type="String" mandatory="false"> + <description>Name of country (ISO 3166-2)</description> + </param> + <param name="postalCode" minlength="0" maxlength="16" type="String" mandatory="false"> + <description>(PLZ, ZIP, PIN, CAP etc.)</description> + </param> + <param name="administrativeArea" minlength="0" maxlength="200" type="String" mandatory="false"> + <description>Portion of country (e.g. state)</description> + </param> + <param name="subAdministrativeArea" minlength="0" maxlength="200" type="String" mandatory="false"> + <description>Portion of e.g. state (e.g. county)</description> + </param> + <param name="locality" minlength="0" maxlength="200" type="String" mandatory="false"> + <description>Hypernym for e.g. city/village</description> + </param> + <param name="subLocality" minlength="0" maxlength="200" type="String" mandatory="false"> + <description>Hypernym for e.g. district</description> + </param> + <param name="thoroughfare" minlength="0" maxlength="200" type="String" mandatory="false"> + <description>Hypernym for street, road etc.</description> + </param> + <param name="subThoroughfare" minlength="0" maxlength="200" type="String" mandatory="false"> + <description>Portion of thoroughfare e.g. house number</description> + </param> +</struct> + </interface> <interface name="Buttons" version="1.0" date="2013-04-12"> @@ -3150,9 +3208,9 @@ <param name="appID" type="Integer" mandatory="true"> <description>ID of application related to this RPC.</description> </param> - <param name="longitudeDegrees" type="Float" minvalue="-180" maxvalue="180" mandatory="true"> + <param name="longitudeDegrees" type="Float" minvalue="-180" maxvalue="180" mandatory="false"> </param> - <param name="latitudeDegrees" type="Float" minvalue="-90" maxvalue="90" mandatory="true"> + <param name="latitudeDegrees" type="Float" minvalue="-90" maxvalue="90" mandatory="false"> </param> <param name="locationName" type="String" maxlength="500" mandatory="false"> <description> Name / title of intended location </description> @@ -3169,6 +3227,16 @@ <param name="locationImage" type="Common.Image" mandatory="false"> <description> Image / icon of intended location (if applicable and supported) </description> </param> + <param name="timeStamp" type="Common.DateTime" mandatory="false"> + <description> + timestamp in ISO 8601 format + </description> + </param> + + <param name="address" type="Common.OASISAddress" mandatory="false"> + <description>Address to be used for setting destination</description> + </param> + </function> <function name="SendLocation" messagetype="response" > </function> diff --git a/src/components/interfaces/MOBILE_API.xml b/src/components/interfaces/MOBILE_API.xml index 1892df6da1..0700aff333 100644 --- a/src/components/interfaces/MOBILE_API.xml +++ b/src/components/interfaces/MOBILE_API.xml @@ -2245,6 +2245,62 @@ <element name="notification" value="2" />
</enum>
+ <struct name="DateTime">
+ <param name="second" type="Integer" minvalue="0" maxvalue="60" mandatory="true">
+ <description>Seconds part of time</description>
+ </param>
+ <param name="minute" type="Integer" minvalue="0" maxvalue="59" mandatory="true">
+ <description>Minutes part of time</description>
+ </param>
+ <param name="hour" type="Integer" minvalue="0" maxvalue="23" mandatory="true">
+ <description>Hours part of time. Note that this structure accepts time only in 24 Hr format</description>
+ </param>
+ <param name="day" type="Integer" minvalue="1" maxvalue="31" mandatory="true">
+ <description>Day of the month</description>
+ </param>
+ <param name="month" type="Integer" minvalue="1" maxvalue="12" mandatory="true">
+ <description>Month of the year</description>
+ </param>
+ <param name="year" type="Integer" maxvalue="4095" mandatory="true">
+ <description>The year in YYYY format</description>
+ </param>
+ <param name="tz_hour" type="Integer" minvalue="-12" maxvalue="14" defvalue="0" mandatory="true">
+ <description>Time zone offset in Hours wrt UTC.</description>
+ </param>
+ <param name="tz_minute" type="Integer" minvalue="0" maxvalue="59" defvalue="0" mandatory="true">
+ <description>Time zone offset in Min wrt UTC.</description>
+ </param>
+ </struct>
+
+<struct name="OASISAddress">
+ <param name="countryName" minlength="0" maxlength="200" type="String" mandatory="false">
+ <description>Name of the country (localized)</description>
+ </param>
+ <param name="countryCode" minlength="0" maxlength="50" type="String" mandatory="false">
+ <description>Name of country (ISO 3166-2)</description>
+ </param>
+ <param name="postalCode" minlength="0" maxlength="16" type="String" mandatory="false">
+ <description>(PLZ, ZIP, PIN, CAP etc.)</description>
+ </param>
+ <param name="administrativeArea" minlength="0" maxlength="200" type="String" mandatory="false">
+ <description>Portion of country (e.g. state)</description>
+ </param>
+ <param name="subAdministrativeArea" minlength="0" maxlength="200" type="String" mandatory="false">
+ <description>Portion of e.g. state (e.g. county)</description>
+ </param>
+ <param name="locality" minlength="0" maxlength="200" type="String" mandatory="false">
+ <description>Hypernym for e.g. city/village</description>
+ </param>
+ <param name="subLocality" minlength="0" maxlength="200" type="String" mandatory="false">
+ <description>Hypernym for e.g. district</description>
+ </param>
+ <param name="thoroughfare" minlength="0" maxlength="200" type="String" mandatory="false">
+ <description>Hypernym for street, road etc.</description>
+ </param>
+ <param name="subThoroughfare" minlength="0" maxlength="200" type="String" mandatory="false">
+ <description>Portion of thoroughfare e.g. house number</description>
+ </param>
+</struct>
<!-- Requests/Responses -->
<function name="RegisterAppInterface" functionID="RegisterAppInterfaceID" messagetype="request">
@@ -4679,9 +4735,9 @@ </function>
<function name="SendLocation" functionID="SendLocationID" messagetype="request">
- <param name="longitudeDegrees" type="Float" minvalue="-180" maxvalue="180" mandatory="true">
+ <param name="longitudeDegrees" type="Double" minvalue="-180" maxvalue="180" mandatory="false">
</param>
- <param name="latitudeDegrees" type="Float" minvalue="-90" maxvalue="90" mandatory="true">
+ <param name="latitudeDegrees" type="Double" minvalue="-90" maxvalue="90" mandatory="false">
</param>
<param name="locationName" type="String" maxlength="500" mandatory="false">
<description>
@@ -4707,6 +4763,16 @@ <description>
Image / icon of intended location (if applicable and supported)
</description>
+ </param>
+
+ <param name="timeStamp" type="DateTime" mandatory="false">
+ <description>
+ timestamp in ISO 8601 format
+ </description>
+ </param>
+
+ <param name="address" type="OASISAddress" mandatory="false">
+ <description>Address to be used for setting destination</description>
</param>
</function>
|