MythTV  master
Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
ImageScanThread< DBFS > Class Template Reference

Image Scanner thread requires a database/filesystem adapter. More...

#include <libmythmetadata/imagescanner.h>

Inheritance diagram for ImageScanThread< DBFS >:
[legend]
Collaboration diagram for ImageScanThread< DBFS >:
[legend]

Public Member Functions

 ImageScanThread (DBFS *dbfs, ImageThumb< DBFS > *thumbGen)
 Constructor. More...
 
 ~ImageScanThread () override
 
void cancel ()
 Clears queued items so that the thread can exit. More...
 
bool IsScanning ()
 Return current scanner status. More...
 
bool ClearsPending ()
 Get status of 'clear device' queue. More...
 
void ChangeState (bool scan)
 Run or interrupt scanner. More...
 
void EnqueueClear (int devId, const QString &action)
 Queues a 'Clear Device' request, which will be actioned immediately. More...
 
QStringList GetProgress ()
 Returns number of images scanned & total number to scan. More...
 
- Public Member Functions inherited from MThread
 MThread (const QString &objectName)
 Standard constructor. More...
 
 MThread (const QString &objectName, QRunnable *runnable)
 Use this constructor if you want the default run() method to run the QRunnable's run() method instead of entering the Qt event loop. More...
 
virtual ~MThread ()
 
 MThread (const MThread &)=delete
 
MThreadoperator= (const MThread &)=delete
 
void RunProlog (void)
 Sets up a thread, call this if you reimplement run(). More...
 
void RunEpilog (void)
 Cleans up a thread's resources, call this if you reimplement run(). More...
 
QThread * qthread (void)
 Returns the thread, this will always return the same pointer no matter how often you restart the thread. More...
 
void setObjectName (const QString &name)
 
QString objectName (void) const
 
void setPriority (QThread::Priority priority)
 
QThread::Priority priority (void) const
 
bool isFinished (void) const
 
bool isRunning (void) const
 
void setStackSize (uint stackSize)
 
uint stackSize (void) const
 
void exit (int retcode=0)
 Use this to exit from the thread if you are using a Qt event loop. More...
 
void start (QThread::Priority p=QThread::InheritPriority)
 Tell MThread to start running the thread in the near future. More...
 
void terminate (void)
 Kill a thread unsafely. More...
 
void quit (void)
 calls exit(0) More...
 
bool wait (std::chrono::milliseconds time=std::chrono::milliseconds::max())
 Wait for the MThread to exit, with a maximum timeout. More...
 

Protected Member Functions

void run () override
 Synchronises database to the storage group. More...
 
- Protected Member Functions inherited from MThread
int exec (void)
 Enters the qt event loop. call exit or quit to exit thread. More...
 

Private Types

using ClearTask = QPair< int, QString >
 

Private Member Functions

void SyncSubTree (const QFileInfo &dirInfo, int parentId, int devId, const QString &base)
 Scans a dir subtree. More...
 
int SyncDirectory (const QFileInfo &dirInfo, int devId, const QString &base, int parentId)
 Updates/populates db for a dir. More...
 
void PopulateMetadata (const QString &path, int type, QString &comment, std::chrono::seconds &time, int &orientation)
 Read image date, orientation, comment from metadata. More...
 
void SyncFile (const QFileInfo &fileInfo, int devId, const QString &base, int parentId)
 Updates/populates db for an image/video file. More...
 
void CountTree (QDir &dir)
 Counts images in a dir subtree. More...
 
void CountFiles (const QStringList &paths)
 Counts images in a list of subtrees. More...
 
void Broadcast (int progress)
 Notify listeners of scan progress. More...
 

Private Attributes

bool m_scanning {false}
 The requested scan state. More...
 
QMutex m_mutexState
 Mutex protecting scan state. More...
 
QList< ClearTaskm_clearQueue
 Queue of pending Clear requests. More...
 
QMutex m_mutexQueue
 Mutex protecting Clear requests. More...
 
DBFS & m_dbfs
 Database/filesystem adapter. More...
 
ImageThumb< DBFS > & m_thumb
 Companion thumbnail generator. More...
 
