Blame view

src/Common/Application.cc 5.52 KB
fbe3c2bb   Benjamin Renard   First commit
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
/*
 * 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"
5ee530c2   Hacene SI HADJ MOHAND   parse nok
46
#include "PluginsParser.hh" 
fbe3c2bb   Benjamin Renard   First commit
47

cebd3f0e   Benjamin Renard   First implementat...
48
49
#include "SpiceKernelMgr.hh"

fbe3c2bb   Benjamin Renard   First commit
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67

// 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 {
bf54b7d4   Hacene SI HADJ MOHAND   not woring yet
68
    namespace Common {
fbe3c2bb   Benjamin Renard   First commit
69

bf54b7d4   Hacene SI HADJ MOHAND   not woring yet
70
71
72
        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;
fbe3c2bb   Benjamin Renard   First commit
73

bf54b7d4   Hacene SI HADJ MOHAND   not woring yet
74
75
76
77
78
79
80
            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");
fbe3c2bb   Benjamin Renard   First commit
81

bf54b7d4   Hacene SI HADJ MOHAND   not woring yet
82
83
                    std::string lLoggerFileconfiguration =
                            lProperties["app.log4cxx.configfile"];
fbe3c2bb   Benjamin Renard   First commit
84

bf54b7d4   Hacene SI HADJ MOHAND   not woring yet
85
86
87
88
89
90
91
92
93
94
                    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());
                    }
fbe3c2bb   Benjamin Renard   First commit
95

bf54b7d4   Hacene SI HADJ MOHAND   not woring yet
96
97
98
99
100
                    ///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);
fbe3c2bb   Benjamin Renard   First commit
101

bf54b7d4   Hacene SI HADJ MOHAND   not woring yet
102
103
                    std::string lPluginPath = lProperties["app.plugin"];
                    if (!lPluginPath.empty() && !skipPluginLoad) {
fe04cd0c   Hacene SI HADJ MOHAND   dynamic impliment...
104
105
106
                        bool b;
                        istringstream(lProperties["app.process.DYNAMIC_LOADING"]) >> std::boolalpha >> b;
                        if (!b) {
bf54b7d4   Hacene SI HADJ MOHAND   not woring yet
107
108
                            AMDA::Plugins::PluginManager::getInstance()->loadPluginFromPath(
                                    lPluginPath);
fe04cd0c   Hacene SI HADJ MOHAND   dynamic impliment...
109
110
111
112
113
114
                               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);
377eb96d   Hacene SI HADJ MOHAND   ok with xmls
115
116
                             for(auto  plug : servicesServer->getPluginsToLoad()) 
                                  servicesServer->loadPlugin(plug);
fe04cd0c   Hacene SI HADJ MOHAND   dynamic impliment...
117
                        }
bf54b7d4   Hacene SI HADJ MOHAND   not woring yet
118
                    }
fbe3c2bb   Benjamin Renard   First commit
119

bf54b7d4   Hacene SI HADJ MOHAND   not woring yet
120
121
                    LOG4CXX_INFO(logger, "Entering application.");
                    result = exec(argc, argv, lProperties);
fbe3c2bb   Benjamin Renard   First commit
122

bf54b7d4   Hacene SI HADJ MOHAND   not woring yet
123
124
125
126
                } catch (AMDA::AMDA_exception & e) {
                    LOG4CXX_ERROR(logger,
                            "Error resume: " << AMDA::traitException(result, e));
                }
fbe3c2bb   Benjamin Renard   First commit
127

bf54b7d4   Hacene SI HADJ MOHAND   not woring yet
128
129
130
131
132
            } catch (AMDA::AMDA_exception & e) {
                std::cerr << "Error resume: " << AMDA::traitException(result, e);
            } catch (...) {
                result = AMDA_ERROR_UNKNOWN;
            }
fbe3c2bb   Benjamin Renard   First commit
133

bf54b7d4   Hacene SI HADJ MOHAND   not woring yet
134
            ServicesServer::releaseInstance();
fbe3c2bb   Benjamin Renard   First commit
135
136


bf54b7d4   Hacene SI HADJ MOHAND   not woring yet
137
            AMDA::Info::ParamMgr::releaseInstance();
fbe3c2bb   Benjamin Renard   First commit
138

bf54b7d4   Hacene SI HADJ MOHAND   not woring yet
139
            AMDA::Info::DataSetMgr::releaseInstance();
fbe3c2bb   Benjamin Renard   First commit
140

bf54b7d4   Hacene SI HADJ MOHAND   not woring yet
141
            AMDA::Info::InstrumentMgr::releaseInstance();
fbe3c2bb   Benjamin Renard   First commit
142

bf54b7d4   Hacene SI HADJ MOHAND   not woring yet
143
            AMDA::Info::MissionMgr::releaseInstance();
fbe3c2bb   Benjamin Renard   First commit
144

bf54b7d4   Hacene SI HADJ MOHAND   not woring yet
145
            AMDA::Plugins::PluginManager::getInstance()->releaseInstance();
fbe3c2bb   Benjamin Renard   First commit
146

bf54b7d4   Hacene SI HADJ MOHAND   not woring yet
147
            AMDA::SpiceKernel::SpiceKernelMgr::getInstance()->releaseInstance();
cebd3f0e   Benjamin Renard   First implementat...
148

bf54b7d4   Hacene SI HADJ MOHAND   not woring yet
149
150
151
152
            if (result != 0) {
                LOG4CXX_ERROR(logger, "Exception: " << getErrorMsg(result));
            }
            LOG4CXX_INFO(logger, "Exiting application (" << result << ")");
80111081   Benjamin Renard   Add executable am...
153

bf54b7d4   Hacene SI HADJ MOHAND   not woring yet
154
155
156
            //release log4cxx
            MDC::remove("PID");
            cout << "-----------------------------------------------------" << endl;
fbe3c2bb   Benjamin Renard   First commit
157

bf54b7d4   Hacene SI HADJ MOHAND   not woring yet
158
159
            return result;
        }
fbe3c2bb   Benjamin Renard   First commit
160

bf54b7d4   Hacene SI HADJ MOHAND   not woring yet
161
    } /* namespace Common */
fbe3c2bb   Benjamin Renard   First commit
162
} /* namespace AMDA */