Add basic function for phosphor-nvme.

Add basic function to monitor temperature of
NVMe drive for phosphor-nvme.

Change-Id: Iebe3c8bf4b5cb958defab5b24a88f4bce477ad5e
Signed-off-by: Tony Lee <tony.lee@quantatw.com>
diff --git a/nvme_manager.hpp b/nvme_manager.hpp
index b6f32c3..2b0e27d 100644
--- a/nvme_manager.hpp
+++ b/nvme_manager.hpp
@@ -1,5 +1,10 @@
+#pragma once
+
 #include "config.h"
 
+#include "nvmes.hpp"
+
+#include <fstream>
 #include <sdbusplus/bus.hpp>
 #include <sdbusplus/server.hpp>
 #include <sdbusplus/server/object.hpp>
@@ -12,6 +17,9 @@
 namespace nvme
 {
 
+/** @class Nvme
+ *  @brief Nvme manager implementation.
+ */
 class Nvme
 {
   public:
@@ -21,23 +29,80 @@
     Nvme(Nvme&&) = delete;
     Nvme& operator=(Nvme&&) = delete;
 
+    /** @brief Constructs Nvme
+     *
+     * @param[in] bus     - Handle to system dbus
+     * @param[in] objPath - The Dbus path of nvme
+     */
     Nvme(sdbusplus::bus::bus& bus) :
         bus(bus), _event(sdeventplus::Event::get_default()),
         _timer(_event, std::bind(&Nvme::read, this))
     {
+        // read json file
+        configs = getNvmeConfig();
     }
 
+    /**
+     * Structure for keeping nvme configure data required by nvme monitoring
+     */
+    struct NVMeConfig
+    {
+        std::string index;
+        uint8_t busID;
+        uint8_t presentPin;
+        uint8_t pwrGoodPin;
+        int8_t criticalHigh;
+        int8_t criticalLow;
+        int8_t maxValue;
+        int8_t minValue;
+        int8_t warningHigh;
+        int8_t warningLow;
+    };
+
+    /**
+     * Structure for keeping nvme data required by nvme monitoring
+     */
+    struct NVMeData
+    {
+        bool present;              /* Whether or not the nvme is present  */
+        std::string vendor;        /* The nvme manufacturer  */
+        std::string serialNumber;  /* The nvme serial number  */
+        std::string smartWarnings; /* Indicates smart warnings for the state  */
+        std::string statusFlags;   /* Indicates the status of the drives  */
+        std::string
+            driveLifeUsed;  /* A vendor specific estimate of the percentage  */
+        int8_t sensorValue; /* Sensor value, if sensor value didn't be
+                                  update, means sensor failure, default set to
+                                  129(0x81) accroding to NVMe-MI SPEC*/
+    };
+
+    /** @brief Setup polling timer in a sd event loop and attach to D-Bus
+     *         event loop.
+     */
     void run();
 
-  private:
-    sdbusplus::bus::bus& bus;
+    /** @brief Get GPIO value of nvme by sysfs */
+    std::string getGPIOValueOfNvme(const std::string& fullPath);
+    /** @brief Map of the object NvmeSSD */
+    std::unordered_map<std::string, std::shared_ptr<phosphor::nvme::NvmeSSD>>
+        nvmes;
 
+  private:
+    /** @brief sdbusplus bus client connection. */
+    sdbusplus::bus::bus& bus;
+    /** @brief the Event Loop structure */
     sdeventplus::Event _event;
     /** @brief Read Timer */
     sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic> _timer;
 
+    std::vector<phosphor::nvme::Nvme::NVMeConfig> configs;
+
+    /** @brief Set up initial configuration value of NVMe */
     void init();
+    /** @brief Monitor NVMe drives every one second  */
     void read();
+
+    std::vector<phosphor::nvme::Nvme::NVMeConfig> getNvmeConfig();
 };
 } // namespace nvme
-} // namespace phosphor
\ No newline at end of file
+} // namespace phosphor