Tezzeret  1
Tezzeret
GeoFatFsSurveyStorage.hpp
1 #ifndef GM_TIVA_FATFS_STORAGE_HPP_
2 #define GM_TIVA_FATFS_STORAGE_HPP_
3 
4 #include <stdio.h>
5 #include <string.h>
6 #include <stdlib.h>
7 #include <stdbool.h>
8 #include <GmFatFs/ff.h>
9 #include "GeoFatFsStorage.hpp"
10 #include <functional>
11 
12 
13 namespace Geometrics
14 {
15 
16 #define FIRST_AVAILABLE_ACQUISITION_FILE -1
17 
19  {
20  public:
22 
23  /* The destructure is virtual, because some storages are deleted in
24  * base class context.
25  */
26  virtual ~GeoFatFsSurveyStorage ();
27  int QuitAcquisition (int iAcquisitionIndex);
28  virtual int Close (int iFileIndex);
29 
30  int WriteData (const char* pcData,
31  unsigned int iDataSize,
32  UInt32 ui32Topic);
33  int SetSessionFolder (const char* *szSurveyName,
34  const int iSessionId);
35  int SetSessionFileName (const char* *szFileName,
36  const int iSessionId);
37  int RunTestSuite ();
38  int ForEachFileInfo (const char *strSurveyId,
39  const char *strAcquisitionId,
40  std::function<void (FILINFO *fInfo)> handler);
41  int ListDataFilesEx (const char *strSurveyId,
42  const char *strAcqusitionId,
43  char pSessions[20][12],
44  //GmSessionNames *psnSessions,
45  int iMaxFiles,
46  int *piFilesCounted,
47  int *piFilesReturned);
48 
49  int ListAcquisitions (const char *strSurveyId,
50  GmSessionNames *psnSessions);
51  int GetSessionDataSize (int iAcquisitionIndex,
52  char* szSessionName,
53  UInt32* uiSize);
54  int SessionTimeString (int iAcquisitionIndex,
55  char *szSessionName,
56  char *szDestination);
57 
58  /****************************************************************************/
59  /* Functions for survey/acquisition/file structure. */
60  /****************************************************************************/
61  int CreateNextSurveyEx (const char *strName,
62  char *pcNewIdBuffer,
63  int iBufferLength);
64 
65  int GetActiveSurveyEx (char *szAnswerBuffer,
66  int iAnswerBufferSize);
67  #if EMBEDDED_DATA_STORAGE == GEO_TRUE
68  int CreateNewSurveyEx (const char *strId,
69  const char *strName);
70  int GetAcquisitionInfoEx (const char *szSurveyId,
71  const char *szAcquisitionId,
72  char *szAcquisitionNameBuffer,
73  int iAcquisitionNameBufferSize,
74  bool *pFilesInDirectories,
75  int *pDirectorySize);
76  int GetAcquisitionCachedLastFile (const char *szSurveyId,
77  const char *szAcquisitionId,
78  int *pLastFileCounted);
79  int LoadAcquisitionInfoEx (const char *szSurveyId,
80  const char *szAcquisitionId);
81  int CreateAcquisitionEx (char *szSurveyId,
82  const char *strAcquisitionId,
83  const char *szNewAcquisitionName) ;
84  int CreateNextAcquisitionEx (char *szSurveyId,
85  const char *szNewAcquisitionName,
86  char *pcNewAcquisitionIdBuffer,
87  int iAcquisitionIdBufferLength);
88  int AddAcquisitionInfoEx (const char *strSurveyId,
89  const char *strAcquisitionId,
90  const char *iAcquisitionName,
91  Bool filesInDirectories,
92  int directorySize);
93  int SaveSurveyInfoEx (const char *szSurveyId,
94  const char *szName,
95  Bool filesInDirectories);
96  int ListAcquisitionsEx (char **ppcResponse,
97  const char *szSurveyId);
98  int ListAcquisitionsEx2 (char **ppcResponse,
99  const char *szSurveyId,
100  const Bool includeSizes);
101  int ListSurveysJsonEx (char **ppcResponse);
102  int ListDataFilesJsonEx (char **ppcResponse,
103  const char *strSurveyId,
104  const char *strAcquisitionId);
105  int ListDataFilesJsonEx2 (char **ppcResponse,
106  const char *strSurveyId,
107  const char *strAcquisitionId);
108  #endif
109  int GetActiveAcquisitionEx (char *szSurveyBuffer,
110  int iSurveyBufferSize,
111  char *szAcquisitionBuffer,
112  int iAcquisitionBufferSize);
113  int GetAcquisitionCachedSize (const char *szSurveyId,
114  const char *szAcquisitionId,
115  int *pLastFileCounted,
116  uint32_t *pRecordedSize);
117  int AcquisitionIsSet ();
118  int AddSurveyInfoEx (int iSurveyIndex,
119  char *szSurveyName);
120  int SelectSurveyEx (const char *strSurveyId);
121  int CloseCurrentSurveyEx ();
122  int CloseCurrentAcquisitionEx ();
123  int SelectAcqJsonEx (const char *strSurveyId,
124  const char *strAcquisitionId);
125  int AcquisitionExistsEx (const char *strSurveyId,
126  const char *strAcquisitionId);
127  int SelectAcqEx (const char *strSurveyId,
128  const char *strAcquisitionId);
129  int SurveyExistsEx (const char *strSurveyId);
130  int OpenNextFileEx (int iLastFile,
131  const char *szOpenMode);
132  int FindSurveyByNameEx (const char *strSurveyName,
133  char *strIdBuffer,
134  const int iBufferSize);
135  int DeleteAcquisitionEx (const char *strSurveyId,
136  const char *szAcquisitionId);
137  int CleanOldFiles ();
138  int AcquisitionTotalSize (const char *strSurveyId,
139  const char *strAcquisitionId,
140  UInt32 *pTotalSize,
141  int32_t *pLastFileIndex);
142  int AcquisitionLastFile (const char *strSurveyId,
143  const char *strAcquisitionId,
144  int32_t *pLastFileIndex);
145 
146 
147  /************************************************************************/
148  /* Delete acquisition including contained files. */
149  /************************************************************************/
150  int DeleteFullAcquisitionEx (const char *strSurveyId,
151  const char *szAcquisitionId);
152  int FileDataSizeEx (const char *strSurveyId,
153  const char *strAcquisitionId,
154  const char *strFileName,
155  UInt32* uiSize,
156  const bool filesInDirectories,
157  const int directorySize);
158  int FileDataSizeEx (const char *strSurveyId,
159  const char *strAcquisitionId,
160  const int fileIndex,
161  UInt32* uiSize,
162  const bool filesInDirectories,
163  const int directorySize);
164 
165  int SurveyFileDataSize (const char *strSurveyId,
166  const char *strAcquisitionId,
167  bool filesInDirectories,
168  int directorySize,
169  int fileIndex,
170  uint32_t *fileSize);
171 
172  static int FileTimeToString (FILINFO *fno,
173  char *szDestination);
174  int FileTimeStringEx (const char *strSurveyId,
175  const char *strAcquisitionId,
176  const char *strFileName,
177  char *szDestination);
178  int OpenDataFileToRead (const char *strSurveyId,
179  const char *strAcquisitionId,
180  const char *strFileName);
181  int OpenDataFileToRead (const char *strSurveyId,
182  const char *strAcquisitionId,
183  const int fileIndex,
184  const bool filesInDirectories,
185  const int directorySize);
186  static int DecodeDownloadName (const char *szDownloadName,
187  char *strSurveyId,
188  char *strAcquisitionName,
189  char *strFileName);
190  static int BuildDownloadName (const char *strSurveyId,
191  const char *strAcquisitionId,
192  const char *strFileName,
193  char *szDest);
194  int DeleteDataFileEx (const char *strSurveyId,
195  const char *strAcquisitionId,
196  const char *strFileName);
197 
198  /****************************************************************************/
199  /* Overrides */
200  /****************************************************************************/
201  Int GetLastError ();
202 
203  #if (GEO_DATA_STORAGE == GEO_TRUE)
204  int RollAndSynchFile ();
205  #endif
206 
207 
208  public:
209  void InitPaths ();
210 
211 
212  protected:
213  int m_iNextFileIndex;
214  char m_szCurrentActiveSurveyId[MAX_SURVEY_ID_LENGTH+1],
215  m_szCurrentActiveAcquisitionId[MAX_ACQUISITION_ID_LENGTH+1];
216  Bool m_filesInDirectories,
217  m_directoriesNested,
218  m_directoryInfoLoaded;
219  int m_directorySize;
220 
221 
222  int SearchNextFileIndex (char *strSurveyPath,
223  int *iNextNumber,
224  Bool filesInDirectories,
225  int directorySize);
226  int FindNextFileName (char *dest,
227  const char *strSurveyPath,
228  int *iNextNumber,
229  Bool bIsText,
230  Bool filesInDirectories,
231  int directorySize);
232  int BuildOutputFileName (char *szDest, int iPathIndex, int iFileIndex, bool inDirectories,
233  int directorySize, bool bIsText);
234  int BuildDataSetName (char *szDest, int iPathIndex, char *strDataSet);
235  int BuildOutputFileName (char *szDest, char* strSurveyPath, int iIndex, bool inDirectories,
236  int directorySize,
237  bool bIsText);
238  int GetAcquisitionPath (char *szDest, int iIndex);
239  static int GetAcquisitionDirectory (char *szDest, const char *strSurveyId, const char *strAcquisitionId);
240  int WriteNameBase (char *szDest, int iIndex );
241 
242  /****************************************************************************/
243  /* Internal functions for survey/acquisition/file structure. */
244  /****************************************************************************/
245  int FindNextSurveyIndexEx (int *iDest);
246  int FindNextAcquisitionIdEx (const char *strSurveyId,
247  char *pNewAcquisitionIdBuffer,
248  int iBufferLength);
249  int CreateSurveyDirectoryEx (const char *szNewSurveyId);
250  int GetSurveyPath (char *szDest, int iIndex);
251  static int GetSurveyPathEx (char *szDest, const char *szSurveyId);
252  static int GetAcquisitionPathEx (const char *szSurveyId,
253  const char *strAcqId,
254  char *strBuffer,
255  int iBufferLength);
256  int CountAcquisitionFilesEx (const char *strSurveyId,
257  const char *strAcquisitionId,
258  int *iCounter);
259 
260  /************************************************************************/
261  /* Delete all the files in an acquisition . */
262  /************************************************************************/
263  int DeleteAcquisitionFilesEx (const char *strSurveyId,
264  const char *strAcquisitionId);
265  int DeleteAcquisitionConfigFileEx (const char *strSurveyId,
266  const char *strAcquisitionId);
267  int CreateAcquisitionDirectoryEx (const char *szSurveyId,
268  const char *strAcqId);
269  int MakeSurveyId (char *pcDest, const int iBufferSize,
270  const int iNewSurveyIndex);
271  int MakeAcquisitionIdEx (char *pcDest, const int iBufferSize,
272  const int iNewAcquisitionIndex);
273  int OpenNextFileEx ( const char *strAcquisitionDirectory,
274  int iLastFile,
275  const char *szOpenMode);
276  int GetAcquisitionConfigFilePath (const char *strSurveyId,
277  const char *strAcquisitionId,
278  char *buffer,
279  const int iBufferSize);
280  int BuildDataFileNameEx (const char *strSurveyId,
281  const char *strAcquisitionId,
282  const char *strFileName,
283  char *strBuffer,
284  int iMaxBufferSize,
285  const bool filesInDirectories,
286  const int directorySize);
287  int BuildDataFileNameEx (const char *strSurveyId,
288  const char *strAcquisitionId,
289  const int fileIndex,
290  char *strBuffer,
291  int iMaxBufferSize,
292  const bool filesInDirectories,
293  const int directorySize);
294  public:
295 
296  /* Sometimes we want a simple, non-survey, file of the same storage
297  * type as this.
298  */
299  virtual GeoFatFsSurveyStorage *GetSimilarStorage () = 0;
300 
301  public:
302 
304  {
305  public:
306  virtual GeoFatFsSurveyStorage *MakeNewSurveyStorage () { return NULL; };
307  int i;
308  };
309 
310  // static int s_recordsPerFile;
311  static ISurveyStorageFactory *s_pSurveyStorageFactoryPrimary,
312  *s_pSurveyStorageFactoryZero,
313  *s_pSurveyStorageFactoryOne;
314  static ISurveyStorageFactory *GetFactory (const char whichFactory);
315  static void SetFactory (const char whichStorage, ISurveyStorageFactory *pFactory);
316 
317 
318  private:
319  /*************************************************************************/
320  /* m_iDataset is the identifier for data obtained between any one */
321  /* START and its corresponding STOP action. */
322  /*************************************************************************/
323  //int m_iCurrentDataSetId;
324  int WriteHeader ();
325 
326  /************************************************************************/
327  /* See explanation of transactions in GMStorage.hpp */
328  /************************************************************************/
329  Bool m_bInTransaction;
330  int mWritesCounted;
331  /* How many records to write before rolling to next file. */
332  int CheckToFlush ();
333  virtual int EnterTransaction () { m_bInTransaction = TRUE; return GM_STORAGE_OK; };
334  virtual int LeaveTransaction ();
335  };
336 }
337 
338 
339 
340 #endif /* GMTIVASDSTORAGE_HPP_ */
Definition: GeoFatFsStorage.hpp:38
Definition: GeoFatFsSurveyStorage.hpp:304
Definition: GeoFatFsSurveyStorage.hpp:19
GmApp/GmLoggingApp.hpp>
Definition: Analogs.hpp:47