APPLINK-6700, Routine to prepare policy table json file and send it
authorIgor Kozyrenko <IKozyrenko@luxoft.com>
Tue, 8 Apr 2014 09:25:48 +0000 (12:25 +0300)
committerJustin Dickow <jjdickow@gmail.com>
Wed, 9 Jul 2014 18:06:10 +0000 (14:06 -0400)
src/components/config_profile/include/config_profile/profile.h
src/components/config_profile/src/profile.cc
src/components/policy
src/components/utils/include/utils/file_system.h
src/components/utils/src/file_system.cc

index e45c932..642f50b 100644 (file)
@@ -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_;
index c188aaf..634ef89 100644 (file)
@@ -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))
index 3bef801..3ed2d58 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 3bef801ae41c14942d8b1a79335fb60e9892254f
+Subproject commit 3ed2d5854422257605016c1f9825567ad105f376
index 9c540c2..e699ecd 100644 (file)
@@ -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
index 642b409..63efbea 100644 (file)
@@ -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)) {