Tezzeret  1
Tezzeret
GmStorage.hpp
1 /*
2  * GmStorage.hpp
3  *
4  * Created on: May 10, 2016
5  * Author: rcram
6  */
7 
8 #ifndef GM_STORAGE_H_
9 #define GM_STORAGE_H_
10 
11 typedef unsigned long DWORD;
12 
13 #include <geotypes.hpp>
14 
15 
16 #ifdef acs
17 #include <xdc/runtime/Types.h>
18 #endif
19 
20 /* Error and return codes. */
21 #define GM_STORAGE_OK 0
22 #define GM_STORAGE_FAIL -1
23 #define GM_STORAGE_ERROR 1
24 #define GM_STORAGE_EOF 2
25 #define GM_STORAGE_DATA_TOO_LARGE 3
26 #define GM_STORAGE_NO_SD_STORAGE_CREATED 4
27 #define GM_STORAGE_NO_USB_STORAGE_CREATED 5
28 #define GM_STORAGE_NO_TOPIC 6
29 #define GM_STORAGE_BAD_TOPIC 7
30 #define GM_STORAGE_UNKNOWN_OPEN_MODE 8
31 #define GM_STORAGE_CANT_BUILD_DATA_SET_NAME 9
32 #define GM_STORAGE_STRING_TOO_LONG 10
33 #define GM_STORAGE_ERROR_390 11
34 #define GM_STORAGE_CANT_DELETE_SURVEY 12
35 #define GM_STORAGE_CANT_VERIFY 13
36 #define GM_STORAGE_FAIL_SDSPI_OPEN 14
37 #define GM_STORAGE_BUFFER_NOT_EMPTY 15
38 #define GM_STORAGE_WRITE_ZERO_LENGTH 16
39 #define GM_STORAGE_FILE_NOT_FOUND 17
40 #define GM_STORAGE_SURVEY_ALREADY_ACTIVE 18
41 #define GM_STORAGE_CURRENTLY_LOGGING 19
42 #define GM_STORAGE_DIRECTORY_NOT_FOUND 20
43 #define GM_STORAGE_ACQUISITION_ALREADY_OPEN 21
44 #define GM_STORAGE_BUFFER_TOO_SMALL 22
45 #define GM_STORAGE_NO_ACTIVE_SURVEY 23
46 #define GM_STORAGE_NO_ACTIVE_ACQUISITION 24
47 #define GM_STORAGE_SURVEY_NOT_FOUND 25
48 #define GM_STORAGE_ACQUISITION_HAS_FILES 26
49 #define GM_STORAGE_ACQUISITION_HAS_NO_FILES 27
50 #define GM_STORAGE_FILE_EXISTS 28
51 #define GM_STORAGE_FLUSH_FAILED 29
52 #define GM_STORAGE_FILE_SYSTEM_NOT_READY 30
53 #define GM_STORAGE_NO_FILE_FOUND 31
54 #define GM_STORAGE_CANT_CREATE_DIRECTORY 32
55 #define GM_STORAGE_CANT_DELETE_FILE 33
56 #define GM_STORAGE_CANT_DELETE_DIRECTORY 34
57 #define GM_STORAGE_NO_CACHED_SIZE_FOUND 35
58 #define GM_STORAGE_ALREADY_CLOSED 36
59 #define GM_STORAGE_FILE_NOT_OPEN 37
60 #define GM_STORAGE_INTERNAL_ERROR_BASE 100
61 
62 /* Flags for opening and closing files */
63 #define GM_STORAGE_NO_FLAGS (0x0000)
64 #define GM_STORAGE_CLOSE_ROLLOVER (GM_STORAGE_NO_FLAGS)
65 #define GM_STORAGE_STOPPING_ACQUISITION (0x0001)
66 #define GM_STORAGE_DO_NOT_REPORT (0x0002)
67 #define GM_STORAGE_DO_NOT_LOCK (0x0004)
68 
69 namespace Geometrics
70 {
71  typedef char** GmSessionNames;
72  #define MAX_SURVEY_ID_LENGTH 10
73  #define MAX_ACQUISITION_ID_LENGTH 10
74  #define MAX_ACQUISITION_NAME_LENGTH 20
75  #define MAX_SURVEY_NAME_LENGTH 20
76  #define GM_DEFAULT_SURVEY_NAME "DEFAULT"
77  #define MAX_DATA_FILE_SHORT_NAME_LENGTH 20
78 
79 
80  class GmStorage
81  {
82  public:
83  // virtual int Open (const char* zName,
84  // const char* szReadWrite) { return 0; };
85  GmStorage ();
86  virtual int Close (int iFileIndex) { return 0;};
87 
88  // Without this variable defined in a cpp file, the CCS linker won't find a place
89  // for the vtable for this class. Hacky. Maybe find some real functionality
90  // in here.
91  virtual int WriteData (const char* pcData,
92  unsigned int iDataSize,
93  UInt32 ui32Topic) = 0;
94 
95  /***********************************************************************************/
96  /* Some storages need to treat some groups of writes as single transactions. For */
97  /* example, file storages may decide to roll over to a new physical file after */
98  /* some number of writes. In the case of array writes, when the header gets */
99  /* written and then a set of records gets written, the file storage must */
100  /* put the array header and all of the individual records all in the same file, */
101  /* and roll over only after the end. The default behavior for storages */
102  /* is a NOP. EnterTransaction and LeaveTransaction handle this feature. */
103  /***********************************************************************************/
104  virtual int EnterTransaction () { return GM_STORAGE_OK; };
105  virtual int LeaveTransaction () { return GM_STORAGE_OK; };
106  virtual int RollAndSynchFile () { return GM_STORAGE_OK; };
107  virtual int SelectSurveyEx (const char *strSurveyId) { return GM_STORAGE_FAIL; };
108  //virtual int IsFileStorage () { return FALSE; };
109  virtual int IsDataStorage () { return FALSE; };
110 
111 
112 
113  virtual int GetLastError () { return -1; };
114 
115  virtual ~GmStorage ();
116 
117  /*******************************************************************************************/
118  /* IsOpen is declared here, and also defined, in order to provide a model of the function */
119  /* throughout the class tree derived from GmStorage. BUT, we don't want to rely on this */
120  /* implementation, so it will break. If you develop code that requires IsOpen(), then */
121  /* you must develop for the correction semantics for that class. */
122  /*******************************************************************************************/
123  virtual bool IsOpen () { return m_bIsOpen; /* m_bIsOpen;*/ };
124 
125  /* TODO RHC really should be SetAttribute, or something generic, because this is pushing
126  * survey information down into the base class.
127  */
128  /* Push a known datasetID into the storage. */
129  void SetDatasetId (const int iDataset);
130 
131  /* Get the current dataset ID. Optionally, increment */
132  /* The result will be a positive integer */
133  int GetDatasetId (bool increment);
134 
135 
136  virtual int Shutdown () { return 0; };
137 
138  static int s_recordsPerFile;
139 
140  static int DecodeDownloadName(const char *szDownloadName,
141  char *strSurveyId,
142  char *strAcquisitionId,
143  char *strFileName);
144 
145 
146  protected:
147  bool m_bIsOpen;
148  int m_iCurrentDataSetId;
149  bool mIncrementDatasetId;
150  };
151 }
152 
153 #endif
Definition: GmStorage.hpp:81
GmApp/GmLoggingApp.hpp>
Definition: Analogs.hpp:47