Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.

Commit ec67345

Browse files
committed
Add Xml binding for Parameter framework configuration
TODO: UPDATE DOC, NAMESPACE OF BINDINGS MAKE CONF A SIMPLE STRUCT Signed-off-by: Jules Clero <julesx.clero@intel.com>
1 parent 7ffcb0c commit ec67345

3 files changed

Lines changed: 159 additions & 153 deletions

File tree

parameter/ParameterFrameworkConfiguration.cpp

Lines changed: 10 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@
2828
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2929
*/
3030
#include "ParameterFrameworkConfiguration.h"
31-
#include "XmlFileDocSource.h"
32-
#include "XmlMemoryDocSink.h"
33-
#include "XmlElement.h"
31+
#include "Deserializer.hpp"
32+
#include "ParameterFrameworkConfigurationXmlBinding.hpp"
3433

3534
CParameterFrameworkConfiguration::CParameterFrameworkConfiguration(const std::string &configurationFile)
3635
: _bTuningAllowed(false), _uiServerPort(0), _configurationFile(configurationFile)
@@ -49,14 +48,14 @@ bool CParameterFrameworkConfiguration::init(std::string &error)
4948
}
5049
_schemasLocation = _configurationFolder + "/Schemas";
5150

52-
CXmlSerializingContext context(error);
53-
CXmlFileDocSource source(_configurationFile,
54-
_schemasLocation + "/ParameterFrameworkConfiguration.xsd",
55-
"ParameterFrameworkConfiguration",
56-
false);
57-
58-
CXmlMemoryDocSink sink(this);
59-
return sink.process(source, context);
51+
try {
52+
core::xml::bindings::ParameterFrameworkConfigurationXmlBinding bindings{*this};
53+
core::xml::serialization::Deserializer test{_configurationFile, bindings.getBindings()};
54+
} catch (std::runtime_error &e) {
55+
error = e.what();
56+
return false;
57+
}
58+
return true;
6059
}
6160

