AppServer class¶
The AppServer class sits at the top of the hierarchy, starting and stopping services, monitoring for messages, and so forth.
Member Functions¶
AppServer(void)
~AppServer(void)
static int32 Poller(void *data)
static int32 Picasso(void *data)
thread_id Run(void)
void MainLoop(void)
bool LoadDecorator(const char*path)
void DispatchMessage(int32 code,int8 *buffer)
void Broadcast(int32 code)
void HandleKeyMessage(int32 code, int8 *buffer)
Global Functions¶
Decorator * instantiate_decorator(Layer *owner, uint32 wflags, uint32 wlook)
AppServer(void)¶
Create the message and input ports
Create any necessary semaphores for regulating the 3 main threads
Initialize all member variables
Allocate the application BList
Read in and process all configuration data
Initialize the desktop
Spawn the Picasso and Poller threads
~AppServer(void)¶
Shut down the desktop
Empty and delete the application list
Wait for Picasso and Poller to exit
Free any allocated heap space
void MainLoop(void)¶
MainLoop is one large loop used to monitor the main message port in the app_server thread. This is a standard port-monitoring loop code:
Call port_buffer_size - which will block if the port is empty
Allocate a buffer on the heap if the port buffer size is greater than 0
Read the port
Pass specified messages to DispatchMessage() for processing, spitting out an error message to stderr if the message’s code is unrecognized
Return from DispatchMessage() and free the message buffer if one was allocated
If the message code matches the B_QUIT_REQUESTED definition and the quit_server flag is true, fall out of the infinite message-monitoring loop
void DispatchMessage(int32 code, int8 *buffer)¶
DispatchMessage implements all the code necessary to respond to a given message sent to the app_server on its main port. This allows for clearer and more manageable code.
CREATE_APP¶
Sent by a new BApplication object via synchronous PortLink messaging. Set up the corresponding ServerApp and reply to the BApplication with the new port to which it will send future communications with the App Server.
Attached Data:
port_id reply_port |
port to which the server is to reply in response to the current message |
port_id app_port |
message port for the requesting BApplication |
int16 sig_length |
length of the following application signature |
const char *signature |
Signature of the requesting BApplication |
Get all attached data
Acquire the application list lock
Allocate a ServerApp object and add it to the list
Release application list lock
Acquire active application pointer lock
Update active application pointer
Release active application lock
Send the message SET_SERVER_PORT (with the ServerApp’s receiver port attached) to the reply port
Run() the new ServerApp instance
DELETE_APP¶
Sent by a ServerApp when told to quit either by its BApplication or the Server itself (during shutdown). It is identified by the unique ID assigned to its thread.
Attached Data:
thread_id app_thread |
Thread id of the ServerApp sending this message |
Get app’s thread_id
Acquire application list lock
Iterate through the application list, searching for the ServerApp object with the sent thread_id
Remove the object from the list and delete it
Acquire active application lock
Check to see if the application is active
If application is/was active, set it to the previous application in the list or NULL if there are no other active applications
Release application list lock
Release active application lock
GET_SCREEN_MODE¶
Received from the OpenBeOS Input Server when requesting the current screen settings via synchronous PortLink messaging. This is a temporary solution which will be deprecated as soon as the BScreen class is complete.
Attached Data:
port_id reply_port |
port to which the server is to reply in response to the current message |
Get height, width, and color depth from the global graphics driver object
Attach via PortLink and reply to sender
B_QUIT_REQUESTED¶
Encountered only under testing situations where the Server is told to quit.
Attached Data: None
Set quit_server flag to true
Call Broadcast(QUIT_APP)
SET_DECORATOR¶
Received from just about anything when a new window decorator is chosen
Attached Data:
const char *path |
Path to the proposed new decorator |
Get the path from the buffer
Call LoadDecorator()
void Run(void)¶
Run() exists mostly for consistency with other regular applications.
Call MainLoop()
bool LoadDecorator(const char *path)¶
Allows for a simple way to change the current window decorator systemwide simply by specifying the path to the desired Decorator addon.
Load the passed string as the path to an addon.
Load all necessary symbols for the decorator
Return false if things didn’t go so well
Call Broadcast(UPDATE_DECORATOR)
Return true
static int32 Picasso(void *data)¶
Picasso is a function, despite its name, dedicated to ensuring that the server deallocates resources to a dead application. It consists of a while(!quit_server) loop as follows:
Acquire the appliction list lock
Iterate through the list, calling each ServerApp object’s PingTarget() method.
If PingTarget returns false, remove the ServerApp from the list and delete it.
Release the appliction list lock
snooze for 3 seconds
static int32 Poller(void *data)¶
Poller is the main workhorse of the AppServer class, polling the Server’s input port constantly for any messages from the Input Server and calling the appropriate handlers. Like Picasso, it, too, is mostly a while(!quit_server) loop.
Call port_buffer_size_etc() with a timeout of 3 seconds.
Check to see if the port_buffer_size_etc() timed out and do a continue to next iteration if it did.
Allocate a buffer on the heap if the port buffer size is greater than 0
Read the port
Pass specified messages to DispatchMessage() for processing, spitting out an error message to stderr if the message’s code is unrecognized
Return from DispatchMessage() and free the message buffer if one was allocated
Decorator * instantiate_decorator(Layer *owner, uint32 wflags, uint32 wlook)¶
instantiate_decorator returns a new instance of the decorator currently in use. The caller is responsible for the memory allocated for the returned object.
Acquire the decorator lock
If create_decorator is NULL, create a new instance of the default decorator
If create_decorator is non-NULL, create a new decorator instance by calling AppServer::create_decorator().
Release the decorator lock
Return the newly allocated instance
void Broadcast(int32 code)¶
Broadcast() provides the AppServer class with an easy way to send a quick message to all ServerApps. Primarily, this is called when a font or decorator has changed, or when the server is shutting down. It is not intended to do anything except send a quick message which requires no extra data, such as for some upadate signalling.
Acquire application list lock
Create a PortLink instance and set its message code to the passed parameter.
Iterate through the application list, targeting the PortLink instance to each ServerApp’s message port and calling Flush().
Release application list lock
void HandleKeyMessage(int32 code, int8 *buffer)¶
Called from DispatchMessage to filter out App Server events and otherwise send keystrokes to the active application.
B_KEY_DOWN¶
Sent when the user presses (or holds down) a key that’s been mapped to a character.
Attached Data:
int64 when |
event time in seconds since 1/1/70 |
int32 rawcode |
code for the physical key pressed |
int32 repeat_count |
number of times a key has been repeated |
int32 modifiers |
flags signifying the states of the modifier keys |
int32 state_count |
number of bytes to follow containing the state of all keys |
int8 *states |
array of the state of all keys at the time of the event |
int8 utf8data[3] |
UTF-8 data generated |
int8 charcount |
number of bytes to follow containing the string generated (usually 1) |
const char *string |
null-terminated string generated by the keystroke |
int32 raw_char |
modifier-independent ASCII code for the character |
Get all attached data
If the command modifier is down, check for Left Ctrl+Left Alt+Left Shift+F12 and reset the workspace to 640 x 480 x 256 @ 60Hz and return if true
If the command modifier is down, check for Alt+F1 through Alt+F12 and set workspace and return if true
If the control modifier is true, check for B_CONTROL_KEY+Tab and, if true, find and send to the Deskbar.
Acquire the active application lock
Create a PortLink instance, target the active ServerApp’s sender port, set the opcode to B_KEY_DOWN, attach the buffer en masse, and send it to the BApplication.
Release the active application lock
B_KEY_UP¶
Sent when the user releases a key that’s been mapped to a character.
Attached Data:
int64 when |
event time in seconds since 1/1/70 |
int32 rawcode |
code for the physical key pressed |
int32 modifiers |
flags signifying the states of the modifier keys |
int32 state_count |
number of bytes to follow containing the state of all keys |
int8 *states |
array of the state of all keys at the time of the event |
int8 utf8data[3] |
UTF-8 data generated |
int8 charcount |
number of bytes to follow containing the string generated (usually 1) |
const char *string |
null-terminated string generated by the keystroke |
int32 raw_char |
modifier-independent ASCII code for the character |
Get all attached data
Acquire the active application lock
Create a PortLink instance, target the active ServerApp’s sender port, set the opcode to B_KEY_UP, attach the buffer en masse, and send it to the BApplication.
Release the active application lock
B_UNMAPPED_KEY_DOWN¶
Sent when the user presses a key that has not been mapped to a character.
Attached Data:
int64 when |
event time in seconds since 1/1/70 |
int32 rawcode |
code for the physical key pressed |
int32 modifiers |
flags signifying the states of the modifier keys |
int8 state_count |
number of bytes to follow containing the state of all keys |
int8 *states |
array of the state of all keys at the time of the event |
Acquire the active application lock
Create a PortLink instance, target the active ServerApp’s sender port, set the opcode to B_UNMAPPED_KEY_DOWN, attach the buffer en masse, and send it to the BApplication.
Release the active application lock
B_UNMAPPED_KEY_UP¶
Sent when the user presses a key that has not been mapped to a character.
Attached Data:
int64 when |
event time in seconds since 1/1/70 |
int32 rawcode |
code for the physical key pressed |
int32 modifiers |
flags signifying the states of the modifier keys |
int8 state_count |
number of bytes to follow containing the state of all keys |
int8 *states |
array of the state of all keys at the time of the event |
Acquire the active application lock
Create a PortLink instance, target the active ServerApp’s sender port, set the opcode to B_UNMAPPED_KEY_UP, attach the buffer en masse, and send it to the BApplication.
Release the active application lock
B_MODIFIERS_CHANGED¶
Sent when the user presses or releases one of the modifier keys
Attached Data:
int64 when |
event time in seconds since 1/1/70 |
int32 modifiers |
flags signifying the states of the modifier keys |
int32 old_modifiers |
former states of the modifier keys |
int8 state_count |
number of bytes to follow containing the state of all keys |
int8 *states |
array of the state of all keys at the time of the event |
Acquire the active application lock
Create a PortLink instance, target the active ServerApp’s sender port, set the opcode to B_MODIFIERS_CHANGED, attach the buffer en masse, and send it to the BApplication.
Release the active application lock