ImageHash m_dbDirMap
 Dirs in the Db from last scan, Map<Db filepath, Db Image> More...
 
ImageHash m_dbFileMap
 Files in the Db from last scan, Map<Db filepath, Db Image> More...
 
ImageHash m_seenDir
 Dirs seen by current scan, Map<Db filepath, Earlier Image> More...
 
NameHash m_seenFile
 Files seen by current scan Map <Db filepath, Earlier abs filepath> More...
 
QStringList m_changedImages
 Ids of dirs/files that have been updates/modified. More...
 
QElapsedTimer m_bcastTimer
 Elapsed time since last progress event generated. More...
 
int m_progressCount {0}
 Number of images scanned. More...
 
int m_progressTotalCount {0}
 Total number of images to scan. More...
 
QMutex m_mutexProgress
 Progress counts mutex. More...
 
QDir m_dir
 Global working dir for file detection. More...
 
QRegularExpression m_exclusions
 Pattern of dir names to ignore whilst scanning. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from MThread
static void ThreadSetup (const QString &name)
 This is to be called on startup in those few threads that haven't been ported to MThread. More...
 
static void ThreadCleanup (void)
 This is to be called on exit in those few threads that haven't been ported to MThread. More...
 
static void Cleanup (void)
 This will print out all the running threads, call exit(1) on each and then wait up to 5 seconds total for all the threads to exit. More...
 
static void GetAllThreadNames (QStringList &list)
 
static void GetAllRunningThreadNames (QStringList &list)
 
- Static Protected Member Functions inherited from MThread
static void setTerminationEnabled (bool enabled=true)
 
static void usleep (std::chrono::microseconds time)
 
template<typename R , typename P >
static std::enable_if_t< std::chrono::treat_as_floating_point< R >::value, void > usleep (std::chrono::duration< R, P > time)
 
- Protected Attributes inherited from MThread
MThreadInternalm_thread {nullptr}
 
QRunnable * m_runnable {nullptr}
 
bool m_prologExecuted {true}
 
bool m_epilogExecuted {true}
 

Detailed Description

template<class DBFS>
class ImageScanThread< DBFS >

Image Scanner thread requires a database/filesystem adapter.

Definition at line 25 of file imagescanner.h.

Member Typedef Documentation

◆ ClearTask

template<class DBFS >
using ImageScanThread< DBFS >::ClearTask = QPair<int, QString>
private

Definition at line 57 of file imagescanner.h.

Constructor & Destructor Documentation

◆ ImageScanThread()

template<class DBFS >
ImageScanThread< DBFS >::ImageScanThread ( DBFS *  dbfs,
ImageThumb< DBFS > *  thumbGen 
)

Constructor.

Parameters
dbfsDatabase/filesystem adapter
thumbGenCompanion thumbnail generator

Definition at line 14 of file imagescanner.cpp.

◆ ~ImageScanThread()

template<class DBFS >
ImageScanThread< DBFS >::~ImageScanThread
override

Definition at line 23 of file imagescanner.cpp.

Member Function Documentation

◆ cancel()

template<class DBFS >
void ImageScanThread< DBFS >::cancel

Clears queued items so that the thread can exit.

Definition at line 34 of file imagescanner.cpp.

◆ IsScanning()

template<class DBFS >
bool ImageScanThread< DBFS >::IsScanning

Return current scanner status.

Returns
bool True if requested state is "scan"

Definition at line 50 of file imagescanner.cpp.

◆ ClearsPending()

template<class DBFS >
bool ImageScanThread< DBFS >::ClearsPending

Get status of 'clear device' queue.

Returns
bool True if pending 'clear' requests exist

Definition at line 62 of file imagescanner.cpp.

◆ ChangeState()

template<class DBFS >
void ImageScanThread< DBFS >::ChangeState ( bool  scan)

Run or interrupt scanner.

Clear requests are actioned before and after every scan

Parameters
scanIf true, scan will start after pending clears are actioned If false, a running scan is interrupted. Pending clear requests will be actioned.

Definition at line 77 of file imagescanner.cpp.

◆ EnqueueClear()

