The Node Monitor is a service that lets you ask to be notified of certain file system changes
The Node Monitor is a service that lets you ask to be notified of certain file system changes. You can ask to be told when a change is made to...The hook functions in this class are by default implemented to do nothing. The lone exception is NodeMonitor::EntryDeleted, which is implemented to simply turn off monitoring for the node since it is now deleted from the file system.
- The contents of a specific directory.
- The name of a specific entry.
- Any stat field of a specific entry.
- Any attribute of a specific entry.
Hook functions must not block. Learn to use inter-thread communication and semaphores. It's easy.
Remember that BStatable is the ancestor to both BNode and BEntry (which is, in turn, the ancestor of BFile, BDirectory, and BSymLink. If you have an entry_ref, reassure yourself that it is not abstract (BEntry::Exists), and then you can turn it into a BStatable derivative. If you are working from a BNode only, ensure that it's properly initialized by calling InitCheck() before building a NodeMonitor on it.
Keep in mind that the reference may or may not be abstract. That's up to you
to find out. Refer to the Storage Kit documentation for the definition of abstract.
In various node monitor hook functions, a parameter is passed in that is a
node_ref to a directory. For subtle reasons in the storage kit, you are allowed
to turn a directory node_ref into its corresponding entry.
Note that the directory object may not be valid if the directory that
contains the node_ref has not been locked. You should test
it (with BDirectory::InitCheck) to make sure.
However, you can guarnatee that the node remains valid by keeping BFile objects
around that point to the nodes you are interested in. Refer to the Storage Kit's documentation on the node
monitor system for an example. Note that this will keep the node valid, but
any entries that to the node are rendered abstract (if the node was a file)
or invalid (if the node was a directory).
Note: It is a valid operation to
Recall that few parts of stat can change:
virtual ~NodeMonitor()
File system utility functions
static entry_ref GetEntryRef(node_ref &from_directory, const char *name)
static BEntry GetEntry(node_ref &from_directory, const char *name)
To test for these conditions, you may wish to try the following code:
BDirectory directory;
BEntry entry;
directory = NodeMonitorHelpers::GetDirectory(dir_node_ref);
if (directory.InitCheck() == B_NO_ERROR) {
directory.Lock();
BEntry entry = NodeMonitorHelpers::GetEntry(dir_node_ref, name)));
if (entry.Exists()) {
}
directory.Unlock();
}
name - The name of the file inside the directory.
static BDirectory GetDirectory(node_ref &directory_ref)
status_t InitCheck()
virtual void EntryDeleted(node_ref &fromDirectory)
delete this
from this hook
function, once you've dealt with the disappearance of this node. This is the
default behaviour unless you override the destructor.
virtual void EntryMoved(node_ref &from_directory, node_ref &to_directory, const char *newName)
virtual void StatChanged()
virtual void AttributeChanged(const char *which)
node_ref mTargetEntry
const BStatable* mWatched
alphabetic index hierarchy of classes
this page has been generated automatically by doc++
(c)opyright by Malte Zöckler, Roland Wunderling
contact: doc++@zib.de