From 6caee6cb22c1334701afe7aa30bcf9668ca3a5c5 Mon Sep 17 00:00:00 2001 From: Mika Laitio Date: Mon, 28 Feb 2011 21:52:26 +0200 Subject: [PATCH] Started defining generic device type base classes that could be used also outside of lib1wire library eventually. Signed-off-by: Mika Laitio --- src/DeviceTypeGeneric.hh | 24 ++++++++++++++++++++++++ src/DeviceTypeSensor.hh | 24 ++++++++++++++++++++++++ src/Makefile.am | 20 ++++++++++++-------- src/W1Device.cc | 5 ++--- src/W1Device.hh | 11 +++++------ 5 files changed, 67 insertions(+), 17 deletions(-) create mode 100644 src/DeviceTypeGeneric.hh create mode 100644 src/DeviceTypeSensor.hh diff --git a/src/DeviceTypeGeneric.hh b/src/DeviceTypeGeneric.hh new file mode 100644 index 0000000..ba944a8 --- /dev/null +++ b/src/DeviceTypeGeneric.hh @@ -0,0 +1,24 @@ +/* + * GenericDevice.hh + * + * Created on: Feb 28, 2011 + * Author: lamikr + */ + +#ifndef DEVICETYPEGENERIC_HH_ +#define DEVICETYPEGENERIC_HH_ + +#include + +namespace plp { + class DeviceTypeGeneric { + public: + virtual std::string get_id() = 0; + virtual std::string get_name() = 0; + virtual void set_name(std::string name_param) = 0; + virtual std::string get_device_type() = 0; + virtual void printout() = 0; + }; +} + +#endif /* DEVICETYPEGENERIC_HH_ */ diff --git a/src/DeviceTypeSensor.hh b/src/DeviceTypeSensor.hh new file mode 100644 index 0000000..99403ef --- /dev/null +++ b/src/DeviceTypeSensor.hh @@ -0,0 +1,24 @@ +/* + * DeviceTypeSensor.hh + * + * Created on: Feb 28, 2011 + * Author: lamikr + */ + +#ifndef DEVICETYPESENSOR_HH_ +#define DEVICETYPESENSOR_HH_ + +#include + +#include "DeviceTypeGeneric.hh" + +namespace plp { + class DeviceTypeSensor : public DeviceTypeGeneric { + public: + virtual std::string get_unit() = 0; + virtual plp::Data *get_data() = 0; + virtual void save_data() = 0; + }; +} + +#endif /* DEVICETYPESENSOR_HH_ */ diff --git a/src/Makefile.am b/src/Makefile.am index 9c6cb21..4ec0e88 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,17 +1,19 @@ lib_LTLIBRARIES = lib1wire.la lib1wire_la_SOURCES = \ + Data.cc Data.hh \ + Date.cc Date.hh \ + DeviceConfig.cc DeviceConfig.hh \ + DeviceData.cc DeviceData.hh \ + DeviceTypeGeneric.hh \ + DeviceTypeSensor.hh \ Factory.cc Factory.hh \ - W1Device.cc W1Device.hh \ Store.cc Store.hh \ StoreDay.cc StoreDay.hh \ StoreCache.cc StoreCache.hh \ - W1TemperatureSensor.cc W1TemperatureSensor.hh \ W1CounterDevice.cc W1CounterDevice.hh \ + W1Device.cc W1Device.hh \ + W1TemperatureSensor.cc W1TemperatureSensor.hh \ W1Util.cc W1Util.hh \ - DeviceData.cc DeviceData.hh \ - DeviceConfig.cc DeviceConfig.hh \ - Data.cc Data.hh \ - Date.cc Date.hh \ W1Configure.hh lib1wire_la_LDFLAGS = $(SRC_LIBS) $(all_libraries) -version-info 1:0:0 -no-undefined AM_CPPFLAGS = $(SRC_CFLAGS) @@ -24,11 +26,13 @@ lib1wireinclude_HEADERS = \ Date.hh \ DeviceConfig.hh \ DeviceData.hh \ + DeviceTypeGeneric.hh \ + DeviceTypeSensor.hh \ Factory.hh \ - W1CounterDevice.hh \ - W1Device.hh \ Store.hh \ StoreDay.hh \ StoreCache.hh \ + W1CounterDevice.hh \ + W1Device.hh \ W1TemperatureSensor.hh \ W1Util.hh \ No newline at end of file diff --git a/src/W1Device.cc b/src/W1Device.cc index 781ef6d..4c108e3 100644 --- a/src/W1Device.cc +++ b/src/W1Device.cc @@ -85,7 +85,7 @@ void W1Device::printout() { Data *data; string text; - data = get_and_collect_data(); + data = get_data(); if (data != NULL) { text = data->to_string(); cout << text << endl; @@ -104,8 +104,7 @@ string W1Device::to_string(double dbl_val, int digit_count) { return ret_val; } - -Data *W1Device::get_and_collect_data() { +Data *W1Device::get_data() { Data *ret_val; vector *vect; diff --git a/src/W1Device.hh b/src/W1Device.hh index e5de6d9..d1371e9 100644 --- a/src/W1Device.hh +++ b/src/W1Device.hh @@ -15,6 +15,7 @@ #include #include "Data.hh" +#include "DeviceTypeSensor.hh" #ifndef W1_SCAN_ROOTDIR #define W1_SCAN_ROOTDIR "/sys/bus/w1/devices" @@ -25,7 +26,7 @@ #endif namespace w1 { - class W1Device { + class W1Device : public plp::DeviceTypeSensor { public: W1Device(int family_code_param, std::string device_id_param, @@ -35,11 +36,9 @@ namespace w1 { std::string get_id(); std::string get_name(); void set_name(std::string name_param); - virtual std::string get_unit() = 0; - virtual std::string get_device_type() = 0; - plp::Data *get_and_collect_data(); - virtual void save_data(); - virtual void printout(); + void printout(); + plp::Data *get_data(); + void save_data(); protected: virtual std::vector *get_raw_data() = 0; virtual unsigned int get_data_decimal_precision() = 0; -- 2.41.1