VPD Tool: Update Hardware

Vpd tool has --Hardware/-H flag which should be given along
with writeKeyword flags, if the user wants to write directly to "Hardware".

In general the user should give only the object path in
--path/-P value.

Only if --Hardware/-H flag is given, the user has an
option to give either eeprom path or the object path in
--path/-P value.

Test:
Tested on simics.

./vpd-tool --writeKeyword -H --path < hardware path/object path > -R < record name > -K < keyword > -V < value in hex/ascii >

CASE 1: <updating eeprom path> < update directly on hardware using -H.>
./vpd-tool -u -H -P /sys/devices/platform/ahb/ahb:apb/ahb:apb:bus@1e78a000/1e78a480.i2c-bus/i2c-8/8-0051/8-00510/nvmem -R VINI -K PN -V 0x717273
updation successful on both dbus and hardware.

CASE 2:
./vpd-tool -u -H -P /sys/devices/platform/ahb/ahb:apb/ahb:apb:bus@1e78a000/1e78a480.i2c-bus/i2c-8/8-0051/8-00510/nvmem -R DINF -K FL -V 0x717273
updation successful on hardware. <this wont get updated in dbus as the given record-keyword pair is not required to update in dbus(only those record keywords
present in dbus_properties.json are required to be updated in dbus).

CASE 3: <failure case - invalid eeprom path>
root@rainier:/tmp# ./vpd-tool -u -H -P /sys/devices/platform/ahb/ahb:apb/ahb:apb:bus@1e78a000/1e78a490.i2c-bus/i2c-8/8-0051/8-00510/nvmem -R VINI -K PN -V 0x717273
Invalid object path : /sys/devices/platform/ahb/ahb:apb/ahb:apb:bus@1e78a000/1e78a490.i2c-bus/i2c-8/8-0051/8-00510/nvmem. Unable to find the corresponding EEPROM path for the given object path : /sys/devices/platform/ahb/ahb:apb/ahb:apb:bus@1e78a000/1e7$

Signed-off-by: PriyangaRamasamy <priyanga24@in.ibm.com>
Change-Id: I6b893e699fe343c90c3a3fd2b07fd8b9a4711687
diff --git a/vpd-manager/editor_impl.cpp b/vpd-manager/editor_impl.cpp
index a20cd44..9ca68fc 100644
--- a/vpd-manager/editor_impl.cpp
+++ b/vpd-manager/editor_impl.cpp
@@ -578,7 +578,7 @@
     }
 }
 
-void EditorImpl::updateKeyword(const Binary& kwdData)
+void EditorImpl::updateKeyword(const Binary& kwdData, const bool& updCache)
 {
     startOffset = 0;
 #ifndef ManagerTest
@@ -649,9 +649,13 @@
 
             // update the ECC data for the record once data has been updated
             updateRecordECC();
+
 #ifndef ManagerTest
-            // update the cache once data has been updated
-            updateCache();
+            if (updCache)
+            {
+                // update the cache once data has been updated
+                updateCache();
+            }
 #endif
         }
         catch (const std::exception& e)
@@ -665,7 +669,6 @@
         return;
     }
 }
-
 } // namespace editor
 } // namespace manager
 } // namespace vpd
diff --git a/vpd-manager/editor_impl.hpp b/vpd-manager/editor_impl.hpp
index 9cf3b8a..96cfd07 100644
--- a/vpd-manager/editor_impl.hpp
+++ b/vpd-manager/editor_impl.hpp
@@ -75,10 +75,25 @@
     {
     }
 
+    /** @brief Construct EditorImpl class
+     *
+     * @param[in] path - EEPROM path
+     * @param[in] json - Parsed inventory json object
+     * @param[in] record - Record name
+     * @param[in] kwd - Keyword name
+     */
+    EditorImpl(const inventory::Path& path, const nlohmann::json& json,
+               const std::string& record, const std::string& kwd) :
+        vpdFilePath(path),
+        jsonFile(json), thisRecord(record, kwd)
+    {
+    }
+
     /** @brief Update data for keyword
      *  @param[in] kwdData - data to update
+     *  @param[in] updCache - Flag which tells whether to update Cache or not.
      */
-    void updateKeyword(const Binary& kwdData);
+    void updateKeyword(const Binary& kwdData, const bool& updCache);
 
     /** @brief Expands location code on DBUS
      *  @param[in] locationCodeType - "fcs" or "mts"
diff --git a/vpd-manager/manager.cpp b/vpd-manager/manager.cpp
index 606d3b5..5344664 100644
--- a/vpd-manager/manager.cpp
+++ b/vpd-manager/manager.cpp
@@ -109,7 +109,7 @@
 
         // instantiate editor class to update the data
         EditorImpl edit(vpdFilePath, jsonFile, recordName, keyword, path);
-        edit.updateKeyword(value);
+        edit.updateKeyword(value, true);
 
         // if it is a motehrboard FRU need to check for location expansion
         if (frus.find(path)->second.second)