Haiku API Bindings
Handler
Not logged in

Documentation | ApplicationKit | Handler

SYNOPSIS

Perl

use HaikuR1::Handler qw(B_OBSERVE_WHAT_CHANGE B_OBSERVE_ORIGINAL_WHAT B_OBSERVER_OBSERVE_ALL);

# define MyHandler subclass here

my $handler = MyHandler->new($name);
$looper->AddHandler($handler);
$looper->PostMessage($message, $handler);

Python

from HaikuR1.ApplicationKit import Handler, B_OBSERVE_WHAT_CHANGE B_OBSERVE_ORIGINAL_WHAT B_OBSERVER_OBSERVE_ALL

# define MyHandler subclass here

handler = MyHandler(name)
looper.AddHandler(handler)
looper.PostMessage(message, handler)

DESCRIPTION

Exposes the BHandler object.

For more information on Handler, see the Be Book class description, the Be Book overview, and the Haiku Book class description.

METHODS

Constructor

Creates a Handler.

Perl

my $handler = HaikuR1::Handler->new($initial);

Python

handler = Handler(initial)

Filters

AddFilter

RemoveFilter

SetFilterList

FilterList

These methods maintain the Handler's filters.

A MessageFilter may only belong to one object at a time. You cannot add a MessageFilter to an object it already belongs to. (Although you can remove it and then re-add it later.)

The Handler's Looper must be locked before changing the filter list. (Although you can call FilterList without locking the Looper.)

AddFilter, RemoveFilter, and SetFilterList can also be called as hooks.

Perl

$handler->AddFilter($filter);
$handler->RemoveFilter($filter);
$handler->SetFilterList($filters);
$handler->FilterList();

Python

handler.AddFilter(filter)
handler.RemoveFilter(filter)
handler.SetFilterList(filters)
handler.FilterList()

Locking

LockLooper

LockLooperWithTimeout

UnlockLooper

These methods do what you expect. LockLooperWithTimeout signals an error if it fails to obtain a lock.

Perl

$handler->LockLooper();
$handler->LockLooperWithTimeout($timeout);
$handler->UnlockLooper();

Python

handler.LockLooper()
handler.LockLooperWithTimeout(timeout)
handler.UnlockLooper()

Looper

Returns the Looper that the Handler belongs to.

Perl

$handler->Looper();

Python

handler.Looper()

Name

SetName

Gets or sets the Handler's name.

Perl

$handler->Name();
$handler->SetName($name);

Python

handler.Name()
handler.SetName(name)

NextHandler

SetNextHandler

Gets or sets the next handler in the handler chain.

SetNextHandler can also be called as a hook.

Perl

$handler->NextHandler();
$handler->SetNextHandler($handler);

Python

handler.NextHandler()
handler.SetNextHandler(handler)

Notifications

StartWatching

StartWatchingAll

StopWatching

StopWatchingAll

SendNotices

IsWatched

SendNotices sends a state change notification to any Handlers that are watching this Handler. (A state change notification is a Message with a what value of B_OBSERVER_NOTICE_CHANGE.)

SendNotices can also be called as a hook.

The other methods do what you expect; they also signal an error on failure.

Take note of the meaning of target, below.

Perl

$handler->StartWatching($target, $what);
$handler->StartWatchingAll($target);
$handler->StopWatching($target, $what);
$handler->StopWatchingAll($target);
$handler->IsWatched();

$handler->SendNotices($what, $notice);

Python

handler.StartWatching(target, what)
handler.StartWatchingAll(target)
handler.StopWatching(target, what)
handler.StopWatchingAll(target)
handler.IsWatched()

handler.SendNotices(what, notice)

In other words:

Perl

$watcher->StartWatching(HaikuR1::Messenger->new($watched), $what);

# but

$watched->StartWatching($watcher, $what);

Python

watcher.StartWatching(Messenger(watched), what)

# but

watched.StartWatching(watcher, what)

Signals an error on failure.

HOOKS

GetSupportedSuites

This hook is generally called in response a request for the scripting property Suites, described below. You should add your suite and then pass it to the base class's version so it can add its own suite.

You should signal an error if you are unable to add your suite to the Message.

Perl

$looper->GetSupportedSuites($data);

Python

looper.GetSupportedSuites(data)

MessageReceived

Called when the Handler receives a message. Determine whether to handle the message by looking at its what property. Pass unhandled messages to the base class version.

Perl

$looper->MessageReceived($message);

Python

looper.MessageReceived(message)

ResolveSpecifier

Returns the Handler that will handle the given scripting message. If you cannot resolve the specifier, pass it to the base class version.

Perl

$looper->ResolveSpecifier(
    message => $message,
    index => $index,
    specifier => $specifier,
    what => $what,
    property => $property,
);

Python

looper.ResolveSpecifier(
    message = message,
    index = index,
    specifier = specifier,
    what = what,
    property = property,
)

ARCHIVABLE INTERFACE

Handler inherits the methods and hooks of Archivable.

CONSTANTS

The name of an int32 stored in the B_OBSERVER_NOTICE_CHANGE message; it contains the what value passed to SendNotices.

The name of an int32 stored in the B_OBSERVER_NOTICE_CHANGE message; it contains the original what value if a Message was passed to SendNotices.

If you use this value as the what for StartWatching or StopWatching, it has the same effect as calling StartWatchingAll or StopWatchingAll.

SCRIPTING SUITE

The name of Handler's scripting suite is suite/vnd.Be-handler.