4 * Created on: Oct 31, 2010
15 #include <sys/types.h>
24 std::string W1Store::location = "/tmp/";
27 // TODO Auto-generated constructor stub
31 // TODO Auto-generated destructor stub
34 void W1Store::set_location(string location_param) {
35 string::size_type pos;
37 location = location_param;
38 pos = location.find_last_of("/");
39 if (pos != location.length()) {
40 location = location + "/";
45 void W1Store::store(std::string device_id, std::list<std::string> *string_list) {
58 ltime = localtime(&wtime);
59 strftime(buffer, 80, "%Y", ltime);
61 strftime(buffer, 80, "%m", ltime);
63 strftime(buffer, 80, "%Y-%m-%d", ltime);
66 struct tm * gmtime(const time_t *timer);
67 struct tm * localtime(const time_t * timer);
70 file_path = location + year;
71 if (stat(file_path.c_str() ,&st) != 0) {
72 mkdir(file_path.c_str(), 0755);
74 file_path = file_path + "/" + month;
75 if (stat(file_path.c_str() ,&st) != 0) {
76 mkdir(file_path.c_str(), 0755);
78 file_path = file_path + "/" + device_id + "_" + date + ".txt";
79 ofstream data_file(file_path.c_str(), ios::app);
80 cout << "storing to " << file_path << ", data size " << string_list->size() << endl;
81 // TODO: add mutex to protect string_list while it's read and emptied
82 if (data_file.is_open()) {
83 while(string_list->size() > 0) {
84 text_line = string_list->front();
85 string_list->pop_front();
86 if (text_line.length() > 0) {
87 cout << "storing line: " << text_line << endl;
88 data_file << text_line << endl;
94 cout << "could not open file " << file_path << " for writing data." << endl;