Fawkes API  Fawkes Development Version
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  void reset();
81 
82  void process_events(int timeout = 0);
83  void interrupt();
84 
85  void add_listener(FamListener *listener);
86  void remove_listener(FamListener *listener);
87 
88  private:
89  LockList<FamListener *> __listeners;
91  LockList<regex_t *> __regexes;
93 
94  int __inotify_fd;
95  char *__inotify_buf;
96  size_t __inotify_bufsize;
97 
98  std::map<int, std::string> __inotify_watches;
99  std::map<int, std::string>::iterator __inotify_wit;
100 
101  bool __interrupted;
102  bool __interruptible;
103  int __pipe_fds[2];
104 };
105 
106 } // end of namespace fawkes
107 
108 #endif
Fawkes library namespace.
static const unsigned int FAM_UNMOUNT
Backing fs was unmounted.
Definition: fam.h:55
static const unsigned int FAM_ONESHOT
Only send event once.
Definition: fam.h:63
static const unsigned int FAM_CREATE
Subfile was created.
Definition: fam.h:50
virtual void fam_event(const char *filename, unsigned int mask)=0
Event has been raised.
static const unsigned int FAM_ISDIR
Event occurred against dir.
Definition: fam.h:62
static const unsigned int FAM_MOVE
Moves.
Definition: fam.h:49
static const unsigned int FAM_OPEN
File was opened.
Definition: fam.h:46
static const unsigned int FAM_ACCESS
File was accessed.
Definition: fam.h:40
static const unsigned int FAM_IGNORED
File was ignored.
Definition: fam.h:57
static const unsigned int FAM_Q_OVERFLOW
Event queued overflowed.
Definition: fam.h:56
static const unsigned int FAM_ONLYDIR
Only watch the path if it is a directory.
Definition: fam.h:59
List with a lock.
Definition: thread.h:40
static const unsigned int FAM_MASK_ADD
Add to the mask of an already existing watch.
Definition: fam.h:61
File Alteration Monitor Listener.
Definition: fam.h:35
Monitors files for changes.
Definition: fam.h:71
static const unsigned int FAM_MOVE_SELF
Self was moved.
Definition: fam.h:53
static const unsigned int FAM_MOVED_FROM
File was moved from X.
Definition: fam.h:47
static const unsigned int FAM_MOVED_TO
File was moved to Y.
Definition: fam.h:48
static const unsigned int FAM_DELETE_SELF
Self was deleted.
Definition: fam.h:52
static const unsigned int FAM_ALL_EVENTS
All events which a program can wait on.
Definition: fam.h:65
static const unsigned int FAM_CLOSE_NOWRITE
Unwrittable file closed.
Definition: fam.h:44
static const unsigned int FAM_DELETE
Subfile was deleted.
Definition: fam.h:51
static const unsigned int FAM_MODIFY
File was modified.
Definition: fam.h:41
static const unsigned int FAM_DONT_FOLLOW
Do not follow a sym link.
Definition: fam.h:60
static const unsigned int FAM_ATTRIB
Metadata changed.
Definition: fam.h:42
virtual ~FamListener()
Virtual empty destructor.
Definition: fam.cpp:451
static const unsigned int FAM_CLOSE_WRITE
Writtable file was closed.
Definition: fam.h:43
static const unsigned int FAM_CLOSE
Close.
Definition: fam.h:45