ServerApp class¶
ServerApps are the server-side counterpart to BApplications. They monitor for messages for the BApplication, create BWindows and BBitmaps, and provide a channel for the app_server to send messages to a user application without having a window.
Member Functions¶
ServerApp(port_id sendport, port_id rcvport, const char*signature, thread_id thread_bapp)
~ServerApp(void)
bool Run(void)
static int32 MonitorApp(void *data)
void Lock(void)
void Unlock(void)
bool IsLocked(void)
void WindowBroadcast(int32 code)
bool IsActive(void)
bool PingTarget(void)
void DispatchMessage(int32 code, int8 *buffer)
ServerApp(port_id sendport, port_id rcvport, const char *sig, thread_id thread_bapp)¶
Create the window list as empty
Save sendport, rcvport, sig, and thread_bapp to the respective ServerApp members
Set quit_app flag to false
Create the window list lock
~ServerApp(void)¶
Empty and delete window list and accompanying windows
Wait for the monitoring thread to exit
Call CursorManager::RemoveAppCursors(this)
Delete the window list lock
If monitoring thread still active, kill it (in case app is deleted without a quit message)
bool Run(void)¶
Run() simply makes a ServerApp start monitoring for messages from its BApplication, telling it to quit if there is a problem.
Spawn the monitoring thread (which utilizes MonitorApp()) 2) If any error, tell the BApplication to quit, spit an error to stderr, and return false
Resume the monitoring thread
Return true
static int32 MonitorApp(void *data)¶
Thread function for monitoring for messages from the ServerApp’s BApplication.
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_app flag is true, fall out of the infinite message-monitoring loop. Otherwise continue to next iteration
Send a DELETE_APP message to the server’s main message to force deleting of the ServerApp instance and exit
bool IsActive(void)¶
Used for determining whether the application is the active one. Simply returns the isactive flag.
void PingTarget(void)¶
PingTarget() is called only from the Picasso thread of the app_server in order to determine whether its respective BApplication still exists. BApplications have been known to crash from time to time without the common courtesy of notifying the server of its intentions. ;D
Call get_thread_info() with the app’s thread_id
if it returns anything but B_OK, return false. Otherwise, return true.
void DispatchMessage(int32 code, int8 *buffer)¶
DispatchMessage implements all the code necessary to respond to a given message sent to the ServerApp on its receiving message port. This allows for clearer and more manageable code.
CREATE_WINDOW¶
Sent by a new BWindow object via synchronous PortLink messaging. Set up the corresponding ServerWindow and reply to the BWindow 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 |
BRect wframe |
frame of the requesting BWindow |
uint32 wflags |
flag data of the requesting BWindow |
port_id win_port |
receiver port of the requesting BWindow |
uint32 workspaces |
workspaces on which the BWindow is to appear |
const char *title |
title of the requesting BWindow |
Get all attached data
Acquire the window list lock
Allocate a ServerWindow object and add it to the list
Release window list lock
Send the message SET_SERVER_PORT (with the ServerWindow’s receiver port attached to the reply port
DELETE_APP¶
Sent by a ServerWindow when told to quit. It is identified by the unique ID assigned to its thread.
Attached Data:
thread_id win_thread |
Thread id of the ServerWindow sending this message |
Get window’s thread_id
Acquire window list lock
Iterate through the window list, searching for the ServerWindow object with the sent thread_id
Remove the object from the list and delete it
Release window list lock
SET_CURSOR_DATA¶
Received from the ServerApp’s BApplication when SetCursor(const void*) is called.
Attached Data:
int8 cursor[68] |
Cursor data in the format as defined in the BeBook |
Create a ServerCursor from the attached cursor data
Add the new ServerCursor to the CursorManager and then call CursorManager::SetCursor
SET_CURSOR_BCURSOR¶
Received from the ServerApp’s BApplication when SetCursor(BCursor *, bool) is called.
Attached Data:
int32 token |
Token identifier of cursor in the BCursor class |
Get the attached token and call CursorManager::SetCursor(token)
B_QUIT_REQUESTED¶
Received from the BApplication when quits, so set the quit flag and ask the server to delete the object
Attached Data: None
Set quit_app flag to true
UPDATE_DECORATOR¶
Received from the poller thread when the window decorator for the system has changed.
Attached Data: None
Call WindowBroadcast(UPDATE_DECORATOR)
void WindowBroadcast(int32 code)¶
Similar to AppServer::Broadcast(), this sends a message to all ServerWindows which belong to the ServerApp.
Acquire window list lock
Create a PortLink instance and set its message code to the passed parameter.
Iterate through the window list, targeting the PortLink instance to each ServerWindow’s message port and calling Flush().
Release window list lock
void Lock(void), void Unlock(void), bool IsLocked(void)¶
These functions are used to regulate access to the ServerApp’s data members. Lock() acquires the internal semaphore, Unlock() releases it, and IsLocked returns true only if the semaphore’s value is positive.