From 4781c5a8abc0c1d6dea5591019dfcd466185625a Mon Sep 17 00:00:00 2001 From: Justin Dickow Date: Tue, 15 Jul 2014 11:41:26 -0400 Subject: [PATCH] Config Profile component Signed-off-by: Justin Dickow --- src/components/config_profile/CMakeLists.txt | 2 +- .../include/config_profile/profile.h | 79 +- src/components/config_profile/src/profile.cc | 979 +++++++++++++-------- 3 files changed, 660 insertions(+), 400 deletions(-) diff --git a/src/components/config_profile/CMakeLists.txt b/src/components/config_profile/CMakeLists.txt index 8df6e96..a3f5ec7 100644 --- a/src/components/config_profile/CMakeLists.txt +++ b/src/components/config_profile/CMakeLists.txt @@ -9,4 +9,4 @@ set (SOURCES ) add_library("ConfigProfile" ${SOURCES}) -target_link_libraries ("ConfigProfile" Utils) +target_link_libraries("ConfigProfile" Utils) diff --git a/src/components/config_profile/include/config_profile/profile.h b/src/components/config_profile/include/config_profile/profile.h index 3a90be2..53707c2 100644 --- a/src/components/config_profile/include/config_profile/profile.h +++ b/src/components/config_profile/include/config_profile/profile.h @@ -72,6 +72,11 @@ class Profile : public utils::Singleton { const std::string& app_storage_folder() const; /** + * @brief Return application resourse folder + */ + const std::string& app_resourse_folder() const; + + /** * @brief Returns the path to the config file */ const std::string& config_file_name() const; @@ -102,9 +107,9 @@ class Profile : public utils::Singleton { const uint16_t& audio_streaming_port() const; /** - * @brief Returns policies file name - */ - const std::string& policies_file_name() const; + * @brief Returns port for time reports + */ + const uint16_t& time_testing_port() const; /** * @brief Returns hmi capabilities file name @@ -182,10 +187,10 @@ class Profile : public utils::Singleton { */ const std::string& named_video_pipe_path() const; - /** - * @brief Returns the audio pipe path - */ - const std::string& named_audio_pipe_path() const; + /** + * @brief Returns the audio pipe path + */ + const std::string& named_audio_pipe_path() const; /** * @brief Returns time scale for max amount of requests for application @@ -265,9 +270,15 @@ class Profile : public utils::Singleton { */ const std::string& policies_snapshot_file_name() const; - /* - * @brief Timeout in transport manager before disconnect + /** + * @brief Should Policy be turned off? (Library not loaded) + * @return Flag */ + bool policy_turn_off() const; + + /* + * @brief Timeout in transport manager before disconnect + */ uint32_t transport_manager_disconnect_timeout() const; /* @@ -285,16 +296,23 @@ class Profile : public utils::Singleton { */ const std::string& system_files_path() const; - // Members section + /** + * @brief Returns port for TCP transport adapter + */ + uint16_t transport_manager_tcp_adapter_port() const; - protected: - // Methods section + /** + * @brief Returns delimiter for SDL-generated TTS chunks + * @return TTS delimiter + */ + const std::string& tts_delimiter() const; - // Members section + /** + * @brief Returns recording file name + */ + const std::string& recording_file() const; private: - // Methods section - /** * Default constructor * @@ -354,7 +372,7 @@ class Profile : public utils::Singleton { const char* const pKey) const; /** - * @brief Reads an int32_t value from the profile + * @brief Reads an uint16/32/64_t value from the profile * * @param value Result value * @param default_value Value to use key wasn't found @@ -362,23 +380,34 @@ class Profile : public utils::Singleton { * @param pKey The key whose value needs to be read out * * @return FALSE if could not read the value out of the profile - * (then the value is not changed) + * (then the value is changed to default) */ - bool ReadIntValue(int32_t* value, - int32_t default_value, - const char* const pSection, - const char* const pKey) const; + bool ReadUIntValue(uint16_t* value, + uint16_t default_value, + const char* const pSection, + const char* const pKey) const; + + bool ReadUIntValue(uint32_t* value, + uint32_t default_value, + const char* const pSection, + const char* const pKey) const; + + bool ReadUIntValue(uint64_t* value, + uint64_t default_value, + const char* const pSection, + const char* const pKey) const; // Members section bool launch_hmi_; std::string app_config_folder_; std::string app_storage_folder_; + std::string app_resourse_folder_; std::string config_file_name_; std::string server_address_; uint16_t server_port_; uint16_t video_streaming_port_; uint16_t audio_streaming_port_; - std::string policies_file_name_; + uint16_t time_testing_port_; std::string hmi_capabilities_file_name_; std::vector help_prompt_; std::vector time_out_promt_; @@ -406,13 +435,17 @@ class Profile : public utils::Singleton { uint32_t delete_file_in_none_; uint32_t list_files_in_none_; std::string app_info_storage_; - int32_t heart_beat_timeout_; + uint32_t heart_beat_timeout_; std::string preloaded_pt_file_; std::string policy_snapshot_file_name_; + bool policy_turn_off_; uint32_t transport_manager_disconnect_timeout_; bool use_last_state_; std::vector supported_diag_modes_; std::string system_files_path_; + uint16_t transport_manager_tcp_adapter_port_; + std::string tts_delimiter_; + std::string recording_file_; DISALLOW_COPY_AND_ASSIGN(Profile); diff --git a/src/components/config_profile/src/profile.cc b/src/components/config_profile/src/profile.cc index f6ed0b9..cfa03b6 100644 --- a/src/components/config_profile/src/profile.cc +++ b/src/components/config_profile/src/profile.cc @@ -32,6 +32,7 @@ #include "config_profile/profile.h" +#include #include #include @@ -41,53 +42,158 @@ #include "utils/file_system.h" namespace { +#define LOG_UPDATED_VALUE(value, key, section) {\ + LOG4CXX_INFO(logger_, "Setting value '" << value\ + << "' for key '" << key\ + << "' in section '" << section << "'.");\ + } + +#define LOG_UPDATED_BOOL_VALUE(value, key, section) {\ + LOG4CXX_INFO(logger_, "Setting value '" << std::boolalpha << value\ + << "' for key '" << key\ + << "' in section '" << section << "'.");\ + } + +const char* kDefaultConfigFileName = "smartDeviceLink.ini"; + const char* kMainSection = "MAIN"; const char* kPolicySection = "Policy"; +const char* kHmiSection = "HMI"; +const char* kAppInfoSection = "AppInfo"; +const char* kMediaManagerSection = "MEDIA MANAGER"; +const char* kGlobalPropertiesSection = "GLOBAL PROPERTIES"; +const char* kVrCommandsSection = "VR COMMANDS"; +const char* kTransportManagerSection = "TransportManager"; +const char* kFilesystemRestrictionsSection = "FILESYSTEM RESTRICTIONS"; + +const char* kHmiCapabilitiesKey = "HMICapabilities"; +const char* kPathToSnapshotKey = "PathToSnapshot"; +const char* kPreloadedPTKey = "PreloadedPT"; +const char* kPoliciesTableKey = "PoliciesTable"; +const char* kServerAddressKey = "ServerAddress"; +const char* kAppInfoStorageKey = "AppInfoStorage"; +const char* kAppStorageFolderKey = "AppStorageFolder"; +const char* kAppResourseFolderKey = "AppResourceFolder"; +const char* kAppConfigFolderKey = "AppConfigFolder"; +const char* kLaunchHMIKey = "LaunchHMI"; +const char* kEnableRedecodingKey = "EnableRedecoding"; +const char* kVideoStreamConsumerKey = "VideoStreamConsumer"; +const char* kAudioStreamConsumerKey = "AudioStreamConsumer"; +const char* kNamedVideoPipePathKey = "NamedVideoPipePath"; +const char* kNamedAudioPipePathKey = "NamedAudioPipePath"; +const char* kVideoStreamFileKey = "VideoStreamFile"; +const char* kAudioStreamFileKey = "AudioStreamFile"; +const char* kMixingAudioSupportedKey = "MixingAudioSupported"; +const char* kHelpPromptKey = "HelpPromt"; +const char* kTimeoutPromptKey = "TimeOutPromt"; +const char* kHelpTitleKey = "HelpTitle"; +const char* kHelpCommandKey = "HelpCommand"; +const char* kSystemFilesPathKey = "SystemFilesPath"; +const char* kHeartBeatTimeoutKey = "HeartBeatTimeout"; +const char* kUseLastStateKey = "UseLastState"; +const char* kTCPAdapterPortKey = "TCPAdapterPort"; +const char* kServerPortKey = "ServerPort"; +const char* kVideoStreamingPortKey = "VideoStreamingPort"; +const char* kAudioStreamingPortKey = "AudioStreamingPort"; +const char* kTimeTestingPortKey = "TimeTestingPort"; +const char* kThreadStackSizeKey = "ThreadStackSize"; +const char* kMaxCmdIdKey = "MaxCmdID"; +const char* kPutFileRequestKey = "PutFileRequest"; +const char* kDeleteFileRequestKey = "DeleteFileRequest"; +const char* kListFilesRequestKey = "ListFilesRequest"; +const char* kDefaultTimeoutKey = "DefaultTimeout"; +const char* kAppResumingTimeoutKey = "ApplicationResumingTimeout"; +const char* kAppDirectoryQuotaKey = "AppDirectoryQuota"; +const char* kAppTimeScaleMaxRequestsKey = "AppTimeScaleMaxRequests"; +const char* kAppRequestsTimeScaleKey = "AppRequestsTimeScale"; +const char* kAppHmiLevelNoneTimeScaleMaxRequestsKey = + "AppHMILevelNoneTimeScaleMaxRequests"; +const char* kAppHmiLevelNoneRequestsTimeScaleKey = + "AppHMILevelNoneRequestsTimeScale"; +const char* kPendingRequestsAmoundKey = "PendingRequestsAmount"; +const char* kSupportedDiagModesKey = "SupportedDiagModes"; +const char* kTransportManagerDisconnectTimeoutKey = "DisconnectTimeout"; +const char* kTTSDelimiterKey = "TTSDelimiter"; +const char* kRecordingFileKey = "RecordingFile"; +const char* kPolicyOffKey = "PolicySwitchOff"; const char* kDefaultPoliciesSnapshotFileName = "sdl_snapshot.json"; -// Heartbeat is disabled by default +const char* kDefaultHmiCapabilitiesFileName = "hmi_capabilities.json"; +const char* kDefaultPreloadedPTFileName = "sdl_preloaded_pt.json"; +const char* kDefaultServerAddress = "127.0.0.1"; +const char* kDefaultAppInfoFileName = "app_info.dat"; +const char* kDefaultSystemFilesPath = "/tmp/fs/mp/images/ivsu_cache"; +const char* kDefaultTtsDelimiter = ","; +const char* kDefaultRecordingFileName = "audio.8bit.wav"; const uint32_t kDefaultHeartBeatTimeout = 0; -} - -log4cxx::LoggerPtr logger_ = log4cxx::LoggerPtr( - log4cxx::Logger::getLogger("Profile")); +const uint16_t kDefautTransportManagerTCPPort = 12345; +const uint16_t kDefaultServerPort = 8087; +const uint16_t kDefaultVideoStreamingPort = 5050; +const uint16_t kDefaultAudioStreamingPort = 5080; +const uint16_t kDefaultTimeTestingPort = 5090; +const uint32_t kDefaultMaxCmdId = 2000000000; +const uint32_t kDefaultPutFileRequestInNone = 5; +const uint32_t kDefaultDeleteFileRequestInNone = 5; +const uint32_t kDefaultListFilesRequestInNone = 5; +const uint32_t kDefaultTimeout = 10000; +const uint32_t kDefaultAppResumingTimeout = 5; +const uint32_t kDefaultDirQuota = 104857600; +const uint32_t kDefaultAppTimeScaleMaxRequests = 100; +const uint32_t kDefaultAppRequestsTimeScale = 10; +const uint32_t kDefaultAppHmiLevelNoneTimeScaleMaxRequests = 100; +const uint32_t kDefaultAppHmiLevelNoneRequestsTimeScale = 10; +const uint32_t kDefaultPendingRequestsAmount = 1000; +const uint32_t kDefaultTransportManagerDisconnectTimeout = 0; + +} // namespace namespace profile { + +CREATE_LOGGERPTR_GLOBAL(logger_, "Profile") + Profile::Profile() - : 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"), - server_port_(8087), - video_streaming_port_(5050), - audio_streaming_port_(5080), - help_prompt_(), - time_out_promt_(), - min_tread_stack_size_(threads::Thread::kMinStackSize), - is_mixing_audio_supported_(false), - is_redecoding_enabled_(false), - max_cmd_id_(2000000000), - default_timeout_(10000), - app_resuming_timeout_(5), - app_dir_quota_(104857600), - app_hmi_level_none_time_scale_max_requests_(100), - app_hmi_level_none_requests_time_scale_(10), - app_time_scale_max_requests_(100), - app_requests_time_scale_(10), - pending_requests_amount_(1000), - put_file_in_none_(5), - delete_file_in_none_(5), - list_files_in_none_(5), - app_info_storage_("app_info.dat"), - heart_beat_timeout_(kDefaultHeartBeatTimeout), - policy_snapshot_file_name_(kDefaultPoliciesSnapshotFileName), - transport_manager_disconnect_timeout_(0), - use_last_state_(false), - supported_diag_modes_(), - system_files_path_("/tmp/fs/mp/images/ivsu_cache"){ + : launch_hmi_(true), + app_config_folder_(), + app_storage_folder_(), + app_resourse_folder_(), + config_file_name_(kDefaultConfigFileName), + hmi_capabilities_file_name_(kDefaultHmiCapabilitiesFileName), + server_address_(kDefaultServerAddress), + server_port_(kDefaultServerPort), + video_streaming_port_(kDefaultVideoStreamingPort), + audio_streaming_port_(kDefaultAudioStreamingPort), + time_testing_port_(kDefaultTimeTestingPort), + help_prompt_(), + time_out_promt_(), + min_tread_stack_size_(threads::Thread::kMinStackSize), + is_mixing_audio_supported_(false), + is_redecoding_enabled_(false), + max_cmd_id_(kDefaultMaxCmdId), + default_timeout_(kDefaultTimeout), + app_resuming_timeout_(kDefaultAppResumingTimeout), + app_dir_quota_(kDefaultDirQuota), + app_hmi_level_none_time_scale_max_requests_( + kDefaultAppHmiLevelNoneTimeScaleMaxRequests), + app_hmi_level_none_requests_time_scale_( + kDefaultAppHmiLevelNoneRequestsTimeScale), + app_time_scale_max_requests_(kDefaultAppTimeScaleMaxRequests), + app_requests_time_scale_(kDefaultAppRequestsTimeScale), + pending_requests_amount_(kDefaultPendingRequestsAmount), + put_file_in_none_(kDefaultPutFileRequestInNone), + delete_file_in_none_(kDefaultDeleteFileRequestInNone), + list_files_in_none_(kDefaultListFilesRequestInNone), + app_info_storage_(kDefaultAppInfoFileName), + heart_beat_timeout_(kDefaultHeartBeatTimeout), + policy_snapshot_file_name_(kDefaultPoliciesSnapshotFileName), + policy_turn_off_(false), + transport_manager_disconnect_timeout_( + kDefaultTransportManagerDisconnectTimeout), + use_last_state_(false), + supported_diag_modes_(), + system_files_path_(kDefaultSystemFilesPath), + transport_manager_tcp_adapter_port_(kDefautTransportManagerTCPPort), + tts_delimiter_(kDefaultTtsDelimiter), + recording_file_(kDefaultRecordingFileName) { } Profile::~Profile() { @@ -117,9 +223,8 @@ const std::string& Profile::app_storage_folder() const { return app_storage_folder_; } - -const std::string& Profile::policies_file_name() const { - return policies_file_name_; +const std::string& Profile::app_resourse_folder() const { + return app_resourse_folder_; } const std::string& Profile::hmi_capabilities_file_name() const { @@ -150,7 +255,7 @@ const uint32_t& Profile::default_timeout() const { return default_timeout_; } -const uint32_t &Profile::app_resuming_timeout() const { +const uint32_t& Profile::app_resuming_timeout() const { return app_resuming_timeout_; } @@ -170,6 +275,11 @@ const uint16_t& Profile::audio_streaming_port() const { return audio_streaming_port_; } +const uint16_t& Profile::time_testing_port() const { + return time_testing_port_; +} + + const uint64_t& Profile::thread_min_stack_size() const { return min_tread_stack_size_; } @@ -254,10 +364,14 @@ const std::string& Profile::preloaded_pt_file() const { return preloaded_pt_file_; } -const std::string& Profile::policies_snapshot_file_name() const{ +const std::string& Profile::policies_snapshot_file_name() const { return policy_snapshot_file_name_; } +bool Profile::policy_turn_off() const { + return policy_turn_off_; +} + uint32_t Profile::transport_manager_disconnect_timeout() const { return transport_manager_disconnect_timeout_; } @@ -274,416 +388,485 @@ const std::vector& Profile::supported_diag_modes() const { return supported_diag_modes_; } +uint16_t Profile::transport_manager_tcp_adapter_port() const { + return transport_manager_tcp_adapter_port_; +} + +const std::string& Profile::tts_delimiter() const { + return tts_delimiter_; +} + +const std::string& Profile::recording_file() const { + return recording_file_; +} + void Profile::UpdateValues() { LOG4CXX_INFO(logger_, "Profile::UpdateValues"); - char value[INI_LINE_LEN + 1]; - *value = '\0'; + // Launch HMI parameter + std::string launch_value; + if (ReadValue(&launch_value, kHmiSection, kLaunchHMIKey) && + 0 == strcmp("true", launch_value.c_str())) { + launch_hmi_ = true; + } else { + launch_hmi_ = false; + } - if ((0 != ini_read_value(config_file_name_.c_str(), "HMI", "LaunchHMI", value)) - && ('\0' != *value)) { - if (0 == strcmp("true", value)) { - launch_hmi_ = true; - } else { - launch_hmi_ = false; - } - LOG4CXX_INFO(logger_, "Set launch HMI to " << launch_hmi_); + LOG_UPDATED_BOOL_VALUE(launch_hmi_, kLaunchHMIKey, kHmiSection); + + // Application config folder + ReadStringValue(&app_config_folder_, + file_system::CurrentWorkingDirectory().c_str(), + kMainSection, kAppConfigFolderKey); + + LOG_UPDATED_VALUE(app_config_folder_, kAppConfigFolderKey, kMainSection); + + // Application storage folder + ReadStringValue(&app_storage_folder_, + file_system::CurrentWorkingDirectory().c_str(), + kMainSection, kAppStorageFolderKey); + + LOG_UPDATED_VALUE(app_storage_folder_, kAppStorageFolderKey, kMainSection); + + // Application resourse folder + ReadStringValue(&app_resourse_folder_, + file_system::CurrentWorkingDirectory().c_str(), + kMainSection, kAppResourseFolderKey); + + LOG_UPDATED_VALUE(app_resourse_folder_, kAppResourseFolderKey, + kMainSection); + + // Application info file name + ReadStringValue(&app_info_storage_, kDefaultAppInfoFileName, + kAppInfoSection, + kAppInfoStorageKey); + + app_info_storage_ = app_storage_folder_ + "/" + app_info_storage_; + + LOG_UPDATED_VALUE(app_info_storage_, kAppInfoStorageKey, + kAppInfoSection); + + // Server address + ReadStringValue(&server_address_, kDefaultServerAddress, kHmiSection, + kServerAddressKey); + + LOG_UPDATED_VALUE(server_address_, kServerAddressKey, kHmiSection); + + // HMI capabilities + ReadStringValue(&hmi_capabilities_file_name_ , + kDefaultHmiCapabilitiesFileName, + kMainSection, kHmiCapabilitiesKey); + + hmi_capabilities_file_name_ = app_config_folder_ + "/" + + hmi_capabilities_file_name_; + + LOG_UPDATED_VALUE(hmi_capabilities_file_name_, kHmiCapabilitiesKey, + kMainSection); + + // Server port + ReadUIntValue(&server_port_, kDefaultServerPort, kHmiSection, + kServerPortKey); + + LOG_UPDATED_VALUE(server_port_, kServerPortKey, kHmiSection); + + // Video streaming port + ReadUIntValue(&video_streaming_port_, kDefaultVideoStreamingPort, + kHmiSection, kVideoStreamingPortKey); + + LOG_UPDATED_VALUE(video_streaming_port_, kVideoStreamingPortKey, + kHmiSection); + + // Audio streaming port + ReadUIntValue(&audio_streaming_port_, kDefaultAudioStreamingPort, + kHmiSection, kAudioStreamingPortKey); + + LOG_UPDATED_VALUE(audio_streaming_port_, kAudioStreamingPortKey, + kHmiSection); + + + // Time testing port + ReadUIntValue(&time_testing_port_, kDefaultTimeTestingPort, kMainSection, + kTimeTestingPortKey); + + LOG_UPDATED_VALUE(time_testing_port_, kTimeTestingPortKey, kMainSection); + + // Minimum thread stack size + ReadUIntValue(&min_tread_stack_size_, threads::Thread::kMinStackSize, + kMainSection, kThreadStackSizeKey); + + if (min_tread_stack_size_ < threads::Thread::kMinStackSize) { + min_tread_stack_size_ = threads::Thread::kMinStackSize; } - *value = '\0'; - if ((0 - != ini_read_value(config_file_name_.c_str(), "MAIN", "AppConfigFolder", - value)) && ('\0' != *value)) { - app_config_folder_ = value; + LOG_UPDATED_VALUE(min_tread_stack_size_, kThreadStackSizeKey, kMainSection); + + // Redecoding parameter + std::string redecoding_value; + if (ReadValue(&redecoding_value, kMediaManagerSection, kEnableRedecodingKey) + && 0 == strcmp("true", redecoding_value.c_str())) { + is_redecoding_enabled_ = true; } else { - // use current working directory - app_config_folder_ = file_system::CurrentWorkingDirectory(); + is_redecoding_enabled_ = false; } - 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; + LOG_UPDATED_BOOL_VALUE(is_redecoding_enabled_, kEnableRedecodingKey, + kMediaManagerSection); + + // Video consumer type + ReadStringValue(&video_consumer_type_, "", kMediaManagerSection, + kVideoStreamConsumerKey); + + LOG_UPDATED_VALUE(video_consumer_type_, kVideoStreamConsumerKey, + kMediaManagerSection); + + // Audio stream consumer + ReadStringValue(&audio_consumer_type_, "", kMediaManagerSection, + kAudioStreamConsumerKey); + + LOG_UPDATED_VALUE(audio_consumer_type_, kAudioStreamConsumerKey, + kMediaManagerSection); + + // Named video pipe path + ReadStringValue(&named_video_pipe_path_, "" , kMediaManagerSection, + kNamedVideoPipePathKey); + + LOG_UPDATED_VALUE(named_video_pipe_path_, kNamedVideoPipePathKey, + kMediaManagerSection); + + // Named audio pipe path + ReadStringValue(&named_audio_pipe_path_, "" , kMediaManagerSection, + kNamedAudioPipePathKey); + + LOG_UPDATED_VALUE(named_audio_pipe_path_, kNamedAudioPipePathKey, + kMediaManagerSection); + + // Video stream file + ReadStringValue(&video_stream_file_, "", kMediaManagerSection, + kVideoStreamFileKey); + + video_stream_file_ = app_storage_folder_ + "/" + video_stream_file_; + + LOG_UPDATED_VALUE(video_stream_file_, kVideoStreamFileKey, + kMediaManagerSection); + + // Audio stream file + ReadStringValue(&audio_stream_file_, "", kMediaManagerSection, + kAudioStreamFileKey); + + audio_stream_file_ = app_storage_folder_ + "/" + audio_stream_file_; + + LOG_UPDATED_VALUE(audio_stream_file_, kAudioStreamFileKey, + kMediaManagerSection); + + // Mixing audio parameter + std::string mixing_audio_value; + if (ReadValue(&mixing_audio_value, kMainSection, kMixingAudioSupportedKey) + && 0 == strcmp("true", mixing_audio_value.c_str())) { + is_mixing_audio_supported_ = true; } 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_); + is_mixing_audio_supported_ = false; } - *value = '\0'; - if ((0 - != ini_read_value(config_file_name_.c_str(), "HMI", "ServerAddress", - value)) && ('\0' != *value)) { - server_address_ = value; - LOG4CXX_INFO(logger_, "Set server address to " << server_address_); - } + LOG_UPDATED_BOOL_VALUE(is_mixing_audio_supported_, kMixingAudioSupportedKey, + kMainSection); - *value = '\0'; - if ((0 != ini_read_value(config_file_name_.c_str(), - kPolicySection, "PoliciesTable", value)) - && ('\0' != *value)) { - policies_file_name_ = app_config_folder_ + '/' + value; - LOG4CXX_INFO(logger_, "Set policy file to " << policies_file_name_); - } + // Maximum command id value + ReadUIntValue(&max_cmd_id_, kDefaultMaxCmdId, kMainSection, kMaxCmdIdKey); - *value = '\0'; - if ((0 != ini_read_value(config_file_name_.c_str(), - kPolicySection, "PreloadedPT", value)) - && ('\0' != *value)) { - preloaded_pt_file_ = app_config_folder_ + '/' + value; - LOG4CXX_INFO(logger_, "Set preloaded policy file to " - << preloaded_pt_file_); + if (max_cmd_id_ < 0) { + max_cmd_id_ = kDefaultMaxCmdId; } - (void) ReadStringValue(&policy_snapshot_file_name_, - kDefaultPoliciesSnapshotFileName, - kPolicySection, "PathToSnapshot"); - policy_snapshot_file_name_ = app_config_folder_ + - '/' + policy_snapshot_file_name_; + LOG_UPDATED_VALUE(max_cmd_id_, kMaxCmdIdKey, kMainSection); - 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_); - } + // PutFile restrictions + ReadUIntValue(&put_file_in_none_, kDefaultPutFileRequestInNone, + kFilesystemRestrictionsSection, kPutFileRequestKey); - *value = '\0'; - if ((0 - != ini_read_value(config_file_name_.c_str(), "HMI", "ServerPort", value)) - && ('\0' != *value)) { - server_port_ = atoi(value); - LOG4CXX_INFO(logger_, "Set server port to " << server_port_); + if (put_file_in_none_ < 0) { + put_file_in_none_ = kDefaultPutFileRequestInNone; } - *value = '\0'; - if ((0 - != ini_read_value(config_file_name_.c_str(), "HMI", "VideoStreamingPort", - value)) && ('\0' != *value)) { - video_streaming_port_ = atoi(value); - LOG4CXX_INFO(logger_, - "Set video streaming port to " << video_streaming_port_); - } + LOG_UPDATED_VALUE(put_file_in_none_, kPutFileRequestKey, + kFilesystemRestrictionsSection); - *value = '\0'; - if ((0 - != ini_read_value(config_file_name_.c_str(), "HMI", "AudioStreamingPort", - value)) && ('\0' != *value)) { - audio_streaming_port_ = atoi(value); - LOG4CXX_INFO(logger_, - "Set audio streaming port to " << audio_streaming_port_); - } + // DeleteFileRestrictions + ReadUIntValue(&delete_file_in_none_, kDefaultDeleteFileRequestInNone, + kFilesystemRestrictionsSection, kDeleteFileRequestKey); - *value = '\0'; - if ((0 - != ini_read_value(config_file_name_.c_str(), "MAIN", "ThreadStackSize", - value)) && ('\0' != *value)) { - min_tread_stack_size_ = atoi(value); - if (min_tread_stack_size_ < threads::Thread::kMinStackSize) { - min_tread_stack_size_ = threads::Thread::kMinStackSize; - } - LOG4CXX_INFO(logger_, - "Set threadStackMinSize to " << min_tread_stack_size_); + if (delete_file_in_none_ < 0) { + delete_file_in_none_ = kDefaultDeleteFileRequestInNone; } - *value = '\0'; - if ((0 - != ini_read_value(config_file_name_.c_str(), "MEDIA MANAGER", - "EnableRedecoding", value)) && ('\0' != *value)) { - if (0 == strcmp("true", value)) { - is_redecoding_enabled_ = true; - } - LOG4CXX_INFO(logger_, "Set RedecodingEnabled to " << value); - } + LOG_UPDATED_VALUE(delete_file_in_none_, kDeleteFileRequestKey, + kFilesystemRestrictionsSection); - *value = '\0'; - if ((0 - != ini_read_value(config_file_name_.c_str(), "MEDIA MANAGER", - "VideoStreamConsumer", value)) && ('\0' != *value)) { - video_consumer_type_ = value; - LOG4CXX_INFO(logger_, - "Set VideoStreamConsumer to " << video_consumer_type_); - } + // ListFiles restrictions + ReadUIntValue(&list_files_in_none_, kDefaultListFilesRequestInNone, + kFilesystemRestrictionsSection, kListFilesRequestKey); - *value = '\0'; - if ((0 - != ini_read_value(config_file_name_.c_str(), "MEDIA MANAGER", - "AudioStreamConsumer", value)) && ('\0' != *value)) { - audio_consumer_type_ = value; - LOG4CXX_INFO(logger_, - "Set AudioStreamConsumer to " << audio_consumer_type_); + if (list_files_in_none_ < 0) { + list_files_in_none_ = kDefaultListFilesRequestInNone; } - *value = '\0'; - if ((0 - != ini_read_value(config_file_name_.c_str(), "MEDIA MANAGER", - "NamedVideoPipePath", value)) && ('\0' != *value)) { - named_video_pipe_path_ = value; - LOG4CXX_INFO(logger_, "Set server address to " << named_video_pipe_path_); - } + LOG_UPDATED_VALUE(list_files_in_none_, kListFilesRequestKey, + kFilesystemRestrictionsSection); - *value = '\0'; - if ((0 - != ini_read_value(config_file_name_.c_str(), "MEDIA MANAGER", - "NamedAudioPipePath", value)) && ('\0' != *value)) { - named_audio_pipe_path_ = value; - LOG4CXX_INFO(logger_, "Set server address to " << named_audio_pipe_path_); - } + // Default timeout + ReadUIntValue(&default_timeout_, kDefaultTimeout, kMainSection, + kDefaultTimeoutKey); - *value = '\0'; - if ((0 - != ini_read_value(config_file_name_.c_str(), "MEDIA MANAGER", - "VideoStreamFile", value)) && ('\0' != *value)) { - video_stream_file_ = app_storage_folder_ + "/" + value; - LOG4CXX_INFO(logger_, "Set video stream file to " << video_stream_file_); + if (default_timeout_ <= 0) { + default_timeout_ = kDefaultTimeout; } - *value = '\0'; - if ((0 != ini_read_value(config_file_name_.c_str(), - "MEDIA MANAGER", "AudioStreamFile", value)) - && ('\0' != *value)) { - audio_stream_file_ = app_storage_folder_ + "/" + value; - LOG4CXX_INFO(logger_, "Set audio stream file to " << audio_stream_file_); - } + LOG_UPDATED_VALUE(default_timeout_, kDefaultTimeoutKey, kMainSection); - *value = '\0'; - if ((0 != ini_read_value(config_file_name_.c_str(), - "MAIN", "MixingAudioSupported", value)) - && ('\0' != *value)) { - if (0 == strcmp("true", value)) { - is_mixing_audio_supported_ = true; - } - LOG4CXX_INFO(logger_, "Set MixingAudioSupported to " << value); - } + // Application resuming timeout + ReadUIntValue(&app_resuming_timeout_, kDefaultAppResumingTimeout, + kMainSection, kAppResumingTimeoutKey); - *value = '\0'; - if ((0 != ini_read_value(config_file_name_.c_str(), "MAIN", "MaxCmdID", value)) - && ('\0' != *value)) { - max_cmd_id_ = atoi(value); - if (max_cmd_id_ < 0) { - max_cmd_id_ = 2000000000; - } - LOG4CXX_INFO(logger_, "Set Maximum Command ID to " << max_cmd_id_); + if (app_resuming_timeout_ <= 0) { + app_resuming_timeout_ = kDefaultAppResumingTimeout; } - *value = '\0'; - if ((0 - != ini_read_value(config_file_name_.c_str(), "FILESYSTEM RESTRICTIONS", - "PutFileRequest", value)) && ('\0' != *value)) { - put_file_in_none_ = atoi(value); - if (put_file_in_none_ < 0) { - put_file_in_none_ = 5; - } - LOG4CXX_INFO(logger_, "Max allowed number of PutFile requests for one " - "application in NONE to " << put_file_in_none_); - } + LOG_UPDATED_VALUE(app_resuming_timeout_, kAppResumingTimeoutKey, + kMainSection); - *value = '\0'; - if ((0 - != ini_read_value(config_file_name_.c_str(), "FILESYSTEM RESTRICTIONS", - "DeleteFileRequest", value)) && ('\0' != *value)) { - delete_file_in_none_ = atoi(value); - if (delete_file_in_none_ < 0) { - delete_file_in_none_ = 5; - } - LOG4CXX_INFO(logger_, "Max allowed number of DeleteFile requests for one " - "application in NONE to " << delete_file_in_none_); - } + // Application directory quota + ReadUIntValue(&app_dir_quota_, kDefaultDirQuota, kMainSection, + kAppDirectoryQuotaKey); - *value = '\0'; - if ((0 - != ini_read_value(config_file_name_.c_str(), "FILESYSTEM RESTRICTIONS", - "ListFilesRequest", value)) && ('\0' != *value)) { - list_files_in_none_ = atoi(value); - if (list_files_in_none_ < 0) { - list_files_in_none_ = 5; - } - LOG4CXX_INFO(logger_, "Max allowed number of ListFiles requests for one " - "application in NONE to " << list_files_in_none_); + if (app_dir_quota_ <= 0) { + app_dir_quota_ = kDefaultDirQuota; } - *value = '\0'; - if ((0 - != ini_read_value(config_file_name_.c_str(), "MAIN", "DefaultTimeout", - value)) && ('\0' != *value)) { - default_timeout_ = atoi(value); - if (default_timeout_ <= 0) { - default_timeout_ = 10000; - } - LOG4CXX_INFO(logger_, "Set Default timeout to " << default_timeout_); - } + LOG_UPDATED_VALUE(app_dir_quota_, kAppDirectoryQuotaKey, kMainSection); - *value = '\0'; - if ((0 != ini_read_value(config_file_name_.c_str(), - "MAIN", "ApplicationResumingTimeout", value)) - && ('\0' != *value)) { - app_resuming_timeout_ = atoi(value); - if (app_resuming_timeout_ <= 0) { - app_resuming_timeout_ = 5; - } - LOG4CXX_INFO(logger_, "Set Resuming timeout to " << app_resuming_timeout_); - } + // TTS delimiter + // Should be gotten before any TTS prompts, since it should be appended back + ReadStringValue(&tts_delimiter_, kDefaultTtsDelimiter, + kGlobalPropertiesSection, kTTSDelimiterKey); - *value = '\0'; - if ((0 != ini_read_value(config_file_name_.c_str(), - "MAIN", "AppDirectoryQuota", value)) - && ('\0' != *value)) { - app_dir_quota_ = atoi(value); - if (app_dir_quota_ <= 0) { - app_dir_quota_ = 104857600; - } - LOG4CXX_INFO(logger_, "Set App Directory Quota " << app_dir_quota_); - } + LOG_UPDATED_VALUE(tts_delimiter_, kTTSDelimiterKey, + kGlobalPropertiesSection); + // Help prompt help_prompt_.clear(); - *value = '\0'; - if ((0 - != ini_read_value(config_file_name_.c_str(), "GLOBAL PROPERTIES", - "HelpPromt", value)) && ('\0' != *value)) { + std::string help_prompt_value; + if (ReadValue(&help_prompt_value, kGlobalPropertiesSection, + kHelpPromptKey)) { char* str = NULL; - str = strtok(value, ","); + str = strtok(const_cast(help_prompt_value.c_str()), ","); while (str != NULL) { - LOG4CXX_INFO(logger_, "Add HelpPromt string" << str); - help_prompt_.push_back(std::string(str)); + // Default prompt should have delimiter included for each item + const std::string prompt_item = std::string(str) + tts_delimiter_; + help_prompt_.push_back(prompt_item); + LOG_UPDATED_VALUE(prompt_item, kHelpPromptKey, + kGlobalPropertiesSection); str = strtok(NULL, ","); } + } else { + help_prompt_value.clear(); + LOG_UPDATED_VALUE(help_prompt_value, kHelpPromptKey, + kGlobalPropertiesSection); } + + + // Timeout prompt time_out_promt_.clear(); - *value = '\0'; - if ((0 - != ini_read_value(config_file_name_.c_str(), "GLOBAL PROPERTIES", - "TimeOutPromt", value)) && ('\0' != *value)) { + std::string timeout_prompt_value; + if (ReadValue(&timeout_prompt_value, kGlobalPropertiesSection, + kTimeoutPromptKey)) { char* str = NULL; - str = strtok(value, ","); + str = strtok(const_cast(timeout_prompt_value.c_str()), ","); while (str != NULL) { - LOG4CXX_INFO(logger_, "Add TimeOutPromt string" << str); - time_out_promt_.push_back(std::string(str)); + // Default prompt should have delimiter included for each item + const std::string prompt_item = std::string(str) + tts_delimiter_; + time_out_promt_.push_back(prompt_item); + LOG_UPDATED_VALUE(prompt_item, kTimeoutPromptKey, + kGlobalPropertiesSection); str = strtok(NULL, ","); } + } else { + timeout_prompt_value.clear(); + LOG_UPDATED_VALUE(timeout_prompt_value, kTimeoutPromptKey, + kGlobalPropertiesSection); } - vr_help_title_ = ""; - *value = '\0'; - if ((0 - != ini_read_value(config_file_name_.c_str(), "GLOBAL PROPERTIES", - "HelpTitle", value)) && ('\0' != *value)) { - vr_help_title_ = value; - LOG4CXX_INFO(logger_, "Add HelpTitle string" << vr_help_title_); - } + // Voice recognition help title + ReadStringValue(&vr_help_title_, "", kGlobalPropertiesSection, + kHelpTitleKey); + LOG_UPDATED_VALUE(vr_help_title_, kHelpTitleKey, + kGlobalPropertiesSection); + + // Voice recognition help command vr_commands_.clear(); - *value = '\0'; - if ((0 - != ini_read_value(config_file_name_.c_str(), "VR COMMANDS", "HelpCommand", - value)) && ('\0' != *value)) { + std::string vr_help_command_value; + if (ReadValue(&vr_help_command_value, kVrCommandsSection, + kHelpCommandKey)) { char* str = NULL; - str = strtok(value, ","); + str = strtok(const_cast(vr_help_command_value.c_str()), ","); while (str != NULL) { - LOG4CXX_INFO(logger_, "Add vr command string" << str); - vr_commands_.push_back(std::string(str)); + const std::string vr_item = str; + vr_commands_.push_back(vr_item); + LOG_UPDATED_VALUE(vr_item, kHelpCommandKey, kVrCommandsSection); str = strtok(NULL, ","); } + } else { + vr_help_command_value.clear(); + LOG_UPDATED_VALUE(vr_help_command_value, kHelpCommandKey, + kVrCommandsSection); } - *value = '\0'; - if ((0 - != ini_read_value(config_file_name_.c_str(), "MAIN", - "AppTimeScaleMaxRequests", value)) - && ('\0' != *value)) { - app_time_scale_max_requests_ = atoi(value); - LOG4CXX_INFO(logger_, "Set max amount of requests per application" - " time scale " << app_time_scale_max_requests_); - } + // Application time scale maximum requests + ReadUIntValue(&app_time_scale_max_requests_, + kDefaultAppTimeScaleMaxRequests, + kMainSection, + kAppTimeScaleMaxRequestsKey); - *value = '\0'; - if ((0 - != ini_read_value(config_file_name_.c_str(), "MAIN", - "AppRequestsTimeScale", value)) && ('\0' != *value)) { - app_requests_time_scale_ = atoi(value); - LOG4CXX_INFO(logger_, "Set Application time scale for max amount" - " of requests " << app_requests_time_scale_); - } + LOG_UPDATED_VALUE(app_time_scale_max_requests_, kAppTimeScaleMaxRequestsKey, + kMainSection); - *value = '\0'; - if ((0 - != ini_read_value(config_file_name_.c_str(), "MAIN", - "AppHMILevelNoneTimeScaleMaxRequests", value)) - && ('\0' != *value)) { - app_hmi_level_none_time_scale_max_requests_ = atoi(value); - LOG4CXX_INFO(logger_, "Set max amount of requests per application" - " time scale " << app_hmi_level_none_time_scale_max_requests_); - } + // Application time scale + ReadUIntValue(&app_requests_time_scale_, kDefaultAppRequestsTimeScale, + kMainSection, kAppRequestsTimeScaleKey); - *value = '\0'; - if ((0 - != ini_read_value(config_file_name_.c_str(), "MAIN", - "AppHMILevelNoneRequestsTimeScale", value)) - && ('\0' != *value)) { - app_hmi_level_none_requests_time_scale_ = atoi(value); - LOG4CXX_INFO(logger_, "Set Application time scale for max amount" - " of requests " << app_hmi_level_none_requests_time_scale_); - } + LOG_UPDATED_VALUE(app_requests_time_scale_, kAppRequestsTimeScaleKey, + kMainSection); - *value = '\0'; - if ((0 - != ini_read_value(config_file_name_.c_str(), "MAIN", - "PendingRequestsAmount", value)) && ('\0' != *value)) { - pending_requests_amount_ = atoi(value); - if (app_dir_quota_ <= 0) { - pending_requests_amount_ = 1000; - } - LOG4CXX_INFO( - logger_, - "Set system pending requests amount " << pending_requests_amount_); + // Application HMI level NONE time scale maximum requests + ReadUIntValue(&app_hmi_level_none_time_scale_max_requests_, + kDefaultAppHmiLevelNoneTimeScaleMaxRequests, + kMainSection, + kAppHmiLevelNoneTimeScaleMaxRequestsKey); + + LOG_UPDATED_VALUE(app_hmi_level_none_time_scale_max_requests_, + kAppHmiLevelNoneTimeScaleMaxRequestsKey, + kMainSection); + + // Application HMI level NONE requests time scale + ReadUIntValue(&app_hmi_level_none_requests_time_scale_, + kDefaultAppHmiLevelNoneRequestsTimeScale, + kMainSection, + kAppHmiLevelNoneRequestsTimeScaleKey); + + LOG_UPDATED_VALUE(app_hmi_level_none_requests_time_scale_, + kAppHmiLevelNoneRequestsTimeScaleKey, + kMainSection); + + // Amount of pending requests + ReadUIntValue(&pending_requests_amount_, kDefaultPendingRequestsAmount, + kMainSection, kPendingRequestsAmoundKey); + + if (pending_requests_amount_ <= 0) { + pending_requests_amount_ = kDefaultPendingRequestsAmount; } + LOG_UPDATED_VALUE(pending_requests_amount_, kPendingRequestsAmoundKey, + kMainSection); + + // Supported diagnostic modes supported_diag_modes_.clear(); - *value = '\0'; - if ((0 - != ini_read_value(config_file_name_.c_str(), "MAIN", - "SupportedDiagModes", value)) && ('\0' != *value)) { + std::string supported_diag_modes_value; + std::string correct_diag_modes; + if (ReadStringValue(&supported_diag_modes_value, "", kMainSection, + kSupportedDiagModesKey)) { char* str = NULL; - str = strtok(value, ","); + str = strtok(const_cast(supported_diag_modes_value.c_str()), ","); while (str != NULL) { - supported_diag_modes_.push_back(strtol(str, NULL, 16)); + uint32_t user_value = strtol(str, NULL, 16); + if (user_value && errno != ERANGE) { + correct_diag_modes += str; + correct_diag_modes += ","; + supported_diag_modes_.push_back(user_value); + } str = strtok(NULL, ","); } } - *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_); + LOG_UPDATED_VALUE(correct_diag_modes, kSupportedDiagModesKey, kMainSection); + + // System files path + ReadStringValue(&system_files_path_, kDefaultSystemFilesPath, kMainSection, + kSystemFilesPathKey); + + LOG_UPDATED_VALUE(system_files_path_, kSystemFilesPathKey, kMainSection); + + // Heartbeat timeout + ReadUIntValue(&heart_beat_timeout_, kDefaultHeartBeatTimeout, kMainSection, + kHeartBeatTimeoutKey); + + LOG_UPDATED_VALUE(heart_beat_timeout_, kHeartBeatTimeoutKey, kMainSection); + + // Use last state value + std::string last_state_value; + if (ReadValue(&last_state_value, kMainSection, kUseLastStateKey) && + 0 == strcmp("true", last_state_value.c_str())) { + use_last_state_ = true; + } else { + use_last_state_ = false; } - (void) ReadIntValue(&heart_beat_timeout_, kDefaultHeartBeatTimeout, - kMainSection, "HeartBeatTimeout"); + LOG_UPDATED_BOOL_VALUE(use_last_state_, kUseLastStateKey, kMainSection); - *value = '\0'; - if ((0 != ini_read_value(config_file_name_.c_str(), - "MAIN", "UseLastState", value)) - && ('\0' != *value)) { - if (0 == strcmp("true", value)) { - use_last_state_ = true; - } - LOG4CXX_INFO(logger_, "Set UseLastState to " << value); + // Transport manager TCP port + ReadUIntValue(&transport_manager_tcp_adapter_port_, + kDefautTransportManagerTCPPort, + kTransportManagerSection, + kTCPAdapterPortKey); + + LOG_UPDATED_VALUE(transport_manager_tcp_adapter_port_, kTCPAdapterPortKey, + kTransportManagerSection); + + // Transport manager disconnect timeout + ReadUIntValue(&transport_manager_disconnect_timeout_, + kDefaultTransportManagerDisconnectTimeout, + kTransportManagerSection, + kTransportManagerDisconnectTimeoutKey); + + LOG_UPDATED_VALUE(transport_manager_disconnect_timeout_, + kTransportManagerDisconnectTimeoutKey, + kTransportManagerSection); + + // Recording file + ReadStringValue(&recording_file_, kDefaultRecordingFileName, + kMediaManagerSection, kSystemFilesPathKey); + + LOG_UPDATED_VALUE(recording_file_, kRecordingFileKey, kMediaManagerSection); + + // Policy preloaded file + ReadStringValue(&preloaded_pt_file_, + kDefaultPreloadedPTFileName, + kPolicySection, kPreloadedPTKey); + + preloaded_pt_file_ = app_config_folder_ + '/' + preloaded_pt_file_; + + LOG_UPDATED_VALUE(preloaded_pt_file_, kPreloadedPTKey, kPolicySection); + + // Policy snapshot file + ReadStringValue(&policy_snapshot_file_name_, + kDefaultPoliciesSnapshotFileName, + kPolicySection, kPathToSnapshotKey); + + policy_snapshot_file_name_ = system_files_path_ + + '/' + policy_snapshot_file_name_; + + LOG_UPDATED_VALUE(policy_snapshot_file_name_, kPathToSnapshotKey, + kPolicySection); + + // Turn Policy Off? + std::string policy_off; + if (ReadValue(&policy_off, kPolicySection, kPolicyOffKey) && + 0 == strcmp("true", policy_off.c_str())) { + policy_turn_off_ = true; + } else { + policy_turn_off_ = false; } + + LOG_UPDATED_BOOL_VALUE(policy_turn_off_, kPolicyOffKey, kPolicySection); } bool Profile::ReadValue(bool* value, const char* const pSection, @@ -732,15 +915,59 @@ bool Profile::ReadStringValue(std::string* value, const char* default_value, return true; } -bool Profile::ReadIntValue(int32_t* value, int32_t default_value, - const char* const pSection, - const char* const pKey) const { +bool Profile::ReadUIntValue(uint16_t* value, uint16_t default_value, + const char* const pSection, + const char* const pKey) const { std::string string_value; if (!ReadValue(&string_value, pSection, pKey)) { *value = default_value; return false; } else { - *value = atoi(string_value.c_str()); + uint16_t user_value = strtoul(string_value.c_str(), NULL, 10); + if (!user_value || errno == ERANGE) { + *value = default_value; + return false; + } + + *value = user_value; + return true; + } +} + +bool Profile::ReadUIntValue(uint32_t* value, uint32_t default_value, + const char* const pSection, + const char* const pKey) const { + std::string string_value; + if (!ReadValue(&string_value, pSection, pKey)) { + *value = default_value; + return false; + } else { + uint32_t user_value = strtoul(string_value.c_str(), NULL, 10); + if (!user_value || errno == ERANGE) { + *value = default_value; + return false; + } + + *value = user_value; + return true; + } +} + +bool Profile::ReadUIntValue(uint64_t* value, uint64_t default_value, + const char* const pSection, + const char* const pKey) const { + std::string string_value; + if (!ReadValue(&string_value, pSection, pKey)) { + *value = default_value; + return false; + } else { + uint64_t user_value = strtoull(string_value.c_str(), NULL, 10); + if (!user_value || errno == ERANGE) { + *value = default_value; + return false; + } + + *value = user_value; return true; } } -- 2.7.4