+/*
+ * W1Store.cc
+ *
+ * Created on: Oct 31, 2010
+ * Author: lamikr
+ */
+
+#include <list>
+#include <string>
+#include <iostream>
+#include <fstream>
+
+#include <time.h>
+
+#include "W1Store.hh"
+
+using namespace std;
+using namespace w1;
+
+std::string W1Store::location = "/tmp/";
+
+W1Store::W1Store() {
+ // TODO Auto-generated constructor stub
+}
+
+W1Store::~W1Store() {
+ // TODO Auto-generated destructor stub
+}
+
+void W1Store::set_location(string location_param) {
+ location = location_param;
+}
+
+void W1Store::store(std::string device_id, std::list<std::string> string_list) {
+
+ string file_path = location + device_id + ".txt";
+ string text_line;
+ ofstream data_file(file_path.c_str(), ios::app);
+
+ cout << "storing to " << file_path << ", data size " << string_list.size() << endl;
+ // TODO: add mutex to protect string_list while it's read and emptied
+ if (data_file.is_open()) {
+ while(string_list.size() > 0) {
+ text_line = string_list.front();
+ string_list.pop_front();
+ if (text_line.length() > 0) {
+ cout << "storing line: " << text_line << endl;
+ data_file << text_line << endl;
+ }
+ }
+ data_file.close();
+ }
+ else {
+ cout << "could not open file " << file_path << " for writing data." << endl;
+ }
+}