16 #include <sys/types.h> 53 string dataSetRegex = string(dataSet) +
"\\.csv$";
54 vector<ISFileManager::file_info_t> infos;
57 if (infos.size() != 0)
62 for (
size_t i = 0; i < infos.size(); i++)
64 files.push_back(infos[i].
name);
66 m_currentFiles[id] = files;
67 m_currentFileIndex[id] = 0;
68 while (OpenNewFile(log,
true) && !GetNextLineForFile(log)) {}
83 for (map<uint32_t, cCsvLog>::iterator i = m_logs.begin(); i != m_logs.end(); i++)
100 if (dataSetName ==
NULL)
113 if (m_directory.empty())
118 _MKDIR(m_directory.c_str());
121 uint32_t serNum = m_devInfo.serialNumber;
131 uint32_t index = m_currentFileIndex[log.
dataId];
132 vector<string>& files = m_currentFiles[log.
dataId];
133 if (index >= files.size())
138 string currentFile = files[index++];
139 m_currentFileIndex[log.
dataId] = index;
140 log.
pFile = fopen(currentFile.c_str(),
"r");
143 stat(currentFile.c_str(), &st);
155 string fileName = GetNewFileName(serNum, log.
fileCount, dataSetName);
156 log.
pFile = fopen(fileName.c_str(),
"w");
159 int fileBytes = m_csv.WriteHeaderToFile(log.
pFile, log.
dataId);
163 m_logSize += fileBytes;
190 char lineBuffer[8192];
196 size_t index = log.
nextLine.find(
',', 0);
224 memcpy(&m_devInfo, dataBuf,
sizeof(
dev_info_t));
228 int nBytes = m_csv.WriteDataToFile(++m_nextId, log.
pFile, *dataHdr, dataBuf);
229 if (ferror(log.
pFile) != 0)
254 if (m_logs.size() == 0)
261 uint64_t nextId = ULLONG_MAX;
262 for (map<uint32_t, cCsvLog>::iterator i = m_logs.begin(); i != m_logs.end(); )
264 if (i->second.orderId < nextId)
266 nextLog = &i->second;
276 if ((data = ReadDataFromFile(*nextLog)) ==
NULL)
293 m_dataBuffer.hdr.id = log.
dataId;
294 m_dataBuffer.hdr.size = log.
dataSize;
299 memcpy(&m_devInfo, m_dataBuffer.buf,
sizeof(
dev_info_t));
302 while (!GetNextLineForFile(log) && OpenNewFile(log,
true)) {}
303 return &m_dataBuffer;
306 while (!GetNextLineForFile(log) && OpenNewFile(log,
true)) {}
313 m_devInfo.serialNumber = serialNumber;
static const char * GetDataSetName(uint32_t dataId)
p_data_t * ReadDataFromFile(cCsvLog &log)
void OnReadData(p_data_t *data)
virtual bool CloseAllFiles()
void SetSerialNumber(uint32_t serialNumber) OVERRIDE
bool GetNextLineForFile(cCsvLog &log)
vector< data_info_t > columnHeaders
virtual bool SaveData(p_data_hdr_t *dataHdr, const uint8_t *dataBuf)
bool OpenNewFile(cCsvLog &log, bool readOnly)
virtual void InitDeviceForWriting(int pHandle, string timestamp, string directory, uint64_t maxDiskSpace, uint32_t maxFileSize)
#define _ARRAY_BYTE_COUNT(a)
static uint32_t GetSize(uint32_t dataId)
void InitDeviceForReading() OVERRIDE
bool SaveData(p_data_hdr_t *dataHdr, const uint8_t *dataBuf) OVERRIDE
void InitDeviceForWriting(int pHandle, std::string timestamp, std::string directory, uint64_t maxDiskSpace, uint32_t maxFileSize) OVERRIDE
USBInterfaceDescriptor data
virtual void InitDeviceForReading()
uint64_t GetDirectorySpaceUsed(const std::string &directory, bool recursive)
p_data_t * ReadData() OVERRIDE
bool CloseAllFiles() OVERRIDE