trikRuntime
configurer.h
Go to the documentation of this file.
1 /* Copyright 2015 CyberTech Labs Ltd.
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License. */
14 
15 #pragma once
16 
17 #include <QtCore/QString>
18 #include <QtCore/QStringList>
19 #include <QtCore/QHash>
20 
21 class QDomElement;
22 
23 namespace trikKernel {
24 
29 {
30 public:
34  Configurer(const QString &systemConfig, const QString &modelConfig);
35 
37  QString attributeByDevice(const QString &deviceClass, const QString &attributeName) const;
38 
40  QString attributeByPort(const QString &port, const QString &attributeName) const;
41 
44  bool isEnabled(const QString &deviceName) const;
45 
47  QStringList ports() const;
48 
50  QString deviceClass(const QString &port) const;
51 
53  QStringList initScripts() const;
54 
58  void configure(const QString &portName, const QString &deviceName);
59 
61  QString version() const;
62 
63 private:
64  struct Device {
65  QString name;
66  QHash<QString, QString> attributes;
67  QHash<QString, QHash<QString, QString>> portSpecificAttributes;
68  bool isOptional = false;
69  };
70 
71  struct DeviceType {
72  QString name;
73  QString deviceClass;
74  QHash<QString, QString> attributes;
75  };
76 
77  struct ModelConfigurationElement {
78  QString port;
79  QString deviceType;
80  QHash<QString, QString> attributes;
81  };
82 
83  struct AdditionalModelConfigurationElement {
84  QString deviceClass;
85  QHash<QString, QString> attributes;
86  };
87 
88  void parseDeviceClasses(const QDomElement &element);
89  void parseDevicePorts(const QDomElement &element);
90  void parseDeviceTypes(const QDomElement &element);
91  void parseInitScript(const QDomElement &element);
92  void parseAdditionalConfigurations(const QDomElement &element);
93  void parseModelConfig(const QDomElement &element);
94 
95  QStringList mInitScripts;
96 
98  QHash<QString, Device> mDevices;
99 
101  QHash<QString, DeviceType> mDeviceTypes;
102 
104  QHash<QString, Device> mAdditionalConfiguration;
105 
107  QHash<QString, ModelConfigurationElement> mModelConfiguration;
108 
110  QHash<QString, AdditionalModelConfigurationElement> mAdditionalModelConfiguration;
111 
113  QString mVersion;
114 };
115 
116 }
Definition: analogSensor.h:23
Configurer(const QString &systemConfig, const QString &modelConfig)
Constructor.
Definition: configurer.cpp:34
Generic configuration helper, parses configuration XML files and presents configuration as a set of a...
Definition: configurer.h:28
static const int port
Definition: trikCommunicatorTest.cpp:24
QStringList initScripts() const
Returns init scripts defined in config files, first from system config then from model config...
Definition: configurer.cpp:183
QString attributeByDevice(const QString &deviceClass, const QString &attributeName) const
Returns value of given attribute of given device.
Definition: configurer.cpp:65
QString version() const
Returns version of the config file which shall correspond to casing model.
Definition: configurer.cpp:193
QString attributeByPort(const QString &port, const QString &attributeName) const
Returns value of given attribute of a device on given port.
Definition: configurer.cpp:87
bool isEnabled(const QString &deviceName) const
Returns true if device is enabled in current configuration (either explicitly enabled in model config...
Definition: configurer.cpp:145
QStringList ports() const
Ports configured in model config.
Definition: configurer.cpp:158
QString deviceClass(const QString &port) const
Returns class of a device configured on given port.
Definition: configurer.cpp:163
void configure(const QString &portName, const QString &deviceName)
Changes configuration by configuring given device on given port.
Definition: configurer.cpp:188