| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
#ifndef SERVICEMETADATA_H |
| 41 |
#define SERVICEMETADATA_H |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 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 |
|
| 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 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
enum ServiceMetadataErr { |
| 110 |
SFW_ERROR_NO_SERVICE = 0, |
| 111 |
SFW_ERROR_NO_SERVICE_NAME, |
| 112 |
SFW_ERROR_NO_SERVICE_PATH, |
| 113 |
SFW_ERROR_NO_SERVICE_INTERFACE, |
| 114 |
SFW_ERROR_NO_INTERFACE_VERSION, |
| 115 |
SFW_ERROR_NO_INTERFACE_NAME, |
| 116 |
SFW_ERROR_UNABLE_TO_OPEN_FILE, |
| 117 |
SFW_ERROR_INVALID_XML_FILE, |
| 118 |
SFW_ERROR_PARSE_SERVICE, |
| 119 |
SFW_ERROR_PARSE_INTERFACE, |
| 120 |
SFW_ERROR_DUPLICATED_INTERFACE, |
| 121 |
SFW_ERROR_INVALID_VERSION, |
| 122 |
SFW_ERROR_DUPLICATED_TAG, |
| 123 |
SFW_ERROR_INVALID_CUSTOM_TAG, |
| 124 |
SFW_ERROR_DUPLICATED_CUSTOM_KEY, |
| 125 |
SFW_ERROR_MULTIPLE_SERVICE_TYPES, |
| 126 |
SFW_ERROR_INVALID_FILEPATH, |
| 127 |
SFW_ERROR_INVALID_XML_VERSION, |
| 128 |
SFW_ERROR_UNSUPPORTED_IPC, |
| 129 |
SFW_ERROR_UNSUPPORTED_XML_VERSION |
| 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 |