Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 从POCO DirectoryWatcher接收到重复事件_C++_Linux_Poco Libraries - Fatal编程技术网

C++ 从POCO DirectoryWatcher接收到重复事件

C++ 从POCO DirectoryWatcher接收到重复事件,c++,linux,poco-libraries,C++,Linux,Poco Libraries,我试图使用POCO文件系统库中的DirectoryWatcher类来监视特定文件夹的更改。代码非常简单,如下所示: Monitor::Monitor() { pattern = new Glob("/path/to/dir/*.dat", Glob::GLOB_DOT_SPECIAL); watcher = new DirectoryWatcher(std::string("/path/to/dir")); watcher

我试图使用POCO文件系统库中的DirectoryWatcher类来监视特定文件夹的更改。代码非常简单,如下所示:

Monitor::Monitor() {
    pattern = new Glob("/path/to/dir/*.dat",
                       Glob::GLOB_DOT_SPECIAL);

    watcher = new DirectoryWatcher(std::string("/path/to/dir"));

    watcher->itemAdded += delegate(this, &Monitor::onFileAdded);
    watcher->itemModified += delegate(this, &Monitor::onFileChanged);
}

void Monitor::onFileAdded(const DirectoryWatcher::DirectoryEvent& addEvent) {
    if (pattern->match(addEvent.item.path())) {
        std::cout << "File added: " << addEvent.item.path() << std::endl;
    }
}

void Monitor::onFileChanged(const DirectoryWatcher::DirectoryEvent& changeEvent) {
    if (pattern->match(changeEvent.item.path())) {
        std::cout << "File changed: " << changeEvent.item.path() << std::endl;
    }
}
Monitor::Monitor(){
pattern=newglob(“/path/to/dir/*.dat”,
Glob::Glob_DOT_SPECIAL);
watcher=newdirectorywatcher(std::string(“/path/to/dir”);
观察者->项目添加+=委托(此,&监视器::未引导);
观察者->项目修改+=委托(此,&Monitor::onFileChanged);
}
无效监视器::onfiled(const DirectoryWatcher::DirectoryEvent和addEvent){
if(模式->匹配(addEvent.item.path()){
标准::cout