xref: /glogg/src/platformfilewatcher.h (revision 96bde7d5e1c8c71a3ad8ee8e2641c176dc312047)
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 
2784b2179eSNicolas Bonnefon #include "watchtower.h"
2884b2179eSNicolas Bonnefon 
29*96bde7d5SNicolas Bonnefon class INotifyWatchTower;
30*96bde7d5SNicolas Bonnefon 
3184b2179eSNicolas Bonnefon // An implementation of FileWatcher, as an adapter to INotifyWatchTower.
3284b2179eSNicolas Bonnefon // This is Linux only, and require a recent version of the kernel.
3384b2179eSNicolas Bonnefon 
3484b2179eSNicolas Bonnefon // Please note that due to the implementation of the constructor
3584b2179eSNicolas Bonnefon // this class is not thread safe and shall always be used from the main UI thread.
3684b2179eSNicolas Bonnefon class PlatformFileWatcher : public FileWatcher {
3784b2179eSNicolas Bonnefon   Q_OBJECT
3884b2179eSNicolas Bonnefon 
3984b2179eSNicolas Bonnefon   public:
4084b2179eSNicolas Bonnefon     // Create the empty object
4184b2179eSNicolas Bonnefon     PlatformFileWatcher();
4284b2179eSNicolas Bonnefon     // Destroy the object
4384b2179eSNicolas Bonnefon     ~PlatformFileWatcher() override;
4484b2179eSNicolas Bonnefon 
4584b2179eSNicolas Bonnefon     void addFile( const QString& fileName ) override;
4684b2179eSNicolas Bonnefon     void removeFile( const QString& fileName ) override;
4784b2179eSNicolas Bonnefon 
4884b2179eSNicolas Bonnefon   signals:
4984b2179eSNicolas Bonnefon     void fileChanged( const QString& );
5084b2179eSNicolas Bonnefon 
5184b2179eSNicolas Bonnefon   private:
52*96bde7d5SNicolas Bonnefon     using PlatformWatchTower = WatchTower<INotifyWatchTowerDriver>;
53*96bde7d5SNicolas Bonnefon 
5484b2179eSNicolas Bonnefon     // The following variables are protected by watched_files_mutex_
5584b2179eSNicolas Bonnefon     QString watched_file_name_;
5684b2179eSNicolas Bonnefon 
5784b2179eSNicolas Bonnefon     // Reference to the (unique) watchtower.
58*96bde7d5SNicolas Bonnefon     static std::shared_ptr<PlatformWatchTower> watch_tower_;
5984b2179eSNicolas Bonnefon 
60*96bde7d5SNicolas Bonnefon     std::shared_ptr<Registration> notification_;
6184b2179eSNicolas Bonnefon };
6284b2179eSNicolas Bonnefon 
6384b2179eSNicolas Bonnefon #endif
64