MCPcopy Create free account
hub / github.com/commontk/CTK / registerModule

Method registerModule

Libs/CommandLineModules/Core/ctkCmdLineModuleManager.cpp:183–331  ·  view source on GitHub ↗

----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

181
182//----------------------------------------------------------------------------
183ctkCmdLineModuleReference
184ctkCmdLineModuleManager::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;

Callers 13

foreachFunction · 0.80
addModuleMethod · 0.80
checkXMLPressedMethod · 0.80
do_somethingMethod · 0.80
mainFunction · 0.80
initTestCaseMethod · 0.80
testCustomizationMethod · 0.80
operator()Method · 0.80
testStrictValidationMethod · 0.80
testWeakValidationMethod · 0.80
testSkipValidationMethod · 0.80
testCachingMethod · 0.80

Calls 15

cacheXmlDescriptionMethod · 0.80
errorCodeMethod · 0.80
whatMethod · 0.80
validateInputMethod · 0.80
QStringClass · 0.50
containsMethod · 0.45
timeStampMethod · 0.45
rawXmlDescriptionMethod · 0.45
toStringMethod · 0.45
locationMethod · 0.45

Tested by 7

initTestCaseMethod · 0.64
testCustomizationMethod · 0.64
testStrictValidationMethod · 0.64
testWeakValidationMethod · 0.64
testSkipValidationMethod · 0.64
testCachingMethod · 0.64
initTestCaseMethod · 0.64