Debian Codegraph @

src/serviceframework/servicemetadata_p.h

raw symbols SCIP
1 /****************************************************************************
2 **
3 ** Copyright (C) 2018 The Qt Company Ltd and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtSystems module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39
40 #ifndef SERVICEMETADATA_H
41 #define SERVICEMETADATA_H
42
43 //
44 // W A R N I N G
45 // -------------
46 //
47 // This file is not part of the Qt API. It exists purely as an
48 // implementation detail. This header file may change from version to
49 // version without notice, or even be removed.
50 //
51 // We mean it.
52 //
53
54 #include "qserviceframeworkglobal.h"
55 #include <QXmlStreamReader>
56 #include <QStringList>
57 #include <QList>
58 #include <QSet>
59 #include "qserviceinterfacedescriptor.h"
60
61 #if defined(IGNORE_SERVICEMETADATA_EXPORT) || defined(SERVICE_XML_GENERATOR)
62 # define SERVICEMETADATA_EXPORT
63 #else
64 # define SERVICEMETADATA_EXPORT Q_AUTOTEST_EXPORT
65 #endif
66
67 QT_BEGIN_NAMESPACE
68 class QIODevice;
69
70 // FORWARD DECLARATIONS
71 class QServiceInterfaceDescriptor;
72
73 class SERVICEMETADATA_EXPORT ServiceMetaDataResults
74 {
75 public:
76 ServiceMetaDataResults() : type(0) {}
77
78 ServiceMetaDataResults(const ServiceMetaDataResults& other)
79 {
80 type = other.type;
81 location = other.location;
82 name = other.name;
83 description = other.description;
84 interfaces = other.interfaces;
85 latestInterfaces = other.latestInterfaces;
86 }
87
88 int type;
89 QString location;
90 QString name;
91 QString description;
92 QList<QServiceInterfaceDescriptor> interfaces;
93 QList<QServiceInterfaceDescriptor> latestInterfaces;
94 };
95
96 #ifndef QT_NO_DATASTREAM
97 SERVICEMETADATA_EXPORT QDataStream &operator<<(QDataStream &, const ServiceMetaDataResults &);
98 SERVICEMETADATA_EXPORT QDataStream &operator>>(QDataStream &, ServiceMetaDataResults &);
99 #endif
100
101 class SERVICEMETADATA_EXPORT ServiceMetaData
102 {
103 public:
104
105 //! ServiceMetaData::ServiceMetadataErr
106 /*!
107 This enum describes the errors that may be returned by the Service metadata parser.
108 */
109 enum ServiceMetadataErr {
110 SFW_ERROR_NO_SERVICE = 0, /* Can not find service root node in XML file*/
111 SFW_ERROR_NO_SERVICE_NAME, /* Can not find service name in XML file */
112 SFW_ERROR_NO_SERVICE_PATH, /* Can not find service filepath in XML file */
113 SFW_ERROR_NO_SERVICE_INTERFACE, /* No interface for the service in XML file*/
114 SFW_ERROR_NO_INTERFACE_VERSION, /* Can not find interface version in XML file */
115 SFW_ERROR_NO_INTERFACE_NAME, /* Can not find interface name in XML file*/
116 SFW_ERROR_UNABLE_TO_OPEN_FILE, /* Error opening XML file*/
117 SFW_ERROR_INVALID_XML_FILE, /* Not a valid XML file*/
118 SFW_ERROR_PARSE_SERVICE, /* Error parsing service node */
119 SFW_ERROR_PARSE_INTERFACE, /* Error parsing interface node */
120 SFW_ERROR_DUPLICATED_INTERFACE, /* The same interface is defined twice */
121 SFW_ERROR_INVALID_VERSION,
122 SFW_ERROR_DUPLICATED_TAG, /* The tag appears twice */
123 SFW_ERROR_INVALID_CUSTOM_TAG, /* The customproperty tag is not corectly formatted or otherwise incorrect*/
124 SFW_ERROR_DUPLICATED_CUSTOM_KEY, /* The customproperty appears twice*/
125 SFW_ERROR_MULTIPLE_SERVICE_TYPES, /* Both filepath and ipcaddress found in the XML file */
126 SFW_ERROR_INVALID_FILEPATH, /* Service path cannot contain IPC prefix */
127 SFW_ERROR_INVALID_XML_VERSION, /* Error parsing serficefw version node */
128 SFW_ERROR_UNSUPPORTED_IPC, /* Servicefw version doesn't support IPC */
129 SFW_ERROR_UNSUPPORTED_XML_VERSION /* Unsupported servicefw version supplied */
130 };
131
132 public:
133
134 ServiceMetaData(const QString &aXmlFilePath);
135
136 ServiceMetaData(QIODevice *device);
137
138 ~ServiceMetaData();
139
140 void setDevice(QIODevice *device);
141
142 QIODevice *device() const;
143
144 bool extractMetadata();
145
146 int getLatestError() const;
147
148 ServiceMetaDataResults parseResults() const;
149
150 private:
151 QList<QServiceInterfaceDescriptor> latestInterfaces() const;
152 QServiceInterfaceDescriptor latestInterfaceVersion(const QString &interfaceName);
153 bool processVersionElement(QXmlStreamReader &aXMLReader);
154 bool processServiceElement(QXmlStreamReader &aXMLReader);
155 bool processInterfaceElement(QXmlStreamReader &aXMLReader);
156 void clearMetadata();
157
158 Q_DISABLE_COPY(ServiceMetaData);
159
160 private:
161 bool lessThan(const QServiceInterfaceDescriptor &d1,
162 const QServiceInterfaceDescriptor &d2) const;
163 bool greaterThan(const QString &v1, const QString &v2) const;
164 bool checkVersion(const QString &version) const;
165 void transformVersion(const QString &version, int *major, int *minor) const;
166
167 QIODevice *xmlDevice;
168 bool ownsXmlDevice;
169 QString xmlVersion;
170 QString serviceName;
171 QString serviceLocation;
172 QString serviceDescription;
173 QService::Type serviceType;
174 QList<QServiceInterfaceDescriptor> serviceInterfaces;
175 QSet<QString> duplicates;
176 int latestError;
177 QHash<QString, int> m_latestIndex;
178 };
179
180 QT_END_NAMESPACE
181
182 #endif // SERVICEMETADATA_H