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,