-
Notifications
You must be signed in to change notification settings - Fork 1
/
FormMain.h
199 lines (183 loc) · 7.24 KB
/
FormMain.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
//---------------------------------------------------------------------------
#ifndef FormMainH
#define FormMainH
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <Vcl.ExtCtrls.hpp>
#include <System.Actions.hpp>
#include <Vcl.ActnList.hpp>
#include <Vcl.ActnMan.hpp>
#include <Vcl.Buttons.hpp>
#include <Vcl.PlatformDefaultStyleActnCtrls.hpp>
#include <Vcl.Dialogs.hpp>
#include <NDrawGrid.h>
#include <Vcl.Grids.hpp>
#include <System.ImageList.hpp>
#include <Vcl.ImgList.hpp>
#include <System.SysUtils.hpp>
#include <Vcl.ActnCtrls.hpp>
#include <Vcl.ActnMenus.hpp>
#include <Vcl.StdActns.hpp>
#include <Vcl.ToolWin.hpp>
#include <Vcl.ComCtrls.hpp>
#include <memory>
#include <utility>
#include <mutex>
#include <atomic>
#include <vector>
#include <future>
#include "LogInMemoryNotify.h"
#include "GridMapper.h"
#include "LogBase.h"
#include "LogAsyncChain.h"
#include <anafestica/PersistFormVCL.h>
#include <anafestica/CfgRegistrySingleton.h>
//---------------------------------------------------------------------------
using TConfigRegistryForm =
Anafestica::TPersistFormVCL<Anafestica::TConfigRegistrySingleton>;
class TfrmMain : public TConfigRegistryForm
{
__published: // IDE-managed Components
TBitBtn *BitBtn1;
TActionManager *ActionManager1;
TAction *actFileSelectFolder;
TAction *actProcessFolderStart;
TFileOpenDialog *fileopndlgSelectFolder;
TComboBox *comboboxSourceFolder;
TPanel *pnlLog;
TPanel *pnlLogViewer;
TNDrawGrid *ndrawgridLog;
TPanel *pnlLogCtrls;
TSpeedButton *SpeedButton1;
TCheckBox *CheckBox1;
TAction *actLogUpdateActive;
TAction *actLogClear;
TImageList *imglistLog;
TLabel *Label1;
TActionMainMenuBar *ActionMainMenuBar1;
TFileExit *actFileExit;
TTimer *Timer1;
TTimer *Timer2;
TStatusBar *StatusBar1;
TEdit *edtDataExtractionTime;
TEdit *edtDBMSStoreTime;
TLabel *Label2;
TLabel *Label3;
void __fastcall actFileSelectFolderExecute(TObject *Sender);
void __fastcall actFileSelectFolderUpdate(TObject *Sender);
void __fastcall actProcessFolderStartExecute(TObject *Sender);
void __fastcall actProcessFolderStartUpdate(TObject *Sender);
void __fastcall actLogUpdateActiveExecute(TObject *Sender);
void __fastcall actLogUpdateActiveUpdate(TObject *Sender);
void __fastcall actLogClearExecute(TObject *Sender);
void __fastcall actLogClearUpdate(TObject *Sender);
void __fastcall ndrawgridLogDrawCell(TObject *Sender, int ACol, int ARow, TRect &Rect,
TGridDrawState State);
void __fastcall ndrawgridLogFixedCellGetText(TObject *Sender, int ACol, int ARow,
UnicodeString &Value);
void __fastcall ndrawgridLogNormalCellGetText(TObject *Sender, int ACol, int ARow,
UnicodeString &Value);
void __fastcall Timer1Timer(TObject *Sender);
void __fastcall Timer2Timer(TObject *Sender);
private: // User declarations
using LogItemType = SvcApp::Log::LogItem;
using LogObjType = SvcApp::Log::LogBase<LogItemType>;
using LogParamsType = SvcApp::Log::LogParams;
using LogInMemType = SvcApp::Log::LogInMemoryNotify<LogItemType>;
using LogAppendCallbackType = LogObjType::AppendCallbackType;
using TaskCont = std::vector<std::future<void>>;
std::mutex mtxLogInMem_;
unsigned guiThId_ { TThread::CurrentThread->ThreadID };
std::atomic<long> logUpdateActive_ { true };
std::unique_ptr<LogInMemType> logInMem_ {
std::make_unique<LogInMemType>(
//[this]( auto& Sender, auto Reason ) {
// LogNotifyChanges( Sender, Reason );
//}
&LogNotifyChanges
, 500000
, 500000
)
};
TaskCont tasks_;
std::atomic<TaskCont::size_type> runningTasks_ {};
double spinCountPerMicroSec_ {};
static String GetModuleFileName();
void SetupCaption();
void RestoreProperties();
void SaveProperties() const;
String GetSourceFolder() const;
void SetSourceFolder( String Val );
static void AddToMRUList( TStrings& List, String Val, int MaxItems = 20 );
TStrings& GetSourceFolderMRUList() const;
void ProcessFolder( String Path );
void UpdateLogViewer( bool Force = false );
static int SeverityToImageIndex( LogInMemType::ItemType::SeverityType Severity );
bool GetLogUpdateActive() const;
void SetLogUpdateActive( bool Val );
int GetLogViewerRowCount() const;
void SetLogViewerRowCount( int Val );
void SetLogViewerSelectedRow( int Val );
static std::unique_ptr<LogObjType> CreateLogSubsystem( LogAppendCallbackType OnLogAppendItem );
void LogNotifyChanges( LogInMemType& Sender, LogInMemType::ReasonType Reason );
void KickLogTimer();
static std::tuple<double,double> EvaluateMTSpinDelay( size_t SampleCount,
size_t SpinCount );
static void DelayMicroSec( double Amount, double SpinPerMicroSec ) {
auto volatile SpinCount =
static_cast<size_t>( ( Amount ) * SpinPerMicroSec );
while ( --SpinCount ) {}
}
static std::tuple<double,double> MeasureMTSpinDelay( size_t SampleCount,
double DelayMicroSec,
double SpinCountPerMicroSec );
static double EstimateSpinCountPerMicroSec();
void DelayMicroSec( double Amount ) {
DelayMicroSec( Amount, spinCountPerMicroSec_ );
}
template<typename M, typename S, typename... A>
void LogMsg( M Message, S const & Severity, A&&... Args ) {
logInMem_->Append(
SvcApp::Log::LogItem(
LOG_ENT_APPLICATION, Message,
SvcApp::Log::LogParams( std::forward<A&&...>( Args )... ),
Now(), Severity
)
);
}
int GetDataExtractionTimeVal() const;
int GetDBMSStoreTimeVal() const;
String GetDataExtractionTime() const;
void SetDataExtractionTime( String Val );
String GetDBMSStoreTime() const;
void SetDBMSStoreTime( String Val );
bool IsDataExtractionTimeValid() const;
bool IsDBMSStoreTimeValid() const;
protected:
virtual void __fastcall WndProc( Winapi::Messages::TMessage &Message ) override;
public: // User declarations
__fastcall TfrmMain( TComponent* Owner ) override;
__fastcall TfrmMain( TComponent* Owner, StoreOpts StoreOptions,
Anafestica::TConfigNode* const RootNode = nullptr );
__fastcall ~TfrmMain();
__property String SourceFolder = {
read = GetSourceFolder, write = SetSourceFolder
};
__property TStrings& SourceFolderMRUList = { read = GetSourceFolderMRUList };
__property bool LogUpdateActive = {
read = GetLogUpdateActive, write = SetLogUpdateActive
};
__property String DataExtractionTime = {
read = GetDataExtractionTime, write = SetDataExtractionTime
};
__property String DBMSStoreTime = {
read = GetDBMSStoreTime, write = SetDBMSStoreTime
};
};
//---------------------------------------------------------------------------
extern PACKAGE TfrmMain *frmMain;
//---------------------------------------------------------------------------
#endif