|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * |
|
5 * This program is free software: you can redistribute it and/or modify |
|
6 * it under the terms of the GNU Lesser General Public License as published by |
|
7 * the Free Software Foundation, version 2.1 of the License. |
|
8 * |
|
9 * This program is distributed in the hope that it will be useful, |
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 * GNU Lesser General Public License for more details. |
|
13 * |
|
14 * You should have received a copy of the GNU Lesser General Public License |
|
15 * along with this program. If not, |
|
16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/". |
|
17 * |
|
18 * Description: |
|
19 * |
|
20 */ |
|
21 |
|
22 #ifndef XQSERVICEMETADATA_H |
|
23 #define XQSERVICEMETADATA_H |
|
24 |
|
25 #include <QXmlStreamReader> |
|
26 #include <QStringList> |
|
27 #include <QList> |
|
28 #include <QSet> |
|
29 #include "qserviceglobal.h" |
|
30 #include "xqaiwinterfacedescriptor.h" |
|
31 |
|
32 class QIODevice; |
|
33 |
|
34 QT_BEGIN_NAMESPACE |
|
35 |
|
36 // FORWARD DECLARATIONS |
|
37 class XQAiwInterfaceDescriptor; |
|
38 |
|
39 class ServiceMetaDataResults |
|
40 { |
|
41 public: |
|
42 ServiceMetaDataResults() {} |
|
43 |
|
44 ServiceMetaDataResults(const ServiceMetaDataResults& other) |
|
45 { |
|
46 description = other.description; |
|
47 location = other.location; |
|
48 name = other.name; |
|
49 interfaces = other.interfaces; |
|
50 latestInterfaces = other.latestInterfaces; |
|
51 } |
|
52 |
|
53 QString location; |
|
54 QString name; |
|
55 QString description; |
|
56 QList<XQAiwInterfaceDescriptor> interfaces; |
|
57 QList<XQAiwInterfaceDescriptor> latestInterfaces; |
|
58 }; |
|
59 |
|
60 #ifndef QT_NO_DATASTREAM |
|
61 Q_SFW_EXPORT QDataStream &operator<<(QDataStream &, const ServiceMetaDataResults &); |
|
62 Q_SFW_EXPORT QDataStream &operator>>(QDataStream &, ServiceMetaDataResults &); |
|
63 #endif |
|
64 |
|
65 class Q_SFW_EXPORT ServiceMetaData |
|
66 { |
|
67 public: |
|
68 |
|
69 //! ServiceMetaData::ServiceMetadataErr |
|
70 /*! |
|
71 This enum describes the errors that may be returned by the Service metadata parser. |
|
72 */ |
|
73 enum ServiceMetadataErr { |
|
74 SFW_ERROR_NO_SERVICE = 0, /* Can not find service root node in XML file*/ |
|
75 SFW_ERROR_NO_SERVICE_NAME, /* Can not find service name in XML file */ |
|
76 SFW_ERROR_NO_SERVICE_FILEPATH, /* Can not find service filepath in XML file */ |
|
77 SFW_ERROR_NO_SERVICE_INTERFACE, /* No interface for the service in XML file*/ |
|
78 SFW_ERROR_NO_INTERFACE_VERSION, /* Can not find interface version in XML file */ |
|
79 SFW_ERROR_NO_INTERFACE_NAME, /* Can not find interface name in XML file*/ |
|
80 SFW_ERROR_UNABLE_TO_OPEN_FILE, /* Error opening XML file*/ |
|
81 SFW_ERROR_INVALID_XML_FILE, /* Not a valid XML file*/ |
|
82 SFW_ERROR_PARSE_SERVICE, /* Error parsing service node */ |
|
83 SFW_ERROR_PARSE_INTERFACE, /* Error parsing interface node */ |
|
84 SFW_ERROR_DUPLICATED_INTERFACE, /* The same interface is defined twice */ |
|
85 SFW_ERROR_INVALID_VERSION, /* Invalid version number */ |
|
86 SFW_ERROR_DUPLICATED_TAG, /* The tag appears twice */ |
|
87 SFW_ERROR_INVALID_CUSTOM_TAG, /* The customproperty tag is not corectly formatted or otherwise incorrect*/ |
|
88 SFW_ERROR_DUPLICATED_CUSTOM_KEY /* The customproperty appears twice*/ |
|
89 }; |
|
90 |
|
91 public: |
|
92 |
|
93 ServiceMetaData(const QString &aXmlFilePath); |
|
94 |
|
95 ServiceMetaData(QIODevice *device); |
|
96 |
|
97 ~ServiceMetaData(); |
|
98 |
|
99 void setDevice(QIODevice *device); |
|
100 |
|
101 QIODevice *device() const; |
|
102 |
|
103 /*TBR: void setServiceFilePath(const QString &aFilePath); */ |
|
104 |
|
105 bool extractMetadata(); |
|
106 |
|
107 int getLatestError(); |
|
108 |
|
109 /*TBR: |
|
110 QString name(); |
|
111 |
|
112 QString filePath(); |
|
113 |
|
114 QString description(); |
|
115 |
|
116 int interfaceCount(); |
|
117 |
|
118 QList<SFWInterface> getInterfaces(); |
|
119 |
|
120 bool checkVersion(const QString &version); |
|
121 */ |
|
122 |
|
123 ServiceMetaDataResults parseResults() const; |
|
124 |
|
125 |
|
126 private: |
|
127 bool getAttributeValue(const QXmlStreamReader &aDomElement, |
|
128 const QString &aAttributeName, QString &aValue); |
|
129 QList<XQAiwInterfaceDescriptor> latestInterfaces() const; |
|
130 XQAiwInterfaceDescriptor latestInterfaceVersion(const QString &interfaceName); |
|
131 bool processServiceElement(QXmlStreamReader &aXMLReader); |
|
132 |
|
133 bool processInterfaceElement(QXmlStreamReader &aXMLReader); |
|
134 |
|
135 void clearMetadata(); |
|
136 |
|
137 private: |
|
138 bool lessThan(const XQAiwInterfaceDescriptor &d1, |
|
139 const XQAiwInterfaceDescriptor &d2) const; |
|
140 bool checkVersion(const QString &version) const; |
|
141 void transformVersion(const QString &version, int *major, int *minor) const; |
|
142 |
|
143 QIODevice *xmlDevice; |
|
144 bool ownsXmlDevice; |
|
145 QString serviceName; |
|
146 QString serviceLocation; |
|
147 QString serviceDescription; |
|
148 QList<XQAiwInterfaceDescriptor> serviceInterfaces; |
|
149 QSet<QString> duplicates; |
|
150 int latestError; |
|
151 QHash<QString, int> m_latestIndex; |
|
152 }; |
|
153 |
|
154 QT_END_NAMESPACE |
|
155 |
|
156 #endif // XQSERVICEMETADATA_H |