2 #include "tkvsdatabasepool.h"
3 #include "tsqldatabasepool.h"
4 #include <TActionThread>
5 #include <TSystemGlobal>
6 #include <TStdErrSystemLogger>
7 #include <TStdOutLogger>
8 #include <TWebApplication>
9 #include <TAppSettings>
14 #if QT_VERSION < 0x060000
15 #define TF_CLI_MAIN(STATICFUNCTION) \
16 int main(int argc, char *argv[]) \
18 class Thread : public TActionThread { \
20 Thread() : TActionThread(0), returnCode(0) { } \
21 volatile int returnCode; \
26 returnCode = STATICFUNCTION(); \
27 commitTransactions(); \
28 for (auto it = sqlDatabases.begin(); it != sqlDatabases.end(); ++it) { \
29 it.value().database().close(); \
31 for (auto it = kvsDatabases.begin(); it != kvsDatabases.end(); ++it) { \
34 QEventLoop eventLoop; \
35 while (eventLoop.processEvents()) { } \
38 TWebApplication app(argc, argv); \
39 QByteArray codecName = Tf::appSettings()->value(Tf::InternalEncoding).toByteArray(); \
40 QTextCodec *codec = QTextCodec::codecForName(codecName); \
41 QTextCodec::setCodecForLocale(codec); \
42 Tf::setupSystemLogger(new TStdErrSystemLogger); \
43 Tf::setupQueryLogger(); \
44 app.setMultiProcessingModule(TWebApplication::Thread); \
45 int idx = QCoreApplication::arguments().indexOf("-e"); \
46 QString env = (idx > 0) ? QCoreApplication::arguments().value(idx + 1) : QString("product"); \
47 app.setDatabaseEnvironment(env); \
49 QObject::connect(&thread, SIGNAL(finished()), &app, SLOT(quit())); \
52 Tf::releaseAppLoggers(); \
53 Tf::releaseQueryLogger(); \
54 return thread.returnCode; \
59 #define TF_CLI_MAIN(STATICFUNCTION) \
60 int main(int argc, char *argv[]) \
62 class Thread : public TActionThread { \
64 Thread() : TActionThread(0), returnCode(0) { } \
65 volatile int returnCode; \
70 returnCode = STATICFUNCTION(); \
71 commitTransactions(); \
72 for (auto it = sqlDatabases.begin(); it != sqlDatabases.end(); ++it) { \
73 it.value().database().close(); \
75 for (auto it = kvsDatabases.begin(); it != kvsDatabases.end(); ++it) { \
78 QEventLoop eventLoop; \
79 while (eventLoop.processEvents()) { } \
82 TWebApplication app(argc, argv); \
83 Tf::setupSystemLogger(new TStdErrSystemLogger); \
84 Tf::setupQueryLogger(); \
85 app.setMultiProcessingModule(TWebApplication::Thread); \
86 int idx = QCoreApplication::arguments().indexOf("-e"); \
87 QString env = (idx > 0) ? QCoreApplication::arguments().value(idx + 1) : QString("product"); \
88 app.setDatabaseEnvironment(env); \
90 QObject::connect(&thread, SIGNAL(finished()), &app, SLOT(quit())); \
93 Tf::releaseAppLoggers(); \
94 Tf::releaseQueryLogger(); \
95 return thread.returnCode; \