Repository navigation
Expand file tree
/
Copy pathtapplicationserverbase.cpp
More file actions
146 lines (121 loc) · 4.08 KB
/
Copy pathtapplicationserverbase.cpp
File metadata and controls
146 lines (121 loc) · 4.08 KB
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
/* Copyright (c) 2010-2015, AOYAMA Kazuharu
* All rights reserved.
*
* This software may be used and distributed according to the terms of
* the New BSD License, which is incorporated herein by reference.
*/
#include <QLibrary>
#include <QList>
#include <QDir>
#include <QDateTime>
#include <TWebApplication>
#include <TActionContext>
#include <TDispatcher>
#include <TActionController>
#include "tapplicationserverbase.h"
#include "tsqldatabasepool.h"
#include "tkvsdatabasepool.h"
#include "turlroute.h"
#include "tsystemglobal.h"
#include "tsystembus.h"
#include "tpublisher.h"
/*!
\class TApplicationServerBase
\brief The TApplicationServerBase class provides functionality common to
an web application server.
*/
static QList<QLibrary*> libsLoaded;
static QDateTime loadedTimestamp;
bool TApplicationServerBase::loadLibraries()
{
T_TRACEFUNC("");
// Loads libraries
if (libsLoaded.isEmpty()) {
// Sets work directory
QString libPath = Tf::app()->libPath();
if (QDir(libPath).exists()) {
// To resolve the symbols in the app libraries
QDir::setCurrent(libPath);
} else {
tSystemError("lib directory not found");
return false;
}
loadedTimestamp = latestLibraryTimestamp();
#if defined(Q_OS_WIN)
QStringList libs = { "controller", "view" };
#elif defined(Q_OS_LINUX)
QStringList libs = { "libcontroller.so", "libview.so" };
#elif defined(Q_OS_DARWIN)
QStringList libs = { "libcontroller.dylib", "libview.dylib" };
#else
QStringList libs = { "libcontroller.so", "libview.so" };
#endif
for (const auto &libname : libs) {
auto lib = new QLibrary(libname);
if (lib->load()) {
tSystemDebug("Library loaded: %s", qPrintable(lib->fileName()));
libsLoaded << lib;
} else {
tSystemWarn("%s", qPrintable(lib->errorString()));
}
}
QStringList controllers = TActionController::availableControllers();
tSystemDebug("Available controllers: %s", qPrintable(controllers.join(" ")));
}
QDir::setCurrent(Tf::app()->webRootPath());
TSystemBus::instantiate();
TPublisher::instantiate();
TUrlRoute::instantiate();
TSqlDatabasePool::instantiate();
TKvsDatabasePool::instantiate();
return true;
}
QDateTime TApplicationServerBase::latestLibraryTimestamp()
{
#if defined(Q_OS_WIN)
QStringList libs = { "controller", "model", "view", "helper" };
#elif defined(Q_OS_LINUX)
QStringList libs = { "libcontroller.so", "libmodel.so", "libview.so", "libhelper.so" };
#elif defined(Q_OS_DARWIN)
QStringList libs = { "libcontroller.dylib", "libmodel.dylib", "libview.dylib", "libhelper.dylib" };
#else
QStringList libs = { "libcontroller.so", "libmodel.so", "libview.so", "libhelper.so" };
#endif
QDateTime ret = QDateTime::fromTime_t(0);
QString libPath = Tf::app()->libPath();
for (auto lib : libs) {
QFileInfo fi(libPath + lib);
if (fi.isFile() && fi.lastModified() > ret) {
ret = fi.lastModified();
}
}
return ret;
}
bool TApplicationServerBase::newerLibraryExists()
{
return (latestLibraryTimestamp() > loadedTimestamp);
}
void TApplicationServerBase::invokeStaticInitialize()
{
// Calls staticInitialize()
TDispatcher<TActionController> dispatcher("applicationcontroller");
bool dispatched = dispatcher.invoke("staticInitialize", QStringList(), Qt::DirectConnection);
if (!dispatched) {
tSystemWarn("No such method: staticInitialize() of ApplicationController");
}
}
void TApplicationServerBase::invokeStaticRelease()
{
// Calls staticRelease()
TDispatcher<TActionController> dispatcher("applicationcontroller");
bool dispatched = dispatcher.invoke("staticRelease", QStringList(), Qt::DirectConnection);
if (!dispatched) {
tSystemDebug("No such method: staticRelease() of ApplicationController");
}
}
TApplicationServerBase::TApplicationServerBase()
{ }
TApplicationServerBase::~TApplicationServerBase()
{
nativeSocketCleanup();
}