summaryrefslogtreecommitdiff
path: root/src/components/application_manager/src/commands/mobile/put_file_request.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/application_manager/src/commands/mobile/put_file_request.cc')
-rw-r--r--src/components/application_manager/src/commands/mobile/put_file_request.cc120
1 files changed, 63 insertions, 57 deletions
diff --git a/src/components/application_manager/src/commands/mobile/put_file_request.cc b/src/components/application_manager/src/commands/mobile/put_file_request.cc
index 9ff52da8f4..68e7ad60d1 100644
--- a/src/components/application_manager/src/commands/mobile/put_file_request.cc
+++ b/src/components/application_manager/src/commands/mobile/put_file_request.cc
@@ -43,25 +43,24 @@ namespace application_manager {
namespace commands {
-PutFileRequest::PutFileRequest(const MessageSharedPtr& message, ApplicationManager& application_manager)
- : CommandRequestImpl(message, application_manager)
- , offset_(0)
- , sync_file_name_()
- , length_(0)
- , file_type_(mobile_apis::FileType::INVALID_ENUM)
- , is_persistent_file_(false) {
-}
+PutFileRequest::PutFileRequest(const MessageSharedPtr& message,
+ ApplicationManager& application_manager)
+ : CommandRequestImpl(message, application_manager)
+ , offset_(0)
+ , sync_file_name_()
+ , length_(0)
+ , file_type_(mobile_apis::FileType::INVALID_ENUM)
+ , is_persistent_file_(false) {}
-PutFileRequest::~PutFileRequest() {
-}
+PutFileRequest::~PutFileRequest() {}
void PutFileRequest::Run() {
LOG4CXX_AUTO_TRACE(logger_);
ApplicationSharedPtr application =
application_manager_.application(connection_key());
- smart_objects::SmartObject response_params = smart_objects::SmartObject(
- smart_objects::SmartType_Map);
+ smart_objects::SmartObject response_params =
+ smart_objects::SmartObject(smart_objects::SmartType_Map);
if (!application) {
LOG4CXX_ERROR(logger_, "Application is not registered");
@@ -71,12 +70,13 @@ void PutFileRequest::Run() {
if (mobile_api::HMILevel::HMI_NONE == application->hmi_level() &&
application_manager_.get_settings().put_file_in_none() <=
- application->put_file_in_none_count()) {
+ application->put_file_in_none_count()) {
// If application is in the HMI_NONE level the quantity of allowed
// PutFile request is limited by the configuration profile
LOG4CXX_ERROR(logger_,
"Too many requests from the app with HMILevel HMI_NONE ");
- SendResponse(false, mobile_apis::Result::REJECTED,
+ SendResponse(false,
+ mobile_apis::Result::REJECTED,
"Too many requests from the app with HMILevel HMI_NONE",
&response_params);
return;
@@ -84,7 +84,8 @@ void PutFileRequest::Run() {
if (!(*message_)[strings::params].keyExists(strings::binary_data)) {
LOG4CXX_ERROR(logger_, "Binary data empty");
- SendResponse(false, mobile_apis::Result::INVALID_DATA,
+ SendResponse(false,
+ mobile_apis::Result::INVALID_DATA,
"Binary data empty",
&response_params);
return;
@@ -92,7 +93,8 @@ void PutFileRequest::Run() {
if (!(*message_)[strings::msg_params].keyExists(strings::sync_file_name)) {
LOG4CXX_ERROR(logger_, "No file name");
- SendResponse(false, mobile_apis::Result::INVALID_DATA,
+ SendResponse(false,
+ mobile_apis::Result::INVALID_DATA,
"No file name",
&response_params);
return;
@@ -100,24 +102,24 @@ void PutFileRequest::Run() {
if (!(*message_)[strings::msg_params].keyExists(strings::file_type)) {
LOG4CXX_ERROR(logger_, "No file type");
- SendResponse(false, mobile_apis::Result::INVALID_DATA,
+ SendResponse(false,
+ mobile_apis::Result::INVALID_DATA,
"No file type",
&response_params);
return;
}
sync_file_name_ =
- (*message_)[strings::msg_params][strings::sync_file_name].asString();
- file_type_ =
- static_cast<mobile_apis::FileType::eType>(
+ (*message_)[strings::msg_params][strings::sync_file_name].asString();
+ file_type_ = static_cast<mobile_apis::FileType::eType>(
(*message_)[strings::msg_params][strings::file_type].asInt());
const std::vector<uint8_t> binary_data =
- (*message_)[strings::params][strings::binary_data].asBinary();
+ (*message_)[strings::params][strings::binary_data].asBinary();
// Policy table update in json format is currently to be received via PutFile
// TODO(PV): after latest discussion has to be changed
if (mobile_apis::FileType::JSON == file_type_) {
- application_manager_.GetPolicyHandler()
- .ReceiveMessageFromSDK(sync_file_name_, binary_data);
+ application_manager_.GetPolicyHandler().ReceiveMessageFromSDK(
+ sync_file_name_, binary_data);
}
offset_ = 0;
@@ -132,15 +134,13 @@ void PutFileRequest::Run() {
offset_ = (*message_)[strings::msg_params][strings::offset].asInt();
}
- if ((*message_)[strings::msg_params].
- keyExists(strings::persistent_file)) {
+ if ((*message_)[strings::msg_params].keyExists(strings::persistent_file)) {
is_persistent_file_ =
- (*message_)[strings::msg_params][strings::persistent_file].asBool();
+ (*message_)[strings::msg_params][strings::persistent_file].asBool();
}
- if ((*message_)[strings::msg_params].
- keyExists(strings::system_file)) {
+ if ((*message_)[strings::msg_params].keyExists(strings::system_file)) {
is_system_file =
- (*message_)[strings::msg_params][strings::system_file].asBool();
+ (*message_)[strings::msg_params][strings::system_file].asBool();
}
std::string file_path;
@@ -155,39 +155,42 @@ void PutFileRequest::Run() {
uint32_t space_available = application->GetAvailableDiskSpace();
if (binary_data.size() > space_available) {
-
response_params[strings::space_available] =
static_cast<uint32_t>(space_available);
LOG4CXX_ERROR(logger_, "Out of memory");
- SendResponse(false, mobile_apis::Result::OUT_OF_MEMORY,
- "Out of memory", &response_params);
+ SendResponse(false,
+ mobile_apis::Result::OUT_OF_MEMORY,
+ "Out of memory",
+ &response_params);
return;
}
}
if (!file_system::CreateDirectoryRecursively(file_path)) {
LOG4CXX_ERROR(logger_, "Can't create folder");
- SendResponse(false, mobile_apis::Result::GENERIC_ERROR,
- "Can't create folder.", &response_params);
+ SendResponse(false,
+ mobile_apis::Result::GENERIC_ERROR,
+ "Can't create folder.",
+ &response_params);
return;
}
const std::string full_path = file_path + "/" + sync_file_name_;
UNUSED(full_path);
- LOG4CXX_DEBUG(logger_, "Wrtiting " << binary_data.size() << "bytes to "
- << full_path << " (current size is"
- << file_system::FileSize(full_path) << ")");
-
- mobile_apis::Result::eType save_result =
- application_manager_.SaveBinary(binary_data, file_path,
- sync_file_name_, offset_);
-
- LOG4CXX_DEBUG(logger_, "New size of "
- << full_path << " is "
- << file_system::FileSize(full_path) << " bytes");
+ LOG4CXX_DEBUG(logger_,
+ "Wrtiting " << binary_data.size() << "bytes to " << full_path
+ << " (current size is"
+ << file_system::FileSize(full_path) << ")");
+
+ mobile_apis::Result::eType save_result = application_manager_.SaveBinary(
+ binary_data, file_path, sync_file_name_, offset_);
+
+ LOG4CXX_DEBUG(logger_,
+ "New size of " << full_path << " is "
+ << file_system::FileSize(full_path) << " bytes");
if (!is_system_file) {
- response_params[strings::space_available] = static_cast<uint32_t>(
- application->GetAvailableDiskSpace());
+ response_params[strings::space_available] =
+ static_cast<uint32_t>(application->GetAvailableDiskSpace());
}
sync_file_name_ = file_path + "/" + sync_file_name_;
@@ -195,23 +198,25 @@ void PutFileRequest::Run() {
case mobile_apis::Result::SUCCESS: {
LOG4CXX_INFO(logger_, "PutFile is successful");
if (!is_system_file) {
- AppFile file(sync_file_name_, is_persistent_file_,
- is_download_compleate, file_type_);
+ AppFile file(sync_file_name_,
+ is_persistent_file_,
+ is_download_compleate,
+ file_type_);
if (0 == offset_) {
LOG4CXX_INFO(logger_, "New file downloading");
if (!application->AddFile(file)) {
-
LOG4CXX_INFO(logger_,
"Couldn't add file to application (File already Exist"
- << " in application and was rewritten on FS)");
+ << " in application and was rewritten on FS)");
/* It can be first part of new big file, so we need to update
information about it's downloading status and persistence */
if (!application->UpdateFile(file)) {
LOG4CXX_ERROR(logger_, "Couldn't update file");
/* If it is impossible to update file, application doesn't
know about existing this file */
- SendResponse(false, mobile_apis::Result::INVALID_DATA,
+ SendResponse(false,
+ mobile_apis::Result::INVALID_DATA,
"Couldn't update file",
&response_params);
return;
@@ -232,20 +237,21 @@ void PutFileRequest::Run() {
break;
}
default:
- LOG4CXX_WARN(logger_, "PutFile is unsuccessful. Result = " << save_result);
+ LOG4CXX_WARN(logger_,
+ "PutFile is unsuccessful. Result = " << save_result);
SendResponse(false, save_result, "Can't save file", &response_params);
break;
}
}
void PutFileRequest::SendOnPutFileNotification() {
- LOG4CXX_INFO(logger_, "SendOnPutFileNotification" );
- smart_objects::SmartObjectSPtr notification = new smart_objects::SmartObject(
- smart_objects::SmartType_Map);
+ LOG4CXX_INFO(logger_, "SendOnPutFileNotification");
+ smart_objects::SmartObjectSPtr notification =
+ new smart_objects::SmartObject(smart_objects::SmartType_Map);
smart_objects::SmartObject& message = *notification;
message[strings::params][strings::function_id] =
- hmi_apis::FunctionID::BasicCommunication_OnPutFile;
+ hmi_apis::FunctionID::BasicCommunication_OnPutFile;
message[strings::params][strings::message_type] = MessageType::kNotification;
message[strings::msg_params][strings::app_id] = connection_key();