]> pilppa.org Git - lib1wire.git/blobdiff - src/W1Device.cc
Started defining generic device type base classes that could be used
[lib1wire.git] / src / W1Device.cc
index a765cd36a6091432b4d2577ae6828efc3f36694b..4c108e3857fdb500c5a296c3f3b2f8809212cc72 100644 (file)
 #include <time.h>
 #include <plp/log.h>
 
-#include "W1Store.hh"
+#include "DeviceConfig.hh"
+#include "Factory.hh"
+#include "StoreDay.hh"
 #include "W1Device.hh"
 
-using namespace w1;
 using namespace std;
+using namespace w1;
+using namespace plp;
 
 W1Device::W1Device(int family_code_param,
                string device_id_param,
@@ -29,10 +32,10 @@ W1Device::W1Device(int family_code_param,
        temp_str        = W1_SLAVE_FILE;
        dir_path        = rootdir + "/" + direntry_param->d_name;
        slave_file      = dir_path + "/" + temp_str;
-       log_debug("w1 data file: %s\n", slave_file.c_str());
+       log_debug("1-wire device's data file: %s\n", slave_file.c_str());
        family_code     = family_code_param;
        id              = device_id_param;
-       name            = device_id_param;
+       name            = "";
 }
 
 W1Device::~W1Device() {
@@ -55,18 +58,34 @@ string W1Device::get_id() {
 }
 
 string W1Device::get_name() {
+       DeviceConfig    *cfg;
+
+       if (name.empty() == true) {
+               cfg     = Factory::get_device_config(id);
+               if (cfg != NULL) {
+                       name    = cfg->get_cfg_value("name");
+                       delete(cfg);
+               }
+       }
        return name;
 }
 
 void W1Device::set_name(string name_param) {
+       DeviceConfig    *cfg;
+
        name    = name_param;
+       cfg     = Factory::get_device_config(id);
+       if (cfg != NULL) {
+               cfg->set_cfg_value("name", name_param);
+               delete(cfg);
+       }
 }
 
 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;
@@ -85,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;
 
@@ -111,7 +129,7 @@ void W1Device::save_data() {
        int                     dec_precision;
 
        dec_precision   = get_data_decimal_precision();
-       W1Store::save(id, &memory_cache, dec_precision);
+       StoreDay::save(id, &memory_cache, dec_precision);
        for(iter = memory_cache.begin(); iter != memory_cache.end(); iter++) {
                data    = (Data *)*iter;
                delete(data);