src/hbcore/devicedialogbase/devicedialogserver/hbpluginnamecache.cpp
changeset 34 ed14f46c0e55
parent 7 923ff622b8b9
equal deleted inserted replaced
31:7516d6d86cf5 34:ed14f46c0e55
    69 // executed automatically after installation to get type strings. Instead application must trigger
    69 // executed automatically after installation to get type strings. Instead application must trigger
    70 // a plugin scan and name cache miss to get plugin executed.
    70 // a plugin scan and name cache miss to get plugin executed.
    71 //#define MONITOR_INSTALLATION_DIRS 1
    71 //#define MONITOR_INSTALLATION_DIRS 1
    72 
    72 
    73 // Thread that scans directories and keeps the cache current
    73 // Thread that scans directories and keeps the cache current
       
    74 /// \cond
    74 class HbPluginNameCacheThread : public QThread
    75 class HbPluginNameCacheThread : public QThread
    75 {
    76 {
    76 public:
    77 public:
    77     typedef HbPluginNameCache::ScanParameters WorkItem;
    78     typedef HbPluginNameCache::ScanParameters WorkItem;
    78 
    79 
    96     WorkItem mCurrentScan;  // directory currently scanned
    97     WorkItem mCurrentScan;  // directory currently scanned
    97     QStringList mLimitSet; // names of plugin-files found from rom-drives
    98     QStringList mLimitSet; // names of plugin-files found from rom-drives
    98     HbPluginNameCache &mNameCache;
    99     HbPluginNameCache &mNameCache;
    99     static QMutex *mMutex;
   100     static QMutex *mMutex;
   100 };
   101 };
       
   102 /// \endcond
   101 
   103 
   102 // Share lock between all instances of the cache.
   104 // Share lock between all instances of the cache.
   103 QMutex *HbPluginNameCacheThread::mMutex = 0;
   105 QMutex *HbPluginNameCacheThread::mMutex = 0;
   104 
   106 
   105 // For file name compare
   107 // For file name compare
   182 }
   184 }
   183 
   185 
   184 // Scan directory for plugins and keys they implement.
   186 // Scan directory for plugins and keys they implement.
   185 void HbPluginNameCacheThread::doDirectoryScan(const WorkItem &workItem)
   187 void HbPluginNameCacheThread::doDirectoryScan(const WorkItem &workItem)
   186 {
   188 {
   187     TRACE_ENTRY_ARGS(path)
   189     TRACE_ENTRY_ARGS(workItem.mDirPath)
   188 
   190 
   189     // Invalidate cache contents for the path
   191     // Invalidate cache contents for the path
   190     mNameCache.insertPath(workItem.mDirPath);
   192     mNameCache.insertPath(workItem.mDirPath);
   191 
   193 
   192     QString fileNameFilter = mPluginFileNameFilter();
   194     QString fileNameFilter = mPluginFileNameFilter();
   296 }
   298 }
   297 
   299 
   298 // Scan directory directory for plugins
   300 // Scan directory directory for plugins
   299 void HbPluginNameCache::scanDirectory(const ScanParameters &parameters)
   301 void HbPluginNameCache::scanDirectory(const ScanParameters &parameters)
   300 {
   302 {
   301     TRACE_ENTRY_ARGS(path)
   303     TRACE_ENTRY_ARGS(parameters.mDirPath)
   302     QString dirPath = directoryPath(parameters.mDirPath);
   304     QString dirPath = directoryPath(parameters.mDirPath);
   303     TRACE(dirPath)
   305     TRACE(dirPath)
   304     if (!dirPath.isEmpty()) {
   306     if (!dirPath.isEmpty()) {
   305         mThread->scanDirectory(ScanParameters(dirPath, parameters.mOptions));
   307         mThread->scanDirectory(ScanParameters(dirPath, parameters.mOptions));
   306     }
   308     }
   374         for(int j = 0; j < fileCount; j++) {
   376         for(int j = 0; j < fileCount; j++) {
   375             const FileItem &fileitem = current.mFiles.at(j);
   377             const FileItem &fileitem = current.mFiles.at(j);
   376             TRACE("File:" << fileitem.mFile)
   378             TRACE("File:" << fileitem.mFile)
   377             int keyCount = fileitem.mKeys.count();
   379             int keyCount = fileitem.mKeys.count();
   378             for(int k = 0; k < keyCount; k++) {
   380             for(int k = 0; k < keyCount; k++) {
   379                 TRACE(fileitem.keys.at(k))
   381                 TRACE(fileitem.mKeys.at(k))
   380             }
   382             }
   381         }
   383         }
   382     }
   384     }
   383 }
   385 }
   384 
   386 
   399 
   401 
   400 // Update cache with \a keys , \a firPath and \a fileName
   402 // Update cache with \a keys , \a firPath and \a fileName
   401 void HbPluginNameCache::insert(const QStringList &keys, const QString &dirPath,
   403 void HbPluginNameCache::insert(const QStringList &keys, const QString &dirPath,
   402     const QString &fileName)
   404     const QString &fileName)
   403 {
   405 {
   404     TRACE_ENTRY_ARGS("keys" << keys << "filePath" << filePath)
   406     TRACE_ENTRY_ARGS("keys" << keys << "filePath" << dirPath)
   405     QMutexLocker(&mThread->lock());
   407     QMutexLocker(&mThread->lock());
   406     // Find directory path
   408     // Find directory path
   407     DirItem searchItem;
   409     DirItem searchItem;
   408     searchItem.mPath = dirPath;
   410     searchItem.mPath = dirPath;
   409     int dirIndex = mCache.indexOf(searchItem);
   411     int dirIndex = mCache.indexOf(searchItem);