Fawkes API  Fawkes Development Version
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
fam.h
1 
2 /***************************************************************************
3  * fam.h - File Alteration Monitor
4  *
5  * Created: Fri May 23 11:38:41 2008
6  * Copyright 2006-2008 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Library General Public License for more details.
19  *
20  * Read the full text in the LICENSE.GPL file in the doc directory.
21  */
22 
23 #ifndef __UTILS_SYSTEM_FAM_H_
24 #define __UTILS_SYSTEM_FAM_H_
25 
26 #include <core/utils/lock_list.h>
27 
28 #include <sys/types.h>
29 #include <map>
30 #include <string>
31 #include <regex.h>
32 
33 namespace fawkes {
34 
36 {
37  public:
38  virtual ~FamListener();
39 
40  static const unsigned int FAM_ACCESS;
41  static const unsigned int FAM_MODIFY;
42  static const unsigned int FAM_ATTRIB;
43  static const unsigned int FAM_CLOSE_WRITE;
44  static const unsigned int FAM_CLOSE_NOWRITE;
45  static const unsigned int FAM_CLOSE;
46  static const unsigned int FAM_OPEN;
47  static const unsigned int FAM_MOVED_FROM;
48  static const unsigned int FAM_MOVED_TO;
49  static const unsigned int FAM_MOVE;
50  static const unsigned int FAM_CREATE;
51  static const unsigned int FAM_DELETE;
52  static const unsigned int FAM_DELETE_SELF;
53  static const unsigned int FAM_MOVE_SELF;
54 
55  static const unsigned int FAM_UNMOUNT;
56  static const unsigned int FAM_Q_OVERFLOW;
57  static const unsigned int FAM_IGNORED;
58 
59  static const unsigned int FAM_ONLYDIR;
60  static const unsigned int FAM_DONT_FOLLOW;
61  static const unsigned int FAM_MASK_ADD;
62  static const unsigned int FAM_ISDIR;
63  static const unsigned int FAM_ONESHOT;
64 
65  static const unsigned int FAM_ALL_EVENTS;
66 
67 
68  virtual void fam_event(const char *filename, unsigned int mask) = 0;
69 };
70 
72 {
73  public:
76 
77  void watch_dir(const char *dirpath);
78  void watch_file(const char *filepath);
79  void add_filter(const char *regex);
80 
81  void process_events(int timeout = 0);
82  void interrupt();
83 
84  void add_listener(FamListener *listener);
85  void remove_listener(FamListener *listener);
86 
87  private:
88  LockList<FamListener *> __listeners;
90  LockList<regex_t *> __regexes;
92 
93  int __inotify_fd;
94  char *__inotify_buf;
95  size_t __inotify_bufsize;
96  std::map<int, std::string> __inotify_watches;
97  std::map<int, std::string>::iterator __inotify_wit;
98 
99  bool __interrupted;
100  bool __interruptible;
101  int __pipe_fds[2];
102 };
103 
104 } // end of namespace fawkes
105 
106 #endif