Loading...
Searching...
No Matches
FileWatcher.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
3
4 This file is part of the TerraLib - a Framework for building GIS enabled
5 applications.
6
7 TerraLib is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation, either version 3 of the License,
10 or (at your option) any later version.
11
12 TerraLib is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with TerraLib. See COPYING. If not, write to
19 TerraLib Team at <terralib-team@terralib.org>.
20 */
21
22/*!
23 \file terralib/core/filesystem/FileWatcher.h
24
25 \brief This class is designed to watch a file.
26
27 \author Matheus Cavassan Zaglia
28*/
29
30#ifndef __TERRALIB_CORE_FILESYSTEM_FILEWATCHER_H__
31#define __TERRALIB_CORE_FILESYSTEM_FILEWATCHER_H__
32
33// TerraLib
34#include "../Config.h"
35
36// STL
37#include <string>
38#include <functional>
39#include <future>
40#include <thread>
41
42namespace te
43{
44 namespace core
45 {
47 {
48 /*!
49 \class FileWatcher
50
51 \brief This class is designed to watch a file.
52 */
53 public:
54 /*!
55 \brief It initializes a new FileWatcher from a given path and callback
56 function
57
58 \param path A UTF-8 String with a path to a file.
59
60 \param callback A function with zero parameters and void return that
61 will be called when the file is changed.
62 */
63 FileWatcher(const std::string& path,
64 const std::function<void()>& callback);
65
66 /*!
67 \brief Destructor.
68 */
70
71 /*!
72 \brief Starts a thread that will monitor the given file and call the
73 previously given callback function.
74 */
75 void watch();
76 /*!
77 \brief Stops the thread watching the file.
78 */
79 void unwatch();
80
81 private:
82 std::mutex m_mutex;
83 std::string m_file;
84 std::function<void()> m_callback;
85 std::thread m_watcher;
87 };
88 } // end namespace core
89} // end namespace te
90#endif //__TERRALIB_CORE_FILESYSTEM_FILEWATCHER_H__
~FileWatcher()
Destructor.
std::thread m_watcher
Definition: FileWatcher.h:85
void watch()
Starts a thread that will monitor the given file and call the previously given callback function.
std::string m_file
Definition: FileWatcher.h:83
void unwatch()
Stops the thread watching the file.
FileWatcher(const std::string &path, const std::function< void()> &callback)
It initializes a new FileWatcher from a given path and callback function.
std::function< void()> m_callback
Definition: FileWatcher.h:84
TerraLib.
#define TECOREEXPORT
Definition: Config.h:52