summaryrefslogtreecommitdiff
path: root/src/components/application_manager/src/application_impl.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/application_manager/src/application_impl.cc')
-rw-r--r--src/components/application_manager/src/application_impl.cc139
1 files changed, 65 insertions, 74 deletions
diff --git a/src/components/application_manager/src/application_impl.cc b/src/components/application_manager/src/application_impl.cc
index b6bea15b90..532675769e 100644
--- a/src/components/application_manager/src/application_impl.cc
+++ b/src/components/application_manager/src/application_impl.cc
@@ -30,9 +30,8 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-#include "application_manager/application_impl.h"
#include <string>
-#include <strings.h>
+#include "application_manager/application_impl.h"
#include "application_manager/message_helper.h"
#include "protocol_handler/protocol_handler.h"
#include "application_manager/application_manager.h"
@@ -72,9 +71,7 @@ mobile_apis::FileType::eType StringToFileType(const char* str) {
}
CREATE_LOGGERPTR_GLOBAL(logger_, "ApplicationManager")
-
namespace application_manager {
-
ApplicationImpl::ApplicationImpl(
uint32_t application_id,
const std::string& mobile_app_id,
@@ -120,10 +117,10 @@ ApplicationImpl::ApplicationImpl(
new ::timer::TimerTaskImpl<ApplicationImpl>(
this, &ApplicationImpl::OnAudioStreamSuspend))
, application_manager_(application_manager) {
- cmd_number_to_time_limits_[mobile_apis::FunctionID::ReadDIDID] = {
- date_time::DateTime::getCurrentTime(), 0};
- cmd_number_to_time_limits_[mobile_apis::FunctionID::GetVehicleDataID] = {
- date_time::DateTime::getCurrentTime(), 0};
+ cmd_number_to_time_limits_[mobile_apis::FunctionID::ReadDIDID] =
+ std::make_pair(date_time::DateTime::getCurrentTime(), 0);
+ cmd_number_to_time_limits_[mobile_apis::FunctionID::GetVehicleDataID] =
+ std::make_pair(date_time::DateTime::getCurrentTime(), 0);
set_mobile_app_id(mobile_app_id);
set_name(app_name);
@@ -131,6 +128,7 @@ ApplicationImpl::ApplicationImpl(
MarkUnregistered();
// subscribe application to custom button by default
SubscribeToButton(mobile_apis::ButtonName::CUSTOM_BUTTON);
+
// load persistent files
LoadPersistentFiles();
HmiStatePtr initial_state = application_manager_.CreateRegularState(
@@ -209,17 +207,17 @@ bool ApplicationImpl::IsAudioApplication() const {
}
void ApplicationImpl::SetRegularState(HmiStatePtr state) {
- LOG4CXX_AUTO_TRACE(logger_);
+ LOGGER_AUTO_TRACE(logger_);
state_.AddState(state);
}
void ApplicationImpl::RemovePostponedState() {
- LOG4CXX_AUTO_TRACE(logger_);
+ LOGGER_AUTO_TRACE(logger_);
state_.RemoveState(HmiState::STATE_ID_POSTPONED);
}
void ApplicationImpl::SetPostponedState(HmiStatePtr state) {
- LOG4CXX_AUTO_TRACE(logger_);
+ LOGGER_AUTO_TRACE(logger_);
state_.AddState(state);
}
@@ -232,12 +230,12 @@ struct StateIDComparator {
};
void ApplicationImpl::AddHMIState(HmiStatePtr state) {
- LOG4CXX_AUTO_TRACE(logger_);
+ LOGGER_AUTO_TRACE(logger_);
state_.AddState(state);
}
void ApplicationImpl::RemoveHMIState(HmiState::StateID state_id) {
- LOG4CXX_AUTO_TRACE(logger_);
+ LOGGER_AUTO_TRACE(logger_);
state_.RemoveState(state_id);
}
@@ -393,19 +391,19 @@ bool ApplicationImpl::audio_streaming_allowed() const {
void ApplicationImpl::StartStreaming(
protocol_handler::ServiceType service_type) {
using namespace protocol_handler;
- LOG4CXX_AUTO_TRACE(logger_);
+ LOGGER_AUTO_TRACE(logger_);
if (ServiceType::kMobileNav == service_type) {
- LOG4CXX_TRACE(logger_, "ServiceType = Video");
+ LOGGER_TRACE(logger_, "ServiceType = Video");
if (!video_streaming_approved()) {
- LOG4CXX_TRACE(logger_, "Video streaming not approved");
+ LOGGER_TRACE(logger_, "Video streaming not approved");
MessageHelper::SendNaviStartStream(app_id(), application_manager_);
set_video_stream_retry_number(0);
}
} else if (ServiceType::kAudio == service_type) {
- LOG4CXX_TRACE(logger_, "ServiceType = Audio");
+ LOGGER_TRACE(logger_, "ServiceType = Audio");
if (!audio_streaming_approved()) {
- LOG4CXX_TRACE(logger_, "Audio streaming not approved");
+ LOGGER_TRACE(logger_, "Audio streaming not approved");
MessageHelper::SendAudioStartStream(app_id(), application_manager_);
set_audio_stream_retry_number(0);
}
@@ -415,7 +413,7 @@ void ApplicationImpl::StartStreaming(
void ApplicationImpl::StopStreamingForce(
protocol_handler::ServiceType service_type) {
using namespace protocol_handler;
- LOG4CXX_AUTO_TRACE(logger_);
+ LOGGER_AUTO_TRACE(logger_);
SuspendStreaming(service_type);
@@ -429,7 +427,7 @@ void ApplicationImpl::StopStreamingForce(
void ApplicationImpl::StopStreaming(
protocol_handler::ServiceType service_type) {
using namespace protocol_handler;
- LOG4CXX_AUTO_TRACE(logger_);
+ LOGGER_AUTO_TRACE(logger_);
SuspendStreaming(service_type);
@@ -442,7 +440,7 @@ void ApplicationImpl::StopStreaming(
}
void ApplicationImpl::StopNaviStreaming() {
- LOG4CXX_AUTO_TRACE(logger_);
+ LOGGER_AUTO_TRACE(logger_);
video_stream_suspend_timer_.Stop();
MessageHelper::SendNaviStopStream(app_id(), application_manager_);
set_video_streaming_approved(false);
@@ -450,7 +448,7 @@ void ApplicationImpl::StopNaviStreaming() {
}
void ApplicationImpl::StopAudioStreaming() {
- LOG4CXX_AUTO_TRACE(logger_);
+ LOGGER_AUTO_TRACE(logger_);
audio_stream_suspend_timer_.Stop();
MessageHelper::SendAudioStopStream(app_id(), application_manager_);
set_audio_streaming_approved(false);
@@ -460,7 +458,7 @@ void ApplicationImpl::StopAudioStreaming() {
void ApplicationImpl::SuspendStreaming(
protocol_handler::ServiceType service_type) {
using namespace protocol_handler;
- LOG4CXX_AUTO_TRACE(logger_);
+ LOGGER_AUTO_TRACE(logger_);
if (ServiceType::kMobileNav == service_type) {
video_stream_suspend_timer_.Stop();
@@ -479,7 +477,7 @@ void ApplicationImpl::SuspendStreaming(
void ApplicationImpl::WakeUpStreaming(
protocol_handler::ServiceType service_type) {
using namespace protocol_handler;
- LOG4CXX_AUTO_TRACE(logger_);
+ LOGGER_AUTO_TRACE(logger_);
if (ServiceType::kMobileNav == service_type) {
sync_primitives::AutoLock lock(video_streaming_suspended_lock_);
@@ -506,15 +504,15 @@ void ApplicationImpl::WakeUpStreaming(
void ApplicationImpl::OnVideoStreamSuspend() {
using namespace protocol_handler;
- LOG4CXX_AUTO_TRACE(logger_);
- LOG4CXX_INFO(logger_, "Suspend video streaming by timer");
+ LOGGER_AUTO_TRACE(logger_);
+ LOGGER_INFO(logger_, "Suspend video streaming by timer");
SuspendStreaming(ServiceType::kMobileNav);
}
void ApplicationImpl::OnAudioStreamSuspend() {
using namespace protocol_handler;
- LOG4CXX_AUTO_TRACE(logger_);
- LOG4CXX_INFO(logger_, "Suspend audio streaming by timer");
+ LOGGER_AUTO_TRACE(logger_);
+ LOGGER_INFO(logger_, "Suspend audio streaming by timer");
SuspendStreaming(ServiceType::kAudio);
}
@@ -606,9 +604,9 @@ bool ApplicationImpl::is_resuming() const {
bool ApplicationImpl::AddFile(const AppFile& file) {
if (app_files_.count(file.file_name) == 0) {
- LOG4CXX_INFO(logger_,
- "AddFile file " << file.file_name << " File type is "
- << file.file_type);
+ LOGGER_INFO(logger_,
+ "AddFile file " << file.file_name << " File type is "
+ << file.file_type);
app_files_[file.file_name] = file;
return true;
}
@@ -617,9 +615,9 @@ bool ApplicationImpl::AddFile(const AppFile& file) {
bool ApplicationImpl::UpdateFile(const AppFile& file) {
if (app_files_.count(file.file_name) != 0) {
- LOG4CXX_INFO(logger_,
- "UpdateFile file " << file.file_name << " File type is "
- << file.file_type);
+ LOGGER_INFO(logger_,
+ "UpdateFile file " << file.file_name << " File type is "
+ << file.file_type);
app_files_[file.file_name] = file;
return true;
}
@@ -629,9 +627,9 @@ bool ApplicationImpl::UpdateFile(const AppFile& file) {
bool ApplicationImpl::DeleteFile(const std::string& file_name) {
AppFilesMap::iterator it = app_files_.find(file_name);
if (it != app_files_.end()) {
- LOG4CXX_INFO(logger_,
- "DeleteFile file " << it->second.file_name << " File type is "
- << it->second.file_type);
+ LOGGER_INFO(logger_,
+ "DeleteFile file " << it->second.file_name << " File type is "
+ << it->second.file_type);
app_files_.erase(it);
return true;
}
@@ -701,8 +699,8 @@ bool ApplicationImpl::IsCommandLimitsExceeded(
CommandNumberTimeLimit::iterator it =
cmd_number_to_time_limits_.find(cmd_id);
if (cmd_number_to_time_limits_.end() == it) {
- LOG4CXX_WARN(logger_,
- "Limits for command id " << cmd_id << "had not been set.");
+ LOGGER_WARN(logger_,
+ "Limits for command id " << cmd_id << "had not been set.");
return true;
}
@@ -718,18 +716,18 @@ bool ApplicationImpl::IsCommandLimitsExceeded(
frequency_restrictions =
application_manager_.get_settings().get_vehicle_data_frequency();
} else {
- LOG4CXX_INFO(logger_, "No restrictions for request");
+ LOGGER_INFO(logger_, "No restrictions for request");
return false;
}
- LOG4CXX_INFO(logger_,
- "Time Info: "
- << "\n Current: " << current.tv_sec << "\n Limit: ("
- << limit.first.tv_sec << "," << limit.second
- << ")"
- "\n frequency_restrictions: ("
- << frequency_restrictions.first << ","
- << frequency_restrictions.second << ")");
+ LOGGER_INFO(logger_,
+ "Time Info: "
+ << "\n Current: " << current.tv_sec << "\n Limit: ("
+ << limit.first.tv_sec << "," << limit.second
+ << ")"
+ "\n frequency_restrictions: ("
+ << frequency_restrictions.first << ","
+ << frequency_restrictions.second << ")");
if (current.tv_sec < limit.first.tv_sec + frequency_restrictions.second) {
if (limit.second < frequency_restrictions.first) {
++limit.second;
@@ -763,7 +761,8 @@ bool ApplicationImpl::IsCommandLimitsExceeded(
cmd_number_to_time_limits_.find(cmd_id);
// If no command with cmd_id had been executed yet, just add to limits
if (cmd_number_to_time_limits_.end() == it) {
- cmd_number_to_time_limits_[cmd_id] = {current, dummy_limit};
+ cmd_number_to_time_limits_[cmd_id] =
+ std::make_pair(current, dummy_limit);
return false;
}
@@ -777,13 +776,13 @@ bool ApplicationImpl::IsCommandLimitsExceeded(
return true;
}
- cmd_number_to_time_limits_[cmd_id] = {current, dummy_limit};
+ cmd_number_to_time_limits_[cmd_id] = std::make_pair(current, dummy_limit);
return false;
break;
}
default: {
- LOG4CXX_WARN(logger_, "Limit source is not implemented.");
+ LOGGER_WARN(logger_, "Limit source is not implemented.");
break;
}
}
@@ -814,7 +813,7 @@ void ApplicationImpl::set_is_application_data_changed(
}
void ApplicationImpl::UpdateHash() {
- LOG4CXX_AUTO_TRACE(logger_);
+ LOGGER_AUTO_TRACE(logger_);
hash_val_ =
utils::gen_hash(application_manager_.get_settings().hash_string_size());
set_is_application_data_changed(true);
@@ -823,9 +822,8 @@ void ApplicationImpl::UpdateHash() {
}
void ApplicationImpl::CleanupFiles() {
- std::string directory_name =
- application_manager_.get_settings().app_storage_folder();
- directory_name += "/" + folder_name();
+ std::string directory_name = file_system::ConcatPath(
+ application_manager_.get_settings().app_storage_folder(), folder_name());
if (file_system::DirectoryExists(directory_name)) {
std::vector<std::string> files = file_system::ListFiles(directory_name);
@@ -833,13 +831,11 @@ void ApplicationImpl::CleanupFiles() {
std::vector<std::string>::const_iterator it = files.begin();
for (; it != files.end(); ++it) {
- std::string file_name = directory_name;
- file_name += "/";
- file_name += *it;
+ std::string file_name = file_system::ConcatPath(directory_name, *it);
app_files_it = app_files_.find(file_name);
if ((app_files_it == app_files_.end()) ||
(!app_files_it->second.is_persistent)) {
- LOG4CXX_INFO(logger_, "DeleteFile file " << file_name);
+ LOGGER_INFO(logger_, "DeleteFile file " << file_name);
file_system::DeleteFile(file_name);
}
}
@@ -855,7 +851,8 @@ void ApplicationImpl::LoadPersistentFiles() {
if (kWaitingForRegistration == app_state_) {
const std::string app_icon_dir(
application_manager_.get_settings().app_icons_folder());
- const std::string full_icon_path(app_icon_dir + "/" + mobile_app_id_);
+ const std::string full_icon_path(
+ file_system::ConcatPath(app_icon_dir, mobile_app_id_));
if (file_system::FileExists(full_icon_path)) {
AppFile file;
file.is_persistent = true;
@@ -867,9 +864,8 @@ void ApplicationImpl::LoadPersistentFiles() {
return;
}
- std::string directory_name =
- application_manager_.get_settings().app_storage_folder();
- directory_name += "/" + folder_name();
+ std::string directory_name = file_system::ConcatPath(
+ application_manager_.get_settings().app_storage_folder(), folder_name());
if (file_system::DirectoryExists(directory_name)) {
std::vector<std::string> persistent_files =
@@ -880,9 +876,7 @@ void ApplicationImpl::LoadPersistentFiles() {
AppFile file;
file.is_persistent = true;
file.is_download_complete = true;
- file.file_name = directory_name;
- file.file_name += "/";
- file.file_name += *it;
+ file.file_name = file_system::ConcatPath(directory_name, *it);
file.file_type = mobile_apis::FileType::BINARY;
// Search file extension and convert it to the type
std::size_t index = it->find_last_of('.');
@@ -891,9 +885,9 @@ void ApplicationImpl::LoadPersistentFiles() {
file.file_type = StringToFileType(file_type.c_str());
}
- LOG4CXX_INFO(logger_,
- "Loaded persistent file "
- << file.file_name << " File type is " << file.file_type);
+ LOGGER_INFO(logger_,
+ "Loaded persistent file "
+ << file.file_name << " File type is " << file.file_type);
AddFile(file);
}
}
@@ -902,11 +896,8 @@ void ApplicationImpl::LoadPersistentFiles() {
uint32_t ApplicationImpl::GetAvailableDiskSpace() {
const uint32_t app_quota =
application_manager_.get_settings().app_dir_quota();
- std::string app_storage_path =
- application_manager_.get_settings().app_storage_folder();
-
- app_storage_path += "/";
- app_storage_path += folder_name();
+ std::string app_storage_path = file_system::ConcatPath(
+ application_manager_.get_settings().app_storage_folder(), folder_name());
if (file_system::DirectoryExists(app_storage_path)) {
size_t size_of_directory = file_system::DirectorySize(app_storage_path);