edelib  2.0.0
DirWatch.h
1 /*
2  * $Id: DirWatch.h 2839 2009-09-28 11:36:20Z karijes $
3  *
4  * Directory changes notifier
5  * Copyright (c) 2005-2007 edelib authors
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library 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 GNU
15  * 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 this library. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef __EDELIB_DIRWATCH_H__
22 #define __EDELIB_DIRWATCH_H__
23 
24 #include "edelib-global.h"
25 
26 EDELIB_NS_BEGIN
27 
33  DW_CREATE = (1 << 1),
34  DW_MODIFY = (1 << 2),
35  DW_ACCESS = (1 << 3),
36  DW_RENAME = (1 << 4),
37  DW_ATTRIB = (1 << 5),
38  DW_DELETE = (1 << 6)
39 };
40 
46  DW_NONE = 0,
49 };
50 
61 };
62 
63 struct DirWatchEntry;
64 struct DirWatchImpl;
65 
66 #ifndef SKIP_DOCS
67 typedef void (DirWatchCallback)(const char* dir, const char* w, int flags, void* data);
68 #endif
69 
180 class EDELIB_API DirWatch {
181 private:
182  static DirWatch* pinstance;
183 
184  DirWatchImpl* impl;
185  DirWatchNotifier backend_notifier;
186 
187  bool init_backend(void);
188 
190 public:
194  DirWatch();
195 
199  ~DirWatch();
200 
201 #ifndef SKIP_DOCS
202  static DirWatch* instance(void);
203 
204  bool add_entry(const char* dir, int flags);
205  bool remove_entry(const char* dir);
206  bool have_entry(const char* dir);
207  void add_callback(DirWatchCallback* cb, void* data);
208  void run_callback(int fd);
209  DirWatchNotifier get_notifier(void) { return backend_notifier; }
210 #endif
211 
215  static bool init(void);
216 
221  static void shutdown(void);
222 
228  static bool add(const char* dir, int flags);
229 
233  static bool remove(const char* dir);
234 
239  static void callback(DirWatchCallback& cb, void* data = 0);
240 
244  static DirWatchNotifier notifier(void);
245 };
246 
247 EDELIB_NS_END
248 #endif