-
-
Notifications
You must be signed in to change notification settings - Fork 226
/
Copy pathtcommandlineinterface.h
51 lines (49 loc) · 4.53 KB
/
tcommandlineinterface.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
#pragma once
#include "tkvsdatabasepool.h"
#include "tsqldatabasepool.h"
#include <TActionThread>
#include <TSystemGlobal>
#include <TStdErrSystemLogger>
#include <TStdOutLogger>
#include <TWebApplication>
#include <TAppSettings>
#include <TLogger>
#include <QtCore>
#define TF_CLI_MAIN(STATICFUNCTION) \
int main(int argc, char *argv[]) \
{ \
class Thread : public TActionThread { \
public: \
Thread() : TActionThread(0), returnCode(0) { } \
volatile int returnCode; \
\
protected: \
virtual void run() \
{ \
returnCode = STATICFUNCTION(); \
commitTransactions(); \
for (auto it = sqlDatabases.begin(); it != sqlDatabases.end(); ++it) { \
it.value().database().close(); /* close SQL database */ \
} \
for (auto it = kvsDatabases.begin(); it != kvsDatabases.end(); ++it) { \
it.value().close(); /* close KVS database */ \
} \
QEventLoop eventLoop; \
while (eventLoop.processEvents()) { } \
} \
}; \
TWebApplication app(argc, argv); \
Tf::setupSystemLogger(new TStdErrSystemLogger); \
Tf::setupQueryLogger(); \
app.setMultiProcessingModule(TWebApplication::Thread); \
int idx = QCoreApplication::arguments().indexOf("-e"); \
QString env = (idx > 0) ? QCoreApplication::arguments().value(idx + 1) : QString("product"); \
app.setDatabaseEnvironment(env); \
Thread thread; \
QObject::connect(&thread, SIGNAL(finished()), &app, SLOT(quit())); \
thread.start(); \
app.exec(); \
Tf::releaseAppLoggers(); \
Tf::releaseQueryLogger(); \
return thread.returnCode; \
}