Rename class Version to BMCVersion

The class Version is renamed to BMCVersion.
This is needed so there is not 2 classes with the same name,
Version, under namespace phosphor software manager.
This name is more appropriate for the BMC Version Class
that handles the active BMC code.

Change-Id: I9eef4f5240f6cac90a31d6c31aa7f518213830e3
Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
diff --git a/bmc_version.cpp b/bmc_version.cpp
new file mode 100644
index 0000000..463b2c4
--- /dev/null
+++ b/bmc_version.cpp
@@ -0,0 +1,57 @@
+#include <iostream>
+#include <string>
+#include <sstream>
+#include <fstream>
+#include <stdexcept>
+#include "bmc_version.hpp"
+
+namespace phosphor
+{
+namespace software
+{
+namespace manager
+{
+
+const std::string BMCVersion::getVersion() const
+{
+    // Get version from /etc/os-release.
+    std::string versionKey = "VERSION_ID=";
+    std::string version{};
+    std::ifstream efile;
+    std::string line;
+    efile.open("/etc/os-release");
+
+    while (getline(efile, line))
+    {
+        if (line.substr(0, versionKey.size()).find(versionKey)
+            != std::string::npos)
+        {
+            // This line looks like VERSION_ID="v1.99.0-353-ga3b8a0a-dirty".
+            // So grab everything in quotes.
+            std::size_t pos = line.find_first_of('"') + 1;
+            version = line.substr(pos, line.find_last_of('"') - pos);
+            break;
+        }
+    }
+    efile.close();
+    return version;
+}
+
+const std::string BMCVersion::getId() const
+{
+    auto version = getVersion();
+    std::stringstream hexId;
+
+    if (version.empty())
+    {
+        throw std::runtime_error("Software version is empty");
+    }
+
+    // Only want 8 hex digits.
+    hexId << std::hex << ((std::hash<std::string> {}(version)) & 0xFFFFFFFF);
+    return hexId.str();
+}
+
+} // namespace manager
+} // namespace software
+} // namepsace phosphor