1*84b2179eSNicolas Bonnefon /* 2*84b2179eSNicolas Bonnefon * Copyright (C) 2014 Nicolas Bonnefon and other contributors 3*84b2179eSNicolas Bonnefon * 4*84b2179eSNicolas Bonnefon * This file is part of glogg. 5*84b2179eSNicolas Bonnefon * 6*84b2179eSNicolas Bonnefon * glogg is free software: you can redistribute it and/or modify 7*84b2179eSNicolas Bonnefon * it under the terms of the GNU General Public License as published by 8*84b2179eSNicolas Bonnefon * the Free Software Foundation, either version 3 of the License, or 9*84b2179eSNicolas Bonnefon * (at your option) any later version. 10*84b2179eSNicolas Bonnefon * 11*84b2179eSNicolas Bonnefon * glogg is distributed in the hope that it will be useful, 12*84b2179eSNicolas Bonnefon * but WITHOUT ANY WARRANTY; without even the implied warranty of 13*84b2179eSNicolas Bonnefon * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14*84b2179eSNicolas Bonnefon * GNU General Public License for more details. 15*84b2179eSNicolas Bonnefon * 16*84b2179eSNicolas Bonnefon * You should have received a copy of the GNU General Public License 17*84b2179eSNicolas Bonnefon * along with glogg. If not, see <http://www.gnu.org/licenses/>. 18*84b2179eSNicolas Bonnefon */ 19*84b2179eSNicolas Bonnefon 20*84b2179eSNicolas Bonnefon #ifndef PLATFORMFILEWATCHER_H 21*84b2179eSNicolas Bonnefon #define PLATFORMFILEWATCHER_H 22*84b2179eSNicolas Bonnefon 23*84b2179eSNicolas Bonnefon #include "filewatcher.h" 24*84b2179eSNicolas Bonnefon 25*84b2179eSNicolas Bonnefon #include <memory> 26*84b2179eSNicolas Bonnefon 27*84b2179eSNicolas Bonnefon #include "watchtower.h" 28*84b2179eSNicolas Bonnefon 29*84b2179eSNicolas Bonnefon // An implementation of FileWatcher, as an adapter to INotifyWatchTower. 30*84b2179eSNicolas Bonnefon // This is Linux only, and require a recent version of the kernel. 31*84b2179eSNicolas Bonnefon 32*84b2179eSNicolas Bonnefon // Please note that due to the implementation of the constructor 33*84b2179eSNicolas Bonnefon // this class is not thread safe and shall always be used from the main UI thread. 34*84b2179eSNicolas Bonnefon class PlatformFileWatcher : public FileWatcher { 35*84b2179eSNicolas Bonnefon Q_OBJECT 36*84b2179eSNicolas Bonnefon 37*84b2179eSNicolas Bonnefon public: 38*84b2179eSNicolas Bonnefon // Create the empty object 39*84b2179eSNicolas Bonnefon PlatformFileWatcher(); 40*84b2179eSNicolas Bonnefon // Destroy the object 41*84b2179eSNicolas Bonnefon ~PlatformFileWatcher() override; 42*84b2179eSNicolas Bonnefon 43*84b2179eSNicolas Bonnefon void addFile( const QString& fileName ) override; 44*84b2179eSNicolas Bonnefon void removeFile( const QString& fileName ) override; 45*84b2179eSNicolas Bonnefon 46*84b2179eSNicolas Bonnefon signals: 47*84b2179eSNicolas Bonnefon void fileChanged( const QString& ); 48*84b2179eSNicolas Bonnefon 49*84b2179eSNicolas Bonnefon private: 50*84b2179eSNicolas Bonnefon // The following variables are protected by watched_files_mutex_ 51*84b2179eSNicolas Bonnefon QString watched_file_name_; 52*84b2179eSNicolas Bonnefon 53*84b2179eSNicolas Bonnefon // Reference to the (unique) watchtower. 54*84b2179eSNicolas Bonnefon static std::shared_ptr<WatchTower> watch_tower_; 55*84b2179eSNicolas Bonnefon 56*84b2179eSNicolas Bonnefon std::shared_ptr<WatchTower::Registration> notification_; 57*84b2179eSNicolas Bonnefon }; 58*84b2179eSNicolas Bonnefon 59*84b2179eSNicolas Bonnefon #endif 60