61 |
61 |
62 typedef QHash<QString,HbWidgetLoader::LayoutDefinition*> ClientHashForLayoutDefs; |
62 typedef QHash<QString,HbWidgetLoader::LayoutDefinition*> ClientHashForLayoutDefs; |
63 Q_GLOBAL_STATIC(ClientHashForLayoutDefs, clientLayoutDefsCache) |
63 Q_GLOBAL_STATIC(ClientHashForLayoutDefs, clientLayoutDefsCache) |
64 |
64 |
65 // List of files that doesn't exist. |
65 // List of files that doesn't exist. |
66 // This reduces the check QFile::exists() at client side as well as the server side. |
66 // This reduces the check QFile::exists() at client side. |
67 // also no unnecessary IPC calls. |
67 Q_GLOBAL_STATIC(QSet<uint>, filesNotPresent) |
68 Q_GLOBAL_STATIC(QStringList, filesNotPresent) |
68 |
|
69 // ValidLayoutsLookup is a map of filenames to a "LayoutExists" structure, |
|
70 // which records whether a given section and layout exists in that file. |
|
71 // ValidLayoutsLookup is also used to check whether files have previously been |
|
72 // loaded by the client and known to exist, to reduce processing overhead |
|
73 typedef QPair<QString, QString> SectionAndLayout; |
|
74 typedef QHash<SectionAndLayout, bool> LayoutExists; |
|
75 typedef QHash<QString, LayoutExists> ValidLayoutsLookup; |
|
76 Q_GLOBAL_STATIC(ValidLayoutsLookup, clientLayoutLookup) |
|
77 |
69 |
78 |
70 // Layout caching |
79 // Layout caching |
71 static HbWidgetLoader::LayoutDefinition *staticCacheLayout = 0; |
80 static HbWidgetLoader::LayoutDefinition *staticCacheLayout = 0; |
72 static QString staticCacheFileName; |
81 static QString staticCacheFileName; |
73 static QString staticCacheName; |
82 static QString staticCacheName; |
162 const QString &name, |
171 const QString &name, |
163 const QString §ion, |
172 const QString §ion, |
164 HbMemoryManager::MemoryType storage) |
173 HbMemoryManager::MemoryType storage) |
165 { |
174 { |
166 Q_D(HbWidgetLoader); |
175 Q_D(HbWidgetLoader); |
|
176 |
|
177 ValidLayoutsLookup *lookup = clientLayoutLookup(); |
|
178 if (lookup && lookup->contains(fileName)) { |
|
179 SectionAndLayout key(section, name); |
|
180 if ((*lookup)[fileName].contains(key)) { |
|
181 bool layoutExistsInFile = (*lookup)[fileName][key]; |
|
182 if (!layoutExistsInFile) { |
|
183 #ifdef HB_WIDGETLOADER_DEBUG |
|
184 qDebug() << "Layout name" << name << "known not to exist in" << fileName; |
|
185 #endif |
|
186 return false; |
|
187 } |
|
188 } |
|
189 } else { |
|
190 if (filesNotPresent()->contains(qHash(fileName))){ |
|
191 #ifdef HB_WIDGETLOADER_DEBUG |
|
192 qDebug() << "File" << fileName << "known not to exist"; |
|
193 #endif |
|
194 return false; |
|
195 } |
|
196 } |
|
197 |
167 bool result(true); |
198 bool result(true); |
168 |
|
169 d->setWidget(widget); |
199 d->setWidget(widget); |
170 |
|
171 LayoutDefinition* layoutDef(0); |
200 LayoutDefinition* layoutDef(0); |
172 |
201 |
173 if (storage == HbMemoryManager::SharedMemory) { |
202 if (storage == HbMemoryManager::SharedMemory |
|
203 && !clientLayoutLookup()->contains(fileName)) { |
174 result = d->getSharedLayoutDefinition(fileName, name, section, layoutDef); |
204 result = d->getSharedLayoutDefinition(fileName, name, section, layoutDef); |
175 } |
205 } |
176 if (result) { |
206 if (result) { |
177 if (!layoutDef) { |
207 if (!layoutDef) { |
178 //fall back |
208 //fall back |
274 // present in the client cache. |
304 // present in the client cache. |
275 layoutDef = clientLayoutDefsCache()->value(key); |
305 layoutDef = clientLayoutDefsCache()->value(key); |
276 return true; |
306 return true; |
277 } |
307 } |
278 |
308 |
279 // Not found in the client cache. |
|
280 if (filesNotPresent()->contains(fileName)){ |
|
281 return false; |
|
282 } |
|
283 // Check for the availability of the file, as QFile::Exists takes more time this |
|
284 // method is used |
|
285 QFile file(fileName); |
|
286 bool fileExists = file.open(QIODevice::ReadOnly); |
|
287 file.close(); |
|
288 if (!fileExists) { |
|
289 // file doesn't exist save the info in the filesNotPresent list. |
|
290 filesNotPresent()->append(fileName); |
|
291 return false; |
|
292 } |
|
293 |
|
294 // get the shared layout definition address. |
309 // get the shared layout definition address. |
295 #ifdef HB_USETHEMESERVER |
310 #ifdef HB_USETHEMESERVER |
296 layoutDef = HbThemeClient::global()->getSharedLayoutDefs(fileName, name, section); |
311 bool fileExists = true; |
|
312 layoutDef = HbThemeClient::global()->getSharedLayoutDefs(fileName, name, section, fileExists); |
297 if (layoutDef) { |
313 if (layoutDef) { |
298 clientLayoutDefsCache()->insert(key, layoutDef); |
314 clientLayoutDefsCache()->insert(key, layoutDef); |
|
315 } else if (!fileExists) { |
|
316 filesNotPresent()->insert(qHash(fileName)); |
299 } |
317 } |
300 #endif |
318 #endif |
301 return true; |
319 return true; |
302 } |
320 } |
303 |
321 |
311 HbWidgetLoader::LayoutDefinition *&layoutDef ) |
329 HbWidgetLoader::LayoutDefinition *&layoutDef ) |
312 { |
330 { |
313 QFileInfo info(fileName); |
331 QFileInfo info(fileName); |
314 |
332 |
315 #ifdef HB_WIDGETLOADER_DEBUG |
333 #ifdef HB_WIDGETLOADER_DEBUG |
316 qDebug() << "Cached layout currently contains" << HbWidgetLoaderActions::mCacheLayout.count() << "items"; |
334 //qDebug() << "Cached layout currently contains" << HbWidgetLoaderActions::mCacheLayout.count() << "items"; |
317 #endif |
335 #endif |
318 bool cacheHit = (name == staticCacheName |
336 bool cacheHit = (name == staticCacheName |
319 && section == staticCacheSection |
337 && section == staticCacheSection |
320 && fileName == staticCacheFileName |
338 && fileName == staticCacheFileName |
321 && info.lastModified() == staticCacheModified); |
339 && info.lastModified() == staticCacheModified); |
322 |
340 |
323 if (cacheHit){ |
341 if (cacheHit){ |
324 #ifdef HB_WIDGETLOADER_DEBUG |
342 #ifdef HB_WIDGETLOADER_DEBUG |
325 qDebug() << "Cache hit."; |
343 qDebug() << "Cache hit."; |
326 #endif |
344 #endif |
327 layoutDef = staticCacheLayout; |
345 layoutDef = staticCacheLayout; |
328 return true; |
346 return true; |
329 } |
347 } |
330 |
348 |
331 #ifdef HB_WIDGETLOADER_DEBUG |
349 #ifdef HB_WIDGETLOADER_DEBUG |
332 qDebug() << "Cache miss, reloading cache data"; |
350 qDebug() << "Cache miss, reloading cache data"; |
333 #endif |
351 #endif |
334 |
352 |
335 // Not found in the client cache. |
353 QFile file(fileName); |
336 if (filesNotPresent()->contains(fileName)){ |
354 if ( !file.open( QFile::ReadOnly | QFile::Text ) ) { |
|
355 #ifdef HB_WIDGETLOADER_DEBUG |
|
356 qDebug() << "Unable to open file" << fileName; |
|
357 #endif |
|
358 filesNotPresent()->insert(qHash(fileName)); |
337 return false; |
359 return false; |
338 } |
360 } |
339 QFile file(fileName); |
|
340 if ( !file.open( QFile::ReadOnly | QFile::Text ) ) { |
|
341 qWarning( "Unable to open file "); |
|
342 filesNotPresent()->append(fileName); |
|
343 return false; |
|
344 } |
|
345 |
361 |
346 if (!staticCacheLayout) { |
362 if (!staticCacheLayout) { |
347 staticCacheLayout = new HbWidgetLoader::LayoutDefinition(HbMemoryManager::HeapMemory); |
363 staticCacheLayout = new HbWidgetLoader::LayoutDefinition(HbMemoryManager::HeapMemory); |
348 } else { |
364 } else { |
349 Q_ASSERT(staticCacheLayout->type == HbMemoryManager::HeapMemory); |
365 Q_ASSERT(staticCacheLayout->type == HbMemoryManager::HeapMemory); |
352 mMemActions->mLayoutDef = staticCacheLayout; |
368 mMemActions->mLayoutDef = staticCacheLayout; |
353 mSyntax->setActions(mMemActions); |
369 mSyntax->setActions(mMemActions); |
354 bool result = mSyntax->load(&file, name, section); |
370 bool result = mSyntax->load(&file, name, section); |
355 if (result){ |
371 if (result){ |
356 layoutDef = staticCacheLayout; |
372 layoutDef = staticCacheLayout; |
357 staticCacheName = name; |
373 staticCacheName = name; |
358 staticCacheSection = section; |
374 staticCacheSection = section; |
359 staticCacheFileName = fileName; |
375 staticCacheFileName = fileName; |
360 staticCacheModified = info.lastModified(); |
376 staticCacheModified = info.lastModified(); |
361 } |
377 } |
|
378 (*clientLayoutLookup())[fileName].insert(SectionAndLayout(section, name), result); |
362 |
379 |
363 return result; |
380 return result; |
364 } |
381 } |
365 |
382 |
366 |
383 |