|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
5 ** |
|
6 ** This file is part of the Qt Mobility Components. |
|
7 ** |
|
8 ** $QT_BEGIN_LICENSE:LGPL$ |
|
9 ** No Commercial Usage |
|
10 ** This file contains pre-release code and may not be distributed. |
|
11 ** You may use this file in accordance with the terms and conditions |
|
12 ** contained in Technology Preview License Agreement accompanying |
|
13 ** this package. |
|
14 ** |
|
15 ** GNU Lesser General Public License Usage |
|
16 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
17 ** General Public License version 2.1 as published by the Free Software |
|
18 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
19 ** packaging of this file. Please review the following information to |
|
20 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
21 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
22 ** |
|
23 ** In addition, as a special exception, Nokia gives you certain |
|
24 ** additional rights. These rights are described in the Nokia Qt LGPL |
|
25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this |
|
26 ** package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please |
|
29 ** contact Nokia at http://qt.nokia.com/contact. |
|
30 ** $QT_END_LICENSE$ |
|
31 ** |
|
32 ****************************************************************************/ |
|
33 |
|
34 #ifndef XQSERVICEMETADATA_H |
|
35 #define XQSERVICEMETADATA_H |
|
36 |
|
37 // |
|
38 // W A R N I N G |
|
39 // ------------- |
|
40 // |
|
41 // This file is not part of the Qt API. It exists for the convenience |
|
42 // of the QLibrary class. This header file may change from |
|
43 // version to version without notice, or even be removed. |
|
44 // |
|
45 // We mean it. |
|
46 // |
|
47 #include <QXmlStreamReader> |
|
48 #include <QStringList> |
|
49 #include <QList> |
|
50 #include <QSet> |
|
51 #include "xqserviceglobal.h" |
|
52 #include "xqserviceerrdefs.h" // error codes |
|
53 #include "xqaiwinterfacedescriptor.h" |
|
54 |
|
55 class QIODevice; |
|
56 |
|
57 QT_BEGIN_NAMESPACE |
|
58 |
|
59 // FORWARD DECLARATIONS |
|
60 class XQAiwInterfaceDescriptor; |
|
61 |
|
62 class ServiceMetaDataResults |
|
63 { |
|
64 public: |
|
65 enum ServiceMetadataVersion { |
|
66 VERSION_1 = 1, |
|
67 VERSION_2 = 2 // default |
|
68 }; |
|
69 |
|
70 ServiceMetaDataResults() {}; |
|
71 |
|
72 ServiceMetaDataResults(const ServiceMetaDataResults& other) |
|
73 { |
|
74 description = other.description; |
|
75 location = other.location; |
|
76 name = other.name; |
|
77 interfaces = other.interfaces; |
|
78 latestInterfaces = other.latestInterfaces; |
|
79 version = other.version; |
|
80 }; |
|
81 |
|
82 QString location; |
|
83 QString name; |
|
84 QString description; |
|
85 QList<XQAiwInterfaceDescriptor> interfaces; |
|
86 QList<XQAiwInterfaceDescriptor> latestInterfaces; |
|
87 int version; // ServiceMetadataVersion |
|
88 }; |
|
89 |
|
90 #ifndef QT_NO_DATASTREAM |
|
91 Q_SFW_EXPORT QDataStream &operator<<(QDataStream &, const ServiceMetaDataResults &); |
|
92 Q_SFW_EXPORT QDataStream &operator>>(QDataStream &, ServiceMetaDataResults &); |
|
93 #endif |
|
94 |
|
95 class Q_SFW_EXPORT ServiceMetaData |
|
96 { |
|
97 public: |
|
98 |
|
99 //! ServiceMetaData::ServiceMetadataErr |
|
100 /*! |
|
101 This enum describes the errors that may be returned by the Service metadata parser. |
|
102 */ |
|
103 enum ServiceMetadataErr { |
|
104 SFW_ERROR_NO_SERVICE = QtService::METADATA_ERR_START_VALUE, /* Can not find service root node in XML file*/ |
|
105 SFW_ERROR_NO_SERVICE_NAME, /* Can not find service name in XML file */ |
|
106 SFW_ERROR_NO_SERVICE_FILEPATH, /* Can not find service filepath in XML file */ |
|
107 SFW_ERROR_NO_SERVICE_INTERFACE, /* No interface for the service in XML file*/ |
|
108 SFW_ERROR_NO_INTERFACE_VERSION, /* Can not find interface version in XML file */ |
|
109 SFW_ERROR_NO_INTERFACE_NAME, /* Can not find interface name in XML file*/ |
|
110 SFW_ERROR_UNABLE_TO_OPEN_FILE, /* Error opening XML file*/ |
|
111 SFW_ERROR_INVALID_XML_FILE, /* Not a valid XML file*/ |
|
112 SFW_ERROR_PARSE_SERVICE, /* Error parsing service node */ |
|
113 SFW_ERROR_PARSE_INTERFACE, /* Error parsing interface node */ |
|
114 SFW_ERROR_DUPLICATED_INTERFACE, /* The same interface is defined twice */ |
|
115 SFW_ERROR_INVALID_VERSION, |
|
116 SFW_ERROR_DUPLICATED_TAG, /* The tag appears twice */ |
|
117 SFW_ERROR_INVALID_CUSTOM_TAG, /* The customproperty tag is not corectly formatted or otherwise incorrect*/ |
|
118 SFW_ERROR_DUPLICATED_CUSTOM_KEY /* The customproperty appears twice*/ |
|
119 }; |
|
120 |
|
121 public: |
|
122 |
|
123 ServiceMetaData(const QString &aXmlFilePath); |
|
124 |
|
125 ServiceMetaData(QIODevice *device); |
|
126 |
|
127 ~ServiceMetaData(); |
|
128 |
|
129 void setDevice(QIODevice *device); |
|
130 |
|
131 QIODevice *device() const; |
|
132 |
|
133 bool extractMetadata(); |
|
134 |
|
135 int getLatestError() const; |
|
136 |
|
137 ServiceMetaDataResults parseResults() const; |
|
138 |
|
139 private: |
|
140 QList<XQAiwInterfaceDescriptor> latestInterfaces() const; |
|
141 XQAiwInterfaceDescriptor latestInterfaceVersion(const QString &interfaceName); |
|
142 bool processServiceElement(QXmlStreamReader &aXMLReader); |
|
143 bool processInterfaceElement(QXmlStreamReader &aXMLReader); |
|
144 |
|
145 // Support for old XML format |
|
146 bool getAttributeValue(const QXmlStreamReader &aDomElement, |
|
147 const QString &aAttributeName, QString &aValue); |
|
148 bool processServiceElementPrevVersion(QXmlStreamReader &aXMLReader); |
|
149 bool processInterfaceElementPrevVersion(QXmlStreamReader &aXMLReader); |
|
150 |
|
151 void clearMetadata(); |
|
152 |
|
153 private: |
|
154 bool lessThan(const XQAiwInterfaceDescriptor &d1, |
|
155 const XQAiwInterfaceDescriptor &d2) const; |
|
156 bool checkVersion(const QString &version) const; |
|
157 void transformVersion(const QString &version, int *major, int *minor) const; |
|
158 |
|
159 QIODevice *xmlDevice; |
|
160 bool ownsXmlDevice; |
|
161 QString serviceName; |
|
162 QString serviceLocation; |
|
163 QString serviceDescription; |
|
164 QList<XQAiwInterfaceDescriptor> serviceInterfaces; |
|
165 QSet<QString> duplicates; |
|
166 int latestError; |
|
167 QHash<QString, int> m_latestIndex; |
|
168 int version; // data version |
|
169 }; |
|
170 |
|
171 QT_END_NAMESPACE |
|
172 |
|
173 #endif // XQSERVICEMETADATA_H |