versadac  1
versadac - Scalable Recorder Firmware
am_archiver.h
1 /*****************************************************************************
2 FILE : am_archiver.h
3 VERSION : $Id: am_archiver.h 4938 2006-10-10 14:20:18Z martinto $
4 AUTHOR : Steve Pickford
5 SYSTEM : GNU C++ for Power PC
6 DESCRIPTION : Archiver class declarations
7 *****************************************************************************/
8 
9 #ifndef __AM_ARCHIVER_H
10 #define __AM_ARCHIVER_H
11 
12 #include "OSTask.h"
13 
14 #include <hostLib.h>
15 
16 #include "am.h"
17 
18 #if !defined(__AM_CSV_H)
19 #include "am_csvstream.h"
20 #endif
21 
22 #ifndef __DRE_HIST_H
23 #include "dre_hist.h"
24 #endif
25 
26 #include "fb_archiver.h"
27 
28 /* Macros */
29 
30 #define SECS_PER_MIN (60)
31 #define SECS_PER_HOUR (60 * SECS_PER_MIN)
32 #define SECS_PER_DAY (24 * SECS_PER_HOUR)
33 #define SECS_PER_WEEK (7 * SECS_PER_DAY)
34 #define SECS_PER_MONTH (31 * SECS_PER_DAY)
35 
36 
37 /* Typedefs */
38 
39 enum AM_ArchiveFileAction
40 {
41  FILE_READ,
42  FILE_WRITE
43 };
44 
45 enum AM_ArchiveFtpServer
46 {
47  PRIMARY_FTP_SERVER,
48  SECONDARY_FTP_SERVER
49 };
50 
51 enum AM_ArchiveStatus
52 {
53  ARCHIVING_ACTIVE,
54  ARCHIVING_SUSPENDED,
55  MEDIA_FAILED,
56  MEDIA_FULL,
57  MEDIA_MISSING,
58  MEDIA_WRITE_PROTECTED
59 };
60 
61 enum AM_ArchiveType
62 {
63  DEMANDED,
64  UNATTENDED
65 };
66 
67 class AM_ArchiveManager;
68 
69 class AM_DemandArchive;
70 class AM_JobArchive;
72 
73 typedef struct
74 {
75  uint8 autoStrategy;
76  bool ftpPrimaryFailed;
77  bool ftpSecondaryFailed;
78  AM_DemandArchive **ppDemandArchive;
79  AM_UnattendedArchive **ppUnattendedArchive;
80  double *pTimeLastWrite;
81  uint8 *pUnattendedStrategy;
82  uint8 routeNumber;
83  uint8 status;
84  uint8 outputFormat;
85  bool stopArchive;
86  bool transferInProgress;
87  bool demandArchiveOK;
89 
91 {
92  public:
93 
94  friend class AM_ArchiveControl;
95 
96  // Methods
97  AM_Archiver(AM_ArchiveManager *z_pArchiveManager);
98 
99  virtual ~AM_Archiver();
100 
101  void accessTimeLastWriteFile(uint8 z_action);
102 
103  double calculateNextArchiveTime(double z_currentTime,
104  uint8 z_unattendedStrategy);
105 
106  DRE_SLICE_T *copyHistoryFilesToMedia(AM_RouteArchive *z_pRoute,
107  DRE_SLICE_T *z_pEarliestSlice,
108  DRE_SLICE_T *z_pLatestSlice,
109  DRE_SLICE_T *z_pActiveSlice,
110  uint32 z_activeSliceSize,
111  uint16 z_groupNumber,
112  uint8 z_archiveType,
113  bool *z_pTranslationStarted,
114  char *z_pszMediaRoot);
115  bool moreMediaSpace(uint32 z_requiredSize);
116  bool routeActive();
117  bool localeUS();
118  bool localefr();
119  uint8 getCurrentAutoStrategy();
120 
121  void detachFromQueues(void);
122 
123 #ifdef ARCHIVE_DEBUG
124  void displayTime(double z_time);
125 #endif
126 
127  DRE_SLICE_T *ftpHistoryFilesToServer(AM_RouteArchive *z_pRoute,
128  DRE_SLICE_T *z_pEarliestSlice,
129  DRE_SLICE_T *z_pLatestSlice,
130  DRE_SLICE_T *z_pActiveSlice,
131  uint32 z_activeSliceSize,
132  uint16 z_groupNumber,
133  uint8 z_server,
134  uint8 z_archiveType,
135  bool *z_pTranslationStarted);
136 
137  DRE_GROUP_HIST_T *getGroupHistoryPointer(uint16 z_groupNumber);
138 
139  bool getTransferInProgress(AM_RouteNumber z_routeNumber );
140  void lockDreHistory(void);
141  void lockDreSlice(DRE_SLICE_T *z_pSlice);
142  void runTask();
143  void sendGroupMessage(double z_time, uint8 z_msgClass, uint8 z_msgNum, uint16 z_groupNumber);
144  void sendSystemMessage(double z_time, uint8 z_msgClass, uint8 z_msgNum);
145  void sendMediaInsertedMessage(double z_time, uint16 z_groupNumber);
146  void setResourceStarting(void);
147  void signalUpdateComplete(void);
148  void stop();
149  void stopArchive(AM_RouteNumber z_routeNumber);
150  void unlockDreHistory(void);
151  void unlockDreSlice(DRE_SLICE_T *z_pSlice);
152  bool startTranslation();
153 
154  uint8 m_ActType;
155 
156  private:
157 
158  // Methods
159  uint8 calculateAutoStrategy(AM_RouteArchive *z_pRoute);
160 
161  double calculateTimeMediaFull(double z_currentTime);
162 
163  bool deleteOldestFile(uint32 z_uInstr, const char *z_szDirectory);
164  bool deleteFilesOfTime(uint32 z_uInstr, const char *z_szDirectory, uint32 z_ModTime);
165  uint32 findOldestFile(uint32 z_uInstr,
166  const char *z_szDirectory,
167  char* z_pOldestDir,
168  uint32 z_oldestModTime);
169  bool deletable( const char * z_szDirectory,
170  const char * z_szFileName,
171  uint32 z_uInstr );
172 
173  DRE_INSTR_HIST_T *getInstHistoryPointer(void);
174 
175  void getMediaStatus(char *z_pszMediaRoot, double *z_pMediaSize, double *z_pMediaFree);
176  void getMessage(exchange_id z_xid, uint32 *z_pMsg);
177  void initialiseArchiving(AM_RouteArchive *z_pRoute,
178  double z_currentTime);
179 
180  void makeFtpPath( char *z_pszFtpServer,
181  char *z_pszPath,
182  char *z_pszUser,
183  char *z_pszPassword );
184  void mediaRouteWait(uint32 z_seconds);
185  void performArchiving(double z_currentTime);
186  bool routeCanArchive(AM_RouteArchive *z_pRoute, double z_currentTime);
187  void sendMessage(exchange_id z_xid, uint32 *z_pMsg);
188  bool copyFileToMedia(FILE *z_pSourceFile,
189  uint32 z_sourceFileTime,
190  char *z_pFileDestPath,
191  DRE_SLICE_T *z_pSlice,
192  DRE_SLICE_T *z_pActiveSlice,
193  uint32 z_activeSliceSize);
194  bool ftpFileToServer(FILE *z_pSourceFile,
195  char *z_pszFtpServer,
196  char *z_pszUser,
197  char *z_pszPassword,
198  char *z_pszDestPath,
199  DRE_SLICE_T *z_pSlice,
200  DRE_SLICE_T *z_pActiveSlice,
201  uint32 z_activeSliceSize);
202  bool csvFileToMedia( FILE *z_pSourceFile,
203  uint32 z_sourceFileTime,
204  char *z_pszFileDestPath,
205  DRE_SLICE_T *z_pSlice,
206  DRE_SLICE_T *z_pActiveSlice,
207  uint32 z_activeSliceSize,
208  uint32 z_CsvMaxFileSize,
209  bool *z_pTranslationStarted);
210  bool csvFileToServer(FILE *z_pSourceFile,
211  char *z_pszFtpServer,
212  char *z_pszUser,
213  char *z_pszPassword,
214  char *z_pszDestPath,
215  DRE_SLICE_T *z_pSlice,
216  DRE_SLICE_T *z_pActiveSlice,
217  uint32 z_activeSliceSize,
218  bool *z_pTranslationStarted);
219  char * generateCsvFilename(char * pBatchName,
220  struct tm * pLocalStartTime,
221  struct tm * pLocalEndTime,
222  char * pDest);
223 
224  // Attributes
225  exchange_id m_amXid;
226  exchange_id m_dreXid;
227  double m_mediaFree;
228  uint16 m_mediaFullStrategy;
229  AM_CsvSetup m_csvSetup;
230 
231  bool m_mediaMissing;
232  double m_mediaSize;
233  uint16 m_numberOfGroups;
234  AM_ArchiveManager *m_pArchiveManager;
235  char *m_pFtpBuf;
236  DRE_INSTR_HIST_T *m_pInstHistory;
237  process_id m_pid;
238  AM_RouteArchive m_route[AM_NUMBER_OF_ROUTES];
239  bool m_resourceStarting;
240  queue m_systemQueue;
241  double m_timeMediaFull;
242  sint32 m_timeSegment;
243  bool m_timeZoneChanged;
244  sint32 m_timeZoneRawOffset;
245  uint8 m_ftpArchivingTooSlow;
246  uint8 m_mediaArchivingTooSlow;
247 
248  string_100 m_szUsbPath; // USB path
249 
250  // FTP server strings
251  char **m_pszFtpPath; // Array of remote paths, each up to 40 chars long
252  string_40 m_szFtpPrimaryPassword; // Primary password up to 40 chars
253  string_100 m_szFtpPrimaryServer; // Primary host up to 100 chars
254  string_40 m_szFtpPrimaryUser; // Primary user up to 40 chars
255  string_40 m_szFtpSecondaryPassword; // Secondary password up to 40 chars
256  string_100 m_szFtpSecondaryServer; // Secondary host up to 100 chars
257  string_40 m_szFtpSecondaryUser; // Secondary user up to 40 chars
258 
259  // Current archiving activity
260  AM_RouteArchive *m_pActRoute;
261  AM_ArchiveControl *m_pActControl;
262  char *m_pszMediaRoot;
263  string_100 m_szUnattendedMediaRoot;
264  string_100 m_szDemandedMediaRoot;
265  string_100 m_ActHistoryDestPath;
266  string_100 m_ActGroupDestPath;
267  string_100 m_ActFileDestPath;
268  string_100 m_CsvFileDestPath;
269  uint32 m_ActInstrumentId;
270  bool m_ActDeleteOK;
271  uint16 m_Wakeup; // Wake-up period, in scos ticks
272  uint8 *m_macAddress;
273  network_data_t *m_net_ramdata;
274  network_nvdata_t *m_net_nvdata;
275 };
276 
277 
278 /*---------------------------------------------------------------------------
279 FUNCTION : AM_Archiver::routeActive
280 DESCRIPTION : Accessor to check archiving on the current route still active
281 ARGUMENTS : None.
282 RETURN : TRUE if archiving active on the current route, FALSE if suspended.
283 NOTES :
284 ---------------------------------------------------------------------------*/
285 inline bool AM_Archiver::routeActive()
286 {
287  return(!m_bStop &&
288  (m_pActRoute != NULL) &&
289  !m_pActRoute->stopArchive &&
290  (m_pActRoute->status == ARCHIVING_ACTIVE));
291 }
292 
293 #endif // __AM_ARCHIVER_H
294 
Definition: ostask.h:16
Definition: dre_hist.h:19
Definition: am_archive.h:50
Definition: am_archiver.h:73
Definition: dre_hist.h:35
Definition: am_csvstream.h:49
Definition: stdtypes.h:204
Definition: am_archive.h:37
Definition: am_archiver.h:90
Definition: am_archivecontrol.h:39
Definition: stdtypes.h:223
Definition: stdtypes.h:213
Definition: dre_hist.h:54
Definition: am_manager.h:12