----------------------------------------------------------------------------
| 181 | |
| 182 | //---------------------------------------------------------------------------- |
| 183 | ctkCmdLineModuleReference |
| 184 | ctkCmdLineModuleManager::registerModule(const QUrl &location) |
| 185 | { |
| 186 | QByteArray xml; |
| 187 | ctkCmdLineModuleBackend* backend = NULL; |
| 188 | { |
| 189 | QMutexLocker lock(&d->Mutex); |
| 190 | |
| 191 | d->checkBackends_unlocked(location); |
| 192 | |
| 193 | // If the module is already registered, just return the reference |
| 194 | if (d->LocationToRef.contains(location)) |
| 195 | { |
| 196 | return d->LocationToRef[location]; |
| 197 | } |
| 198 | |
| 199 | backend = d->SchemeToBackend[location.scheme()]; |
| 200 | } |
| 201 | |
| 202 | bool fromCache = false; |
| 203 | qint64 newTimeStamp = 0; |
| 204 | qint64 cacheTimeStamp = 0; |
| 205 | int timeout = backend->timeOutForXmlRetrieval(); |
| 206 | if (timeout == 0) |
| 207 | { |
| 208 | timeout = d->XmlTimeOut; |
| 209 | } |
| 210 | |
| 211 | if (d->ModuleCache) |
| 212 | { |
| 213 | newTimeStamp = backend->timeStamp(location); |
| 214 | cacheTimeStamp = d->ModuleCache->timeStamp(location); |
| 215 | if (cacheTimeStamp < 0 // i.e. timestamp is invalid |
| 216 | || cacheTimeStamp < newTimeStamp) // i.e. timestamp is genuinely out of date |
| 217 | { |
| 218 | // newly fetch the XML description |
| 219 | try |
| 220 | { |
| 221 | xml = backend->rawXmlDescription(location, timeout); |
| 222 | } |
| 223 | catch (const ctkCmdLineModuleTimeoutException&) |
| 224 | { |
| 225 | // in case of a time-out, do not cache it as a failed attempt |
| 226 | // by recording an empty QByteArray in the cache |
| 227 | throw; |
| 228 | } |
| 229 | catch (...) |
| 230 | { |
| 231 | // cache the failed attempt |
| 232 | d->ModuleCache->cacheXmlDescription(location, newTimeStamp, QByteArray()); |
| 233 | throw; |
| 234 | } |
| 235 | } |
| 236 | else |
| 237 | { |
| 238 | // use the cached XML description |
| 239 | xml = d->ModuleCache->rawXmlDescription(location); |
| 240 | fromCache = true; |