1 /* 2 * Copyright 2007-2013, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _PATH_MONITOR_H 6 #define _PATH_MONITOR_H 7 8 9 #include <NodeMonitor.h> 10 11 12 // Monitoring a path always implies B_WATCH_NAME for the path itself. I.e. even 13 // if only B_WATCH_STAT is specified, B_ENTRY_{CREATED,MOVED,REMOVED} 14 // notifications are sent when the respective entry is created/moved/removed. 15 16 // additional flags (combined with those in NodeMonitor.h) 17 #define B_WATCH_RECURSIVELY 0x0100 18 // Watch not only the entry specified by the path, but also recursively all 19 // descendents. A recursive B_WATCH_DIRECTORY is implied, i.e. 20 // B_ENTRY_{CREATED,MOVED,REMOVED} notifications will be sent for any entry 21 // change below the given path, unless explicitly suppressed by 22 // B_WATCH_{FILES,DIRECTORIES}_ONLY. 23 #define B_WATCH_FILES_ONLY 0x0200 24 // A notification will only be sent when the node it concerns is not a 25 // directory. No effect in non-recursive mode. 26 #define B_WATCH_DIRECTORIES_ONLY 0x0400 27 // A notification will only be sent when the node it concerns is a 28 // directory. No effect in non-recursive mode. 29 30 #define B_PATH_MONITOR '_PMN' 31 32 33 namespace BPrivate { 34 35 36 class BPathMonitor { 37 public: 38 class BWatchingInterface; 39 40 public: 41 static status_t StartWatching(const char* path, uint32 flags, 42 const BMessenger& target); 43 44 static status_t StopWatching(const char* path, 45 const BMessenger& target); 46 static status_t StopWatching(const BMessenger& target); 47 48 static void SetWatchingInterface( 49 BWatchingInterface* watchingInterface); 50 // pass NULL to reset to default 51 52 private: 53 BPathMonitor(); 54 ~BPathMonitor(); 55 56 static status_t _InitIfNeeded(); 57 static void _Init(); 58 }; 59 60 61 /*! Base class just delegates to the respective C functions. 62 */ 63 class BPathMonitor::BWatchingInterface { 64 public: 65 BWatchingInterface(); 66 virtual ~BWatchingInterface(); 67 68 virtual status_t WatchNode(const node_ref* node, uint32 flags, 69 const BMessenger& target); 70 virtual status_t WatchNode(const node_ref* node, uint32 flags, 71 const BHandler* handler, 72 const BLooper* looper = NULL); 73 74 virtual status_t StopWatching(const BMessenger& target); 75 virtual status_t StopWatching(const BHandler* handler, 76 const BLooper* looper = NULL); 77 }; 78 79 80 } // namespace BPrivate 81 82 83 using BPrivate::BPathMonitor; 84 85 86 #endif // _PATH_MONITOR_H 87