// --------------------------------------------------------------------------
// Components initialization
-
- profile::Profile::instance()->config_file_name("smartDeviceLink.ini");
+ if ((argc > 1)&&(0 != argv)) {
+ profile::Profile::instance()->config_file_name(argv[1]);
+ } else {
+ profile::Profile::instance()->config_file_name("smartDeviceLink.ini");
+ }
main_namespace::LifeCycle::instance()->StartComponents();
; in Ubuntu : PTHREAD_STACK_MIN = 16384
; in QNX : PTHREAD_STACK_MIN = 256
;The value of a variable ThreadStackSize used only if its realy needed, other way stack size will be PTHREAD_STACK_MIN
+;
+AppConfigFolder =
+AppStorageFolder =
ThreadStackSize = 16384
MixingAudioSupported = true
HMICapabilities = hmi_capabilities.json
SystemFilesPath = /tmp/fs/mp/images/ivsu_cache
UseLastState = true
+
[MEDIA MANAGER]
EnableRedecoding = false
;VideoStreamConsumer = socket
[AppInfo]
+; The path for applcations info storage.
AppInfoStorage = app_info.dat
[Policy]
}
mobile_apis::Result::eType ApplicationManagerImpl::SaveBinary(
- const std::vector<uint8_t>& binary_data, const std::string& file_path,
- const uint32_t offset) {
- LOG4CXX_INFO(
- logger_,
- "SaveBinaryWithOffset binary_size = " << binary_data.size()
- << " offset = " << offset);
+ const std::vector<uint8_t>& binary_data, const std::string& file_path,
+ const std::string& file_name, const uint32_t offset) {
+ LOG4CXX_INFO(logger_,
+ "SaveBinaryWithOffset binary_size = " << binary_data.size()
+ << " offset = " << offset);
- if (binary_data.size() > file_system::GetAvailableDiskSpace()) {
+ if (binary_data.size() > file_system::GetAvailableDiskSpace(file_path)) {
LOG4CXX_ERROR(logger_, "Out of free disc space.");
return mobile_apis::Result::OUT_OF_MEMORY;
}
- uint32_t file_size = file_system::FileSize(file_path);
+ const std::string full_file_path = file_path + "/" + file_name;
+ uint32_t file_size = file_system::FileSize(full_file_path);
std::ofstream* file_stream;
if (offset != 0) {
if (file_size != offset) {
- LOG4CXX_INFO(
- logger_,
- "ApplicationManagerImpl::SaveBinaryWithOffset offset does'n match existing filesize");
+ LOG4CXX_INFO(logger_,
+ "ApplicationManagerImpl::SaveBinaryWithOffset offset"
+ << " does'n match existing file size");
return mobile_apis::Result::INVALID_DATA;
}
- file_stream = file_system::Open(file_path, std::ios_base::app);
+ file_stream = file_system::Open(full_file_path, std::ios_base::app);
} else {
LOG4CXX_INFO(
logger_,
"ApplicationManagerImpl::SaveBinaryWithOffset offset is 0, rewrite");
// if offset == 0: rewrite file
- file_stream = file_system::Open(file_path, std::ios_base::out);
+ file_stream = file_system::Open(full_file_path, std::ios_base::out);
}
if (!file_system::Write(file_stream, binary_data.data(),
file_system::Close(file_stream);
return mobile_apis::Result::GENERIC_ERROR;
}
+
file_system::Close(file_stream);
LOG4CXX_INFO(logger_, "Successfully write data to file");
return mobile_apis::Result::SUCCESS;
}
+uint32_t ApplicationManagerImpl::GetAvailableSpaceForApp(
+ const std::string& app_name) {
+ const uint32_t app_quota = profile::Profile::instance()->app_dir_quota();
+ std::string app_storage_path =
+ profile::Profile::instance()->app_storage_folder();
+
+ app_storage_path += "/";
+ app_storage_path += app_name;
+
+ if (file_system::DirectoryExists(app_storage_path)) {
+ uint32_t size_of_directory = file_system::DirectorySize(app_storage_path);
+ if (app_quota < size_of_directory) {
+ return 0;
+ }
+
+ uint32_t current_app_quota = app_quota - size_of_directory;
+ uint32_t available_disk_space =
+ file_system::GetAvailableDiskSpace(app_storage_path);
+
+ if (current_app_quota > available_disk_space) {
+ return available_disk_space;
+ } else {
+ return current_app_quota;
+ }
+ } else {
+ return app_quota;
+ }
+}
+
bool ApplicationManagerImpl::IsHMICooperating() const {
return hmi_cooperating_;
}
return mobile_apis::Result::INVALID_DATA;
}
- std::string relative_file_path;
- if (file_name.size() > 0 && file_name[0] == '/') {
- relative_file_path = file_name;
+ std::string full_file_path =
+ profile::Profile::instance()->app_storage_folder() + "/";
+
+ if (file_name.size() > 0 && file_name[0] == '/' ) {
+ full_file_path += file_name;
} else {
- relative_file_path = app->name();
- relative_file_path += "/";
- relative_file_path += file_name;
- }
- std::string full_file_path = file_system::FullPath(relative_file_path);
+ full_file_path += app->name();
+ full_file_path += "/";
+ full_file_path += file_name;
+ }
if (!file_system::FileExists(full_file_path)) {
return mobile_apis::Result::INVALID_DATA;
void ResumeCtrl::SaveApplication(ApplicationConstSharedPtr application) {
LOG4CXX_INFO(logger_, "ResumeCtrl::SaveApplication");
+
DCHECK(application.get());
Json::Value* json_app = NULL;
include_directories (
./include
../utils/include/
- ../media_manager/include/
- ../protocol_handler/include
)
set (SOURCES
virtual ~Profile();
/**
+ * @brief Returns true if HMI should be started, otherwise false
+ */
+ bool launch_hmi() const;
+
+ /**
+ * @brief Returns application configuration path
+ */
+ const std::string& app_config_folder() const;
+
+ /**
+ * @brief Returns application storage path
+ */
+ const std::string& app_storage_folder() const;
+
+ /**
* @brief Returns the path to the config file
*/
const std::string& config_file_name() const;
void config_file_name(const std::string& fileName);
/**
- * @brief Returns true if HMI should be started, otherwise false
- */
- bool launch_hmi() const;
-
- /**
* @brief Returns server address
*/
const std::string& server_address() const;
// Members section
bool launch_hmi_;
+ std::string app_config_folder_;
+ std::string app_storage_folder_;
std::string config_file_name_;
std::string server_address_;
uint16_t server_port_;
#include "config_profile/ini_file.h"
#include "utils/logger.h"
#include "utils/threads/thread.h"
+#include "utils/file_system.h"
namespace {
const char* kMainSection = "MAIN";
-const char* kPolicySection = "Policy";
-
-const char* kDefaultPoliciesSnapshotFileName = "sdl_snapshot.json";
// Heartbeat is disabled by default
const uint32_t kDefaultHeartBeatTimeout = 0;
}
namespace profile {
Profile::Profile()
- : config_file_name_("smartDeviceLink.ini"),
- launch_hmi_(true),
+ : launch_hmi_(true),
+ app_config_folder_(""),
+ app_storage_folder_(""),
+ config_file_name_("smartDeviceLink.ini"),
policies_file_name_("policy_table.json"),
hmi_capabilities_file_name_("hmi_capabilities.json"),
server_address_("127.0.0.1"),
list_files_in_none_(5),
app_info_storage_("app_info.dat"),
heart_beat_timeout_(kDefaultHeartBeatTimeout),
- policy_shapshot_file_name_(kDefaultPoliciesSnapshotFileName),
transport_manager_disconnect_timeout_(0),
use_last_state_(false),
- supported_diag_modes_() {
- UpdateValues();
+ supported_diag_modes_(),
+ system_files_path_("/tmp/fs/mp/images/ivsu_cache"){
}
Profile::~Profile() {
return launch_hmi_;
}
+const std::string& Profile::app_config_folder() const {
+ return app_config_folder_;
+}
+
+const std::string& Profile::app_storage_folder() const {
+ return app_storage_folder_;
+}
+
+
const std::string& Profile::policies_file_name() const {
return policies_file_name_;
}
return preloaded_pt_file_;
}
-const std::string&Profile::policies_snapshot_file_name() const{
- return policy_shapshot_file_name_;
-}
-
uint32_t Profile::transport_manager_disconnect_timeout() const {
return transport_manager_disconnect_timeout_;
}
return use_last_state_;
}
+const std::string& Profile::system_files_path() const {
+ return system_files_path_;
+}
+
const std::vector<uint32_t>& Profile::supported_diag_modes() const {
return supported_diag_modes_;
}
LOG4CXX_INFO(logger_, "Set launch HMI to " << launch_hmi_);
}
+ *value = '\0';
+ if ((0
+ != ini_read_value(config_file_name_.c_str(), "MAIN", "AppConfigFolder",
+ value)) && ('\0' != *value)) {
+ app_config_folder_ = value;
+ } else {
+ // use current working directory
+ app_config_folder_ = file_system::CurrentWorkingDirectory();
+ }
+ LOG4CXX_INFO(logger_, "Set App config folder to " << app_config_folder_);
+
+ *value = '\0';
+ if ((0
+ != ini_read_value(config_file_name_.c_str(), "MAIN", "AppStorageFolder",
+ value)) && ('\0' != *value)) {
+ app_storage_folder_ = value;
+ } else {
+ // use current working directory
+ app_storage_folder_ = file_system::CurrentWorkingDirectory();
+ }
+ LOG4CXX_INFO(logger_, "Set App storage folder to " << app_storage_folder_);
+
+ *value = '\0';
+ if ((0
+ != ini_read_value(config_file_name_.c_str(), "AppInfo", "AppInfoStorage",
+ value)) && ('\0' != *value)) {
+ app_info_storage_ = app_storage_folder_ + "/" + value;
+ LOG4CXX_INFO(
+ logger_,
+ "Set Application information storage to " << app_info_storage_);
+ }
+
+ *value = '\0';
if ((0
!= ini_read_value(config_file_name_.c_str(), "HMI", "ServerAddress",
value)) && ('\0' != *value)) {
*value = '\0';
if ((0 != ini_read_value(config_file_name_.c_str(),
- kPolicySection, "PoliciesTable", value))
+ "Policy", "PoliciesTable", value))
&& ('\0' != *value)) {
- policies_file_name_ = value;
+ policies_file_name_ = app_config_folder_ + value;
LOG4CXX_INFO(logger_, "Set policy file to " << policies_file_name_);
}
*value = '\0';
if ((0 != ini_read_value(config_file_name_.c_str(),
- kPolicySection, "PreloadedPT", value))
+ "Policy", "PreloadedPT", value))
&& ('\0' != *value)) {
- preloaded_pt_file_ = value;
+ preloaded_pt_file_ = app_config_folder_ + value;
LOG4CXX_INFO(logger_, "Set preloaded policy file to "
<< preloaded_pt_file_);
}
- (void) ReadStringValue(&policy_shapshot_file_name_,
- kDefaultPoliciesSnapshotFileName,
- kPolicySection, "PathToSnapshot");
-
- *value = '\0';
- if ((0 != ini_read_value(config_file_name_.c_str(),
- "MAIN", "HMICapabilities", value))
- && ('\0' != *value)) {
- hmi_capabilities_file_name_ = value;
- LOG4CXX_INFO(
- logger_,
- "Set hmi capabilities file to " << hmi_capabilities_file_name_);
+ if ((0
+ != ini_read_value(config_file_name_.c_str(), "MAIN", "HMICapabilities",
+ value)) && ('\0' != *value)) {
+ hmi_capabilities_file_name_ = app_config_folder_ + "/" + value;
+ LOG4CXX_INFO(logger_,
+ "Set hmi capabilities file to " << hmi_capabilities_file_name_);
}
*value = '\0';
if ((0
!= ini_read_value(config_file_name_.c_str(), "MEDIA MANAGER",
"VideoStreamFile", value)) && ('\0' != *value)) {
- video_stream_file_ = value;
+ video_stream_file_ = app_storage_folder_ + "/" + value;
LOG4CXX_INFO(logger_, "Set video stream file to " << video_stream_file_);
}
if ((0 != ini_read_value(config_file_name_.c_str(),
"MEDIA MANAGER", "AudioStreamFile", value))
&& ('\0' != *value)) {
- audio_stream_file_ = value;
+ audio_stream_file_ = app_storage_folder_ + "/" + value;
LOG4CXX_INFO(logger_, "Set audio stream file to " << audio_stream_file_);
}
"Set system pending requests amount " << pending_requests_amount_);
}
- *value = '\0';
- if ((0
- != ini_read_value(config_file_name_.c_str(), "AppInfo", "AppInfoStorage",
- value)) && ('\0' != *value)) {
- app_info_storage_ = value;
- LOG4CXX_INFO(
- logger_,
- "Set Application information storage to " << app_info_storage_);
- }
-
supported_diag_modes_.clear();
*value = '\0';
if ((0
}
}
+ *value = '\0';
+ if ((0
+ != ini_read_value(config_file_name_.c_str(), "MAIN",
+ "SystemFilesPath", value)) && ('\0' != *value)) {
+ system_files_path_ = value;
+ LOG4CXX_INFO(logger_, "Set system files path to " << system_files_path_);
+ }
+
(void) ReadIntValue(&heart_beat_timeout_, kDefaultHeartBeatTimeout,
kMainSection, "HeartBeatTimeout");
application_manager::ApplicationSharedPtr app =
application_manager::ApplicationManagerImpl::instance()->
application(application_key);
- std::string relative_file_path =
- file_system::CreateDirectory(app->name());
- relative_file_path += "/";
- relative_file_path += output_file;
- from_mic_listener_ = new FromMicRecorderListener(relative_file_path);
+ std::string file_path = profile::Profile::instance()->app_storage_folder();
+ file_path += "/";
+ file_path += app->name();
+ file_system::CreateDirectory(file_path);
+
+ file_path += "/";
+ file_path += output_file;
+ from_mic_listener_ = new FromMicRecorderListener(file_path);
#if defined(EXTENDED_MEDIA_MODE)
if (from_mic_recorder_) {
from_mic_recorder_->AddListener(from_mic_listener_);
from_mic_recorder_->StartActivity(application_key);
}
#else
- if (file_system::FileExists(relative_file_path)) {
+ if (file_system::FileExists(file_path)) {
LOG4CXX_INFO(logger_, "File " << output_file << " exists, removing");
- if (file_system::DeleteFile(relative_file_path)) {
+ if (file_system::DeleteFile(file_path)) {
LOG4CXX_INFO(logger_, "File " << output_file << " removed");
}
else {
LOG4CXX_WARN(logger_, "Could not remove file " << output_file);
}
}
- const std::string predefined_rec_file = "audio.8bit.wav";
+ const std::string predefined_rec_file =
+ profile::Profile::instance()->app_storage_folder() + "/audio.8bit.wav";
std::vector<uint8_t> buf;
if (file_system::ReadBinaryFile(predefined_rec_file, buf)) {
- if (file_system::Write(relative_file_path, buf)) {
+ if (file_system::Write(file_path, buf)) {
LOG4CXX_INFO(logger_,
"File " << predefined_rec_file << " copied to " << output_file);
}
snprintf(url, sizeof(url) / sizeof(url[0]), "%s",
profile::Profile::instance()->named_video_pipe_path().c_str());
} else {
- DCHECK(snprintf(url, sizeof(url) / sizeof(url[0]), "%s", file_system::FullPath(
- profile::Profile::instance()->video_stream_file()).c_str()));
+ DCHECK(snprintf(url, sizeof(url) / sizeof(url[0]), "%s",
+ profile::Profile::instance()->video_stream_file().c_str()));
}
application_manager::MessageHelper::SendNaviStartStream(url,
application_key);
profile::Profile::instance()->named_audio_pipe_path().c_str());
} else {
DCHECK(snprintf(url, sizeof(url) / sizeof(url[0]), "%s",
- file_system::FullPath(profile::Profile::instance()->
- audio_stream_file()).c_str()));
+ profile::Profile::instance()->audio_stream_file().c_str()));
}
application_manager::MessageHelper::SendAudioStartStream(url,
-Subproject commit dcb8e5a81ee4dbd771f5c3142a5c60132e12f608
+Subproject commit c2ad2f65576e200d8977acbcc046606c0dcb1360
include_directories (
./include
../utils/include/
+ ../config_profile/include/
${CMAKE_SOURCE_DIR}/src/thirdPartyLibs/jsoncpp/include
)
private:
/**
- * @brief File to save Dictionary
- */
- static const std::string filename;
-/**
* @brief Saving dictionary to filesystem
*/
void SaveToFileSystem();
*/
#include "resumption/last_state.h"
+#include "config_profile/profile.h"
#include "utils/file_system.h"
namespace resumption {
-const std::string LastState::filename = "LastState.dat";
-
void LastState::SaveToFileSystem() {
+ const std::string file =
+ profile::Profile::instance()->app_info_storage();
const std::string& str = dictionary.toStyledString();
const std::vector<uint8_t> char_vector_pdata(
str.begin(), str.end());
- DCHECK(file_system::Write(filename, char_vector_pdata));
+ DCHECK(file_system::Write(file, char_vector_pdata));
}
void LastState::LoadFromFileSystem() {
+ const std::string file =
+ profile::Profile::instance()->app_info_storage();
std::string buffer;
- bool result = file_system::ReadFile(filename,buffer);
+ bool result = file_system::ReadFile(file, buffer);
if (result) {
Json::Reader m_reader;
DCHECK(m_reader.parse(buffer, dictionary));
/**
* @brief Get available disc space.
*
+ * @param path to directory
* @return free disc space.
*/
-uint64_t GetAvailableDiskSpace();
+uint64_t GetAvailableDiskSpace(const std::string& path);
/*
* @brief Get size of current directory
*/
uint32_t FileSize(const std::string& path);
-
-/**
- * @brief Get available app space
- * @param name of app
- * @return free app space.
- */
-uint32_t GetAvailableSpaceForApp(const std::string& name);
-
/**
* @brief Creates directory
* @param name path to directory
void Close(std::ofstream* file_stream);
/**
- * @brief Returns full file path
+ * @brief Returns current working directory path
* If filename begins with "/", return unchanged filename
* @param name file name
* @return returns full file path.
*/
-std::string FullPath(const std::string& name);
+std::string CurrentWorkingDirectory();
/**
* @brief Removes file
#include <fstream>
#include <cstddef>
#include <algorithm>
-#include "config_profile/profile.h"
-
-uint64_t file_system::GetAvailableDiskSpace() {
- char currentAppPath[FILENAME_MAX];
- memset(reinterpret_cast<void*>(currentAppPath), 0, FILENAME_MAX);
- getcwd(currentAppPath, FILENAME_MAX - 1);
+uint64_t file_system::GetAvailableDiskSpace(const std::string& path) {
struct statvfs fsInfo;
memset(reinterpret_cast<void*>(&fsInfo), 0, sizeof(fsInfo));
- if( statvfs(currentAppPath, &fsInfo) == 0) {
+ if (statvfs(path.c_str(), &fsInfo) == 0) {
return fsInfo.f_bsize * fsInfo.f_bfree;
} else {
return 0;
return size;
}
-uint32_t file_system::GetAvailableSpaceForApp(const std::string& app_name) {
- const uint32_t app_quota = profile::Profile::instance()->app_dir_quota();
- if (DirectoryExists(app_name)) {
- std::string full_path = FullPath(app_name);
- uint32_t size_of_directory = DirectorySize(full_path);
- if (app_quota < size_of_directory) {
- return 0;
- }
- uint32_t current_app_quota = app_quota - size_of_directory;
- uint32_t available_disk_space = GetAvailableDiskSpace();
- if (current_app_quota > available_disk_space) {
- return available_disk_space;
- } else {
- return current_app_quota;
- }
- } else {
- return app_quota;
- }
-}
-
std::string file_system::CreateDirectory(const std::string& name) {
if (!DirectoryExists(name)) {
mkdir(name.c_str(), S_IRWXU);
return false;
}
-
-
std::ofstream* file_system::Open(const std::string& file_name,
std::ios_base::openmode mode) {
}
}
-std::string file_system::FullPath(const std::string& file) {
- // FILENAME_MAX defined stdio_lim.h was replaced with less value
- // since it seems, that is caused overflow in some cases
- if (file.size() > 0 && file[0] == '/') {
- return file;
- }
-
+std::string file_system::CurrentWorkingDirectory() {
size_t filename_max_lenght = 1024;
char currentAppPath[filename_max_lenght];
memset(currentAppPath, 0, filename_max_lenght);
char path[filename_max_lenght];
memset(path, 0, filename_max_lenght);
- snprintf(path, filename_max_lenght - 1, "%s/%s", currentAppPath, file.c_str());
+ snprintf(path, filename_max_lenght - 1, "%s", currentAppPath);
return std::string(path);
}