source: pacpusframework/branches/0.1.x/src/PacpusLib/XmlComponentConfig.cpp@ 257

Last change on this file since 257 was 165, checked in by Marek Kurdej, 11 years ago

Major: changed plugins section name to plugings. Parameters section will be used for something else.

  • Property svn:executable set to *
File size: 4.9 KB
Line 
1// %pacpus:license{
2// This file is part of the PACPUS framework distributed under the
3// CECILL-C License, Version 1.0.
4// %pacpus:license}
5/// @version $Id: XmlComponentConfig.cpp 79 2013-01-14 08:52:06Z kurdejma $
6
7#include <Pacpus/kernel/XmlComponentConfig.h>
8#include <Pacpus/kernel/Log.h>
9#include <Pacpus/kernel/XmlConfigFile.h>
10
11using namespace pacpus;
12using namespace std;
13
14DECLARE_STATIC_LOGGER("pacpus.core.XmlComponentConfig");
15
16static const char* kPropertyComponentName = "name";
17static const char* kPropertyComponentType = "type";
18static const char* kPropertyConnectionType = "type";
19static const char* kPropertyConnectionInput = "input";
20static const char* kPropertyConnectionOutput = "output";
21static const char* kPropertyConnectionPriority = "priority";
22
23XmlComponentConfig::XmlComponentConfig(const QString& name)
24{
25 LOG_TRACE("XmlComponentConfig(QString)");
26
27 // Get the pointer to the document and create the component.
28 parentDocument_ = XmlConfigFile::create();
29 if (name != QString::null)
30 component_ = parentDocument_->createComponent(name);
31}
32
33/// Destructor.
34XmlComponentConfig::~XmlComponentConfig()
35{
36 LOG_TRACE("~XmlComponentConfig()");
37}
38
39void XmlComponentConfig::addProperty(const QString& name)
40{
41 if (hasProperty(name))
42 {
43 LOG_ERROR("cannot add component property:"
44 << " component '" << component_.attribute(kPropertyComponentName) << "'"
45 << " already contains property '" << name << "'"
46 << " and its value is '" << component_.attribute(name) << "'"
47 );
48 return;
49 }
50
51 // The property does not exist, it can be added.
52 component_.setAttribute(name, 0);
53 LOG_INFO("property '" << name << "'"
54 << " was added to the component " << component_.attribute(kPropertyComponentName) << "'"
55 << " and set to '" << component_.attribute(name) << "'"
56 );
57}
58
59int XmlComponentConfig::delProperty(const QString& name)
60{
61 if (!hasProperty(name)) {
62 LOG_WARN("cannot delete compoenent property '" << name << "'"
63 << " of component '" << component_.attribute(kPropertyComponentName) << "'"
64 << ". Component does not contain this property."
65 );
66 return false;
67 }
68
69 // The property exists, it can be removed.
70 component_.removeAttribute(name);
71 LOG_INFO("property '" << name << "' "
72 << " of component '" << component_.attribute(kPropertyComponentName) << "'"
73 << " was deleted"
74 );
75
76 return true;
77}
78
79QString XmlComponentConfig::getProperty(const QString& name, const QString& defaultValue) const
80{
81 if (!hasProperty(name))
82 {
83 LOG_WARN("cannot retrieve component property '" << name << "'"
84 << " of component '" << component_.attribute(kPropertyComponentName) << "'"
85 << ". Component does not contain this property."
86 );
87 return defaultValue;
88 }
89
90 // The property exists, the value can be retrieved.
91 return component_.attribute(name);
92}
93
94bool XmlComponentConfig::getBoolProperty(const QString& name, bool defaultValue) const
95{
96 return hasProperty(name) ? getProperty(name) == "true" : defaultValue;
97}
98
99int XmlComponentConfig::getIntProperty(const QString& name, int defaultValue) const
100{
101 return hasProperty(name) ? getProperty(name).toInt() : defaultValue;
102}
103
104double XmlComponentConfig::getDoubleProperty(const QString& name, double defaultValue) const
105{
106 return hasProperty(name) ? getProperty(name).toDouble() : defaultValue;
107}
108
109void XmlComponentConfig::setProperty(const QString& name, const QString& value)
110{
111 component_.setAttribute(name, value);
112 LOG_INFO("property " << name
113 << " of the component " << component_.attribute(kPropertyComponentName)
114 << " was set to : " << value
115 );
116}
117
118bool XmlComponentConfig::hasProperty(const QString& name) const
119{
120 return component_.hasAttribute(name);
121}
122
123QDomElement XmlComponentConfig::qDomElement() const
124{
125 return component_;
126}
127
128void XmlComponentConfig::localCopy(const QDomElement& elementToCopy)
129{
130 component_ = elementToCopy;
131}
132
133QString const XmlComponentConfig::getComponentName() const
134{
135 return getProperty(kPropertyComponentName);
136}
137
138QString const XmlComponentConfig::getComponentType() const
139{
140 return getProperty(kPropertyComponentType);
141}
142
143QString const XmlComponentConfig::getConnectionType() const
144{
145 return getProperty(kPropertyConnectionType);
146}
147
148QString const XmlComponentConfig::getConnectionInput() const
149{
150 return getProperty(kPropertyConnectionInput);
151}
152
153QString const XmlComponentConfig::getConnectionOutput() const
154{
155 return getProperty(kPropertyConnectionOutput);
156}
157
158int const XmlComponentConfig::getConnectionPriority() const
159{
160 return getIntProperty(kPropertyConnectionPriority, /*defaultValue=*/0);
161}
Note: See TracBrowser for help on using the repository browser.