OpendTect  6.3
autosaver.h
Go to the documentation of this file.
1 #pragma once
2 
3 /*+
4 ________________________________________________________________________
5 
6  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
7  Author: Bert
8  Date: April 2016
9 ________________________________________________________________________
10 
11 -*/
12 
13 #include "generalmod.h"
14 #include "monitorable.h"
15 #include "uistring.h"
16 class IOStream;
17 class Saveable;
18 
19 
20 namespace OD
21 {
22 
23 class AutoSaver;
24 
25 
26 mExpClass(General) AutoSaveObj : public CallBacker
28 public:
29 
30  typedef Monitorable::DirtyCountType DirtyCountType;
31 
33  ~AutoSaveObj();
34 
35  bool prevSaveFailed() const { return prevsavefailed_; }
36  uiRetVal messages() const { return msgs_; }
37  bool isFinished() const;
38  const Saveable* saver() const { return saver_; }
39 
40 private:
41 
42  const Saveable* saver_;
45  mutable uiRetVal msgs_;
46  mutable bool prevsavefailed_;
47 
48  mutable DirtyCountType lastautosavedirtycount_;
49  mutable int lastsaveclockseconds_;
51  mutable int autosavenr_;
52 
53  bool time4AutoSave() const;
54  int autoSave(bool) const;
55  void removeHiddenSaves();
56 
57  void removeIOObjAndData(IOStream*&) const;
58  void saverDelCB(CallBacker*);
59 
60  friend class AutoSaver;
61 
62 };
63 
64 
79 mExpClass(General) AutoSaver : public CallBacker
81 public:
82 
83  bool isActive() const;
84  void setActive(bool yn=true);
85  bool useHiddenMode() const;
86  void setUseHiddenMode(bool yn=true);
87  int nrSecondsBetweenSaves() const;
88  void setNrSecondsBetweenSaves(int);
89 
90  void add(const Saveable&);
91  bool restore(IOStream&,const char* newnm);
92 
93  // triggered from mgr's thread. CB obj is AutoSaveObj
96 
97  static const char* sKeyAutosaved();
98 
99 private:
100 
101  AutoSaver();
102  ~AutoSaver();
103 
107  bool isactive_;
113 
114  void remove(AutoSaveObj*);
115  void appExitCB(CallBacker*);
116  void svrDelCB(CallBacker*);
117  void survChgCB(CallBacker*);
118 
119  void go();
120  static inline void goCB(CallBacker*);
121 
122  void handleSurvChg();
123 
124  friend class AutoSaveObj;
125 
126 public:
127 
128  // Probably not useful 4 u:
129 
130  static AutoSaver& getInst(); // use OD::AUTOSAVE()
131  void setEmpty(); // try setActive(false)
132  Threads::Thread& thread() { return *thread_; }
133 
134 };
135 
136 
137 mGlobal(General) inline AutoSaver& AUTOSAVE()
138 { return AutoSaver::getInst(); }
139 
140 
141 }; //namespace OD
#define mExpClass(module)
Definition: commondefs.h:157
int lastsaveclockseconds_
Definition: autosaver.h:49
Inherit from this class to be able to send and/or receive CallBacks.
Definition: callback.h:182
const Saveable * saver_
Definition: autosaver.h:42
Definition: iostrm.h:24
int64_t DirtyCountType
Definition: monitorable.h:84
A lock of a type that (hopefully) suits your needs. To use it, you need the Locker class...
Definition: threadlock.h:51
AutoSaver & mgr_
Definition: autosaver.h:44
#define mODTextTranslationClass(clss)
Definition: uistring.h:37
#define mGlobal(module)
Definition: commondefs.h:160
AutoSaver & AUTOSAVE()
Definition: autosaver.h:137
Threads::Lock lock_
Definition: autosaver.h:104
bool usehiddenmode_
Definition: autosaver.h:108
bool prevSaveFailed() const
Definition: autosaver.h:35
Auto-save manager. Singleton class. Works from its own thread.
Definition: autosaver.h:79
Notifier< AutoSaver > saveFailed
Definition: autosaver.h:95
bool isactive_
Definition: autosaver.h:107
Notifier< AutoSaver > saveDone
Definition: autosaver.h:94
Object that can be saved at any time.
Definition: saveable.h:23
static AutoSaver & getInst()
Class to help setup a callback handling.
Definition: notify.h:121
Set of pointers to objects.
Definition: commontypes.h:28
Definition: autosaver.h:26
bool prevsavefailed_
Definition: autosaver.h:46
Is the base class for all threads. Start it by creating it and give it the function or CallBack to ex...
Definition: thread.h:290
Threads::Thread * thread_
Definition: autosaver.h:105
ObjectSet< AutoSaveObj > asobjs_
Definition: autosaver.h:106
Threads::Atomic< bool > appexits_
Definition: autosaver.h:111
Threads::Lock lock_
Definition: autosaver.h:43
uiRetVal messages() const
Definition: autosaver.h:36
int curclockseconds_
Definition: autosaver.h:109
int autosavenr_
Definition: autosaver.h:51
Threads::Thread & thread()
Definition: autosaver.h:132
Definition: uistring.h:299
OpendTect.
Definition: commontypes.h:25
bool isFinished(const uiRetVal &)
const Saveable * saver() const
Definition: autosaver.h:38
Threads::Atomic< bool > surveychanges_
Definition: autosaver.h:112
IOStream * lastautosaveioobj_
Definition: autosaver.h:50
DirtyCountType lastautosavedirtycount_
Definition: autosaver.h:48
uiRetVal msgs_
Definition: autosaver.h:45
int nrclocksecondsbetweensaves_
Definition: autosaver.h:110

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B. V. 2017