Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
treefrog-framework/src/tapplicationserverbase.cpp at master · treefrogframework/treefrog-framework · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
treefrogframework
treefrog-framework
Repository navigation
Code
Issues
4
(4)
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
treefrog-framework
/
src
/
tapplicationserverbase.cpp
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
187 lines (154 loc) · 4.8 KB
master
Breadcrumbs
treefrog-framework
/
src
/
tapplicationserverbase.cpp
Copy path
Top
File metadata and controls
Code
Blame
187 lines (154 loc) · 4.8 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/*
Copyright (c) 2010-2019, 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
"
tapplicationserverbase.h
"
#
include
<
QDateTime
>
#
include
<
QDir
>
#
include
<
QLibrary
>
#
include
<
QList
>
#
include
<
TActionContext
>
#
include
<
TActionController
>
#
include
<
TDispatcher
>
#
include
<
TWebApplication
>
#
ifdef
Q_OS_WIN
#
include
<
winsock2.h
>
#
include
<
ws2tcpip.h
>
#
endif
#
ifdef
Q_OS_UNIX
#
include
<
tfcore_unix.h
>
#
endif
/*
!
\class TApplicationServerBase
\brief The TApplicationServerBase class provides functionality common to
an web application server.
*/
namespace
{
QList<QLibrary *> libsLoaded;
QDateTime loadedTimestamp;
}
bool
TApplicationServerBase::loadLibraries
()
{
bool
ret =
true
;
//
Loads libraries
if
(libsLoaded.
isEmpty
()) {
//
Sets work directory
QString libPath =
Tf::app
()->
libPath
();
if
(!
QDir
(libPath).
exists
()) {
tSystemError
(
"
lib directory not found
"
);
return
false
;
}
//
To resolve the symbols in the app libraries
QDir::setCurrent
(libPath);
#
if
defined(Q_OS_WIN)
const
QStringList libs = {
"
controller
"
,
"
view
"
};
#
else
const
QStringList libs = {
"
libcontroller
"
,
"
libview
"
};
#
endif
for
(
auto
&libname : libs) {
auto
lib =
new
QLibrary
(libPath + libname);
if
(lib->
load
()) {
tSystemDebug
(
"
Library loaded: {}
"
, lib->
fileName
());
libsLoaded << lib;
}
else
{
tSystemWarn
(
"
{}
"
, lib->
errorString
());
ret =
false
;
unloadLibraries
();
break
;
}
}
QStringList controllers =
TActionController::availableControllers
();
tSystemDebug
(
"
Available controllers: {}
"
, controllers.
join
(
"
"
));
if
(ret) {
loadedTimestamp =
latestLibraryTimestamp
();
}
}
QDir::setCurrent
(
Tf::app
()->
webRootPath
());
return
ret;
}
void
TApplicationServerBase::unloadLibraries
()
{
for
(
auto
lib : libsLoaded) {
lib->
unload
();
tSystemDebug
(
"
Library unloaded: {}
"
, lib->
fileName
());
}
libsLoaded.
clear
();
}
QDateTime
TApplicationServerBase::latestLibraryTimestamp
()
{
#
if
defined(Q_OS_WIN)
const
QStringList libs = {
"
controller
"
,
"
model
"
,
"
view
"
,
"
helper
"
};
#
elif
defined(Q_OS_LINUX)
const
QStringList libs = {
"
libcontroller.so
"
,
"
libmodel.so
"
,
"
libview.so
"
,
"
libhelper.so
"
};
#
elif
defined(Q_OS_DARWIN)
const
QStringList libs = {
"
libcontroller.dylib
"
,
"
libmodel.dylib
"
,
"
libview.dylib
"
,
"
libhelper.dylib
"
};
#
else
const
QStringList libs = {
"
libcontroller.so
"
,
"
libmodel.so
"
,
"
libview.so
"
,
"
libhelper.so
"
};
#
endif
QDateTime ret =
QDateTime::fromSecsSinceEpoch
(
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);
}
QPair<QHostAddress,
uint16_t
>
TApplicationServerBase::getPeerInfo
(
int
socketDescriptor)
{
auto
peerInfo = QPair<QHostAddress,
uint16_t
>(
QHostAddress
(),
0
);
union
{
sockaddr a;
sockaddr_in a4;
sockaddr_in6 a6;
} sa;
socklen_t
sasize =
sizeof
(sa);
std::memset
(&sa,
0
,
sizeof
(sa));
if
(socketDescriptor <=
0
|| ::
getpeername
(socketDescriptor, &sa.
a
, &sasize) <
0
) {
return
peerInfo;
}
if
(sa.
a
.
sa_family
==
AF_INET6
) {
//
IPv6
Q_IPV6ADDR
tmp;
std::memcpy
(&tmp, &sa.
a6
.
sin6_addr
,
sizeof
(tmp));
peerInfo.
first
.
setAddress
(tmp);
peerInfo.
second
=
ntohs
(sa.
a6
.
sin6_port
);
}
else
{
//
IPv4
peerInfo.
first
.
setAddress
(
ntohl
(sa.
a4
.
sin_addr
.
s_addr
));
peerInfo.
second
=
ntohs
(sa.
a4
.
sin_port
);
}
return
peerInfo;
}
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
();
}
You can’t perform that action at this time.