Documentation | KernelKit
SYNOPSIS
Perl
use HaikuR1::KernelKit;
Python
from HaikuR1.KernelKit import *
DESCRIPTION
Contains several constants.
CLASSES AND SUBMODULES
KernelKit contains no classes or submodules
FUNCTIONS
snooze
This function snoozes a thread. Calling snooze
on a thread is like calling
sleep
, with one important difference: snooze
allows the thread to switch.
Ordinarily, the system will handle thread switching by itself, with no input
from you. But if your thread is waiting on another thread, snooze
tells the
system that our thread isn't going to do anything for a while, so it can give
your time to another thread.
Perl
snooze($amount);
Python
snooze(amount)
object
The time to snooze, in microseconds.
rewrap
This utility function is not part of the Haiku R1 API; it is for convenience.
Sometimes function return objects of a certain class, but the underlying C++ object may be a subclass. For example, Looper.HandlerAt returns a Handler, Window.FindView returns a View object, but the object might actually be a Button or a StringView or a Menu.
The glue code does not know what the underlying C++ class is. And since it may be an object created by the system, the glue code cannot simply assume that a target language wrapper object already exists. So instead, the glue code creates a new wrapper object for the C++ object.
Usually, this is not a problem, since calling a hook method on the passed instance will result in the proper hook method for the underlying C++ class. However, if you want to call a non-hook method, you will either get the base class version (if it exists) or crash due to calling a non-existent function.
In C++, the solution is simple: you simply cast the object into the class you want. Unfortunately, this is not possible in most interpreted languages.
The rewrap
function allows you to get around this shortcoming. If you know
the real class of the object in question, you can can create a brand new
wrapper object for the the C++ object, and you will then be able to call the
proper versions of non-hook methods.
Perl
my $copy = rewrap($object, $new_class, $transfer);
Python
copy = rewrap(object, new_class, transfer)
object
The object to be recast.
new_class
The class to recast into.
new_class
A boolean; if true and the original object had ownership, then ownership will be transferred to the new object; defaults to true.
Perl
Unless you actually need two wrappers, it's easier to simply rebless the object into the desired class:
bless($object, $new_class);
If ownership is transferred, the old object can safely go out of scope, allowing code like this:
Perl
$object = rewrap($object, $new_class);
Python
object = rewrap(object, new_class)
CONSTANTS
System constants
Perl
use HaikuR1::KernelKit qw(:system)
Python
Python does not support export tags.
- B_OS_NAME_LENGTH
- B_PAGE_SIZE
- B_INFINITE_TIMEOUT
Team constants
Perl
use HaikuR1::KernelKit qw(:team)
Python
Python does not support export tags.
- B_CURRENT_TEAM
- B_SYSTEM_TEAM
Thread priority constants
Perl
use HaikuR1::KernelKit qw(:thread_priority)
Python
Python does not support export tags.
- B_IDLE_PRIORITY
- B_LOWEST_ACTIVE_PRIORITY
- B_LOW_PRIORITY
- B_NORMAL_PRIORITY
- B_DISPLAY_PRIORITY
- B_URGENT_DISPLAY_PRIORITY
- B_REAL_TIME_DISPLAY_PRIORITY
- B_URGENT_PRIORITY
- B_REAL_TIME_PRIORITY
- B_FIRST_REAL_TIME_PRIORITY
Timeout constants
Perl
use HaikuR1::KernelKit qw(:timeout)
Python
Python does not support export tags.
- B_TIMEOUT
- B_RELATIVE_TIMEOUT
- B_ABSOLUTE_TIMEOUT
- B_TIMEOUT_REAL_TIME_BASE
- B_ABSOLUTE_REAL_TIME_TIMEOUT
- B_SYSTEM_TIMEBASE