6261
// System class name
@@ -76,134 +75,3 @@ uint16_t CParameterFrameworkConfiguration::getServerPort() const
7675
{
7776
return _uiServerPort;
7877
}
79-
80-
bool CParameterFrameworkConfiguration::retrieveSettingsConfiguration(const CXmlElement &settingsNode,
81-
CXmlSerializingContext& context)
82-
{
83-
if (settingsNode.getNbChildElements() > 2) {
84-
context.setError("too much settings node");
85-
return false;
86-
}
87-
bool settingsChildFound = false;
88-
CXmlElement childNode;
89-
CXmlElement::CChildIterator childIterator(settingsNode);
90-
while (childIterator.next(childNode)) {
91-
if (childNode.getType() == "ConfigurableDomainsFileLocation") {
92-
if(!retrievePathAttribute(childNode, _settingsFile, context)) {
93-
return false;
94-
}
95-
settingsChildFound = true;
96-
} else if (childNode.getType() == "BinarySettingsFileLocation") {
97-
if (!retrievePathAttribute(childNode, _binarySettingsFile, context)) {
98-
return false;
99-
}
100-
} else {
101-
context.setError("Unknown child");
102-
return false;
103-
}
104-
}
105-
if (!settingsChildFound) {
106-
context.setError("No ConfigurableDomainsFileLocation element found"
107-
" for SystemClass " + _strSystemClassName);
108-
return false;
109-
}
110-
return true;
111-
}
112-
113-
bool CParameterFrameworkConfiguration::retrievePathAttribute(const CXmlElement &xmlElement,
114-
std::string &path,
115-
CXmlSerializingContext& context)
116-
{
117-
xmlElement.getAttribute("Path", path);
118-
if (path.empty()) {
119-
context.setError("Empty Path attribute in element " + xmlElement.getPath());
120-
return false;
121-
}
122-
if (path[0] != '/') {
123-
// Path is relative
124-
path = _configurationFolder + "/" + path;
125-
}
126-
return true;
127-
}
128-
129-
bool CParameterFrameworkConfiguration::retrievePluginsConfiguration(const CXmlElement &pluginNode,
130-
CXmlSerializingContext& context)
131-
{
132-
CXmlElement::CChildIterator childLocation(pluginNode);
133-
CXmlElement xmlPluginLocation;
134-
while (childLocation.next(xmlPluginLocation)) {
135-
if (!(xmlPluginLocation.getType() == "Location")) {
136-
context.setError("pas de location");
137-
return false;
138-
}
139-
// Retrieve folder
140-
std::string pluginFolder;
141-
pluginNode.getAttribute("Folder", pluginFolder);
142-
if (!pluginFolder.empty()) {
143-
pluginFolder += "/";
144-
}
145-
146-
// Get Info from children
147-
CXmlElement::CChildIterator childIterator(xmlPluginLocation);
148-
CXmlElement xmlPluginElement;
149-
while (childIterator.next(xmlPluginElement)) {
150-
if (!(xmlPluginElement.getType() == "Plugin")) {
151-
context.setError("pas de plugin");
152-
return false;
153-
}
154-
155-
// Fill Plugin List
156-
_plugins.push_back(pluginFolder + xmlPluginElement.getNameAttribute());
157-
}
158-
}
159-
return true;
160-
}
161-
162-
// From IXmlSink
163-
bool CParameterFrameworkConfiguration::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext)
164-
{
165-
// System class name
166-
xmlElement.getAttribute("SystemClassName", _strSystemClassName);
167-
168-
// Tuning allowed
169-
xmlElement.getAttribute("TuningAllowed", _bTuningAllowed);
170-
171-
// Server port
172-
xmlElement.getAttribute("ServerPort", _uiServerPort);
173-
174-
CXmlElement childNode;
175-
CXmlElement::CChildIterator childIterator(xmlElement);
176-
177-
bool structureChildFound = false;
178-
bool subsystemPluginsChildFound = false;
179-
while (childIterator.next(childNode)) {
180-
if (childNode.getType() == "SubsystemPlugins") {
181-
if(!retrievePluginsConfiguration(childNode, serializingContext)) {
182-
return false;
183-
}
184-
subsystemPluginsChildFound = true;
185-
} else if (childNode.getType() == "StructureDescriptionFileLocation") {
186-
if(!retrievePathAttribute(childNode, _structureFile, serializingContext)) {
187-
return false;
188-
}
189-
structureChildFound = true;
190-
} else if (childNode.getType() == "SettingsConfiguration") {
191-
if (!retrieveSettingsConfiguration(childNode, serializingContext)) {
192-
return false;
193-
}
194-
} else {
195-
serializingContext.setError("Unknown child");
196-
return false;
197-
}
198-
}
199-
if (!structureChildFound) {
200-
serializingContext.setError("No StructureDescriptionFileLocation element"
201-
" found for SystemClass " + _strSystemClassName);
202-
}
203-
if (!subsystemPluginsChildFound) {
204-
serializingContext.setError("Parameter Framework Configuration: couldn't "
205-
"find SubsystemPlugins element");
206-
}
207-
return true;
208-
}
209-

parameter/ParameterFrameworkConfiguration.h

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@
3131

3232
#include <string>
3333
#include <list>
34-
#include "XmlSink.h"
3534

36-
class CParameterFrameworkConfiguration : public IXmlSink
35+
class CParameterFrameworkConfiguration
3736
{
3837
public:
3938
CParameterFrameworkConfiguration(const std::string &configurationFile);
@@ -79,14 +78,6 @@ class CParameterFrameworkConfiguration : public IXmlSink
7978
_schemasLocation = location;
8079
}
8180

82-
private:
83-
// From IXmlSink
84-
virtual bool fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext);
85-
86-
bool retrieveSettingsConfiguration(const CXmlElement &settingsNode, CXmlSerializingContext& serializingContext);
87-
bool retrievePathAttribute(const CXmlElement &xmlElement, std::string &path, CXmlSerializingContext& serializingContext);
88-
bool retrievePluginsConfiguration(const CXmlElement &pluginNode, CXmlSerializingContext& serializingContext);
89-
9081
// System class name
9182
std::string _strSystemClassName;
9283
// Tuning allowed
@@ -102,6 +93,5 @@ class CParameterFrameworkConfiguration : public IXmlSink
10293
std::string _settingsFile;
10394
std::string _binarySettingsFile;
10495

