TreeFrogFramework 2.10
Loading...
Searching...
No Matches
tcommandlineinterface.h
Go to the documentation of this file.
1#pragma once
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>
10#include <TLogger>
11#include <QtCore>
12
13
14#define TF_CLI_MAIN(STATICFUNCTION) \
15 int main(int argc, char *argv[]) \
16 { \
17 class Thread : public TActionThread { \
18 public: \
19 Thread() : TActionThread(0), returnCode(0) { } \
20 volatile int returnCode; \
21 \
22 protected: \
23 virtual void run() \
24 { \
25 returnCode = STATICFUNCTION(); \
26 commitTransactions(); \
27 for (auto it = sqlDatabases.begin(); it != sqlDatabases.end(); ++it) { \
28 it.value().database().close(); /* close SQL database */ \
29 } \
30 for (auto it = kvsDatabases.begin(); it != kvsDatabases.end(); ++it) { \
31 it.value().close(); /* close KVS database */ \
32 } \
33 QEventLoop eventLoop; \
34 while (eventLoop.processEvents()) { } \
35 } \
36 }; \
37 TWebApplication app(argc, argv); \
38 Tf::setupSystemLogger(new TStdErrSystemLogger); \
39 Tf::setupQueryLogger(); \
40 app.setMultiProcessingModule(TWebApplication::Thread); \
41 int idx = QCoreApplication::arguments().indexOf("-e"); \
42 QString env = (idx > 0) ? QCoreApplication::arguments().value(idx + 1) : QString("product"); \
43 app.setDatabaseEnvironment(env); \
44 Thread thread; \
45 QObject::connect(&thread, SIGNAL(finished()), &app, SLOT(quit())); \
46 thread.start(); \
47 app.exec(); \
48 Tf::releaseAppLoggers(); \
49 Tf::releaseQueryLogger(); \
50 return thread.returnCode; \
51 }