| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2015 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:LGPL21$ |
| 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 http://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at http://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 2.1 or version 3 as published by the Free |
| 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and |
| 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the |
| 22 | ** following information to ensure the GNU Lesser General Public License |
| 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and |
| 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
| 25 | ** |
| 26 | ** As a special exception, The Qt Company gives you certain additional |
| 27 | ** rights. These rights are described in The Qt Company LGPL Exception |
| 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
| 29 | ** |
| 30 | ** $QT_END_LICENSE$ |
| 31 | ** |
| 32 | ****************************************************************************/ |
| 33 | |
| 34 | #ifndef SERVICEMETADATA_H |
| 35 | #define SERVICEMETADATA_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 purely as an |
| 42 | // implementation detail. This header file may change from version to |
| 43 | // version without notice, or even be removed. |
| 44 | // |
| 45 | // We mean it. |
| 46 | // |
| 47 | |
| 48 | #include "qserviceframeworkglobal.h" |
| 49 | #include <QXmlStreamReader> |
| 50 | #include <QStringList> |
| 51 | #include <QList> |
| 52 | #include <QSet> |
| 53 | #include "qserviceinterfacedescriptor.h" |
| 54 | |
| 55 | #if defined(IGNORE_SERVICEMETADATA_EXPORT) || defined(SERVICE_XML_GENERATOR) |
| 56 | # define SERVICEMETADATA_EXPORT |
| 57 | #else |
| 58 | # define SERVICEMETADATA_EXPORT Q_AUTOTEST_EXPORT |
| 59 | #endif |
| 60 | |
| 61 | QT_BEGIN_NAMESPACE |
| 62 | class QIODevice; |
| 63 | |
| 64 | // FORWARD DECLARATIONS |
| 65 | class QServiceInterfaceDescriptor; |
| 66 | |
| 67 | class SERVICEMETADATA_EXPORT ServiceMetaDataResults |
| 68 | { |
| 69 | public: |
| 70 | ServiceMetaDataResults() : type(0) {} |
| 71 | |
| 72 | ServiceMetaDataResults(const ServiceMetaDataResults& other) |
| 73 | { |
| 74 | type = other.type; |
| 75 | location = other.location; |
| 76 | name = other.name; |
| 77 | description = other.description; |
| 78 | interfaces = other.interfaces; |
| 79 | latestInterfaces = other.latestInterfaces; |
| 80 | } |
| 81 | |
| 82 | int type; |
| 83 | QString location; |
| 84 | QString name; |
| 85 | QString description; |
| 86 | QList<QServiceInterfaceDescriptor> interfaces; |
| 87 | QList<QServiceInterfaceDescriptor> latestInterfaces; |
| 88 | }; |
| 89 | |
| 90 | #ifndef QT_NO_DATASTREAM |
| 91 | SERVICEMETADATA_EXPORT QDataStream &operator<<(QDataStream &, const ServiceMetaDataResults &); |
| 92 | SERVICEMETADATA_EXPORT QDataStream &operator>>(QDataStream &, ServiceMetaDataResults &); |
| 93 | #endif |
| 94 | |
| 95 | class SERVICEMETADATA_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 = 0, /* 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_PATH, /* 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 | SFW_ERROR_MULTIPLE_SERVICE_TYPES, /* Both filepath and ipcaddress found in the XML file */ |
| 120 | SFW_ERROR_INVALID_FILEPATH, /* Service path cannot contain IPC prefix */ |
| 121 | SFW_ERROR_INVALID_XML_VERSION, /* Error parsing serficefw version node */ |
| 122 | SFW_ERROR_UNSUPPORTED_IPC, /* Servicefw version doesn't support IPC */ |
| 123 | SFW_ERROR_UNSUPPORTED_XML_VERSION /* Unsupported servicefw version supplied */ |
| 124 | }; |
| 125 | |
| 126 | public: |
| 127 | |
| 128 | ServiceMetaData(const QString &aXmlFilePath); |
| 129 | |
| 130 | ServiceMetaData(QIODevice *device); |
| 131 | |
| 132 | ~ServiceMetaData(); |
| 133 | |
| 134 | void setDevice(QIODevice *device); |
| 135 | |
| 136 | QIODevice *device() const; |
| 137 | |
| 138 | bool (); |
| 139 | |
| 140 | int getLatestError() const; |
| 141 | |
| 142 | ServiceMetaDataResults parseResults() const; |
| 143 | |
| 144 | private: |
| 145 | QList<QServiceInterfaceDescriptor> latestInterfaces() const; |
| 146 | QServiceInterfaceDescriptor latestInterfaceVersion(const QString &interfaceName); |
| 147 | bool processVersionElement(QXmlStreamReader &aXMLReader); |
| 148 | bool processServiceElement(QXmlStreamReader &aXMLReader); |
| 149 | bool processInterfaceElement(QXmlStreamReader &aXMLReader); |
| 150 | void clearMetadata(); |
| 151 | |
| 152 | Q_DISABLE_COPY(ServiceMetaData); |
| 153 | |
| 154 | private: |
| 155 | bool lessThan(const QServiceInterfaceDescriptor &d1, |
| 156 | const QServiceInterfaceDescriptor &d2) const; |
| 157 | bool greaterThan(const QString &v1, const QString &v2) const; |
| 158 | bool checkVersion(const QString &version) const; |
| 159 | void transformVersion(const QString &version, int *major, int *minor) const; |
| 160 | |
| 161 | QIODevice *xmlDevice; |
| 162 | bool ownsXmlDevice; |
| 163 | QString xmlVersion; |
| 164 | QString serviceName; |
| 165 | QString serviceLocation; |
| 166 | QString serviceDescription; |
| 167 | QService::Type serviceType; |
| 168 | QList<QServiceInterfaceDescriptor> serviceInterfaces; |
| 169 | QSet<QString> duplicates; |
| 170 | int latestError; |
| 171 | QHash<QString, int> m_latestIndex; |
| 172 | }; |
| 173 | |
| 174 | QT_END_NAMESPACE |
| 175 | |
| 176 | #endif // SERVICEMETADATA_H |
| 177 | |