57 |
57 |
58 return in; |
58 return in; |
59 } |
59 } |
60 #endif |
60 #endif |
61 |
61 |
62 /* |
62 /*! |
63 \class ServiceMetaData |
63 \class ServiceMetaData |
|
64 \brief Utility class offering support for parsing metadata |
|
65 service xml registry files. |
64 |
66 |
65 Utility class (used by service database) that offers support for |
67 Utility class (used by service database) that offers support for |
66 parsing metadata service xml registry file during service registration. \n |
68 parsing metadata service xml registry file during service registration. \n |
67 |
69 |
68 It uses QXMLStreamReader class for parsing. Supproted Operations are: |
70 It uses QXMLStreamReader class for parsing. Supproted Operations are: |
69 - Parse the service and interfaces defined in XML file |
71 - Parse the service and interfaces defined in XML file |
70 - name, version, capabilitiesList, description and filePath of service can be retrieved |
72 - name, version, capabilitiesList, description and filePath of service can be retrieved |
71 - each interface can be retrieved |
73 - each interface can be retrieved |
72 */ |
74 */ |
73 |
75 |
74 /* |
76 /*! |
75 * Class constructor |
77 Constructor |
76 * |
78 \param aXmlFilePath Path to the xml file that describes the service. |
77 * @param aXmlFilePath path to the xml file that describes the service. |
79 */ |
78 */ |
|
79 ServiceMetaData::ServiceMetaData(const QString &aXmlFilePath) |
80 ServiceMetaData::ServiceMetaData(const QString &aXmlFilePath) |
80 { |
81 { |
81 XQSERVICE_DEBUG_PRINT("ServiceMetaData::ServiceMetaData(1)"); |
82 XQSERVICE_DEBUG_PRINT("ServiceMetaData::ServiceMetaData(1)"); |
82 XQSERVICE_DEBUG_PRINT("aXmlFilePath: %s", qPrintable(aXmlFilePath)); |
83 XQSERVICE_DEBUG_PRINT("aXmlFilePath: %s", qPrintable(aXmlFilePath)); |
83 xmlDevice = new QFile(aXmlFilePath); |
84 xmlDevice = new QFile(aXmlFilePath); |
84 ownsXmlDevice = true; |
85 ownsXmlDevice = true; |
85 latestError = 0; |
86 latestError = 0; |
86 } |
87 } |
87 |
88 |
88 /* |
89 /*! |
89 * Class constructor |
90 Constructor |
90 * |
91 \param device QIODevice that contains the XML data that describes the service. |
91 * @param device QIODevice that contains the XML data that describes the service. |
92 */ |
92 */ |
|
93 ServiceMetaData::ServiceMetaData(QIODevice *device) |
93 ServiceMetaData::ServiceMetaData(QIODevice *device) |
94 { |
94 { |
95 XQSERVICE_DEBUG_PRINT("ServiceMetaData::ServiceMetaData(2)"); |
95 XQSERVICE_DEBUG_PRINT("ServiceMetaData::ServiceMetaData(2)"); |
96 xmlDevice = device; |
96 xmlDevice = device; |
97 ownsXmlDevice = false; |
97 ownsXmlDevice = false; |
98 latestError = 0; |
98 latestError = 0; |
99 } |
99 } |
100 |
100 |
101 /* |
101 /*! |
102 * Class destructor |
102 Destructor |
103 * |
103 */ |
104 */ |
|
105 ServiceMetaData::~ServiceMetaData() |
104 ServiceMetaData::~ServiceMetaData() |
106 { |
105 { |
107 XQSERVICE_DEBUG_PRINT("ServiceMetaData::~ServiceMetaData"); |
106 XQSERVICE_DEBUG_PRINT("ServiceMetaData::~ServiceMetaData"); |
108 if (ownsXmlDevice) |
107 if (ownsXmlDevice) |
109 delete xmlDevice; |
108 delete xmlDevice; |
110 } |
109 } |
111 |
110 |
112 /* |
111 /*! |
113 Sets the device containing the XML data that describes the service to \a device. |
112 Sets the device containing the XML data that describes the service to \a device. |
114 */ |
113 \param device Device containing XML data. |
|
114 */ |
115 void ServiceMetaData::setDevice(QIODevice *device) |
115 void ServiceMetaData::setDevice(QIODevice *device) |
116 { |
116 { |
117 XQSERVICE_DEBUG_PRINT("ServiceMetaData::setDevice"); |
117 XQSERVICE_DEBUG_PRINT("ServiceMetaData::setDevice"); |
118 clearMetadata(); |
118 clearMetadata(); |
119 xmlDevice = device; |
119 xmlDevice = device; |
120 ownsXmlDevice = false; |
120 ownsXmlDevice = false; |
121 } |
121 } |
122 |
122 |
123 /* |
123 /*! |
124 Returns the device containing the XML data that describes the service. |
124 Gets the device containing the XML data that describes the service. |
|
125 \return Device containing the XML data. |
125 */ |
126 */ |
126 QIODevice *ServiceMetaData::device() const |
127 QIODevice *ServiceMetaData::device() const |
127 { |
128 { |
128 XQSERVICE_DEBUG_PRINT("ServiceMetaData::device"); |
129 XQSERVICE_DEBUG_PRINT("ServiceMetaData::device"); |
129 return xmlDevice; |
130 return xmlDevice; |
130 } |
131 } |
131 |
132 |
132 /* |
133 /*! |
133 * Gets the service name |
134 Gets the service name. |
134 * |
135 \return Service name or default value (empty string) if it is not available. |
135 * @return service name or default value (empty string) if it is not available |
136 */ |
136 */ |
137 |
137 /*QString ServiceMetaData::name() const |
138 /*QString ServiceMetaData::name() const |
138 { |
139 { |
139 return serviceName; |
140 return serviceName; |
140 }*/ |
141 }*/ |
141 |
142 |
142 /* |
143 /*! |
143 * Gets the path of the service implementation file |
144 Gets the path of the service implementation file. |
144 * |
145 \return Service implementation filepath. |
145 * @return service implementation filepath |
146 */ |
146 */ |
|
147 /*QString ServiceMetaData::location() const |
147 /*QString ServiceMetaData::location() const |
148 { |
148 { |
149 return serviceLocation; |
149 return serviceLocation; |
150 }*/ |
150 }*/ |
151 |
151 |
152 /* |
152 /*! |
153 * Gets the service description |
153 Gets the service description. |
154 * |
154 \return Service description or default value (empty string) if it is not available. |
155 * @return service description or default value (empty string) if it is not available |
155 */ |
156 */ |
|
157 /*QString ServiceMetaData::description() const |
156 /*QString ServiceMetaData::description() const |
158 { |
157 { |
159 return serviceDescription; |
158 return serviceDescription; |
160 }*/ |
159 }*/ |
161 |
160 |
162 /* |
161 /*! |
163 Returns the metadata of the interace at \a index; otherwise |
162 Gets the list of interfaces. |
164 returns 0. |
163 \return List interfaces. |
165 */ |
164 */ |
166 /*QList<XQServiceInterfaceDescriptor> ServiceMetaData::getInterfaces() const |
165 /*QList<XQServiceInterfaceDescriptor> ServiceMetaData::getInterfaces() const |
167 { |
166 { |
168 return serviceInterfaces; |
167 return serviceInterfaces; |
169 } */ |
168 } */ |
170 |
169 |
171 /*! |
170 /*! |
172 \internal |
171 \internal |
173 |
|
174 Returns a streamable object containing the results of the parsing. |
172 Returns a streamable object containing the results of the parsing. |
175 */ |
173 */ |
176 ServiceMetaDataResults ServiceMetaData::parseResults() const |
174 ServiceMetaDataResults ServiceMetaData::parseResults() const |
177 { |
175 { |
178 XQSERVICE_DEBUG_PRINT("ServiceMetaData::parseResults"); |
176 XQSERVICE_DEBUG_PRINT("ServiceMetaData::parseResults"); |
186 results.version = version; |
184 results.version = version; |
187 |
185 |
188 return results; |
186 return results; |
189 } |
187 } |
190 |
188 |
191 /* |
189 /*! |
192 Parses the file and extracts the service metadata \n |
190 Parses the file and extracts the service metadata \n |
193 Custom error codes: \n |
191 Custom error codes: \n |
194 SFW_ERROR_UNABLE_TO_OPEN_FILE in case can not open the XML file \n |
192 SFW_ERROR_UNABLE_TO_OPEN_FILE in case can not open the XML file \n |
195 SFW_ERROR_INVALID_XML_FILE in case service registry is not a valid XML file \n |
193 SFW_ERROR_INVALID_XML_FILE in case service registry is not a valid XML file \n |
196 SFW_ERROR_NO_SERVICE in case XML file has no service tag\n |
194 SFW_ERROR_NO_SERVICE in case XML file has no service tag\n |
197 @return true if the metadata was read properly, false if there is an error |
195 \return true if the metadata was read properly, false if there is an error. |
198 */ |
196 */ |
199 bool ServiceMetaData::extractMetadata() |
197 bool ServiceMetaData::extractMetadata() |
200 { |
198 { |
201 XQSERVICE_DEBUG_PRINT("ServiceMetaData::extractMetadata"); |
199 XQSERVICE_DEBUG_PRINT("ServiceMetaData::extractMetadata"); |
202 latestError = 0; |
200 latestError = 0; |
254 } |
252 } |
255 XQSERVICE_DEBUG_PRINT("XML parseError: %d", parseError); |
253 XQSERVICE_DEBUG_PRINT("XML parseError: %d", parseError); |
256 return !parseError; |
254 return !parseError; |
257 } |
255 } |
258 |
256 |
259 /* |
257 /*! |
260 Gets the latest parsing error \n |
258 Gets the latest parsing error. |
261 @return parsing error(negative value) or 0 in case there is none |
259 \return Parsing error(negative value) or 0 in case there is none. |
262 */ |
260 */ |
263 int ServiceMetaData::getLatestError() const |
261 int ServiceMetaData::getLatestError() const |
264 { |
262 { |
265 XQSERVICE_DEBUG_PRINT("ServiceMetaData::getLatestError"); |
263 XQSERVICE_DEBUG_PRINT("ServiceMetaData::getLatestError"); |
266 XQSERVICE_DEBUG_PRINT("latestError: %d", latestError); |
264 XQSERVICE_DEBUG_PRINT("latestError: %d", latestError); |
267 return latestError; |
265 return latestError; |
268 } |
266 } |
269 |
267 |
270 /* |
268 /*! |
271 Parses and extracts the service from the current xml <service> node |
269 Parses and extracts the service from the current xml <service> node |
272 using the new format (Version 2) \n |
270 using the new format (Version 2). |
273 Schema: |
271 Schema: |
274 <!ELEMENT service ( name, filepath, description?, interface+ ) > |
272 <!ELEMENT service ( name, filepath, description?, interface+ ) > |
275 <!ELEMENT description ( #CDATA ) > |
273 <!ELEMENT description ( #CDATA ) > |
276 <!ELEMENT filepath ( #PCDATA ) > |
274 <!ELEMENT filepath ( #PCDATA ) > |
277 <!ELEMENT interface ( name, version, description?, capabilities?, customproperty* ) > |
275 <!ELEMENT interface ( name, version, description?, capabilities?, customproperty* ) > |
361 |
359 |
362 /*! |
360 /*! |
363 Parses and extracts the service from the current xml <service> node |
361 Parses and extracts the service from the current xml <service> node |
364 using the new format (Version 1) \n |
362 using the new format (Version 1) \n |
365 |
363 |
366 <!ELEMENT service ( description?, interface+ ) > |
364 <!ELEMENT service ( description?, interface+ ) > |
367 <!ATTLIST service name #CDATA #REQUIRED > |
365 <!ATTLIST service name #CDATA #REQUIRED > |
368 <!ATTLIST service filepath #CDATA #REQUIRED > |
366 <!ATTLIST service filepath #CDATA #REQUIRED > |
369 <!ELEMENT description ( #CDATA ) > |
367 <!ELEMENT description ( #CDATA ) > |
370 <!ELEMENT interface ( description? ) > |
368 <!ELEMENT interface ( description? ) > |
371 <!ATTLIST interface name #CDATA #REQUIRED > |
369 <!ATTLIST interface name #CDATA #REQUIRED > |
372 <!ATTLIST interface version #CDATA #REQUIRED > |
370 <!ATTLIST interface version #CDATA #REQUIRED > |
373 <!ATTLIST interface capabilities #CDATA > |
371 <!ATTLIST interface capabilities #CDATA > |
374 |
372 |
375 Custom error codes: \n |
373 Custom error codes: \n |
376 SFW_ERROR_NO_SERVICE_NAME in case no service name in XML file \n |
374 SFW_ERROR_NO_SERVICE_NAME in case no service name in XML file \n |
377 SFW_ERROR_NO_INTERFACE_VERSION in case no interface version in XML file \n |
375 SFW_ERROR_NO_INTERFACE_VERSION in case no interface version in XML file \n |
378 SFW_ERROR_PARSE_SERVICE in case can not parse service section in XML file \n |
376 SFW_ERROR_PARSE_SERVICE in case can not parse service section in XML file \n |
379 SFW_ERROR_NO_SERVICE_FILEPATH in case no service file path in XML file \n |
377 SFW_ERROR_NO_SERVICE_FILEPATH in case no service file path in XML file \n |
380 SFW_ERROR_INVALID_XML_FILE in case XML file is not valid \n |
378 SFW_ERROR_INVALID_XML_FILE in case XML file is not valid \n |
381 SFW_ERROR_NO_SERVICE_INTERFACE in case no interface defined for service in XML file \n |
379 SFW_ERROR_NO_SERVICE_INTERFACE in case no interface defined for service in XML file. |
382 @param aXMLReader xml stream reader |
380 \param aXMLReader xml stream reader . |
383 @return true if the metadata was read properly, false if there is an error |
381 \return true if the metadata was read properly, false if there is an error. |
384 |
382 |
385 |
383 |
386 */ |
384 */ |
387 bool ServiceMetaData::processServiceElementPrevVersion(QXmlStreamReader &aXMLReader) |
385 bool ServiceMetaData::processServiceElementPrevVersion(QXmlStreamReader &aXMLReader) |
388 { |
386 { |
578 XQSERVICE_DEBUG_PRINT("processInterfaceElement parseError: %d", parseError); |
578 XQSERVICE_DEBUG_PRINT("processInterfaceElement parseError: %d", parseError); |
579 return !parseError; |
579 return !parseError; |
580 } |
580 } |
581 |
581 |
582 /*! |
582 /*! |
583 Parses and extracts the interface metadata from the current xml <interface> node \n |
583 Parses and extracts the interface metadata from the current xml <interface> node. \n |
584 Custome error codes: \n |
584 Custome error codes: \n |
585 SFW_ERROR_NO_INTERFACE_NAME in case no interface name in XML file \n |
585 SFW_ERROR_NO_INTERFACE_NAME in case no interface name in XML file \n |
586 SFW_ERROR_PARSE_INTERFACE in case error parsing interface section \n |
586 SFW_ERROR_PARSE_INTERFACE in case error parsing interface section \n |
587 SFW_ERROR_INVALID_XML_FILE in case XML file is not valid \n |
587 SFW_ERROR_INVALID_XML_FILE in case XML file is not valid \n |
588 @param aXMLReader xml stream reader |
588 \param aXMLReader xml stream reader. |
589 @return true if the metadata was read properly, false if there is an error |
589 \return true if the metadata was read properly, false if there is an error. |
590 */ |
590 */ |
591 bool ServiceMetaData::processInterfaceElementPrevVersion(QXmlStreamReader &aXMLReader) |
591 bool ServiceMetaData::processInterfaceElementPrevVersion(QXmlStreamReader &aXMLReader) |
592 { |
592 { |
593 XQSERVICE_DEBUG_PRINT("ServiceMetaData::processInterfaceElementPrevVersion"); |
593 XQSERVICE_DEBUG_PRINT("ServiceMetaData::processInterfaceElementPrevVersion"); |
594 Q_ASSERT(aXMLReader.isStartElement() && aXMLReader.name() == INTERFACE_TAG); |
594 Q_ASSERT(aXMLReader.isStartElement() && aXMLReader.name() == INTERFACE_TAG); |
595 bool parseError = false; |
595 bool parseError = false; |
710 return !parseError; |
710 return !parseError; |
711 } |
711 } |
712 |
712 |
713 |
713 |
714 /*! |
714 /*! |
715 Gets the value of the attribute from the XML node \n |
715 Gets the value of the attribute from the XML node. |
716 @param aDomElement xml node |
716 \param aDomElement Xml node. |
717 @param aAttributeName attribute name |
717 \param aAttributeName Attribute name. |
718 @param aValue [out] attribute value |
718 \param aValue [out] attribute value. |
719 @return true if the value was read, false otherwise |
719 \return true if the value was read, false otherwise. |
720 */ |
720 */ |
721 bool ServiceMetaData::getAttributeValue(const QXmlStreamReader &aXMLReader, const QString &aAttributeName, QString &aValue) |
721 bool ServiceMetaData::getAttributeValue(const QXmlStreamReader &aXMLReader, const QString &aAttributeName, QString &aValue) |
722 { |
722 { |
723 XQSERVICE_DEBUG_PRINT("ServiceMetaData::getAttributeValue"); |
723 XQSERVICE_DEBUG_PRINT("ServiceMetaData::getAttributeValue"); |
724 XQSERVICE_DEBUG_PRINT("aAttributeName: %s", qPrintable(aAttributeName)); |
724 XQSERVICE_DEBUG_PRINT("aAttributeName: %s", qPrintable(aAttributeName)); |
725 bool result = false; |
725 bool result = false; |