105-
std::string _subsystemPlugins;
10696
std::list<std::string> _plugins;
10797
};
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
/*
2+
* Copyright (c) 2015, Intel Corporation
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without modification,
6+
* are permitted provided that the following conditions are met:
7+
*
8+
* 1. Redistributions of source code must retain the above copyright notice, this
9+
* list of conditions and the following disclaimer.
10+
*
11+
* 2. Redistributions in binary form must reproduce the above copyright notice,
12+
* this list of conditions and the following disclaimer in the documentation and/or
13+
* other materials provided with the distribution.
14+
*
15+
* 3. Neither the name of the copyright holder nor the names of its contributors
16+
* may be used to endorse or promote products derived from this software without
17+
* specific prior written permission.
18+
*
19+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
#pragma once
31+
32+
#include "Node.hpp"
33+
#include "ParameterFrameworkConfiguration.h"
34+
35+
#include <string>
36+
#include <stdexcept>
37+
38+
namespace core
39+
{
40+
namespace xml
41+
{
42+
namespace bindings
43+
{
44+
45+
class ParameterFrameworkConfigurationXmlBinding
46+
{
47+
public:
48+
/** @param[in] configuration the reference on the configuration to fill */
49+
ParameterFrameworkConfigurationXmlBinding(CParameterFrameworkConfiguration &configuration)
50+
: mConfiguration(configuration), mPluginFolder("")
51+
{
52+
}
53+
54+
55+
/** Generate Xml bindings for a ParameterFrameworkConfiguration object
56+
*
57+
* return root Node of generated bindings
58+
*/
59+
core::xml::binding::Node getBindings()
60+
{
61+
using namespace core::xml::binding;
62+
Node plugin {
63+
"Plugin",
64+
Body {
65+
Attributes {
66+
{ "Name",
67+
Type<std::string>{},
68+
[] () { throw std::runtime_error("Unimplemented serialization behavior of"
69+
" ParameterFrameworkConfiguration");
70+
return ""; },
71+
[this] (std::string name) {
72+
mConfiguration._plugins.push_back(
73+
mPluginFolder + (mPluginFolder.empty() ? "" : "/") + name);
74+
}
75+
}
76+
},
77+
Nodes {}
78+
}
79+
};
80+
Node location {
81+
"Location",
82+
Body {
83+
Attributes { { "Folder", makeAccessor(mPluginFolder) } },
84+
Nodes { plugin }
85+
}
86+
};
87+
Node subsystemPlugins { "SubsystemPlugins", Body { Attributes {}, Nodes { location } } };
88+
Node structure {
89+
"StructureDescriptionFileLocation",
90+
Body { Attributes { makePathAttribute(mConfiguration._structureFile) }, Nodes {} }
91+
};
92+
Node configurableDomains {
93+
"ConfigurableDomainsFileLocation",
94+
Body { Attributes { makePathAttribute(mConfiguration._settingsFile) }, Nodes {} }
95+
};
96+
Node settingsBinary {
97+
"BinarySettingsFileLocation",
98+
Body { Attributes { makePathAttribute(mConfiguration._binarySettingsFile) }, Nodes {} }
99+
};
100+
Node settings {
101+
"SettingsConfiguration",
102+
Body { Attributes {}, Nodes { configurableDomains, settingsBinary } }
103+
};
104+
Node configuration {
105+
"ParameterFrameworkConfiguration",
106+
Body {
107+
Attributes {
108+
{ "SystemClassName", makeAccessor(mConfiguration._strSystemClassName) },
109+
{ "ServerPort", makeAccessor(mConfiguration._uiServerPort) },
110+
{ "TuningAllowed", makeAccessor(mConfiguration._bTuningAllowed) }
111+
},
112+
Nodes { subsystemPlugins, structure, settings }
113+
}
114+
};
115+
116+
return configuration;
117+
}
118+
119+
private:
120+
/** Helper for Path attribute binding generation
121+
* Prepare, in the setter, the path by adding the configuration folder to any
122+
* relative path.
123+
*
124+
* @return an Attribute which can hold a path
125+
*/
126+
core::xml::binding::Attribute makePathAttribute(std::string &pathSink)
127+
{
128+
using namespace core::xml::binding;
129+
return { "Path", Type<std::string>{},
130+
[&pathSink] () { return pathSink; },
131+
[&pathSink, this] (std::string path) {
132+
if (path[0] != '/') {
133+
// Path is relative
134+
pathSink = mConfiguration._configurationFolder + "/" + path;
135+
}
136+
}
137+
};
138+
}
139+
/** Reference on the Configuration object to fill */
140+
CParameterFrameworkConfiguration &mConfiguration;
141+
142+
/** Plugin Folder temporary variable */
143+
std::string mPluginFolder;
144+
};
145+
146+
} /** bindings namespace */
147+
} /** xml namespace */
148+
} /** core namespace */

0 commit comments

Comments
 (0)