| /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| /* |
| * Copyright (c) 2012-2013 University of California, Los Angeles |
| * |
| * This program is free software; you can redistribute it and/or modify |
| * it under the terms of the GNU General Public License version 2 as |
| * published by the Free Software Foundation; |
| * |
| * This program is distributed in the hope that it will be useful, |
| * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| * GNU General Public License for more details. |
| * |
| * You should have received a copy of the GNU General Public License |
| * along with this program; if not, write to the Free Software |
| * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| * |
| * Author: Jared Lindblom <lindblom@cs.ucla.edu> |
| * Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| * Zhenkai Zhu <zhenkai@cs.ucla.edu> |
| */ |
| #ifndef FS_WATCHER_H |
| #define FS_WATCHER_H |
| |
| #include <vector> |
| #include <QFileSystemWatcher> |
| #include <boost/filesystem.hpp> |
| |
| #include "executor.h" |
| |
| class FsWatcher : public QObject |
| { |
| Q_OBJECT |
| |
| public: |
| typedef boost::function<void (const boost::filesystem::path &)> LocalFile_Change_Callback; |
| |
| // constructor |
| FsWatcher (QString dirPath, |
| LocalFile_Change_Callback onChange, LocalFile_Change_Callback onDelete, |
| QObject* parent = 0); |
| |
| // destructor |
| ~FsWatcher (); |
| |
| private slots: |
| // handle callback from watcher |
| void |
| DidDirectoryChanged (QString dirPath); |
| |
| /** |
| * @brief This even will be triggered either by actual file change or via directory change event |
| * (i.e., can happen twice in a row, as well as trigger false alarm) |
| */ |
| void |
| DidFileChanged (QString filePath); |
| |
| private: |
| // handle callback from the watcher |
| void |
| DidDirectoryChanged_Execute (QString dirPath); |
| |
| // scan directory and notify callback about any file changes |
| void |
| ScanDirectory_Notify_Execute (QString dirPath); |
| |
| // // reconcile directory, find changes |
| // std::vector<sEventInfo> |
| // reconcileDirectory (QHash<QString, qint64> fileList, QString dirPath); |
| |
| // // calculate checksum |
| // QByteArray calcChecksum(QString absFilePath); |
| |
| // // print Changes (DEBUG) |
| // void printChanges(std::vector<sEventInfo> dirChanges); |
| |
| private: |
| QFileSystemWatcher* m_watcher; // filesystem watcher |
| Executor m_executor; |
| |
| QString m_dirPath; // monitored path |
| |
| LocalFile_Change_Callback m_onChange; |
| LocalFile_Change_Callback m_onDelete; |
| }; |
| |
| #endif // FILESYSTEMWATCHER_H |