Apache Log4cxx  Version 1.3.1
filewatchdog.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef _LOG4CXX_HELPERS_FILEWATCHDOG_H
19 #define _LOG4CXX_HELPERS_FILEWATCHDOG_H
20 
21 #include <log4cxx/logstring.h>
22 #include <time.h>
23 #include <log4cxx/helpers/pool.h>
24 #include <log4cxx/file.h>
25 #include <atomic>
26 #include <thread>
27 #include <condition_variable>
28 
29 namespace LOG4CXX_NS
30 {
31 namespace helpers
32 {
33 
38 class LOG4CXX_EXPORT FileWatchdog
39 {
40  public:
41  virtual ~FileWatchdog();
45  static long DEFAULT_DELAY /*= 60000 ms*/;
46 
47  protected:
48  FileWatchdog(const File& filename);
49  virtual void doOnChange() = 0;
51  const File& file();
52 
53  public:
57  void setDelay(long delay);
58 
62  void start();
63 
67  void stop();
68 
72  bool is_active();
73 
74  private:
75  void run();
76  bool is_interrupted();
77 
78 
79  FileWatchdog(const FileWatchdog&);
80  FileWatchdog& operator=(const FileWatchdog&);
81 
82  LOG4CXX_DECLARE_PRIVATE_MEMBER_PTR(FileWatchdogPrivate, m_priv)
83 };
84 } // namespace helpers
85 } // namespace log4cxx
86 
87 
88 #endif // _LOG4CXX_HELPERS_FILEWATCHDOG_H
An abstract representation of file and directory path names.
Definition: file.h:41
Check every now and then that a certain file has not changed.
Definition: filewatchdog.h:39
void setDelay(long delay)
Use delay as the number of milliseconds to wait between each check for file changes.
bool is_active()
Is the thread that periodically checks for a file change running?
void start()
Create a thread that periodically checks for a file change after first calling doOnChange() on the cu...
void stop()
Stop the thread that periodically checks for a file change.
FileWatchdog(const File &filename)