diff options
author | Igor Kozyrenko <IKozyrenko@luxoft.com> | 2014-04-08 12:25:48 +0300 |
---|---|---|
committer | Justin Dickow <jjdickow@gmail.com> | 2014-07-09 14:06:10 -0400 |
commit | 7f0c50b59cd0957d5a96665752926de98a57f882 (patch) | |
tree | b6c781dd77b958f714908e2c73008ef865569709 | |
parent | 405ee8379b614079cfbfe397a0352facb5a2801b (diff) | |
download | smartdevicelink-7f0c50b59cd0957d5a96665752926de98a57f882.tar.gz |
APPLINK-6700, Routine to prepare policy table json file and send it
-rw-r--r-- | src/components/config_profile/include/config_profile/profile.h | 7 | ||||
-rw-r--r-- | src/components/config_profile/src/profile.cc | 16 | ||||
m--------- | src/components/policy | 0 | ||||
-rw-r--r-- | src/components/utils/include/utils/file_system.h | 9 | ||||
-rw-r--r-- | src/components/utils/src/file_system.cc | 9 |
5 files changed, 39 insertions, 2 deletions
diff --git a/src/components/config_profile/include/config_profile/profile.h b/src/components/config_profile/include/config_profile/profile.h index e45c9329a..642f50bbc 100644 --- a/src/components/config_profile/include/config_profile/profile.h +++ b/src/components/config_profile/include/config_profile/profile.h @@ -249,6 +249,12 @@ class Profile : public utils::Singleton<Profile> { */ const std::string& preloaded_pt_file() const; + /** + * @brief Path to policies snapshot file + * @return file path + */ + const std::string& policies_snapshot_file_name() const; + /* * @brief Timeout in transport manager before disconnect */ @@ -385,6 +391,7 @@ class Profile : public utils::Singleton<Profile> { std::string app_info_storage_; int32_t heart_beat_timeout_; std::string preloaded_pt_file_; + std::string policy_shapshot_file_name_; uint32_t transport_manager_disconnect_timeout_; bool use_last_state_; std::vector<uint32_t> supported_diag_modes_; diff --git a/src/components/config_profile/src/profile.cc b/src/components/config_profile/src/profile.cc index c188aaf2b..634ef89d0 100644 --- a/src/components/config_profile/src/profile.cc +++ b/src/components/config_profile/src/profile.cc @@ -41,6 +41,9 @@ 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; } @@ -77,6 +80,7 @@ Profile::Profile() 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_() { @@ -238,6 +242,10 @@ const std::string& Profile::preloaded_pt_file() const { 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_; } @@ -275,7 +283,7 @@ void Profile::UpdateValues() { *value = '\0'; if ((0 != ini_read_value(config_file_name_.c_str(), - "Policy", "PoliciesTable", value)) + kPolicySection, "PoliciesTable", value)) && ('\0' != *value)) { policies_file_name_ = value; LOG4CXX_INFO(logger_, "Set policy file to " << policies_file_name_); @@ -283,13 +291,17 @@ void Profile::UpdateValues() { *value = '\0'; if ((0 != ini_read_value(config_file_name_.c_str(), - "Policy", "PreloadedPT", value)) + kPolicySection, "PreloadedPT", value)) && ('\0' != *value)) { preloaded_pt_file_ = 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)) diff --git a/src/components/policy b/src/components/policy -Subproject 3bef801ae41c14942d8b1a79335fb60e9892254 +Subproject 3ed2d5854422257605016c1f9825567ad105f37 diff --git a/src/components/utils/include/utils/file_system.h b/src/components/utils/include/utils/file_system.h index 9c540c22a..e699ecd83 100644 --- a/src/components/utils/include/utils/file_system.h +++ b/src/components/utils/include/utils/file_system.h @@ -183,6 +183,15 @@ bool IsAccessible(const std::string& name, int32_t how); std::vector<std::string> ListFiles(const std::string& directory_name); /** + * @brief Creates or overwrites file with given binary contents + * @param name path to the file + * @param contents data to be written into the file + * @returns true if file write succeeded + */ +bool WriteBinaryFile(const std::string& name, + const std::vector<uint8_t>& contents); + +/** * @brief Reads from file * * @param name path to file diff --git a/src/components/utils/src/file_system.cc b/src/components/utils/src/file_system.cc index 642b4098d..63efbea84 100644 --- a/src/components/utils/src/file_system.cc +++ b/src/components/utils/src/file_system.cc @@ -347,6 +347,15 @@ std::vector<std::string> file_system::ListFiles( return listFiles; } +bool file_system::WriteBinaryFile(const std::string& name, + const std::vector<uint8_t>& contents) { + using namespace std; + ofstream output(name.c_str(), ios_base::binary|ios_base::trunc); + output.write(reinterpret_cast<const char*>(&contents.front()), + contents.size()); + return output.good(); +} + bool file_system::ReadBinaryFile(const std::string& name, std::vector<uint8_t>& result) { if (!FileExists(name) || !IsAccessible(name, R_OK)) { |