edelib
2.0.0
|
00001 /* 00002 * $Id: DirWatch.h 2839 2009-09-28 11:36:20Z karijes $ 00003 * 00004 * Directory changes notifier 00005 * Copyright (c) 2005-2007 edelib authors 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2 of the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public License 00018 * along with this library. If not, see <http://www.gnu.org/licenses/>. 00019 */ 00020 00021 #ifndef __EDELIB_DIRWATCH_H__ 00022 #define __EDELIB_DIRWATCH_H__ 00023 00024 #include "edelib-global.h" 00025 00026 EDELIB_NS_BEGIN 00027 00032 enum DirWatchFlags { 00033 DW_CREATE = (1 << 1), 00034 DW_MODIFY = (1 << 2), 00035 DW_ACCESS = (1 << 3), 00036 DW_RENAME = (1 << 4), 00037 DW_ATTRIB = (1 << 5), 00038 DW_DELETE = (1 << 6) 00039 }; 00040 00045 enum DirWatchNotifier { 00046 DW_NONE = 0, 00047 DW_INOTIFY, 00048 DW_FAM 00049 }; 00050 00055 enum DirWatchReportFlags { 00056 DW_REPORT_NONE = -1, 00057 DW_REPORT_CREATE = 0, 00058 DW_REPORT_MODIFY, 00059 DW_REPORT_RENAME, 00060 DW_REPORT_DELETE 00061 }; 00062 00063 struct DirWatchEntry; 00064 struct DirWatchImpl; 00065 00066 #ifndef SKIP_DOCS 00067 typedef void (DirWatchCallback)(const char* dir, const char* w, int flags, void* data); 00068 #endif 00069 00180 class EDELIB_API DirWatch { 00181 private: 00182 static DirWatch* pinstance; 00183 00184 DirWatchImpl* impl; 00185 DirWatchNotifier backend_notifier; 00186 00187 bool init_backend(void); 00188 00189 E_DISABLE_CLASS_COPY(DirWatch) 00190 public: 00194 DirWatch(); 00195 00199 ~DirWatch(); 00200 00201 #ifndef SKIP_DOCS 00202 static DirWatch* instance(void); 00203 00204 bool add_entry(const char* dir, int flags); 00205 bool remove_entry(const char* dir); 00206 bool have_entry(const char* dir); 00207 void add_callback(DirWatchCallback* cb, void* data); 00208 void run_callback(int fd); 00209 DirWatchNotifier get_notifier(void) { return backend_notifier; } 00210 #endif 00211 00215 static bool init(void); 00216 00221 static void shutdown(void); 00222 00228 static bool add(const char* dir, int flags); 00229 00233 static bool remove(const char* dir); 00234 00239 static void callback(DirWatchCallback& cb, void* data = 0); 00240 00244 static DirWatchNotifier notifier(void); 00245 }; 00246 00247 EDELIB_NS_END 00248 #endif