Add history::RecordManager class

This class will manage the records for the input power
history that has to be maintained on D-Bus.  This includes
the average power and maximum power over 30 second intervals.

The actual power values come from the power supply, and the
PowerSupply class will pass that data to this class every time
it is read, which is faster than the data actually changes since
it only changes every 30s.  This class will only save new data
when it has changed.

If there is new data available, this class will let the caller
know that it should then ask for the D-Bus property values for
the maximum and average power values, which are each arrays with
entries made up of timestamps along with the values.

This commit just includes some base functionality.  The rest will
come in future commits.

Change-Id: I1e521ba2ff7f733376b769ffa0d7053a0231d732
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/power-supply/Makefile.am b/power-supply/Makefile.am
index 01f8b5e..862db7c 100644
--- a/power-supply/Makefile.am
+++ b/power-supply/Makefile.am
@@ -7,7 +7,8 @@
 witherspoon_psu_monitor_SOURCES = \
 	main.cpp \
 	argument.cpp \
-	power_supply.cpp
+	power_supply.cpp \
+	record_manager.cpp
 
 witherspoon_psu_monitor_CXXFLAGS = \
 	$(SDBUSPLUS_CFLAGS) \
diff --git a/power-supply/record_manager.cpp b/power-supply/record_manager.cpp
new file mode 100644
index 0000000..bfc2f17
--- /dev/null
+++ b/power-supply/record_manager.cpp
@@ -0,0 +1,28 @@
+/**
+ * Copyright © 2017 IBM Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "record_manager.hpp"
+
+namespace witherspoon
+{
+namespace power
+{
+namespace history
+{
+
+
+}
+}
+}
diff --git a/power-supply/record_manager.hpp b/power-supply/record_manager.hpp
new file mode 100644
index 0000000..fe35db0
--- /dev/null
+++ b/power-supply/record_manager.hpp
@@ -0,0 +1,119 @@
+#pragma once
+
+#include <deque>
+#include <tuple>
+#include <vector>
+
+namespace witherspoon
+{
+namespace power
+{
+namespace history
+{
+
+static constexpr auto recIDPos = 0;
+static constexpr auto recTimePos = 1;
+static constexpr auto recAvgPos = 2;
+static constexpr auto recMaxPos = 3;
+using Record = std::tuple<size_t, int64_t, int64_t, int64_t>;
+
+/**
+ * @class RecordManager
+ *
+ * This class manages the records for the input power history of
+ * a power supply.
+ *
+ * The history is the average and maximum power values across 30s
+ * intervals.  Every 30s, a new record will be available from the
+ * PS.  This class takes that raw PS data and converts it into
+ * something useable by D-Bus.  It ensures the readings are always
+ * sorted newest to oldest, and prunes out the oldest entries when
+ * necessary.  If there is a problem with the ordering IDs coming
+ * from the PS, it will clear out the old records and start over.
+ */
+class RecordManager
+{
+    public:
+
+        static constexpr auto LAST_SEQUENCE_ID = 0xFF;
+
+        using DBusRecord = std::tuple<uint64_t, int64_t>;
+        using DBusRecordList = std::vector<DBusRecord>;
+
+        RecordManager() = delete;
+        ~RecordManager() = default;
+        RecordManager(const RecordManager&) = default;
+        RecordManager& operator=(const RecordManager&) = default;
+        RecordManager(RecordManager&&) = default;
+        RecordManager& operator=(RecordManager&&) = default;
+
+        /**
+         * @brief Constructor
+         *
+         * @param[in] maxRec - the maximum number of history
+         *                     records to keep at a time
+         */
+        RecordManager(size_t maxRec) :
+                RecordManager(maxRec, LAST_SEQUENCE_ID)
+        {
+        }
+
+        /**
+         * @brief Constructor
+         *
+         * @param[in] maxRec - the maximum number of history
+         *                     records to keep at a time
+         * @param[in] lastSequenceID - the last sequence ID the power supply
+         *                             will use before starting over
+         */
+        RecordManager(size_t maxRec, size_t lastSequenceID) :
+                maxRecords(maxRec),
+                lastSequenceID(lastSequenceID)
+        {
+        }
+
+        /**
+         * @brief Returns the number of records
+         *
+         * @return size_t - the number of records
+         *
+         */
+        inline size_t getNumRecords() const
+        {
+            return records.size();
+        }
+
+        /**
+         * @brief Deletes all records
+         */
+        inline void clear()
+        {
+            records.clear();
+        }
+
+    private:
+
+        /**
+         * @brief The maximum number of entries to keep in the history.
+         *
+         * When a new record is added, the oldest one will be removed.
+         */
+        const size_t maxRecords;
+
+        /**
+         * @brief The last ID the power supply returns before rolling over
+         *        back to the first ID of 0.
+         */
+        const size_t lastSequenceID;
+
+        /**
+         * @brief The list of timestamp/average/maximum records.
+         *        Newer records are added to the front, and older ones
+         *        removed from the back.
+         */
+        std::deque<Record> records;
+};
+
+}
+}
+}