VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
snapshotManager.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2020 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 #pragma once
6 
7 #ifdef WIN32
8 #include <winsock2.h>
9 #endif
10 
11 #include "vrfcgf/vrfcgfDefines.h"
13 #include "vrfutil/rwUUID.h"
14 #include <vrfutil/objectCounter.h>
17 #include "vrfutil/scenario.h"
18 #include "vrfmsgs/ifSaveScenario.h"
19 #include <vlpi/simulationAddress.h>
20 #include <sstream>
21 #include <vector>
22 
23 #include <boost/unordered_map.hpp>
24 
25 class DtCgf;
27 class DtSimMessage;
28 class DtVrfCallbackQueue;
30 class DtConsoleCommand;
32 
35 #ifdef DtObjectDebugger_Enable
36  : public DtObjectDebugger<DtInMemorySnapshot>
37 #endif
38 {
39  DtInMemorySnapshot() : myId(0), mySimTime(0), myIsPeriodic(false) {};
40 
41  virtual ~DtInMemorySnapshot();
42 
43  int myId;
44  double mySimTime;
46 
47  typedef std::vector<std::string*> OOB;
49  std::string myPlans;
50  std::string myScenarioExtras;
51  std::string myScenarioScripts;
52  std::string myOrbat;
54 };
55 
56 using DtInMemorySnapshotPtr = std::shared_ptr<DtInMemorySnapshot>;
57 
59 
61 {
62 private:
66  DtSnapshotManager& operator=(const DtSnapshotManager&);
67 
68 public:
70  virtual ~DtSnapshotManager();
71 
72  virtual bool init();
73 
74  virtual void tick();
75 
78  virtual void setSimTime(double);
79 
81  virtual void setSnapshotsEnabled(bool flag);
82  virtual bool snapshotsEnabled() const;
83 
85  virtual void setSnapshotPeriod(double period);
86  virtual double snapshotPeriod() const;
87 
89  virtual void setCheckpointPeriod(double period);
90  virtual double checkpointPeriod() const;
91 
93  virtual void setNumberOfSnapshotsToKeep(int);
94  virtual int numberOfSnapshotsToKeep() const;
95 
98  virtual void setPauseCleanup(bool);
99  bool pauseCleanup() const { return myPauseCleanup; }
100 
101  virtual void clear(bool allButBase = false);
102 
104  virtual bool isBaseSnapshot(DtInMemorySnapshotPtr) const;
105 
108  virtual bool findScenarioFragment(const DtString& scenarioName, const DtString& runId, double simTime, DtScenario& scenario) const;
109 
113  virtual DtInMemorySnapshotPtr takeSnapshot(bool isPeriodic = false, bool makeBase = false);
114  virtual void saveCheckpoint(DtInMemorySnapshotPtr ptr);
115 
118  virtual void rollbackToSimTime(double simTime);
119 
121  virtual void rollbackTo(DtInMemorySnapshotPtr, const DtUUID& scenarioRunId = DtUUID::nullUUID());
122 
124  virtual void clearOutStaleSnapshots();
125 
127  virtual DtInMemorySnapshotPtr snapshotFor(int id) const;
128 
130  virtual void setSnapshotHeartbeatTime(double d);
131  virtual double snapshotHeartbeatTime() const;
132 
133  virtual void setCheckpointsEnabled(bool);
134  virtual bool checkpointsEnabled() const;
135 
137  virtual void sendCurrentSnapshots();
138 
141  virtual bool saveSnapshot(const DtFilename& saveFolder, DtCompressedFileTransporter& tr, DtIfSaveScenario* msg,
142  const DtScenario* currentScenario, const DtSimulationAddress& requestor);
143 
146  virtual DtInMemorySnapshotPtr snapshotClosestToSimTime(double simTime, const DtString& checkpointName = "", const DtString& runId = "") const;
147 
149  virtual void removeSnapshotsAfter(double simTime);
150 
152  virtual bool hasSnapshots() const;
153 
155  virtual void clearAllSnapshots();
156 
157  DtCgf* cgf() const
158  {
159  return myCgf;
160  }
161 
162  virtual unsigned int numberOfSaveJobsQueued() const;
163  virtual unsigned int maxQueuedSaveJobsBeforeSkip() const;
164 
166  virtual void setMaxQueuedSaveJobsBeforeSkip(unsigned int);
167 
169 protected:
170  static void clearAllSnapshotsCallback(DtSimMessage*, void*);
171 
172  static void settingConsumerCallback(
173  const DtSettingsObject* settingsObject, void* usr);
174  virtual void processSettings(const DtPeriodicSnapshotSettings*);
175 
176  static void checkpointOperationCallback(DtSimMessage*, void*);
177  virtual void processCheckpointOperation(DtSimMessage*);
178 
179  static void requestSnapshots(DtSimMessage*, void*);
180  virtual void processSnapshotsRequest(DtSimMessage*);
181 
182  static void requestCheckpointFiles(DtSimMessage*, void*);
183  virtual void processCheckpointFilesRequest(DtSimMessage*);
184 
185  static void rollbackToSnapshot(DtSimMessage*, void*);
186  virtual void processRollbackToSnapshot(DtSimMessage*);
187 
189  virtual void finishSavingSnapshots();
190 
194  virtual void deleteCheckpoint(const DtString& scenarioName, const DtString& runId, double simTime);
195 
198  virtual void setMetaDataToCheckpoint(const DtString& scenarioName, const DtString& runId, const std::map<DtString, DtString>& displayName);
199 
202  virtual void checkpointCount(const DtString& scenarioName, const DtString& runId, unsigned long requestId);
203 
205  virtual void sendCheckpointRun(unsigned long);
206 
207  virtual DtFilename scenarioFilenameFromScenario(const DtScenario& scenario) const;
208  virtual DtFilename strippedPath(const DtFilename& fullName) const;
209 
210 protected:
212  {
213  public:
214  DtWriteSnapshotJob(const DtSimulationAddress& addr,
216  virtual ~DtWriteSnapshotJob() override;
217  virtual void run() override;
218 
219  DtSimulationAddress myRequestor;
223  bool mySuccess;
224  bool myStarted;
225 
226  protected:
227  virtual bool writeAndSendOrderOfBattleFile();
228  virtual bool writeAndSendPlanFile();
229  virtual bool writeAndSendScenarioExtrasFile();
230  virtual bool writeAndSendScenarioScriptsFile();
231  virtual bool writeAndSendOrbatFile();
232  };
233 
235  {
236  public:
238  virtual ~DtSaveScenarioJob() override;
239  virtual void run() override;
240 
241  protected:
243  virtual void writeReadmeTo(const DtFilename&) const;
244  virtual void createFragmentDirectory(DtFilename& root, DtFilename& scenario);
245 
246  protected:
250  };
251 
252 protected:
259  mutable int myNextSnapshotId;
261 
262  typedef std::map<int, DtInMemorySnapshotPtr> Snapshots;
265 
267 
269 
271 
272  typedef std::map<int, DtVrfCallbackQueue::CallbackInterface::Ptr> SavingSnapshots;
274 
282  int myMaxQueuedSaveJobsBeforeSkip = 10;
283 };
UUID is a unique ID wrapper class.
Definition: uuid.h:59
std::map< int, DtInMemorySnapshotPtr > Snapshots
Definition: snapshotManager.h:262
DtInMemorySnapshotPtr mySnapshot
Definition: snapshotManager.h:248
DtCgf * cgf() const
Definition: snapshotManager.h:157
DtSimulationServices * myServices
Definition: snapshotManager.h:247
DtScenario myScenarioInformation
Definition: snapshotManager.h:53
int myLastCheckpointStep
Definition: snapshotManager.h:281
std::string myOrbat
Definition: snapshotManager.h:52
Definition: snapshotManager.h:234
DtVrfCallbackQueue * myFileWriterJobQueue
Definition: snapshotManager.h:275
double mySnapshotHeartbeatTime
Definition: snapshotManager.h:257
std::string myPlans
Definition: snapshotManager.h:49
Structure holds a complete single-backend snapshot state in memory.
Definition: snapshotManager.h:34
Definition: scenario.h:52
int myLastSnapshotStep
Definition: snapshotManager.h:260
int myNextSnapshotId
Definition: snapshotManager.h:259
double mySnapshotPeriod
Definition: snapshotManager.h:255
class DtIfSaveScenario:
Definition: ifSaveScenario.h:23
double myLastSnapshotHeartbeat
Definition: snapshotManager.h:256
Snapshots mySnapshots
Definition: snapshotManager.h:263
#define DT_DEFINE_OBJECT_DEBUGGER_NAME(type)
Definition: objectCounter.h:31
Default on in debug, off in release.
Definition: objectCounter.h:27
bool mySuccess
Definition: snapshotManager.h:223
Simple asynchronous callback queue.
Definition: vrfCallbackQueue.h:31
Contains the DtUUID class declaration.
OOB myOob
Definition: snapshotManager.h:48
Definition: settingsObject.h:27
DtSnapshotManager * myManager
Definition: snapshotManager.h:249
int myNumberOfSnapshotsToKeep
Definition: snapshotManager.h:258
int myId
Definition: snapshotManager.h:43
bool mySnapshotsModified
Definition: snapshotManager.h:266
std::vector< std::string * > OOB
Definition: snapshotManager.h:47
DtIfSnapshotsResponse myCurrentSnapshots
Definition: snapshotManager.h:268
static const DtUUID & nullUUID()
bool myCheckpointsEnabled
Definition: snapshotManager.h:279
API for writing callbacks.
Definition: vrfCallbackQueue.h:57
bool myPauseCleanup
Definition: snapshotManager.h:270
std::string myScenarioExtras
Definition: snapshotManager.h:50
std::shared_ptr< DtInMemorySnapshot > DtInMemorySnapshotPtr
Definition: snapshotManager.h:56
DtCompressedFileTransporter & myTransporter
Definition: snapshotManager.h:222
class DtIfSnapshotsResponse:
Definition: ifSnapshotsResponse.h:25
std::string myScenarioScripts
Definition: snapshotManager.h:51
File: simMsg.h.
Definition: simMessage.h:35
double myCheckpointPeriod
Definition: snapshotManager.h:280
bool myStarted
Definition: snapshotManager.h:224
Definition: snapshotManager.h:211
SavingSnapshots myCheckpointing
Definition: snapshotManager.h:273
Definition: compressedFileTransporter.h:24
system includes
Definition: consoleCommandManager.h:28
DtCgf * myCgf
Definition: snapshotManager.h:253
std::map< int, DtVrfCallbackQueue::CallbackInterface::Ptr > SavingSnapshots
Definition: snapshotManager.h:272
double mySimTime
Definition: snapshotManager.h:44
DtInMemorySnapshot()
Definition: snapshotManager.h:39
bool pauseCleanup() const
Definition: snapshotManager.h:99
DtConsoleCommand * myCheckpointCommand
Definition: snapshotManager.h:277
Central access point of all non-object-specific the services and managers that are available for use ...
Definition: simulationServices.h:97
DtIfSaveScenario mySaveMessage
Definition: snapshotManager.h:220
DtVrfCallbackQueue * myScenarioSaveJobQueue
Definition: snapshotManager.h:278
DT_DLL_DEBUGDRAWRENDERER void init(makVrv::DtDe &de)
Work function for the plugin initialization.
DtSimulationAddress myRequestor
Definition: snapshotManager.h:219
bool myIsPeriodic
Definition: snapshotManager.h:45
DtInMemorySnapshotPtr mySnapshot
Definition: snapshotManager.h:221
Definition: snapshotManager.h:60
bool myPeriodicSnapshotsEnabled
Definition: snapshotManager.h:254
DtConsoleCommand * mySnapshotCommand
Definition: snapshotManager.h:276
The top level class of a VR-Forces Simulation Engine, representing a Computer Generated Forces instan...
Definition: cgf.h:157
#define DT_DLL_vrfcgf
This file is used to determine how to build.
Definition: vrfcgfDefines.h:25
Snapshots myPeriodicSnapshots
Definition: snapshotManager.h:264
Periodic snapshot settings are used to keep track of whether or not periodic snapshots are enabled an...
Definition: periodicSnapshotSettings.h:28

Document ID: Generated on Thu Oct 15 21:27:02 EDT 2026 from SVN revision 296421
Copyright © 2005-2026 MAK Technologies. All Rights Reserved (www.mak.com)