<Pclass="Body"style="margin: 0px">The AppServer class sits at the top of the hierarchy, starting and stopping services, monitoring for messages, and so forth.</P>
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:</P>
<Pclass="Body"style="margin: 0px"><BR>
1) Call port_buffer_size - which will block if the port is empty</P>
<Pclass="Body"style="margin: 0px">2) Allocate a buffer on the heap if the port buffer size is greater than 0</P>
<Pclass="Body"style="margin: 0px">3) Read the port</P>
<Pclass="Body"style="margin: 0px">4) Pass specified messages to DispatchMessage() for processing, spitting out an error message to stderr if the message's code is unrecognized</P>
<Pclass="Body"style="margin: 0px">5) Return from DispatchMessage() and free the message buffer if one was allocated</P>
<Pclass="Body"style="margin: 0px">6) 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</P>
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.</P>
<Pclass="Body"style="margin: 0px"><BR>
CREATE_APP:</P>
<Pclass="Body"style="margin: 0px"><BR>
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.</P>
<Pclass="Body"style="margin: 0px">2) Acquire the application list lock</P>
<Pclass="Body"style="margin: 0px">3) Allocate a ServerApp object and add it to the list</P>
<Pclass="Body"style="margin: 0px">4) Release application list lock</P>
<Pclass="Body"style="margin: 0px">5) Acquire active application pointer lock</P>
<Pclass="Body"style="margin: 0px">6) Update active application pointer</P>
<Pclass="Body"style="margin: 0px">7) Release active application lock</P>
<Pclass="Body"style="margin: 0px">8) Send the message SET_SERVER_PORT (with the ServerApp's receiver port attached) to the reply port</P>
<Pclass="Body"style="margin: 0px">9) Run() the new ServerApp instance</P>
<Pclass="Body"style="margin: 0px"><BR>
<BR>
DELETE_APP:</P>
<Pclass="Body"style="margin: 0px"><BR>
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.</P>
<Pclass="Body"style="text-align: left; margin: 0px">2) Acquire application list lock</P>
<Pclass="Body"style="text-align: left; margin: 0px">3) Iterate through the application list, searching for the ServerApp object with the sent thread_id</P>
<Pclass="Body"style="text-align: left; margin: 0px">4) Remove the object from the list and delete it</P>
<Pclass="Body"style="text-align: left; margin: 0px">5) Acquire active application lock</P>
<Pclass="Body"style="text-align: left; margin: 0px">6) Check to see if the application is active</P>
<Pclass="Body"style="text-align: left; margin: 0px">7) If application is/was active, set it to the previous application in the list or NULL if there are no other active applications</P>
<Pclass="Body"style="text-align: left; margin: 0px">8) Release application list lock</P>
<Pclass="Body"style="text-align: left; margin: 0px">9) Release active application lock</P>
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.</P>
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:</P>
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.</P>
<Pclass="Body"style="margin: 0px">1) Call port_buffer_size_etc() with a timeout of 3 seconds.</P>
<Pclass="Body"style="margin: 0px">2) Check to see if the port_buffer_size_etc() timed out and do a continue to next iteration if it did.</P>
<Pclass="Body"style="margin: 0px">3) Allocate a buffer on the heap if the port buffer size is greater than 0</P>
<Pclass="Body"style="margin: 0px">4) Read the port</P>
<Pclass="Body"style="margin: 0px">5) Pass specified messages to DispatchMessage() for processing, spitting out an error message to stderr if the message's code is unrecognized</P>
<Pclass="Body"style="margin: 0px">6) Return from DispatchMessage() and free the message buffer if one was allocated</P>
instantiate_decorator returns a new instance of the decorator currently in use. The caller is responsible for the memory allocated for the returned object.</P>
<Pclass="Body"style="margin: 0px"><BR>
1) Acquire the decorator lock</P>
<Pclass="Body"style="margin: 0px">2) If create_decorator is NULL, create a new instance of the default decorator</P>
<Pclass="Body"style="margin: 0px">3) If create_decorator is non-NULL, create a new decorator instance by calling AppServer::create_decorator().</P>
<Pclass="Body"style="margin: 0px">4) Release the decorator lock</P>
<Pclass="Body"style="margin: 0px">5) Return the newly allocated instance</P>
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.</P>
<Pclass="Body"style="margin: 0px"><BR>
</P>
<Pclass="Body"style="text-align: left; margin: 0px">1) Acquire application list lock</P>
<Pclass="Body"style="text-align: left; margin: 0px">2) Create a PortLink instance and set its message code to the passed parameter.</P>
<Pclass="Body"style="text-align: left; margin: 0px">3) Iterate through the application list, targeting the PortLink instance to each ServerApp's message port and calling Flush().</P>
<Pclass="Body"style="text-align: left; margin: 0px">4) Release application list lock</P>
<Pclass="Body"style="margin: 0px">Called from DispatchMessage to filter out App Server events and otherwise send keystrokes to the active application. </P>
<Pclass="Body"style="margin: 0px"><BR>
B_KEY_DOWN:</P>
<Pclass="Body"style="margin: 0px"><BR>
Sent when the user presses (or holds down) a key that's been mapped to a character.</P>
<Pclass="Body"style="margin: 0px">2) 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</P>
<Pclass="Body"style="margin: 0px">3) If the command modifier is down, check for Alt+F1 through Alt+F12 and set workspace and return if true</P>
<Pclass="Body"style="margin: 0px">4) If the control modifier is true, check for B_CONTROL_KEY+Tab and, if true, find and send to the Deskbar.</P>
<Pclass="Body"style="margin: 0px">4) Acquire the active application lock</P>
<Pclass="Body"style="margin: 0px">5) Create a PortLink instance, target the active ServerApp's sender port, set the opcode to B_KEY_DOWN, attach the buffer <spanstyle="font-style: italic">en masse</span>, and send it to the BApplication.</P>
<Pclass="Body"style="margin: 0px">6) Release the active application lock</P>
<Pclass="Body"style="margin: 0px">2) Acquire the active application lock</P>
<Pclass="Body"style="margin: 0px">3) Create a PortLink instance, target the active ServerApp's sender port, set the opcode to B_KEY_UP, attach the buffer <spanstyle="font-style: italic">en masse</span>, and send it to the BApplication.</P>
<Pclass="Body"style="margin: 0px">4) Release the active application lock</P>
<Pclass="Body"style="margin: 0px">2) Create a PortLink instance, target the active ServerApp's sender port, set the opcode to B_UNMAPPED_KEY_DOWN, attach the buffer <spanstyle="font-style: italic">en masse</span>, and send it to the BApplication.</P>
<Pclass="Body"style="margin: 0px">3) Release the active application lock</P>
<Pclass="Body"style="margin: 0px">2) Create a PortLink instance, target the active ServerApp's sender port, set the opcode to B_UNMAPPED_KEY_UP, attach the buffer <spanstyle="font-style: italic">en masse</span>, and send it to the BApplication.</P>
<Pclass="Body"style="margin: 0px">3) Release the active application lock</P>
<Pclass="Body"style="margin: 0px">2) Create a PortLink instance, target the active ServerApp's sender port, set the opcode to B_MODIFIERS_CHANGED, attach the buffer <spanstyle="font-style: italic">en masse</span>, and send it to the BApplication.</P>
<Pclass="Body"style="margin: 0px">3) Release the active application lock</P>