1 /* 2 * Copyright (C) 2010, 2014, 2015 Nicolas Bonnefon and other contributors 3 * 4 * This file is part of glogg. 5 * 6 * glogg is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * glogg is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with glogg. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #include "platformfilewatcher.h" 21 22 #include "log.h" 23 24 std::shared_ptr<PlatformFileWatcher::PlatformWatchTower> PlatformFileWatcher::watch_tower_; 25 26 PlatformFileWatcher::PlatformFileWatcher() : FileWatcher() 27 { 28 // Caution, this is NOT thread-safe or re-entrant! 29 if ( !watch_tower_ ) 30 { 31 watch_tower_ = std::make_shared<PlatformWatchTower>(); 32 } 33 } 34 35 PlatformFileWatcher::~PlatformFileWatcher() 36 { 37 } 38 39 void PlatformFileWatcher::addFile( const QString& fileName ) 40 { 41 LOG(logDEBUG) << "FileWatcher::addFile " << fileName.toStdString(); 42 43 watched_file_name_ = fileName; 44 45 notification_ = std::make_shared<Registration>( 46 watch_tower_->addFile( fileName.toStdString(), [this, fileName] { 47 emit fileChanged( fileName ); } ) ); 48 } 49 50 void PlatformFileWatcher::removeFile( const QString& fileName ) 51 { 52 LOG(logDEBUG) << "FileWatcher::removeFile " << fileName.toStdString(); 53 54 notification_ = nullptr; 55 } 56 57 void PlatformFileWatcher::setPollingInterval( uint32_t interval_ms ) 58 { 59 watch_tower_->setPollingInterval( interval_ms ); 60 } 61