]> pilppa.com Git - lib1wire.git/commitdiff
Started defining generic device type base classes that could be used
authorMika Laitio <lamikr@pilppa.org>
Mon, 28 Feb 2011 19:52:26 +0000 (21:52 +0200)
committerMika Laitio <lamikr@pilppa.org>
Mon, 28 Feb 2011 19:52:26 +0000 (21:52 +0200)
also outside of lib1wire library eventually.

Signed-off-by: Mika Laitio <lamikr@pilppa.org>
src/DeviceTypeGeneric.hh [new file with mode: 0644]
src/DeviceTypeSensor.hh [new file with mode: 0644]
src/Makefile.am
src/W1Device.cc
src/W1Device.hh

diff --git a/src/DeviceTypeGeneric.hh b/src/DeviceTypeGeneric.hh
new file mode 100644 (file)
index 0000000..ba944a8
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * GenericDevice.hh
+ *
+ *  Created on: Feb 28, 2011
+ *      Author: lamikr
+ */
+
+#ifndef DEVICETYPEGENERIC_HH_
+#define DEVICETYPEGENERIC_HH_
+
+#include <string>
+
+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 (file)
index 0000000..99403ef
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * DeviceTypeSensor.hh
+ *
+ *  Created on: Feb 28, 2011
+ *      Author: lamikr
+ */
+
+#ifndef DEVICETYPESENSOR_HH_
+#define DEVICETYPESENSOR_HH_
+
+#include <string>
+
+#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_ */
index 9c6cb215c6cd06ad4c997d6783ea07270c2d15e3..4ec0e883ffe3d4a6869ceaaa296aa089acaa7887 100644 (file)
@@ -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
index 781ef6d878e2191a8f2fdc83f271d255a4e81494..4c108e3857fdb500c5a296c3f3b2f8809212cc72 100644 (file)
@@ -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<double>  *vect;
 
index e5de6d971cd0f0b9e233ea883e061fde3a56202f..d1371e9e5214a598bd267872bfef9a076789c03f 100644 (file)
@@ -15,6 +15,7 @@
 #include <stdbool.h>
 
 #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<double> *get_raw_data() = 0;
                        virtual unsigned int get_data_decimal_precision() = 0;