test: dbus: passive read interface

Added basic unit-tests and added a factory for creating the
DbusPassive read interface so that it can be nicely error checked.  This
is handled via a valid type check where the only valid types are 'fan'
and 'temp'.

Change-Id: I558ed09bf509d26f20c6e431bb0789074e9aa841
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/dbus/dbuspassive.cpp b/dbus/dbuspassive.cpp
index 6b4ea5f..daeef62 100644
--- a/dbus/dbuspassive.cpp
+++ b/dbus/dbuspassive.cpp
@@ -13,12 +13,31 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 #include <chrono>
 #include <cmath>
+#include <memory>
 #include <mutex>
+#include <sdbusplus/bus.hpp>
+#include <string>
 
 #include "dbuspassive.hpp"
+#include "dbus/util.hpp"
+
+std::unique_ptr<ReadInterface> DbusPassive::CreateDbusPassive(
+    sdbusplus::bus::bus& bus, const std::string& type,
+    const std::string& id, DbusHelperInterface *helper)
+{
+    if (helper == nullptr)
+    {
+        return nullptr;
+    }
+    if (!ValidType(type))
+    {
+        return nullptr;
+    }
+
+    return std::make_unique<DbusPassive>(bus, type, id, helper);
+}
 
 DbusPassive::DbusPassive(
     sdbusplus::bus::bus& bus,
diff --git a/dbus/dbuspassive.hpp b/dbus/dbuspassive.hpp
index 8ecfe71..545b928 100644
--- a/dbus/dbuspassive.hpp
+++ b/dbus/dbuspassive.hpp
@@ -4,6 +4,7 @@
 #include <cmath>
 #include <iostream>
 #include <map>
+#include <memory>
 #include <mutex>
 #include <set>
 #include <string>
@@ -33,6 +34,10 @@
 class DbusPassive : public ReadInterface
 {
     public:
+        static std::unique_ptr<ReadInterface> CreateDbusPassive(
+            sdbusplus::bus::bus& bus, const std::string& type,
+            const std::string& id, DbusHelperInterface *helper);
+
         DbusPassive(sdbusplus::bus::bus& bus,
                     const std::string& type,
                     const std::string& id,
diff --git a/dbus/util.cpp b/dbus/util.cpp
index f0ffffb..91cc840 100644
--- a/dbus/util.cpp
+++ b/dbus/util.cpp
@@ -1,4 +1,5 @@
 #include <iostream>
+#include <set>
 
 #include "dbus/util.hpp"
 
@@ -105,3 +106,8 @@
                        "path='" + GetSensorPath(type, id) + "'");
 }
 
+bool ValidType(const std::string& type)
+{
+    static std::set<std::string> valid = {"fan", "temp"};
+    return (valid.find(type) != valid.end());
+}
diff --git a/dbus/util.hpp b/dbus/util.hpp
index e858c0c..44e137c 100644
--- a/dbus/util.hpp
+++ b/dbus/util.hpp
@@ -58,3 +58,4 @@
 
 std::string GetSensorPath(const std::string& type, const std::string& id);
 std::string GetMatch(const std::string& type, const std::string& id);
+bool ValidType(const std::string& type);