2007-05-04 20:02:04 +04:00
|
|
|
/*
|
2013-06-27 23:46:29 +04:00
|
|
|
* Copyright 2007-2013, Haiku, Inc. All Rights Reserved.
|
2007-05-04 20:02:04 +04:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
|
|
|
#ifndef _PATH_MONITOR_H
|
|
|
|
#define _PATH_MONITOR_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <NodeMonitor.h>
|
|
|
|
|
|
|
|
|
2013-06-27 23:46:29 +04:00
|
|
|
// Monitoring a path always implies B_WATCH_NAME for the path itself. I.e. even
|
|
|
|
// if only B_WATCH_STAT is specified, B_ENTRY_{CREATED,MOVED,REMOVED}
|
|
|
|
// notifications are sent when the respective entry is created/moved/removed.
|
|
|
|
|
2007-05-04 20:02:04 +04:00
|
|
|
// additional flags (combined with those in NodeMonitor.h)
|
2013-06-27 23:46:29 +04:00
|
|
|
#define B_WATCH_RECURSIVELY 0x0100
|
|
|
|
// Watch not only the entry specified by the path, but also recursively all
|
|
|
|
// descendents. A recursive B_WATCH_DIRECTORY is implied, i.e.
|
|
|
|
// B_ENTRY_{CREATED,MOVED,REMOVED} notifications will be sent for any entry
|
|
|
|
// change below the given path, unless explicitly suppressed by
|
|
|
|
// B_WATCH_{FILES,DIRECTORIES}_ONLY.
|
|
|
|
#define B_WATCH_FILES_ONLY 0x0200
|
|
|
|
// A notification will only be sent when the node it concerns is not a
|
|
|
|
// directory. No effect in non-recursive mode.
|
2013-06-23 15:01:09 +04:00
|
|
|
#define B_WATCH_DIRECTORIES_ONLY 0x0400
|
2013-06-27 23:46:29 +04:00
|
|
|
// A notification will only be sent when the node it concerns is a
|
|
|
|
// directory. No effect in non-recursive mode.
|
2007-05-04 20:02:04 +04:00
|
|
|
|
|
|
|
#define B_PATH_MONITOR '_PMN'
|
|
|
|
|
2013-06-20 15:59:22 +04:00
|
|
|
|
2007-05-04 20:02:04 +04:00
|
|
|
namespace BPrivate {
|
|
|
|
|
2013-06-20 15:59:22 +04:00
|
|
|
|
2007-05-04 20:02:04 +04:00
|
|
|
class BPathMonitor {
|
2013-06-20 15:59:22 +04:00
|
|
|
public:
|
|
|
|
class BWatchingInterface;
|
|
|
|
|
2008-08-04 17:04:45 +04:00
|
|
|
public:
|
|
|
|
static status_t StartWatching(const char* path, uint32 flags,
|
2013-06-23 15:12:38 +04:00
|
|
|
const BMessenger& target);
|
2007-05-04 20:02:04 +04:00
|
|
|
|
2008-08-04 17:04:45 +04:00
|
|
|
static status_t StopWatching(const char* path,
|
2013-06-23 15:12:38 +04:00
|
|
|
const BMessenger& target);
|
|
|
|
static status_t StopWatching(const BMessenger& target);
|
2007-05-04 20:02:04 +04:00
|
|
|
|
2013-06-20 15:59:22 +04:00
|
|
|
static void SetWatchingInterface(
|
|
|
|
BWatchingInterface* watchingInterface);
|
|
|
|
// pass NULL to reset to default
|
|
|
|
|
2008-08-04 17:04:45 +04:00
|
|
|
private:
|
|
|
|
BPathMonitor();
|
|
|
|
~BPathMonitor();
|
2007-05-08 04:30:59 +04:00
|
|
|
|
2013-06-20 15:48:21 +04:00
|
|
|
static status_t _InitIfNeeded();
|
|
|
|
static void _Init();
|
2007-05-04 20:02:04 +04:00
|
|
|
};
|
|
|
|
|
2013-06-20 15:59:22 +04:00
|
|
|
|
|
|
|
/*! Base class just delegates to the respective C functions.
|
|
|
|
*/
|
|
|
|
class BPathMonitor::BWatchingInterface {
|
|
|
|
public:
|
|
|
|
BWatchingInterface();
|
|
|
|
virtual ~BWatchingInterface();
|
|
|
|
|
|
|
|
virtual status_t WatchNode(const node_ref* node, uint32 flags,
|
|
|
|
const BMessenger& target);
|
|
|
|
virtual status_t WatchNode(const node_ref* node, uint32 flags,
|
|
|
|
const BHandler* handler,
|
|
|
|
const BLooper* looper = NULL);
|
|
|
|
|
|
|
|
virtual status_t StopWatching(const BMessenger& target);
|
|
|
|
virtual status_t StopWatching(const BHandler* handler,
|
|
|
|
const BLooper* looper = NULL);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-05-04 20:02:04 +04:00
|
|
|
} // namespace BPrivate
|
|
|
|
|
2013-06-20 15:59:22 +04:00
|
|
|
|
2013-06-27 23:46:29 +04:00
|
|
|
using BPrivate::BPathMonitor;
|
|
|
|
|
|
|
|
|
2007-05-04 20:02:04 +04:00
|
|
|
#endif // _PATH_MONITOR_H
|