-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
161 lines (140 loc) · 5.81 KB
/
main.cpp
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
/**
* @file main.cpp
* @author Thomas Saquet, Florent Poinsaut
* @date
* @brief File containing example of doxygen usage for quick reference.
*
* Alert - API is a part of the Alert software
* Copyright (C) 2013-2017
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include <signal.h>
#include "Conf.h"
#include "PublicApiResource.h"
#include "AddonResource.h"
#include "AlertResource.h"
#include "AssetResource.h"
#include "CriterionResource.h"
#include "FilterResource.h"
#include "InformationResource.h"
#include "InformationDataResource.h"
#include "MediaResource.h"
#include "OptionResource.h"
#include "OrganizationResource.h"
#include "PluginResource.h"
#include "ProbeResource.h"
#include "RoleResource.h"
#include "SearchResource.h"
#include "SourceResource.h"
#include "UnitResource.h"
#include "UserResource.h"
#include "itooki/ItookiAckReceiver.h"
#include "itooki/ItookiAswReceiver.h"
#endif
using namespace std;
/**
* Main function
* @param argc Number of arguments passed to the program
* @param argv Array of arguments passed to the program
* @return Exit status
*/
int main(int argc, char **argv)
{
#ifndef main
int res = EXIT_FAILURE;
try
{
// use argv[0] as the application name to match a suitable entry
// in the Wt configuration file
Wt::WServer server(argv[0]);
// On définit la configuration du serveur en lui passant les paramètres d'entrée et son fichier de configuration
server.setServerConfiguration(argc, argv);
if (conf.readProperties(server))
{
Echoes::Dbo::Session session(conf.getSessConnectParams());
AddonResource addonResource(session);
AlertResource alertResource(session);
AssetResource assetResource(session);
CriterionResource criteriaResource(session);
FilterResource filterResource(session);
InformationResource informationRessource(session);
InformationDataResource informationDataRessource(session);
MediaResource mediaResource(session);
OptionResource optionRessource(session);
OrganizationResource organizationRessource(session);
PluginResource pluginResource(session);
ProbeResource probeResource(session);
SearchResource searchResource(session);
SourceResource sourceResource(session);
UnitResource unitResource(session);
UserResource userResource(session);
RoleResource roleResource(session);
ItookiAckReceiver itookiAckReceiver(session);
ItookiAswReceiver itookiAswReceiver(session);
server.addResource(&addonResource, "/addons");
server.addResource(&alertResource, "/alerts");
server.addResource(&assetResource, "/assets");
server.addResource(&criteriaResource, "/criteria");
server.addResource(&filterResource, "/filters");
server.addResource(&informationRessource, "/informations");
server.addResource(&informationDataRessource, "/information_datas");
server.addResource(&mediaResource, "/medias");
server.addResource(&optionRessource, "/options");
server.addResource(&organizationRessource, "/organizations");
server.addResource(&pluginResource, "/plugins");
server.addResource(&probeResource, "/probes");
server.addResource(&roleResource, "/roles");
server.addResource(&searchResource, "/searches");
server.addResource(&sourceResource, "/sources");
server.addResource(&unitResource, "/units");
server.addResource(&userResource, "/users");
server.addResource(&itookiAckReceiver, "/itooki/ack");
server.addResource(&itookiAswReceiver, "/itooki/asw");
Echoes::Dbo::Session::configureAuth();
Wt::WString::setDefaultEncoding(Wt::CharEncoding::UTF8);
// démarrage du serveur en arrière plan
if (server.start())
{
// méthode qui bloque le thread courant en attendant le signal d'exctinction
int sig = Wt::WServer::waitForShutdown(argv[0]);
Wt::log("info") << "[Main] Shutdown (signal = " << sig << ")";
server.stop();
if (sig == SIGHUP)
{
Wt::WServer::restart(argc, argv, environ);
}
res = EXIT_SUCCESS;
}
}
else
{
Wt::log("fatal") << "[Main] Every properties are not correctly set in " << WT_CONFIG_XML;
}
}
catch (Wt::WServer::Exception& e)
{
cerr << e.what() << endl;
}
catch (exception& e)
{
cerr << "exception: " << e.what() << endl;
}
return res;
#else
return 0;
#endif
}