Apache log4cxx  Version 0.12.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
30 {
31 namespace helpers
32 {
33 
38 class LOG4CXX_EXPORT FileWatchdog
39 {
40  public:
41  virtual ~FileWatchdog();
45  static long DEFAULT_DELAY /*= 60000*/;
46 
47  protected:
52 
56  long delay;
57  log4cxx_time_t lastModif;
59  volatile int interrupted;
60 
61  protected:
62  FileWatchdog(const File& filename);
63  virtual void doOnChange() = 0;
64  void checkAndConfigure();
65 
66  public:
70  void setDelay(long delay1)
71  {
72  this->delay = delay1;
73  }
74 
75  void start();
76 
77  private:
78  void run();
79  bool is_interrupted();
80  Pool pool;
81  std::thread thread;
82  std::condition_variable interrupt;
83  std::mutex interrupt_mutex;
84 
85  FileWatchdog(const FileWatchdog&);
86  FileWatchdog& operator=(const FileWatchdog&);
87 
88 };
89 } // namespace helpers
90 } // namespace log4cxx
91 
92 
93 #endif // _LOG4CXX_HELPERS_FILEWATCHDOG_H
Check every now and then that a certain file has not changed.
Definition: filewatchdog.h:38
volatile int interrupted
Definition: filewatchdog.h:59
File file
The name of the file to observe for changes.
Definition: filewatchdog.h:51
log4cxx_time_t lastModif
Definition: filewatchdog.h:57
Definition: pool.h:32
long delay
The delay to observe between every check.
Definition: filewatchdog.h:56
An abstract representation of file and directory path names.
Definition: file.h:45
Definition: appender.h:32
bool warnedAlready
Definition: filewatchdog.h:58
void setDelay(long delay1)
Set the delay to observe between each check of the file changes.
Definition: filewatchdog.h:70