template<class DBFS >
void ImageScanThread< DBFS >::EnqueueClear ( int  devId,
const QString &  action 
)

Queues a 'Clear Device' request, which will be actioned immediately.

If scanner is already running, any scan will be aborted to process the clear.

Parameters
devIdDevice id
action[DEVICE] (CLOSE | CLEAR)

Definition at line 96 of file imagescanner.cpp.

◆ GetProgress()

template<class DBFS >
QStringList ImageScanThread< DBFS >::GetProgress

Returns number of images scanned & total number to scan.

Returns
QStringList (scanner id, #done, #total)

Definition at line 111 of file imagescanner.cpp.

◆ run()

template<class DBFS >
void ImageScanThread< DBFS >::run
overrideprotectedvirtual

Synchronises database to the storage group.

Scans all dirs and files and populates database with metadata for each. Broadcasts progress events whilst scanning, initiates thumbnail generation and notifies clients when finished.

Reimplemented from MThread.

Definition at line 126 of file imagescanner.cpp.

◆ SyncSubTree()

template<class DBFS >
void ImageScanThread< DBFS >::SyncSubTree ( const QFileInfo &  dirInfo,
int  parentId,
int  devId,
const QString &  base 
)
private

Scans a dir subtree.

Uses a recursive depth-first scan to detect all files matching image/video filters. Dirs that match exclusions regexp are ignored.

Parameters
dirInfoDir info at root of this subtree
parentIdId of parent dir
devIdDevice id being scanned
baseRoot device path

Definition at line 240 of file imagescanner.cpp.

◆ SyncDirectory()

template<class DBFS >
int ImageScanThread< DBFS >::SyncDirectory ( const QFileInfo &  dirInfo,
int  devId,
const QString &  base,
int  parentId 
)
private

Updates/populates db for a dir.

Db is updated if dir modified time has changed since last scan. Contents are scanned even if dir is unchanged. Clones are dirs within the Storage Group with the same path (relative to SG). They resolve to a single Db dir - their contents are amalgamated. ie. <SG dir 1>/somePath/dirName and <SG dir 2>/somePath/dirName result in a single Gallery dir of "somePath/dirName"

Parameters
dirInfoDir info
devIdId of device containing dir
baseDevice path
parentIdDb id of the dir's parent
Returns
int Db id of this dir in db

Definition at line 315 of file imagescanner.cpp.

◆ PopulateMetadata()

template<class DBFS >
void ImageScanThread< DBFS >::PopulateMetadata ( const QString &  path,
int  type,
QString &  comment,
std::chrono::seconds &  time,
int &  orientation 
)
private

Read image date, orientation, comment from metadata.

Parameters
[in]pathImage filepath
[in]typePicture or Video
[out]commentImage comment
[out]timeTime/date of image capture
[out]orientationExif orientation code

Definition at line 411 of file imagescanner.cpp.

◆ SyncFile()

template<class DBFS >
void ImageScanThread< DBFS >::SyncFile ( const QFileInfo &  fileInfo,
int  devId,
const QString &  base,
int  parentId 
)
private

Updates/populates db for an image/video file.

Db is updated if file modified time has changed since last scan. Extracts orientation, date and 2 comments from exif/video metadata. Duplicates are files within the Storage Group with the same path (relative to SG). They are invalid (user error?) - only the first is accepted; others are ignored. ie. <SG dir 1>/somePath/fileName and <SG dir 2>/somePath/fileName result in a single image from <SG dir 1>. This is consistent with StorageGroup::FindFile(), which will never find the second file.

Parameters
fileInfoFile info
devIdId of device containing dir
baseDevice path
parentIdDb id of the dir's parent

Definition at line 445 of file imagescanner.cpp.

◆ CountTree()

template<class DBFS >
void ImageScanThread< DBFS >::CountTree ( QDir &  dir)
private

Counts images in a dir subtree.

Ignores dirs that match exclusions regexp

Parameters
dirRoot of subtree

Definition at line 541 of file imagescanner.cpp.

◆ CountFiles()

template<class DBFS >
void ImageScanThread< DBFS >::CountFiles ( const QStringList &  paths)
private

Counts images in a list of subtrees.

Parameters
pathsList of dir trees to scan

Definition at line 569 of file imagescanner.cpp.

◆ Broadcast()

template<class DBFS >
void ImageScanThread< DBFS >::Broadcast ( int  progress)
private

Notify listeners of scan progress.

Note
Count mutex must be held before calling this
Parameters
progressNumber of images processed

Definition at line 610 of file imagescanner.cpp.

Member Data Documentation

◆ m_scanning

template<class DBFS >
bool ImageScanThread< DBFS >::m_scanning {false}
private

The requested scan state.

Definition at line 59 of file imagescanner.h.

◆ m_mutexState

template<class DBFS >
QMutex ImageScanThread< DBFS >::m_mutexState
private

Mutex protecting scan state.

Definition at line 60 of file imagescanner.h.

◆ m_clearQueue

template<class DBFS >
QList<ClearTask> ImageScanThread< DBFS >::m_clearQueue
private

Queue of pending Clear requests.

Definition at line 61 of file imagescanner.h.

◆ m_mutexQueue

template<class DBFS >
QMutex ImageScanThread< DBFS >::m_mutexQueue
private

Mutex protecting Clear requests.

Definition at line 62 of file imagescanner.h.

◆ m_dbfs

template<class DBFS >
DBFS& ImageScanThread< DBFS >::m_dbfs
private

Database/filesystem adapter.

Definition at line 63 of file imagescanner.h.

◆ m_thumb

template<class DBFS >
ImageThumb<DBFS>& ImageScanThread< DBFS >::m_thumb
private

Companion thumbnail generator.

Definition at line 64 of file imagescanner.h.

◆ m_dbDirMap

template<class DBFS >
ImageHash ImageScanThread< DBFS >::m_dbDirMap
private

Dirs in the Db from last scan, Map<Db filepath, Db Image>

Definition at line 67 of file imagescanner.h.

◆ m_dbFileMap

template<class DBFS >
ImageHash ImageScanThread< DBFS >::m_dbFileMap
private

Files in the Db from last scan, Map<Db filepath, Db Image>

Definition at line 69 of file imagescanner.h.

◆ m_seenDir

template<class DBFS >
ImageHash ImageScanThread< DBFS >::m_seenDir
private

Dirs seen by current scan, Map<Db filepath, Earlier Image>

Definition at line 71 of file imagescanner.h.

◆ m_seenFile

template<class DBFS >
NameHash ImageScanThread< DBFS >::m_seenFile
private

Files seen by current scan Map <Db filepath, Earlier abs filepath>

Definition at line 73 of file imagescanner.h.

◆ m_changedImages

template<class DBFS >
QStringList ImageScanThread< DBFS >::m_changedImages
private

Ids of dirs/files that have been updates/modified.

Definition at line 75 of file imagescanner.h.

◆ m_bcastTimer

template<class DBFS >
QElapsedTimer ImageScanThread< DBFS >::m_bcastTimer
private

Elapsed time since last progress event generated.

Definition at line 78 of file imagescanner.h.

◆ m_progressCount

template<class DBFS >
int ImageScanThread< DBFS >::m_progressCount {0}
private

Number of images scanned.

Definition at line 79 of file imagescanner.h.

◆ m_progressTotalCount

template<class DBFS >
int ImageScanThread< DBFS >::m_progressTotalCount {0}
private

Total number of images to scan.

Definition at line 80 of file imagescanner.h.

◆ m_mutexProgress

template<class DBFS >
QMutex ImageScanThread< DBFS >::m_mutexProgress
private

Progress counts mutex.

Definition at line 81 of file imagescanner.h.

◆ m_dir

template<class DBFS >
QDir ImageScanThread< DBFS >::m_dir
private

Global working dir for file detection.

Definition at line 84 of file imagescanner.h.

◆ m_exclusions

template<class DBFS >
QRegularExpression ImageScanThread< DBFS >::m_exclusions
private

Pattern of dir names to ignore whilst scanning.

Definition at line 86 of file imagescanner.h.


The documentation for this class was generated from the following files: