Alexander Afanasyev | 9e5a470 | 2013-01-24 13:15:23 -0800 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2012-2013 University of California, Los Angeles |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation; |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | * |
| 18 | * Author: Jared Lindblom <lindblom@cs.ucla.edu> |
| 19 | * Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 20 | * Zhenkai Zhu <zhenkai@cs.ucla.edu> |
| 21 | */ |
| 22 | #ifndef FS_WATCHER_H |
| 23 | #define FS_WATCHER_H |
| 24 | |
| 25 | #include <vector> |
| 26 | #include <QFileSystemWatcher> |
| 27 | |
| 28 | #include "structs.h" |
| 29 | |
| 30 | #include "executor.h" |
| 31 | |
| 32 | class FsWatcher : public QObject |
| 33 | { |
| 34 | Q_OBJECT |
| 35 | |
| 36 | public: |
| 37 | // constructor |
| 38 | FsWatcher (QString dirPath, QObject* parent = 0); |
| 39 | |
| 40 | // destructor |
| 41 | ~FsWatcher (); |
| 42 | |
| 43 | private slots: |
| 44 | // handle callback from watcher |
| 45 | void |
| 46 | DidDirectoryChanged (QString dirPath); |
| 47 | |
| 48 | /** |
| 49 | * @brief This even will be triggered either by actual file change or via directory change event |
| 50 | * (i.e., can happen twice in a row, as well as trigger false alarm) |
| 51 | */ |
| 52 | void |
| 53 | DidFileChanged (QString filePath); |
| 54 | |
| 55 | private: |
| 56 | // handle callback from the watcher |
| 57 | void |
| 58 | DidDirectoryChanged_Execute (QString dirPath); |
| 59 | |
| 60 | // scan directory and notify callback about any file changes |
| 61 | void |
| 62 | ScanDirectory_Notify_Execute (QString dirPath); |
| 63 | |
| 64 | // // reconcile directory, find changes |
| 65 | // std::vector<sEventInfo> |
| 66 | // reconcileDirectory (QHash<QString, qint64> fileList, QString dirPath); |
| 67 | |
| 68 | // // calculate checksum |
| 69 | // QByteArray calcChecksum(QString absFilePath); |
| 70 | |
| 71 | // // print Changes (DEBUG) |
| 72 | // void printChanges(std::vector<sEventInfo> dirChanges); |
| 73 | |
| 74 | private: |
| 75 | QFileSystemWatcher* m_watcher; // filesystem watcher |
| 76 | Executor m_executor; |
| 77 | |
| 78 | QString m_dirPath; // monitored path |
| 79 | }; |
| 80 | |
| 81 | #endif // FILESYSTEMWATCHER_H |