CDirectoryMonitorComp.h
Go to the documentation of this file.
1 #ifndef ihotfgui_CDirectoryMonitorComp_included
2 #define ihotfgui_CDirectoryMonitorComp_included
3 
4 
5 // Qt includes
6 #include <QtCore/QFileSystemWatcher>
7 #include <QtCore/QThread>
8 #include <QtCore/QDir>
9 #include <QtCore/QSet>
10 #include <QtCore/QMutex>
11 
12 // ACF includes
14 #include "icomp/CComponentBase.h"
15 #include "ilog/TLoggerCompWrap.h"
16 #include "iprm/IParamsSet.h"
17 #include "ifile/IFileNameParam.h"
18 
19 // AcfSln includes
24 
25 
26 namespace ihotfgui
27 {
28 
29 
34  public QThread,
36  virtual public ihotf::IDirectoryMonitor
37 {
38  Q_OBJECT
39 
40 public:
42  typedef QThread BaseClass2;
43 
44  I_BEGIN_COMPONENT(CDirectoryMonitorComp);
45  I_REGISTER_INTERFACE(ihotf::IDirectoryMonitor);
46  I_ASSIGN(m_paramsSetCompPtr, "ParamsSet", "Default parameter set for the directory monitoring", false, "ParamsSet");
47  I_ASSIGN_TO(m_paramsSetModelCompPtr, m_paramsSetCompPtr, false);
48  I_ASSIGN(m_monitoringSessionManagerCompPtr, "SessionManager", "Provider of previous monitoring sessions", false, "SessionManager");
49  I_ASSIGN(m_fileSystemChangeStorageCompPtr, "FileSystemChangeStorage", "File storage", true, "FileSystemChangeStorage");
50  I_ASSIGN(m_directoryPathIdAttrPtr, "DirParamId", "Parameter ID of the path to be observed in the parameter set", true, "DirParamId");
51  I_ASSIGN(m_directoryMonitorParamsIdAttrPtr, "DirectoryMonitorParamsId", "ID of the directory observing parameters in the parameter set", true, "DirectoryMonitorParamsId");
52  I_ASSIGN(m_autoStartAttrPtr, "AutoStart", "If enabled, start the directory monitoring after initialization", false, false);
53  I_END_COMPONENT;
54 
56 
57  // reimplemented (ihotf::IDirectoryMonitor)
58  virtual bool StartObserving(const iprm::IParamsSet* paramsSetPtr = NULL);
59  virtual void StopObserving();
60 
61 protected:
62  // reimplemented (icomp::CComponentBase)
63  virtual void OnComponentCreated();
64  virtual void OnComponentDestroyed();
65 
66  // reimplemented (QThread)
67  virtual void run();
68 
69 private Q_SLOTS:
73  void OnFolderChanged(int changeFlags);
74 
78  void OnDirectoryChangeNotification(const QString& directory);
79 
80 Q_SIGNALS:
84  void FolderChanged(int changeFlags);
85 
86 private:
87  void SetFolderPath(const QString& folderPath);
88  void StartObserverThread();
89  void StopObserverThread();
90  void ResetFiles();
91  bool ConnectToParameterModel(const iprm::IParamsSet& paramsSet);
92  void DisconnectFromParameterModel();
93  void UpdateMonitoringSession() const;
94 
95 private:
96  struct FileSystemChanges
97  {
98  QStringList addedFiles;
99  QStringList removedFiles;
100  QStringList modifiedFiles;
101  QStringList attributeChangedFiles;
102  };
103 
104  class MonitoringParamsObserver: public imod::TSingleModelObserverBase<ihotf::IDirectoryMonitorParams>
105  {
106  public:
108 
109  MonitoringParamsObserver(CDirectoryMonitorComp& parent);
110 
111  // reimplemented (imod::IObserver)
112  virtual void AfterUpdate(imod::IModel* modelPtr, int updateFlags, istd::IPolymorphic* updateParamsPtr);
113 
114  private:
115  CDirectoryMonitorComp& m_parent;
116  };
117 
118  class DirectoryParamsObserver: public imod::TSingleModelObserverBase<ifile::IFileNameParam>
119  {
120  public:
122 
123  DirectoryParamsObserver(CDirectoryMonitorComp& parent);
124 
125  // reimplemented (imod::IObserver)
126  virtual void AfterUpdate(imod::IModel* modelPtr, int updateFlags, istd::IPolymorphic* updateParamsPtr);
127 
128  private:
129  CDirectoryMonitorComp& m_parent;
130  };
131 
132 
133  typedef QSet<QString> FilesSet;
134 
135  ihotf::IMonitoringSession::FileItems m_directoryFiles;
136  FilesSet m_nonAccessedFiles;
137 
138  bool m_finishThread;
139 
140  FileSystemChanges m_folderChanges;
141 
142  QDir m_currentDirectory;
143 
144  int m_directoryPendingChangesCounter;
145 
146  QFileSystemWatcher m_directoryWatcher;
147 
148  // Model shadows:
149  double m_poolingFrequency;
150  QStringList m_fileFilterExpressions;
151  int m_observingItemTypes;
152  int m_observingChanges;
153 
154  MonitoringParamsObserver m_monitoringParamsObserver;
155  DirectoryParamsObserver m_directoryParamsObserver;
156 
157  // Component attributes
158  I_REF(iprm::IParamsSet, m_paramsSetCompPtr);
159  I_REF(imod::IModel, m_paramsSetModelCompPtr);
160  I_REF(ihotf::IMonitoringSessionManager, m_monitoringSessionManagerCompPtr);
161  I_REF(ihotf::IFileSystemChangeStorage, m_fileSystemChangeStorageCompPtr);
162  I_ATTR(QByteArray, m_directoryPathIdAttrPtr);
163  I_ATTR(QByteArray, m_directoryMonitorParamsIdAttrPtr);
164  I_ATTR(bool, m_autoStartAttrPtr);
165 
166  bool m_lockChanges;
167 
168  mutable QMutex m_mutex;
169 };
170 
171 
172 } // namespace ihotfgui
173 
174 
175 #endif // !ihotfgui_CDirectoryMonitorComp_included
176 
177 
Common interface for a monitoring session's manager.
void FolderChanged(int changeFlags)
Signal is emitted from observing thread to notifiy the main thread about changes in a directory...
Component for monitoring of the file folder.
virtual void StopObserving()
Stop observing process.
QMap< QString, QDateTime > FileItems
Map absolute file path to modification time.
virtual bool StartObserving(const iprm::IParamsSet *paramsSetPtr=NULL)
Start observing process.
Common interface for a storage of files.
ilog::CLoggerComponentBase BaseClass
I_ASSIGN_TO(m_paramsSetModelCompPtr, m_paramsSetCompPtr, false)
Interface for a folder monitor.

© 2007-2011 Witold Gantzke and Kirill Lepskiy