184b2179eSNicolas Bonnefon /* 284b2179eSNicolas Bonnefon * Copyright (C) 2014 Nicolas Bonnefon and other contributors 384b2179eSNicolas Bonnefon * 484b2179eSNicolas Bonnefon * This file is part of glogg. 584b2179eSNicolas Bonnefon * 684b2179eSNicolas Bonnefon * glogg is free software: you can redistribute it and/or modify 784b2179eSNicolas Bonnefon * it under the terms of the GNU General Public License as published by 884b2179eSNicolas Bonnefon * the Free Software Foundation, either version 3 of the License, or 984b2179eSNicolas Bonnefon * (at your option) any later version. 1084b2179eSNicolas Bonnefon * 1184b2179eSNicolas Bonnefon * glogg is distributed in the hope that it will be useful, 1284b2179eSNicolas Bonnefon * but WITHOUT ANY WARRANTY; without even the implied warranty of 1384b2179eSNicolas Bonnefon * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1484b2179eSNicolas Bonnefon * GNU General Public License for more details. 1584b2179eSNicolas Bonnefon * 1684b2179eSNicolas Bonnefon * You should have received a copy of the GNU General Public License 1784b2179eSNicolas Bonnefon * along with glogg. If not, see <http://www.gnu.org/licenses/>. 1884b2179eSNicolas Bonnefon */ 1984b2179eSNicolas Bonnefon 2084b2179eSNicolas Bonnefon #ifndef PLATFORMFILEWATCHER_H 2184b2179eSNicolas Bonnefon #define PLATFORMFILEWATCHER_H 2284b2179eSNicolas Bonnefon 2384b2179eSNicolas Bonnefon #include "filewatcher.h" 2484b2179eSNicolas Bonnefon 2584b2179eSNicolas Bonnefon #include <memory> 2684b2179eSNicolas Bonnefon 27f09fa651SNicolas Bonnefon #ifdef _WIN32 28f09fa651SNicolas Bonnefon # include "winwatchtowerdriver.h" 29f09fa651SNicolas Bonnefon #else 30f09fa651SNicolas Bonnefon # include "inotifywatchtowerdriver.h" 31f09fa651SNicolas Bonnefon #endif 32f09fa651SNicolas Bonnefon 3384b2179eSNicolas Bonnefon #include "watchtower.h" 3484b2179eSNicolas Bonnefon 3596bde7d5SNicolas Bonnefon class INotifyWatchTower; 3696bde7d5SNicolas Bonnefon 3784b2179eSNicolas Bonnefon // An implementation of FileWatcher, as an adapter to INotifyWatchTower. 3884b2179eSNicolas Bonnefon // This is Linux only, and require a recent version of the kernel. 3984b2179eSNicolas Bonnefon 4084b2179eSNicolas Bonnefon // Please note that due to the implementation of the constructor 4184b2179eSNicolas Bonnefon // this class is not thread safe and shall always be used from the main UI thread. 4284b2179eSNicolas Bonnefon class PlatformFileWatcher : public FileWatcher { 4384b2179eSNicolas Bonnefon Q_OBJECT 4484b2179eSNicolas Bonnefon 4584b2179eSNicolas Bonnefon public: 4684b2179eSNicolas Bonnefon // Create the empty object 4784b2179eSNicolas Bonnefon PlatformFileWatcher(); 4884b2179eSNicolas Bonnefon // Destroy the object 49dc7f5916SNicolas Bonnefon ~PlatformFileWatcher(); 5084b2179eSNicolas Bonnefon 51dc7f5916SNicolas Bonnefon void addFile( const QString& fileName ); 52dc7f5916SNicolas Bonnefon void removeFile( const QString& fileName ); 5384b2179eSNicolas Bonnefon 5484b2179eSNicolas Bonnefon signals: 5584b2179eSNicolas Bonnefon void fileChanged( const QString& ); 5684b2179eSNicolas Bonnefon 5784b2179eSNicolas Bonnefon private: 58f09fa651SNicolas Bonnefon #ifdef _WIN32 59*58f443c7SNicolas Bonnefon # ifdef HAS_TEMPLATE_ALIASES 60f09fa651SNicolas Bonnefon using PlatformWatchTower = WatchTower<WinWatchTowerDriver>; 61*58f443c7SNicolas Bonnefon # else 62*58f443c7SNicolas Bonnefon typedef WatchTower<WinWatchTowerDriver> PlatformWatchTower; 63f09fa651SNicolas Bonnefon # endif 64f09fa651SNicolas Bonnefon #else 65*58f443c7SNicolas Bonnefon # ifdef HAS_TEMPLATE_ALIASES 6696bde7d5SNicolas Bonnefon using PlatformWatchTower = WatchTower<INotifyWatchTowerDriver>; 67*58f443c7SNicolas Bonnefon # else 68*58f443c7SNicolas Bonnefon typedef WatchTower<INotifyWatchTowerDriver> PlatformWatchTower; 69dc7f5916SNicolas Bonnefon # endif 70f09fa651SNicolas Bonnefon #endif 7196bde7d5SNicolas Bonnefon 7284b2179eSNicolas Bonnefon // The following variables are protected by watched_files_mutex_ 7384b2179eSNicolas Bonnefon QString watched_file_name_; 7484b2179eSNicolas Bonnefon 7584b2179eSNicolas Bonnefon // Reference to the (unique) watchtower. 7696bde7d5SNicolas Bonnefon static std::shared_ptr<PlatformWatchTower> watch_tower_; 7784b2179eSNicolas Bonnefon 7896bde7d5SNicolas Bonnefon std::shared_ptr<Registration> notification_; 7984b2179eSNicolas Bonnefon }; 8084b2179eSNicolas Bonnefon 8184b2179eSNicolas Bonnefon #endif 82