00001 #include <sys/types.h>
00002 #include <sys/stat.h>
00003 #include <fcntl.h>
00004 #include <unistd.h>
00005 #include <errno.h>
00006 #include <string>
00007 #include "log.h"
00008 #include "data.h"
00009
00010 Data::Data()
00011 {
00012 }
00013
00014 void Data::Load(std::string _filename)
00015 {
00016 filename = _filename;
00017 ConfigImpl::Load(filename);
00018 }
00019
00020 void Data::Save()
00021 {
00022 int fd = open(filename.c_str(), O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
00023 if(fd == -1)
00024 {
00025 log(LogError, "Couldn't open data file %s : %s", filename.c_str(), strerror(errno));
00026 return;
00027 }
00028
00029 std::string conf = GetAsString();
00030
00031 if(write(fd, conf.c_str(), conf.size()) == -1)
00032 log(LogError, "Couldn't write data to file %s : %s", filename.c_str(), strerror(errno));
00033
00034 close(fd);
00035 log(LogInfo, "Data saved into %s", filename.c_str());
00036 }