haiku/headers/private/storage/PathMonitor.h

43 lines
1012 B
C
Raw Normal View History

/*
* Copyright 2007-2008, Haiku Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _PATH_MONITOR_H
#define _PATH_MONITOR_H
#include <NodeMonitor.h>
// additional flags (combined with those in NodeMonitor.h)
* TRACE macro no longer needs double parenthesis. * The global BPathMonitor looper is now always used, no more optional looper and no more BApplication looper usage. This way we know how the looper behaves and PathHandler::Quit() can be synchronous. In the end, the bug I was observing was not caused by the previous asynchronous node monitor stopping, but this should be safer anyways. When BPathMonitor::StopWatching() returns, you have really stopped watching and not some time later. * Introduced "FileEntry" which is an entry_ref plus node id. This is now used instead of the node_ref for the "watched files set". The whole point is to really be able to add the "path" field to the B_PATH_MONITOR message. Previously, the initial path that was passed to StartWatching() was added, regardless if the message was for an entry somewhere down the hierarchy when watching recursively. The downside of the new method is that it uses a lot more RAM per entry. Another option would be to store the node id of the parent directory and iterate the directory always when in need to construct the path. * Watching a folder recursively now really adds all the existing subfolders as well as all the files if not watching for folders only. The tests for the old implementation only tested what happens when the watched folder was newly created and then subfolders were created. Those where already added by the code. Now it also adds the subfolders of folder that appear in a watched folder. TODO: Remove folders and files recursively when they dissappear. More testing for B_ENTRY_MOVED. Optimizations are possible when some information is retrieved twice. I am also planning to add a way for the BPathMonitor user to filter the automatically watched files/folders in B_WATCH_RECURSIVELY mode. I grepped the entire Haiku tree for usage of BPathMonitor. Only net_server and Mail were using it, but both in a way that is not affected by these changes. Anyways, TextSearch works more reliable now, even for entries in subfolders. Feedback very welcome! :-) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26936 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-08-12 00:02:59 +04:00
#define B_WATCH_FILES_ONLY 0x0100
#define B_WATCH_RECURSIVELY 0x0200
#define B_WATCH_FOLDERS_ONLY 0x0400
// NOTE: B_WATCH_RECURSIVELY usually implies to watch for file changes as well,
// if that is not desired, add B_WATCH_FOLDERS_ONLY to the flags.
#define B_PATH_MONITOR '_PMN'
namespace BPrivate {
class BPathMonitor {
public:
static status_t StartWatching(const char* path, uint32 flags,
* TRACE macro no longer needs double parenthesis. * The global BPathMonitor looper is now always used, no more optional looper and no more BApplication looper usage. This way we know how the looper behaves and PathHandler::Quit() can be synchronous. In the end, the bug I was observing was not caused by the previous asynchronous node monitor stopping, but this should be safer anyways. When BPathMonitor::StopWatching() returns, you have really stopped watching and not some time later. * Introduced "FileEntry" which is an entry_ref plus node id. This is now used instead of the node_ref for the "watched files set". The whole point is to really be able to add the "path" field to the B_PATH_MONITOR message. Previously, the initial path that was passed to StartWatching() was added, regardless if the message was for an entry somewhere down the hierarchy when watching recursively. The downside of the new method is that it uses a lot more RAM per entry. Another option would be to store the node id of the parent directory and iterate the directory always when in need to construct the path. * Watching a folder recursively now really adds all the existing subfolders as well as all the files if not watching for folders only. The tests for the old implementation only tested what happens when the watched folder was newly created and then subfolders were created. Those where already added by the code. Now it also adds the subfolders of folder that appear in a watched folder. TODO: Remove folders and files recursively when they dissappear. More testing for B_ENTRY_MOVED. Optimizations are possible when some information is retrieved twice. I am also planning to add a way for the BPathMonitor user to filter the automatically watched files/folders in B_WATCH_RECURSIVELY mode. I grepped the entire Haiku tree for usage of BPathMonitor. Only net_server and Mail were using it, but both in a way that is not affected by these changes. Anyways, TextSearch works more reliable now, even for entries in subfolders. Feedback very welcome! :-) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26936 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-08-12 00:02:59 +04:00
BMessenger target);
static status_t StopWatching(const char* path,
BMessenger target);
static status_t StopWatching(BMessenger target);
private:
BPathMonitor();
~BPathMonitor();
static status_t _InitLockerIfNeeded();
static status_t _InitLooperIfNeeded();
};
} // namespace BPrivate
#endif // _PATH_MONITOR_H