Documentation | StorageKit | The Node Monitor
SYNOPSIS
Perl
use HaikuR1::NodeMonitor qw(watch_node B_WATCH_NAME); watch_node($node, B_WATCH_NAME, $target);
Python
from HaikuR1.StorageKit import watch_node, B_WATCH_NAME watch_node(node, B_WATCH_NAME, $target);
DESCRIPTION
Exposes the node monitor function.
For more information on the node monitor, see the Be Book class description and the Haiku Book class description.
FUNCTIONS
Watching
watch_volume
watch_node
stop_watching
watch_node
will watch a specific node for certain changes, or for volume
mounting and unmounting.
watch_volume
will watch all nodes on a volume for certain changes.
stop_watching
will stop sending notifications to the given target.
The notification will come in the form of a Message with a what
value
of B_NODE_MONITOR
and a field called opcode
, which will be one of the
opcode constants.
To watch for mounting and unmounting: Use watch_node
with an empty value
in place of the node. watch_volume
is used to watch all nodes on a volume,
not to watch volumes.
(Actually, the node does not have to be empty; you could combine node flags with B_WATCH_MOUNT, and you will get notifications for both the given node and for volume mounting.)
To stop watching a node: Use B_STOP_WATCHING with watch_node
.
stop_watching
stops all notifications to a given target.
Perl
HaikuR1::NodeMonitor::watch_node($node, $flags, $target); HaikuR1::NodeMonitor::watch_volume($volume, $flags, $target, $looper); HaikuR1::NodeMonitor::stop_watching($target);
Python
NodeMonitor.watch_node(node, flags, target) NodeMonitor.watch_volume(volume, flags, target, looper) NodeMonitor.stop_watching(target)
volume
An integer device id. You can get one from Volume.Device).
node
A native map representing the node. You can get one from Statable.GetNodeRef. (Remember that Node inherits from Statable.) Pass the empty value to watch for volume mounting and unmounting.
flags
An integer, one or more of the node monitor flags.
target
A Messenger or Handler, the target that will receive the notifications.
looper
A Looper; only used when
target
is a Handler. (Iflooper
is used,handler
must belong tolooper
.)
CONSTANTS
Cause
When the B_ATTR_CHANGED
notification is sent, the message will have a
cause
field, which can either be B_ATTR_CHANGED
itself, or one of the
following:
Perl
use HaikuR1::NodeMonitor qw(:cause)
Python
Python does not support export tags.
- B_ATTR_CREATED
- B_ATTR_REMOVED
Fields
When the B_STAT_CHANGED
notification is sent, the message will have a
fields
field, which will be an integer combining the following values,
representing which part of the stat actually changed.
Perl
use HaikuR1::NodeMonitor qw(:fields)
Python
Python does not support export tags.
- B_STAT_MODE
- B_STAT_UID
- B_STAT_GID
- B_STAT_SIZE
- B_STAT_ACCESS_TIME
- B_STAT_MODIFICATION_TIME
- B_STAT_CREATION_TIME
- B_STAT_CHANGE_TIME
- B_STAT_INTERIM_UPDATE
Flags
These are the values you pass to watch_node or watch_volume.
Perl
use HaikuR1::NodeMonitor qw(:flags)
Python
Python does not support export tags.
B_STOP_WATCHING
Use this to stop sending notifications for a given node (or for all nodes all on a given volume).
B_WATCH_NAME
Watches for name changes
B_WATCH_STAT
Watches for changes in stat values (size, modification date, owner, etc.)
B_WATCH_ATTR
Watches for changes in attributes
B_WATCH_DIRECTORY
Watches for new entries, deleted entries, renamed entries, etc., in the given directory. (It will cause an error when used on non-directories, but it will have no effect.)
B_WATCH_ALL
Combines B_WATCH_NAME, B_WATCH_STAT, B_WATCH_ATTR, and B_WATCH_DIRECTORY
B_WATCH_MOUNT
Watches for volumes being mounted and unmounted.
B_WATCH_INTERIM_STAT
If an open file is being written to frequently, the system will send
B_WATCH_STAT
less frequently. If you really want to catch every write, you can use this instead.B_WATCH_CHILDREN
There is no documentation on this flag; presumably it is meant to be combined with other flags and used on a directory in order to watch its children as well.
Opcodes
These are sent in the opcode
field of the notification message and indicate
the type of notification.
Perl
use HaikuR1::NodeMonitor qw(:opcodes)
Python
Python does not support export tags.
- B_ENTRY_CREATED
- B_ENTRY_REMOVED
- B_ENTRY_MOVED
- B_STAT_CHANGED
- B_ATTR_CHANGED
- B_DEVICE_MOUNTED
- B_DEVICE_UNMOUNTED