Blame view

src/Parameters/PluginsParser.cc 4.03 KB
901bcd2b   Hacene SI HADJ MOHAND   reading xml
1
2
3
4
5
6
7
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/* 
5ee530c2   Hacene SI HADJ MOHAND   parse nok
8
 * File:   PluginsParser.cc
901bcd2b   Hacene SI HADJ MOHAND   reading xml
9
10
11
12
13
14
 * Author: hacene
 * 
 * Created on March 17, 2020, 10:16 AM
 */

#include "PluginsParser.hh"
5ee530c2   Hacene SI HADJ MOHAND   parse nok
15
16
17
#include "NodeCfg.hh"
#include <boost/lexical_cast.hpp>

a93672f8   Hacene SI HADJ MOHAND   charement xml ok
18

5ee530c2   Hacene SI HADJ MOHAND   parse nok
19
using namespace AMDA::XMLConfigurator;
901bcd2b   Hacene SI HADJ MOHAND   reading xml
20
21

namespace AMDA {
5ee530c2   Hacene SI HADJ MOHAND   parse nok
22
    namespace Parameters {
a93672f8   Hacene SI HADJ MOHAND   charement xml ok
23
24

        class PluginNode : public NodeCfg {
901bcd2b   Hacene SI HADJ MOHAND   reading xml
25
26

            void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext) {
a93672f8   Hacene SI HADJ MOHAND   charement xml ok
27
                if ((pNode->children != NULL) && (pNode->children->content != NULL)) {
901bcd2b   Hacene SI HADJ MOHAND   reading xml
28
                    AMDA::Parameters::PluginObject *pluginObject = pContext.get<AMDA::Parameters::PluginObject *>();
a93672f8   Hacene SI HADJ MOHAND   charement xml ok
29
30
31
32
33
                    if (pluginObject != NULL) {
                        pluginObject->setPluginPath(std::string((char*) pNode->children->content));
                    } else {
                        // throw exception 
                    }
901bcd2b   Hacene SI HADJ MOHAND   reading xml
34
35
                }
            }
901bcd2b   Hacene SI HADJ MOHAND   reading xml
36
37
        };

a93672f8   Hacene SI HADJ MOHAND   charement xml ok
38
        class RequestProcessNode : public NodeGrpCfg {
901bcd2b   Hacene SI HADJ MOHAND   reading xml
39
40
        public:

a93672f8   Hacene SI HADJ MOHAND   charement xml ok
41
42
            RequestProcessNode() : NodeGrpCfg() {
                getChildList()["plugin"] = NodeCfgSPtr(new PluginNode);
901bcd2b   Hacene SI HADJ MOHAND   reading xml
43
44
            }

a93672f8   Hacene SI HADJ MOHAND   charement xml ok
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
            void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext) {
                xmlChar* value = xmlGetProp(pNode, (const xmlChar *) "name");
                std::string name;
                if (value != NULL) {
                    name = (char *) value;
                    xmlFree(value);
                }
                value = xmlGetProp(pNode, (const xmlChar *) "type");
                std::string type;
                if (value != NULL) {
                    type = (char *) value;
                    xmlFree(value);
                }
                if (!name.empty() && !type.empty()) {
                    AMDA::Parameters::CfgContext ctx;
                    PluginObject pluginObject;
                    ctx.push<PluginObject*>(&pluginObject);
                    pluginObject.setRequestProcess(name);
                    pluginObject.setType(type);

                    NodeGrpCfg::proceed(pNode, ctx);
                    AMDA::Parameters::AMDA_ProcessPluginMaps *processPluginMaps = pContext.get<AMDA::Parameters::AMDA_ProcessPluginMaps *>();
                    (*processPluginMaps)[type][name] = pluginObject.getPluginPath();
                }
901bcd2b   Hacene SI HADJ MOHAND   reading xml
69
70
            }

901bcd2b   Hacene SI HADJ MOHAND   reading xml
71
        };
901bcd2b   Hacene SI HADJ MOHAND   reading xml
72
73
74
75
76
77
78
79
80
        ///////////////////////////////////////////////////////////////////////////////

        /*
         * @brief plugins node
         */
        class PluginsNode : public NodeGrpCfg {
        public:

            PluginsNode() : NodeGrpCfg() {
a93672f8   Hacene SI HADJ MOHAND   charement xml ok
81
                getChildList()["requestProcess"] = NodeCfgSPtr(new RequestProcessNode);
901bcd2b   Hacene SI HADJ MOHAND   reading xml
82
83
84
            }

            void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext) {
a93672f8   Hacene SI HADJ MOHAND   charement xml ok
85

901bcd2b   Hacene SI HADJ MOHAND   reading xml
86
87
88
89
90
91
92
93
94
95
96

                // Proceed nodes
                NodeGrpCfg::proceed(pNode, pContext);
            }
        };

        ///////////////////////////////////////////////////////////////////////////////

        /*
         * @brief plugins node parser
         */
a93672f8   Hacene SI HADJ MOHAND   charement xml ok
97
        PluginsParser::PluginsParser(const char* pXSDFile) : XMLConfigurator(pXSDFile, true) {
901bcd2b   Hacene SI HADJ MOHAND   reading xml
98
99

            // functions root node
a93672f8   Hacene SI HADJ MOHAND   charement xml ok
100
            getXmlConfiguratorMap()["plugins"] = RootNodeCfgSPtr(new PluginsNode());
901bcd2b   Hacene SI HADJ MOHAND   reading xml
101
102
        }

a93672f8   Hacene SI HADJ MOHAND   charement xml ok
103
        AMDA::Parameters::AMDA_ProcessPluginMaps PluginsParser::parse(const std::string& pluginsFile) {
5ee530c2   Hacene SI HADJ MOHAND   parse nok
104
            AMDA::Parameters::CfgContext ctx;
901bcd2b   Hacene SI HADJ MOHAND   reading xml
105
106
            AMDA::Parameters::AMDA_ProcessPluginMaps processPluginMaps;
            ctx.push<AMDA::Parameters::AMDA_ProcessPluginMaps *> (&processPluginMaps);
a93672f8   Hacene SI HADJ MOHAND   charement xml ok
107
108
109
110
111
112
113
114
            // Check schema validity and parse xml file
            try {
                if (!XMLConfigurator::proceed(pluginsFile.c_str(), ctx, true)) {
                    return processPluginMaps;
                }
            } catch (...) {
                throw;
            }
901bcd2b   Hacene SI HADJ MOHAND   reading xml
115
116
117
            return processPluginMaps;
        }
    } // end AMDA
5ee530c2   Hacene SI HADJ MOHAND   parse nok
118
} //end parameters