Application.cc
5.37 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
* Main.cc
*
* Created on: Feb 1, 2013
* Author: f.casimir
*/
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <iostream>
#include <string>
#include <sstream>
//includes boost
#include <boost/shared_ptr.hpp>
// include log4cxx header files.
#include "log4cxx/logger.h"
#include "log4cxx/basicconfigurator.h"
#include "log4cxx/helpers/exception.h"
#include "log4cxx/propertyconfigurator.h"
#include "log4cxx/mdc.h"
// DD_Client_r_lib module includes
#include "TimeUtil.hh"
#include "Properties.hh"
#include "Helper.hh"
#include "AMDA_exception.hh"
#include "DicError.hh"
#include "Application.hh"
// Parameters module include
#include "ServicesServer.hh"
#include "ParamMgr.hh"
#include "DataSetMgr.hh"
#include "InstrumentMgr.hh"
#include "MissionMgr.hh"
#include "PluginsParser.hh"
#include "SpiceKernelMgr.hh"
// Plugin module include
#include "PluginManager.hh"
// XMLRequest module include
#include "XMLParameterConfigurator.hh"
using namespace std;
using namespace boost;
using namespace log4cxx;
using namespace log4cxx::helpers;
using namespace AMDA::Parameters;
using namespace AMDA::XMLParameterConfigurator;
LoggerPtr logger(Logger::getLogger("AMDA-Kernel"));
namespace AMDA {
namespace Common {
int Application::main(int argc, char *argv[],
std::function<int(int argc, char *argv[], AMDA::helpers::Properties&) > exec, bool skipPluginLoad) {
int result = AMDA_EXIT_OK;
try {
if (access("app.properties", F_OK) != 0) {
BOOST_THROW_EXCEPTION(
AMDA::AMDA_exception() << AMDA::errno_code(AMDA_FILEPROPERTIES_ERR) << AMDA::ex_msg("Properties file not found"));
}
try {
AMDA::helpers::Properties lProperties("app.properties");
std::string lLoggerFileconfiguration =
lProperties["app.log4cxx.configfile"];
if (lLoggerFileconfiguration.empty()) {
/// Set up a simple configuration that logs on the console.
BasicConfigurator::configure();
LOG4CXX_WARN(logger,
"No properties: 'app.log4cxx.configfile' found. log4cxx basic configuration set ");
} else {
PropertyConfigurator::configure(
lLoggerFileconfiguration.c_str());
MDC::put("PID", AMDA::Helpers::Helper::getPID());
}
///Create ParameterManager
ServicesServer *servicesServer = ServicesServer::getInstance();
ParameterConfiguratorSPtr configurator(new AMDA::XMLParameterConfigurator::XMLParameterConfigurator(lProperties["app.parameter.xsd"].c_str()));
configurator->setParamPath(lProperties["app.param.path"]);
servicesServer->setConfigurator(configurator);
std::string lPluginPath = lProperties["app.plugin"];
if (!lPluginPath.empty() && !skipPluginLoad) {
bool b;
istringstream(lProperties["app.process.DYNAMIC_LOADING"]) >> std::boolalpha >> b;
if (!b) {
AMDA::Plugins::PluginManager::getInstance()->loadPluginFromPath(
lPluginPath);
servicesServer->generatePluginsXml((lProperties["app.process.plugins.xml"]).c_str());
} else {
std::string xmlFile= (lProperties["app.process.plugins.xml"]).c_str();
std::string xsdFile= (lProperties["app.process.plugins.xsd"]).c_str();
servicesServer->setPluginsDynamicLoading(true);
servicesServer->fillPluginsMap(xmlFile,xsdFile);
}
}
LOG4CXX_INFO(logger, "Entering application.");
result = exec(argc, argv, lProperties);
} catch (AMDA::AMDA_exception & e) {
LOG4CXX_ERROR(logger,
"Error resume: " << AMDA::traitException(result, e));
}
} catch (AMDA::AMDA_exception & e) {
std::cerr << "Error resume: " << AMDA::traitException(result, e);
} catch (...) {
result = AMDA_ERROR_UNKNOWN;
}
ServicesServer::releaseInstance();
AMDA::Info::ParamMgr::releaseInstance();
AMDA::Info::DataSetMgr::releaseInstance();
AMDA::Info::InstrumentMgr::releaseInstance();
AMDA::Info::MissionMgr::releaseInstance();
AMDA::Plugins::PluginManager::getInstance()->releaseInstance();
AMDA::SpiceKernel::SpiceKernelMgr::getInstance()->releaseInstance();
if (result != 0) {
LOG4CXX_ERROR(logger, "Exception: " << getErrorMsg(result));
}
LOG4CXX_INFO(logger, "Exiting application (" << result << ")");
//release log4cxx
MDC::remove("PID");
cout << "-----------------------------------------------------" << endl;
return result;
}
} /* namespace Common */
} /* namespace AMDA */