2003-01-20 23:38:49 +03:00
|
|
|
//------------------------------------------------------------------------------
|
2004-09-21 02:50:02 +04:00
|
|
|
// Copyright (c) 2001-2002, Haiku, Inc.
|
2003-01-20 23:38:49 +03:00
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
// copy of this software and associated documentation files (the "Software"),
|
|
|
|
// to deal in the Software without restriction, including without limitation
|
|
|
|
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
// and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
// Software is furnished to do so, subject to the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
// DEALINGS IN THE SOFTWARE.
|
|
|
|
//
|
|
|
|
// File Name: AppServer.cpp
|
|
|
|
// Author: DarkWyrm <bpmagic@columbus.rr.com>
|
|
|
|
// Description: main manager object for the app_server
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------------------
|
2004-01-27 03:38:14 +03:00
|
|
|
#include <Accelerant.h>
|
2005-05-15 04:22:55 +04:00
|
|
|
#include <AppDefs.h>
|
|
|
|
#include <Directory.h>
|
2003-03-30 04:17:50 +04:00
|
|
|
#include <Entry.h>
|
2005-05-15 04:22:55 +04:00
|
|
|
#include <File.h>
|
|
|
|
#include <Message.h>
|
2003-10-09 03:18:30 +04:00
|
|
|
#include <Path.h>
|
2003-07-12 02:30:55 +04:00
|
|
|
#include <PortLink.h>
|
2005-05-15 04:22:55 +04:00
|
|
|
#include <StopWatch.h>
|
2003-08-31 21:38:34 +04:00
|
|
|
|
2005-05-15 04:22:55 +04:00
|
|
|
#include "BitmapManager.h"
|
2003-03-31 01:09:39 +04:00
|
|
|
#include "ColorSet.h"
|
2005-05-15 04:22:55 +04:00
|
|
|
#include "CursorManager.h"
|
|
|
|
#include "DefaultDecorator.h"
|
|
|
|
#include "Desktop.h"
|
2003-01-27 22:43:15 +03:00
|
|
|
#include "DisplayDriver.h"
|
2005-05-15 04:22:55 +04:00
|
|
|
#include "FontServer.h"
|
|
|
|
#include "RegistrarDefs.h"
|
|
|
|
#include "RGBColor.h"
|
|
|
|
#include "RootLayer.h"
|
2003-01-27 22:43:15 +03:00
|
|
|
#include "ServerApp.h"
|
2003-02-20 23:14:57 +03:00
|
|
|
#include "ServerCursor.h"
|
2003-01-27 22:43:15 +03:00
|
|
|
#include "ServerProtocol.h"
|
2003-02-07 15:53:57 +03:00
|
|
|
#include "ServerWindow.h"
|
2003-03-30 04:17:50 +04:00
|
|
|
#include "Utils.h"
|
2005-05-15 04:22:55 +04:00
|
|
|
|
|
|
|
#include "AppServer.h"
|
|
|
|
|
2003-03-30 04:17:50 +04:00
|
|
|
//#define DEBUG_KEYHANDLING
|
2004-09-05 04:52:45 +04:00
|
|
|
//#define DEBUG_SERVER
|
2004-07-30 19:16:59 +04:00
|
|
|
|
2003-09-09 01:08:27 +04:00
|
|
|
#ifdef DEBUG_KEYHANDLING
|
|
|
|
# include <stdio.h>
|
2004-07-30 19:16:59 +04:00
|
|
|
# define KBTRACE(x) printf x
|
|
|
|
#else
|
|
|
|
# define KBTRACE(x) ;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DEBUG_SERVER
|
|
|
|
# include <stdio.h>
|
2003-09-09 01:08:27 +04:00
|
|
|
# define STRACE(x) printf x
|
|
|
|
#else
|
|
|
|
# define STRACE(x) ;
|
|
|
|
#endif
|
2004-01-20 01:18:37 +03:00
|
|
|
|
2003-02-15 18:28:22 +03:00
|
|
|
// Globals
|
|
|
|
|
2004-01-20 01:18:37 +03:00
|
|
|
Desktop *desktop;
|
2004-01-13 03:56:36 +03:00
|
|
|
|
2003-02-15 18:28:22 +03:00
|
|
|
//! Used to access the app_server from new_decorator
|
2003-02-14 14:04:01 +03:00
|
|
|
AppServer *app_server=NULL;
|
2003-01-20 23:38:49 +03:00
|
|
|
|
2003-02-15 18:28:22 +03:00
|
|
|
//! Default background color for workspaces
|
|
|
|
RGBColor workspace_default_color(51,102,160);
|
2003-02-24 00:40:44 +03:00
|
|
|
|
2003-03-31 01:09:39 +04:00
|
|
|
//! System-wide GUI color object
|
|
|
|
ColorSet gui_colorset;
|
|
|
|
|
2003-01-27 22:43:15 +03:00
|
|
|
/*!
|
|
|
|
\brief Constructor
|
|
|
|
|
|
|
|
This loads the default fonts, allocates all the major global variables, spawns the main housekeeping
|
|
|
|
threads, loads user preferences for the UI and decorator, and allocates various locks.
|
|
|
|
*/
|
2005-03-29 23:49:55 +04:00
|
|
|
#if TEST_MODE
|
2005-04-20 00:44:09 +04:00
|
|
|
AppServer::AppServer(void) : BApplication (SERVER_SIGNATURE),
|
2003-03-23 23:52:37 +03:00
|
|
|
#else
|
2005-04-20 00:44:09 +04:00
|
|
|
AppServer::AppServer(void) :
|
2003-02-15 18:28:22 +03:00
|
|
|
#endif
|
2005-04-20 00:44:09 +04:00
|
|
|
fCursorSem(-1),
|
|
|
|
fCursorArea(-1)
|
2003-01-20 23:38:49 +03:00
|
|
|
{
|
2005-05-07 19:56:15 +04:00
|
|
|
fMessagePort = create_port(200, SERVER_PORT_NAME);
|
2005-04-17 16:26:16 +04:00
|
|
|
if (fMessagePort == B_NO_MORE_PORTS)
|
|
|
|
debugger("app_server could not create message port");
|
|
|
|
|
|
|
|
// Create the input port. The input_server will send it's messages here.
|
|
|
|
// TODO: If we want multiple user support we would need an individual
|
|
|
|
// port for each user and do the following for each RootLayer.
|
|
|
|
fServerInputPort = create_port(200, SERVER_INPUT_PORT);
|
|
|
|
if (fServerInputPort == B_NO_MORE_PORTS)
|
|
|
|
debugger("app_server could not create input port");
|
|
|
|
|
2005-05-15 04:22:55 +04:00
|
|
|
fAppList= new BList();
|
2004-01-20 01:18:37 +03:00
|
|
|
fQuittingServer= false;
|
|
|
|
make_decorator= NULL;
|
|
|
|
|
|
|
|
// We need this in order for new_decorator to be able to instantiate new decorators
|
|
|
|
app_server=this;
|
2003-01-27 22:43:15 +03:00
|
|
|
|
|
|
|
// Create the font server and scan the proper directories.
|
|
|
|
fontserver=new FontServer;
|
|
|
|
fontserver->Lock();
|
2003-08-02 04:13:30 +04:00
|
|
|
|
|
|
|
// Used for testing purposes
|
2003-01-27 22:43:15 +03:00
|
|
|
|
2004-08-29 19:01:44 +04:00
|
|
|
// TODO: Re-enable scanning of all font directories when server is actually put to use
|
2003-08-31 21:38:34 +04:00
|
|
|
fontserver->ScanDirectory("/boot/beos/etc/fonts/ttfonts/");
|
2003-01-27 22:43:15 +03:00
|
|
|
// fontserver->ScanDirectory("/boot/beos/etc/fonts/PS-Type1/");
|
2003-08-31 21:38:34 +04:00
|
|
|
// fontserver->ScanDirectory("/boot/home/config/fonts/ttfonts/");
|
|
|
|
// fontserver->ScanDirectory("/boot/home/config/fonts/psfonts/");
|
2003-01-27 22:43:15 +03:00
|
|
|
fontserver->SaveList();
|
|
|
|
|
2005-04-14 04:11:33 +04:00
|
|
|
if (!fontserver->SetSystemPlain(DEFAULT_PLAIN_FONT_FAMILY,
|
|
|
|
DEFAULT_PLAIN_FONT_STYLE,
|
|
|
|
DEFAULT_PLAIN_FONT_SIZE) &&
|
|
|
|
!fontserver->SetSystemPlain(FALLBACK_PLAIN_FONT_FAMILY,
|
|
|
|
DEFAULT_PLAIN_FONT_STYLE,
|
|
|
|
DEFAULT_PLAIN_FONT_SIZE)) {
|
|
|
|
printf("Couldn't set plain to %s (fallback: %s), %s %d pt\n",
|
2005-04-12 17:15:38 +04:00
|
|
|
DEFAULT_PLAIN_FONT_FAMILY,
|
2005-04-14 04:11:33 +04:00
|
|
|
FALLBACK_PLAIN_FONT_FAMILY,
|
2005-04-12 17:15:38 +04:00
|
|
|
DEFAULT_PLAIN_FONT_STYLE,
|
|
|
|
DEFAULT_PLAIN_FONT_SIZE);
|
|
|
|
}
|
|
|
|
|
2005-04-14 04:11:33 +04:00
|
|
|
if (!fontserver->SetSystemBold(DEFAULT_BOLD_FONT_FAMILY,
|
|
|
|
DEFAULT_BOLD_FONT_STYLE,
|
|
|
|
DEFAULT_BOLD_FONT_SIZE) &&
|
|
|
|
!fontserver->SetSystemBold(FALLBACK_BOLD_FONT_FAMILY,
|
|
|
|
DEFAULT_BOLD_FONT_STYLE,
|
|
|
|
DEFAULT_BOLD_FONT_SIZE)) {
|
|
|
|
printf("Couldn't set bold to %s (fallback: %s), %s %d pt\n",
|
2005-04-12 17:15:38 +04:00
|
|
|
DEFAULT_BOLD_FONT_FAMILY,
|
2005-04-14 04:11:33 +04:00
|
|
|
FALLBACK_BOLD_FONT_FAMILY,
|
2005-04-12 17:15:38 +04:00
|
|
|
DEFAULT_BOLD_FONT_STYLE,
|
|
|
|
DEFAULT_BOLD_FONT_SIZE);
|
|
|
|
}
|
|
|
|
|
2005-04-14 04:11:33 +04:00
|
|
|
if (!fontserver->SetSystemFixed(DEFAULT_FIXED_FONT_FAMILY,
|
|
|
|
DEFAULT_FIXED_FONT_STYLE,
|
|
|
|
DEFAULT_FIXED_FONT_SIZE) &&
|
|
|
|
!fontserver->SetSystemFixed(FALLBACK_FIXED_FONT_FAMILY,
|
|
|
|
DEFAULT_FIXED_FONT_STYLE,
|
|
|
|
DEFAULT_FIXED_FONT_SIZE)) {
|
|
|
|
printf("Couldn't set fixed to %s (fallback: %s), %s %d pt\n",
|
2005-04-12 17:15:38 +04:00
|
|
|
DEFAULT_FIXED_FONT_FAMILY,
|
2005-04-14 04:11:33 +04:00
|
|
|
FALLBACK_FIXED_FONT_FAMILY,
|
2005-04-12 17:15:38 +04:00
|
|
|
DEFAULT_FIXED_FONT_STYLE,
|
|
|
|
DEFAULT_FIXED_FONT_SIZE);
|
|
|
|
}
|
|
|
|
|
2003-01-27 22:43:15 +03:00
|
|
|
fontserver->Unlock();
|
2003-03-31 01:09:39 +04:00
|
|
|
|
|
|
|
|
2003-07-05 21:40:42 +04:00
|
|
|
// Load the GUI colors here and set the global set to the values contained therein. If this
|
|
|
|
// is not possible, set colors to the defaults
|
|
|
|
if(!LoadGUIColors(&gui_colorset))
|
2003-10-06 01:52:54 +04:00
|
|
|
gui_colorset.SetToDefaults();
|
2003-07-12 02:30:55 +04:00
|
|
|
|
|
|
|
InitDecorators();
|
2005-01-19 01:23:34 +03:00
|
|
|
|
2003-01-27 22:43:15 +03:00
|
|
|
// Set up the Desktop
|
2004-01-20 01:18:37 +03:00
|
|
|
desktop= new Desktop();
|
2004-01-13 03:56:36 +03:00
|
|
|
desktop->Init();
|
2003-01-27 22:43:15 +03:00
|
|
|
|
2003-02-20 23:14:57 +03:00
|
|
|
// Create the bitmap allocator. Object declared in BitmapManager.cpp
|
2004-01-20 01:18:37 +03:00
|
|
|
bitmapmanager= new BitmapManager();
|
2003-02-20 23:14:57 +03:00
|
|
|
|
2003-01-27 22:43:15 +03:00
|
|
|
// This is necessary to mediate access between the Poller and app_server threads
|
2004-01-20 01:18:37 +03:00
|
|
|
fActiveAppLock= create_sem(1,"app_server_active_sem");
|
2003-01-27 22:43:15 +03:00
|
|
|
|
|
|
|
// This locker is for app_server and Picasso to vy for control of the ServerApp list
|
2004-01-20 01:18:37 +03:00
|
|
|
fAppListLock= create_sem(1,"app_server_applist_sem");
|
2003-01-27 22:43:15 +03:00
|
|
|
|
|
|
|
// This locker is to mediate access to the make_decorator pointer
|
2004-01-20 01:18:37 +03:00
|
|
|
fDecoratorLock= create_sem(1,"app_server_decor_sem");
|
2003-01-27 22:43:15 +03:00
|
|
|
|
|
|
|
// Spawn our thread-monitoring thread
|
2005-03-25 23:39:43 +03:00
|
|
|
fPicassoThreadID= spawn_thread(PicassoThread,"picasso", B_NORMAL_PRIORITY, this);
|
2004-01-20 01:18:37 +03:00
|
|
|
if (fPicassoThreadID >= 0)
|
|
|
|
resume_thread(fPicassoThreadID);
|
2003-01-27 22:43:15 +03:00
|
|
|
|
2004-01-20 01:18:37 +03:00
|
|
|
fDecoratorName="Default";
|
2005-04-30 19:00:10 +04:00
|
|
|
|
2005-04-17 16:26:16 +04:00
|
|
|
#if 0
|
2005-04-20 00:44:09 +04:00
|
|
|
LaunchCursorThread();
|
2005-04-17 16:26:16 +04:00
|
|
|
#endif
|
2003-01-20 23:38:49 +03:00
|
|
|
}
|
|
|
|
|
2003-01-27 22:43:15 +03:00
|
|
|
/*!
|
|
|
|
\brief Destructor
|
|
|
|
|
|
|
|
Reached only when the server is asked to shut down in Test mode. Kills all apps, shuts down the
|
|
|
|
desktop, kills the housekeeping threads, etc.
|
|
|
|
*/
|
2003-01-20 23:38:49 +03:00
|
|
|
AppServer::~AppServer(void)
|
|
|
|
{
|
2005-03-08 00:52:41 +03:00
|
|
|
debugger("We shouldn't be here! MainLoop()::B_QUIT_REQUESTED should see if we can exit the server.\n");
|
|
|
|
/*
|
2003-01-27 22:43:15 +03:00
|
|
|
ServerApp *tempapp;
|
|
|
|
int32 i;
|
2004-01-20 01:18:37 +03:00
|
|
|
acquire_sem(fAppListLock);
|
|
|
|
for(i=0;i<fAppList->CountItems();i++)
|
2003-01-27 22:43:15 +03:00
|
|
|
{
|
2004-01-20 01:18:37 +03:00
|
|
|
tempapp=(ServerApp *)fAppList->ItemAt(i);
|
2003-01-27 22:43:15 +03:00
|
|
|
if(tempapp!=NULL)
|
|
|
|
delete tempapp;
|
|
|
|
}
|
2004-01-20 01:18:37 +03:00
|
|
|
delete fAppList;
|
|
|
|
release_sem(fAppListLock);
|
2003-01-27 22:43:15 +03:00
|
|
|
|
2003-02-20 23:14:57 +03:00
|
|
|
delete bitmapmanager;
|
|
|
|
|
2004-01-13 03:56:36 +03:00
|
|
|
delete desktop;
|
|
|
|
|
2003-01-27 22:43:15 +03:00
|
|
|
// If these threads are still running, kill them - after this, if exit_poller
|
|
|
|
// is deleted, who knows what will happen... These things will just return an
|
|
|
|
// error and fail if the threads have already exited.
|
2004-01-20 01:18:37 +03:00
|
|
|
kill_thread(fPicassoThreadID);
|
2005-04-20 00:44:09 +04:00
|
|
|
kill_thread(fCursorThreadID);
|
|
|
|
kill_thread(fISThreadID);
|
2003-01-27 22:43:15 +03:00
|
|
|
|
|
|
|
delete fontserver;
|
|
|
|
|
|
|
|
make_decorator=NULL;
|
2005-03-08 00:52:41 +03:00
|
|
|
*/
|
2003-01-20 23:38:49 +03:00
|
|
|
}
|
|
|
|
|
2003-01-27 22:43:15 +03:00
|
|
|
/*!
|
|
|
|
\brief Thread function for watching for dead apps
|
|
|
|
\param data Pointer to the app_server to which the thread belongs
|
|
|
|
\return Throwaway value - always 0
|
|
|
|
*/
|
2003-01-20 23:38:49 +03:00
|
|
|
int32 AppServer::PicassoThread(void *data)
|
|
|
|
{
|
2004-01-13 03:56:36 +03:00
|
|
|
int32 i;
|
2004-01-20 01:18:37 +03:00
|
|
|
AppServer *appserver=(AppServer*)data;
|
2004-01-13 03:56:36 +03:00
|
|
|
ServerApp *app;
|
2003-01-27 22:43:15 +03:00
|
|
|
for(;;)
|
|
|
|
{
|
2005-01-17 00:35:02 +03:00
|
|
|
i = 0;
|
2004-01-20 01:18:37 +03:00
|
|
|
acquire_sem(appserver->fAppListLock);
|
2005-01-17 00:35:02 +03:00
|
|
|
for(;;)
|
2003-01-27 22:43:15 +03:00
|
|
|
{
|
2005-01-17 00:35:02 +03:00
|
|
|
app=(ServerApp*)appserver->fAppList->ItemAt(i++);
|
2003-01-27 22:43:15 +03:00
|
|
|
if(!app)
|
2005-01-17 00:35:02 +03:00
|
|
|
break;
|
|
|
|
|
2003-01-27 22:43:15 +03:00
|
|
|
app->PingTarget();
|
|
|
|
}
|
2005-01-17 00:35:02 +03:00
|
|
|
release_sem(appserver->fAppListLock);
|
2003-01-27 22:43:15 +03:00
|
|
|
// we do this every other second so as not to suck *too* many CPU cycles
|
2005-03-04 02:21:36 +03:00
|
|
|
snooze(1000000);
|
2003-01-27 22:43:15 +03:00
|
|
|
}
|
2003-01-20 23:38:49 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-04-20 00:44:09 +04:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Starts Input Server
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
AppServer::LaunchInputServer()
|
|
|
|
{
|
|
|
|
// We are supposed to start the input_server, but it's a BApplication
|
|
|
|
// that depends on the registrar running, which is started after app_server
|
|
|
|
// so we wait on roster thread to launch the input server
|
|
|
|
|
|
|
|
fISThreadID = B_ERROR;
|
|
|
|
|
2005-05-15 04:22:55 +04:00
|
|
|
while (find_thread(BPrivate::kRosterThreadName) == B_NAME_NOT_FOUND && !fQuittingServer) {
|
2005-04-20 00:44:09 +04:00
|
|
|
snooze(250000);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fQuittingServer)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// we use an area for cursor data communication with input_server
|
|
|
|
// area id and sem id are sent to the input_server
|
|
|
|
|
|
|
|
if (fCursorArea < B_OK)
|
|
|
|
fCursorArea = create_area("isCursor", (void**) &fCursorAddr, B_ANY_ADDRESS, B_PAGE_SIZE, B_FULL_LOCK, B_READ_AREA | B_WRITE_AREA);
|
|
|
|
if (fCursorSem < B_OK)
|
2005-05-15 04:22:55 +04:00
|
|
|
fCursorSem = create_sem(0, "isSem");
|
2005-04-20 00:44:09 +04:00
|
|
|
|
|
|
|
int32 arg_c = 1;
|
|
|
|
char **arg_v = (char **)malloc(sizeof(char *) * (arg_c + 1));
|
2005-04-28 14:10:52 +04:00
|
|
|
#if TEST_MODE
|
|
|
|
arg_v[0] = strdup("/boot/home/svnhaiku/trunk/distro/x86.R1/beos/system/servers/input_server");
|
|
|
|
#else
|
|
|
|
arg_v[0] = strdup("/system/servers/input_server");
|
|
|
|
#endif
|
2005-04-20 00:44:09 +04:00
|
|
|
arg_v[1] = NULL;
|
|
|
|
fISThreadID = load_image(arg_c, (const char**)arg_v, (const char **)environ);
|
|
|
|
free(arg_v[0]);
|
|
|
|
|
|
|
|
int32 tmpbuf[2] = {fCursorSem, fCursorArea};
|
2005-05-15 04:22:55 +04:00
|
|
|
int32 code = 0;
|
|
|
|
send_data(fISThreadID, code, (void *)tmpbuf, sizeof(tmpbuf));
|
2005-04-20 00:44:09 +04:00
|
|
|
|
|
|
|
resume_thread(fISThreadID);
|
|
|
|
setpgid(fISThreadID, 0);
|
|
|
|
|
|
|
|
// we receive
|
|
|
|
|
|
|
|
thread_id sender;
|
2005-05-15 04:22:55 +04:00
|
|
|
code = receive_data(&sender, (void *)tmpbuf, sizeof(tmpbuf));
|
|
|
|
fISASPort = tmpbuf[0];
|
|
|
|
fISPort = tmpbuf[1];
|
2005-04-20 00:44:09 +04:00
|
|
|
|
|
|
|
// if at any time, one of these ports is error prone, it might mean input_server is gone
|
|
|
|
// then relaunch input_server
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Starts the Cursor Thread
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
AppServer::LaunchCursorThread()
|
|
|
|
{
|
|
|
|
// Spawn our cursor thread
|
2005-05-15 04:22:55 +04:00
|
|
|
fCursorThreadID = spawn_thread(CursorThread, "CursorThreadOfTheDeath", B_REAL_TIME_DISPLAY_PRIORITY - 1, this);
|
2005-04-20 00:44:09 +04:00
|
|
|
if (fCursorThreadID >= 0)
|
2005-05-15 04:22:55 +04:00
|
|
|
resume_thread(fCursorThreadID);
|
2005-04-20 00:44:09 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief The Cursor Thread task
|
|
|
|
*/
|
|
|
|
int32
|
|
|
|
AppServer::CursorThread(void* data)
|
|
|
|
{
|
|
|
|
AppServer *app = (AppServer *)data;
|
|
|
|
|
|
|
|
BPoint p;
|
2005-04-28 14:10:52 +04:00
|
|
|
|
|
|
|
app->LaunchInputServer();
|
2005-04-20 00:44:09 +04:00
|
|
|
|
|
|
|
do {
|
|
|
|
|
|
|
|
while (acquire_sem(app->fCursorSem) == B_OK) {
|
|
|
|
|
2005-05-15 04:22:55 +04:00
|
|
|
p.y = *app->fCursorAddr & 0x7fff;
|
2005-04-30 19:00:10 +04:00
|
|
|
p.x = *app->fCursorAddr >> 15 & 0x7fff;
|
2005-04-20 00:44:09 +04:00
|
|
|
|
2005-04-28 14:10:52 +04:00
|
|
|
desktop->GetDisplayDriver()->MoveCursorTo(p.x, p.y);
|
2005-04-30 19:00:10 +04:00
|
|
|
STRACE(("CursorThread : %f, %f\n", p.x, p.y));
|
2005-04-20 00:44:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
snooze(100000);
|
|
|
|
|
|
|
|
} while (!app->fQuittingServer);
|
|
|
|
|
|
|
|
return B_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-15 18:28:22 +03:00
|
|
|
/*!
|
|
|
|
\brief The call that starts it all...
|
|
|
|
\return Always 0
|
|
|
|
*/
|
|
|
|
thread_id AppServer::Run(void)
|
2003-01-20 23:38:49 +03:00
|
|
|
{
|
2003-01-27 22:43:15 +03:00
|
|
|
MainLoop();
|
2005-03-25 23:39:43 +03:00
|
|
|
kill_thread(fPicassoThreadID);
|
2003-02-15 18:28:22 +03:00
|
|
|
return 0;
|
2003-01-20 23:38:49 +03:00
|
|
|
}
|
|
|
|
|
2003-01-27 22:43:15 +03:00
|
|
|
|
|
|
|
//! Main message-monitoring loop for the regular message port - no input messages!
|
2003-01-20 23:38:49 +03:00
|
|
|
void AppServer::MainLoop(void)
|
|
|
|
{
|
2004-07-30 19:16:59 +04:00
|
|
|
BPortLink pmsg(-1,fMessagePort);
|
|
|
|
int32 code=0;
|
|
|
|
status_t err=B_OK;
|
2003-01-27 22:43:15 +03:00
|
|
|
|
2004-01-20 01:18:37 +03:00
|
|
|
while(1)
|
2003-01-27 22:43:15 +03:00
|
|
|
{
|
2004-07-30 19:16:59 +04:00
|
|
|
STRACE(("info: AppServer::MainLoop listening on port %ld.\n", fMessagePort));
|
|
|
|
err=pmsg.GetNextReply(&code);
|
|
|
|
|
|
|
|
if(err<B_OK)
|
2003-01-27 22:43:15 +03:00
|
|
|
{
|
2004-07-30 19:16:59 +04:00
|
|
|
STRACE(("MainLoop:pmsg.GetNextReply failed\n"));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(code)
|
|
|
|
{
|
|
|
|
case B_QUIT_REQUESTED:
|
|
|
|
case AS_CREATE_APP:
|
|
|
|
case AS_DELETE_APP:
|
2005-04-30 00:30:04 +04:00
|
|
|
case AS_SCREEN_GET_MODE:
|
|
|
|
case AS_SCREEN_SET_MODE:
|
2004-07-30 19:16:59 +04:00
|
|
|
case AS_UPDATED_CLIENT_FONTLIST:
|
|
|
|
case AS_QUERY_FONTS_CHANGED:
|
|
|
|
case AS_SET_UI_COLORS:
|
|
|
|
case AS_GET_UI_COLOR:
|
|
|
|
case AS_SET_DECORATOR:
|
|
|
|
case AS_GET_DECORATOR:
|
|
|
|
case AS_R5_SET_DECORATOR:
|
|
|
|
DispatchMessage(code,pmsg);
|
|
|
|
break;
|
|
|
|
default:
|
2003-01-27 22:43:15 +03:00
|
|
|
{
|
2004-07-30 19:16:59 +04:00
|
|
|
STRACE(("Server::MainLoop received unexpected code %ld(offset %ld)\n",
|
|
|
|
code,code-SERVER_TRUE));
|
|
|
|
break;
|
2003-01-27 22:43:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-01-20 23:38:49 +03:00
|
|
|
}
|
|
|
|
|
2003-01-27 22:43:15 +03:00
|
|
|
/*!
|
|
|
|
\brief Loads the specified decorator and sets the system's decorator to it.
|
|
|
|
\param path Path to the decorator to load
|
|
|
|
\return True if successful, false if not.
|
|
|
|
|
2003-10-09 03:18:30 +04:00
|
|
|
If the server cannot load the specified decorator, nothing changes. Passing a
|
|
|
|
NULL string to this function sets the decorator to the internal one.
|
2003-01-27 22:43:15 +03:00
|
|
|
*/
|
2003-01-20 23:38:49 +03:00
|
|
|
bool AppServer::LoadDecorator(const char *path)
|
|
|
|
{
|
2003-01-27 22:43:15 +03:00
|
|
|
// Loads a window decorator based on the supplied path and forces a decorator update.
|
|
|
|
// If it cannot load the specified decorator, it will retain the current one and
|
2003-10-09 03:18:30 +04:00
|
|
|
// return false. Note that passing a NULL string to this function sets the decorator
|
|
|
|
// to the internal one.
|
|
|
|
|
|
|
|
// passing the string "Default" will set the window decorator to the app_server's
|
|
|
|
// internal one
|
|
|
|
if(!path)
|
|
|
|
{
|
2004-01-20 01:18:37 +03:00
|
|
|
make_decorator= NULL;
|
2003-10-09 03:18:30 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2004-01-20 01:18:37 +03:00
|
|
|
create_decorator *pcreatefunc= NULL;
|
2004-01-13 03:56:36 +03:00
|
|
|
status_t stat;
|
|
|
|
image_id addon;
|
2003-01-27 22:43:15 +03:00
|
|
|
|
2004-01-20 01:18:37 +03:00
|
|
|
addon= load_add_on(path);
|
2004-01-13 03:56:36 +03:00
|
|
|
if(addon < 0)
|
2003-07-12 02:30:55 +04:00
|
|
|
return false;
|
2003-01-27 22:43:15 +03:00
|
|
|
|
|
|
|
// As of now, we do nothing with decorator versions, but the possibility exists
|
|
|
|
// that the API will change even though I cannot forsee any reason to do so. If
|
|
|
|
// we *did* do anything with decorator versions, the assignment to a global would
|
|
|
|
// go here.
|
|
|
|
|
|
|
|
// Get the instantiation function
|
2004-01-20 01:18:37 +03:00
|
|
|
stat= get_image_symbol(addon, "instantiate_decorator", B_SYMBOL_TYPE_TEXT, (void**)&pcreatefunc);
|
2004-07-30 19:16:59 +04:00
|
|
|
if(stat != B_OK)
|
|
|
|
{
|
2003-01-27 22:43:15 +03:00
|
|
|
unload_add_on(addon);
|
|
|
|
return false;
|
|
|
|
}
|
2003-10-09 03:18:30 +04:00
|
|
|
|
2004-07-30 19:16:59 +04:00
|
|
|
BPath temppath(path);
|
|
|
|
fDecoratorName=temppath.Leaf();
|
2003-10-09 03:18:30 +04:00
|
|
|
|
2004-01-20 01:18:37 +03:00
|
|
|
acquire_sem(fDecoratorLock);
|
|
|
|
make_decorator=pcreatefunc;
|
|
|
|
fDecoratorID=addon;
|
|
|
|
release_sem(fDecoratorLock);
|
2003-01-27 22:43:15 +03:00
|
|
|
return true;
|
2003-01-20 23:38:49 +03:00
|
|
|
}
|
|
|
|
|
2003-07-12 02:30:55 +04:00
|
|
|
//! Loads decorator settings on disk or the default if settings are invalid
|
|
|
|
void AppServer::InitDecorators(void)
|
|
|
|
{
|
|
|
|
BMessage settings;
|
|
|
|
|
|
|
|
BDirectory dir,newdir;
|
|
|
|
if(dir.SetTo(SERVER_SETTINGS_DIR)==B_ENTRY_NOT_FOUND)
|
|
|
|
create_directory(SERVER_SETTINGS_DIR,0777);
|
|
|
|
|
|
|
|
BString path(SERVER_SETTINGS_DIR);
|
|
|
|
path+="DecoratorSettings";
|
|
|
|
BFile file(path.String(),B_READ_ONLY);
|
|
|
|
|
|
|
|
if(file.InitCheck()==B_OK)
|
|
|
|
{
|
|
|
|
if(settings.Unflatten(&file)==B_OK)
|
|
|
|
{
|
|
|
|
BString itemtext;
|
|
|
|
if(settings.FindString("decorator",&itemtext)==B_OK)
|
|
|
|
{
|
|
|
|
path.SetTo(DECORATORS_DIR);
|
|
|
|
path+=itemtext;
|
|
|
|
if(LoadDecorator(path.String()))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We got this far, so something must have gone wrong. We set make_decorator
|
|
|
|
// to NULL so that the decorator allocation routine knows to utilize the included
|
|
|
|
// default decorator instead of an addon.
|
|
|
|
make_decorator=NULL;
|
|
|
|
}
|
|
|
|
|
2003-01-27 22:43:15 +03:00
|
|
|
/*!
|
|
|
|
\brief Message handling function for all messages sent to the app_server
|
|
|
|
\param code ID of the message sent
|
2004-07-30 19:16:59 +04:00
|
|
|
\param buffer Attachment buffer for the message.
|
2003-01-27 22:43:15 +03:00
|
|
|
|
|
|
|
*/
|
2004-07-30 19:16:59 +04:00
|
|
|
void AppServer::DispatchMessage(int32 code, BPortLink &msg)
|
2003-01-20 23:38:49 +03:00
|
|
|
{
|
2004-07-30 19:16:59 +04:00
|
|
|
switch(code)
|
2003-01-27 22:43:15 +03:00
|
|
|
{
|
2003-02-24 18:47:06 +03:00
|
|
|
case AS_CREATE_APP:
|
2003-01-27 22:43:15 +03:00
|
|
|
{
|
|
|
|
// Create the ServerApp to node monitor a new BApplication
|
|
|
|
|
|
|
|
// Attached data:
|
2003-10-04 04:56:43 +04:00
|
|
|
// 1) port_id - receiver port of a regular app
|
2004-01-13 03:56:36 +03:00
|
|
|
// 2) port_id - client looper port - for send messages to the client
|
|
|
|
// 2) team_id - app's team ID
|
|
|
|
// 3) int32 - handler token of the regular app
|
|
|
|
// 4) char * - signature of the regular app
|
2003-01-27 22:43:15 +03:00
|
|
|
|
|
|
|
// Find the necessary data
|
2004-07-30 19:16:59 +04:00
|
|
|
team_id clientTeamID=-1;
|
|
|
|
port_id clientLooperPort=-1;
|
|
|
|
port_id app_port=-1;
|
|
|
|
int32 htoken=B_NULL_TOKEN;
|
|
|
|
char *app_signature=NULL;
|
|
|
|
|
|
|
|
msg.Read<port_id>(&app_port);
|
|
|
|
msg.Read<port_id>(&clientLooperPort);
|
|
|
|
msg.Read<team_id>(&clientTeamID);
|
|
|
|
msg.Read<int32>(&htoken);
|
|
|
|
msg.ReadString(&app_signature);
|
2003-01-27 22:43:15 +03:00
|
|
|
|
|
|
|
// Create the ServerApp subthread for this app
|
2004-01-20 01:18:37 +03:00
|
|
|
acquire_sem(fAppListLock);
|
2003-01-27 22:43:15 +03:00
|
|
|
|
2004-07-30 19:16:59 +04:00
|
|
|
port_id server_listen=create_port(DEFAULT_MONITOR_PORT_SIZE, app_signature);
|
|
|
|
if(server_listen<B_OK)
|
2003-01-27 22:43:15 +03:00
|
|
|
{
|
2004-01-20 01:18:37 +03:00
|
|
|
release_sem(fAppListLock);
|
2003-02-14 04:53:53 +03:00
|
|
|
printf("No more ports left. Time to crash. Have a nice day! :)\n");
|
2003-01-27 22:43:15 +03:00
|
|
|
break;
|
|
|
|
}
|
2004-07-30 19:16:59 +04:00
|
|
|
ServerApp *newapp=NULL;
|
|
|
|
newapp= new ServerApp(app_port,server_listen, clientLooperPort, clientTeamID,
|
|
|
|
htoken, app_signature);
|
2004-01-13 03:56:36 +03:00
|
|
|
|
2004-07-30 19:16:59 +04:00
|
|
|
// add the new ServerApp to the known list of ServerApps
|
2004-01-20 01:18:37 +03:00
|
|
|
fAppList->AddItem(newapp);
|
2003-01-27 22:43:15 +03:00
|
|
|
|
2004-01-20 01:18:37 +03:00
|
|
|
release_sem(fAppListLock);
|
2003-01-27 22:43:15 +03:00
|
|
|
|
2004-08-09 02:34:36 +04:00
|
|
|
BPortLink replylink(app_port);
|
2004-08-22 04:27:15 +04:00
|
|
|
replylink.StartMessage(SERVER_TRUE);
|
2005-05-07 19:56:15 +04:00
|
|
|
replylink.Attach<int32>(server_listen);
|
2003-10-04 04:56:43 +04:00
|
|
|
replylink.Flush();
|
2003-01-27 22:43:15 +03:00
|
|
|
|
2004-07-30 19:16:59 +04:00
|
|
|
// This is necessary because BPortLink::ReadString allocates memory
|
|
|
|
if(app_signature)
|
|
|
|
free(app_signature);
|
2004-01-13 03:56:36 +03:00
|
|
|
|
2003-01-27 22:43:15 +03:00
|
|
|
break;
|
|
|
|
}
|
2003-02-24 18:47:06 +03:00
|
|
|
case AS_DELETE_APP:
|
2003-01-27 22:43:15 +03:00
|
|
|
{
|
|
|
|
// Delete a ServerApp. Received only from the respective ServerApp when a
|
|
|
|
// BApplication asks it to quit.
|
|
|
|
|
|
|
|
// Attached Data:
|
|
|
|
// 1) thread_id - thread ID of the ServerApp to be deleted
|
|
|
|
|
2004-07-30 19:16:59 +04:00
|
|
|
int32 i=0,
|
|
|
|
appnum=fAppList->CountItems();
|
|
|
|
|
|
|
|
ServerApp *srvapp=NULL;
|
|
|
|
thread_id srvapp_id=-1;
|
2004-01-13 03:56:36 +03:00
|
|
|
|
2004-07-30 19:16:59 +04:00
|
|
|
if(msg.Read<thread_id>(&srvapp_id)<B_OK)
|
|
|
|
break;
|
2004-01-13 03:56:36 +03:00
|
|
|
|
2004-01-20 01:18:37 +03:00
|
|
|
acquire_sem(fAppListLock);
|
2004-01-13 03:56:36 +03:00
|
|
|
|
2003-01-27 22:43:15 +03:00
|
|
|
// Run through the list of apps and nuke the proper one
|
2004-01-20 01:18:37 +03:00
|
|
|
for(i= 0; i < appnum; i++)
|
2003-01-27 22:43:15 +03:00
|
|
|
{
|
2004-01-20 01:18:37 +03:00
|
|
|
srvapp=(ServerApp *)fAppList->ItemAt(i);
|
2003-01-27 22:43:15 +03:00
|
|
|
|
2005-05-07 19:56:15 +04:00
|
|
|
if(srvapp != NULL && srvapp->MonitorThreadID() == srvapp_id)
|
2003-01-27 22:43:15 +03:00
|
|
|
{
|
2004-01-20 01:18:37 +03:00
|
|
|
srvapp=(ServerApp *)fAppList->RemoveItem(i);
|
2004-07-30 19:16:59 +04:00
|
|
|
if(srvapp)
|
|
|
|
{
|
2003-01-27 22:43:15 +03:00
|
|
|
delete srvapp;
|
2004-01-20 01:18:37 +03:00
|
|
|
srvapp= NULL;
|
2003-01-27 22:43:15 +03:00
|
|
|
}
|
|
|
|
break; // jump out of our for() loop
|
|
|
|
}
|
|
|
|
}
|
2004-01-13 03:56:36 +03:00
|
|
|
|
2004-01-20 01:18:37 +03:00
|
|
|
release_sem(fAppListLock);
|
2003-01-27 22:43:15 +03:00
|
|
|
break;
|
|
|
|
}
|
2003-02-24 18:47:06 +03:00
|
|
|
case AS_UPDATED_CLIENT_FONTLIST:
|
2003-01-27 22:43:15 +03:00
|
|
|
{
|
|
|
|
// received when the client-side global font list has been
|
|
|
|
// refreshed
|
|
|
|
fontserver->Lock();
|
|
|
|
fontserver->FontsUpdated();
|
|
|
|
fontserver->Unlock();
|
|
|
|
break;
|
|
|
|
}
|
2003-02-24 18:47:06 +03:00
|
|
|
case AS_QUERY_FONTS_CHANGED:
|
2003-01-27 22:43:15 +03:00
|
|
|
{
|
|
|
|
// Client application is asking if the font list has changed since
|
|
|
|
// the last client-side refresh
|
|
|
|
|
|
|
|
// Attached data:
|
|
|
|
// 1) port_id reply port
|
|
|
|
|
|
|
|
fontserver->Lock();
|
|
|
|
bool needs_update=fontserver->FontsNeedUpdated();
|
|
|
|
fontserver->Unlock();
|
|
|
|
|
2004-07-30 19:16:59 +04:00
|
|
|
// Seeing how the client merely wants an answer, we'll skip the BPortLink
|
2003-10-04 04:56:43 +04:00
|
|
|
// and all its overhead and just write the code to port.
|
|
|
|
port_id replyport;
|
2004-07-30 19:16:59 +04:00
|
|
|
if (msg.Read<port_id>(&replyport) < B_OK)
|
|
|
|
break;
|
|
|
|
BPortLink replylink(replyport);
|
|
|
|
replylink.StartMessage(needs_update ? SERVER_TRUE : SERVER_FALSE);
|
|
|
|
replylink.Flush();
|
2003-01-27 22:43:15 +03:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2003-10-06 01:52:54 +04:00
|
|
|
case AS_SET_UI_COLORS:
|
|
|
|
{
|
2003-10-09 03:18:30 +04:00
|
|
|
// Client application is asking to set all the system colors at once
|
|
|
|
// using a ColorSet object
|
|
|
|
|
|
|
|
// Attached data:
|
|
|
|
// 1) ColorSet new colors to use
|
|
|
|
|
|
|
|
gui_colorset.Lock();
|
2004-07-30 19:16:59 +04:00
|
|
|
msg.Read<ColorSet>(&gui_colorset);
|
2003-10-09 03:18:30 +04:00
|
|
|
gui_colorset.Unlock();
|
|
|
|
Broadcast(AS_UPDATE_COLORS);
|
2003-10-06 01:52:54 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case AS_SET_DECORATOR:
|
|
|
|
{
|
2003-10-09 03:18:30 +04:00
|
|
|
// Received from an application when the user wants to set the window
|
|
|
|
// decorator to a new one
|
|
|
|
|
|
|
|
// Attached Data:
|
|
|
|
// char * name of the decorator in the decorators path to use
|
|
|
|
|
2004-07-30 19:16:59 +04:00
|
|
|
char *decname=NULL;
|
|
|
|
msg.ReadString(&decname);
|
2003-10-09 03:18:30 +04:00
|
|
|
if(decname)
|
|
|
|
{
|
|
|
|
if(strcmp(decname,"Default")!=0)
|
|
|
|
{
|
|
|
|
BString decpath;
|
|
|
|
decpath.SetTo(DECORATORS_DIR);
|
|
|
|
decpath+=decname;
|
|
|
|
if(LoadDecorator(decpath.String()))
|
|
|
|
Broadcast(AS_UPDATE_DECORATOR);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LoadDecorator(NULL);
|
|
|
|
Broadcast(AS_UPDATE_DECORATOR);
|
|
|
|
}
|
|
|
|
}
|
2004-07-30 19:16:59 +04:00
|
|
|
free(decname);
|
2003-10-09 03:18:30 +04:00
|
|
|
|
2003-10-06 01:52:54 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case AS_GET_DECORATOR:
|
|
|
|
{
|
2003-10-09 03:18:30 +04:00
|
|
|
// Attached Data:
|
|
|
|
// 1) port_id reply port
|
|
|
|
|
2004-07-30 19:16:59 +04:00
|
|
|
port_id replyport=-1;
|
|
|
|
if(msg.Read<port_id>(&replyport)<B_OK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
BPortLink replylink(replyport);
|
|
|
|
replylink.StartMessage(AS_GET_DECORATOR);
|
2004-01-20 01:18:37 +03:00
|
|
|
replylink.AttachString(fDecoratorName.String());
|
2003-10-09 03:18:30 +04:00
|
|
|
replylink.Flush();
|
2003-10-06 01:52:54 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case AS_R5_SET_DECORATOR:
|
|
|
|
{
|
2003-10-09 03:18:30 +04:00
|
|
|
// Sort of supports Tracker's nifty Easter Egg. It was easy to do and
|
|
|
|
// it's kind of neat, so why not?
|
|
|
|
|
|
|
|
// Attached Data:
|
|
|
|
// char * name of the decorator in the decorators path to use
|
|
|
|
|
2004-07-30 19:16:59 +04:00
|
|
|
int32 decindex=0;
|
|
|
|
if(msg.Read<int32>(&decindex)<B_OK)
|
|
|
|
break;
|
2003-10-09 03:18:30 +04:00
|
|
|
|
|
|
|
BString decpath;
|
|
|
|
decpath.SetTo(DECORATORS_DIR);
|
|
|
|
switch(decindex)
|
|
|
|
{
|
|
|
|
case 0: decpath+="BeOS"; break;
|
|
|
|
case 1: decpath+="AmigaOS"; break;
|
|
|
|
case 2: decpath+="Windows"; break;
|
|
|
|
case 3: decpath+="MacOS"; break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(LoadDecorator(decpath.String()))
|
|
|
|
Broadcast(AS_UPDATE_DECORATOR);
|
|
|
|
|
2003-10-06 01:52:54 +04:00
|
|
|
break;
|
|
|
|
}
|
2003-01-27 22:43:15 +03:00
|
|
|
case B_QUIT_REQUESTED:
|
|
|
|
{
|
2005-04-14 04:11:33 +04:00
|
|
|
#if TEST_MODE
|
2003-01-27 22:43:15 +03:00
|
|
|
// Attached Data:
|
|
|
|
// none
|
|
|
|
|
|
|
|
// We've been asked to quit, so (for now) broadcast to all
|
|
|
|
// test apps to quit. This situation will occur only when the server
|
|
|
|
// is compiled as a regular Be application.
|
2005-03-08 00:52:41 +03:00
|
|
|
|
2003-02-24 18:47:06 +03:00
|
|
|
Broadcast(AS_QUIT_APP);
|
2003-01-27 22:43:15 +03:00
|
|
|
|
2004-01-20 01:18:37 +03:00
|
|
|
// we have to wait until *all* threads have finished!
|
|
|
|
ServerApp *app= NULL;
|
|
|
|
acquire_sem(fAppListLock);
|
|
|
|
thread_info tinfo;
|
|
|
|
for(int32 i= 0; i < fAppList->CountItems(); i++)
|
2004-01-13 03:56:36 +03:00
|
|
|
{
|
2004-01-20 01:18:37 +03:00
|
|
|
app=(ServerApp*)fAppList->ItemAt(i);
|
2004-01-13 03:56:36 +03:00
|
|
|
if(!app)
|
2004-01-20 01:18:37 +03:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// Instead of calling wait_for_thread, we will wait a bit, check for the
|
|
|
|
// thread_id. We will only wait so long, because then the app is probably crashed
|
|
|
|
// or hung. Seeing that being the case, we'll kill its BApp team and fake the
|
|
|
|
// quit message
|
2005-05-07 19:56:15 +04:00
|
|
|
if(get_thread_info(app->MonitorThreadID(), &tinfo)==B_OK)
|
2004-01-20 01:18:37 +03:00
|
|
|
{
|
|
|
|
bool killteam=true;
|
|
|
|
|
|
|
|
for(int32 j=0; j<5; j++)
|
|
|
|
{
|
2005-03-04 02:21:36 +03:00
|
|
|
snooze(500000); // wait half a second for it to quit
|
2005-05-07 19:56:15 +04:00
|
|
|
if(get_thread_info(app->MonitorThreadID(), &tinfo)!=B_OK)
|
2004-01-20 01:18:37 +03:00
|
|
|
{
|
|
|
|
killteam=false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(killteam)
|
|
|
|
{
|
|
|
|
kill_team(app->ClientTeamID());
|
|
|
|
app->PostMessage(B_QUIT_REQUESTED);
|
|
|
|
}
|
|
|
|
}
|
2004-01-13 03:56:36 +03:00
|
|
|
}
|
2005-03-04 02:21:36 +03:00
|
|
|
|
|
|
|
kill_thread(fPicassoThreadID);
|
|
|
|
|
2004-01-20 01:18:37 +03:00
|
|
|
release_sem(fAppListLock);
|
2004-01-13 03:56:36 +03:00
|
|
|
|
2005-03-04 02:21:36 +03:00
|
|
|
delete desktop;
|
2005-03-08 00:52:41 +03:00
|
|
|
delete fAppList;
|
|
|
|
delete bitmapmanager;
|
|
|
|
delete fontserver;
|
|
|
|
make_decorator=NULL;
|
2005-03-04 02:21:36 +03:00
|
|
|
|
|
|
|
exit_thread(0);
|
2004-01-17 21:37:57 +03:00
|
|
|
|
|
|
|
// we are now clear to exit
|
2005-03-29 19:39:08 +04:00
|
|
|
#endif
|
2003-01-27 22:43:15 +03:00
|
|
|
break;
|
|
|
|
}
|
2003-07-24 23:38:24 +04:00
|
|
|
case AS_SET_SYSCURSOR_DEFAULTS:
|
|
|
|
{
|
2005-01-19 20:55:50 +03:00
|
|
|
// although this isn't pretty, ATM we only have RootLayer.
|
|
|
|
// this messages should be handled somewhere into a RootLayer
|
|
|
|
// specific area - this set is intended for a RootLayer.
|
|
|
|
desktop->ActiveRootLayer()->GetCursorManager().SetDefaults();
|
2003-07-24 23:38:24 +04:00
|
|
|
break;
|
|
|
|
}
|
2003-01-27 22:43:15 +03:00
|
|
|
default:
|
|
|
|
// we should never get here.
|
|
|
|
break;
|
|
|
|
}
|
2003-01-20 23:38:49 +03:00
|
|
|
}
|
|
|
|
|
2003-01-27 22:43:15 +03:00
|
|
|
/*!
|
|
|
|
\brief Send a quick (no attachments) message to all applications
|
|
|
|
|
|
|
|
Quite useful for notification for things like server shutdown, system
|
|
|
|
color changes, etc.
|
|
|
|
*/
|
2003-01-20 23:38:49 +03:00
|
|
|
void AppServer::Broadcast(int32 code)
|
|
|
|
{
|
2004-01-20 01:18:37 +03:00
|
|
|
ServerApp *app= NULL;
|
2003-08-31 21:38:34 +04:00
|
|
|
|
2004-01-20 01:18:37 +03:00
|
|
|
acquire_sem(fAppListLock);
|
|
|
|
for(int32 i= 0; i < fAppList->CountItems(); i++)
|
2003-01-27 22:43:15 +03:00
|
|
|
{
|
2004-01-20 01:18:37 +03:00
|
|
|
app=(ServerApp*)fAppList->ItemAt(i);
|
2003-01-27 22:43:15 +03:00
|
|
|
if(!app)
|
2004-01-13 03:56:36 +03:00
|
|
|
{ printf("PANIC in AppServer::Broadcast()\n"); continue; }
|
2004-08-23 02:33:57 +04:00
|
|
|
app->PostMessage(code);
|
2003-01-27 22:43:15 +03:00
|
|
|
}
|
2004-01-20 01:18:37 +03:00
|
|
|
release_sem(fAppListLock);
|
2003-01-20 23:38:49 +03:00
|
|
|
}
|
|
|
|
|
2003-02-04 03:20:15 +03:00
|
|
|
/*!
|
|
|
|
\brief Finds the application with the given signature
|
|
|
|
\param sig MIME signature of the application to find
|
|
|
|
\return the corresponding ServerApp or NULL if not found
|
|
|
|
|
|
|
|
This call should be made only when necessary because it locks the app list
|
|
|
|
while it does its searching.
|
|
|
|
*/
|
|
|
|
ServerApp *AppServer::FindApp(const char *sig)
|
|
|
|
{
|
|
|
|
if(!sig)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
ServerApp *foundapp=NULL;
|
|
|
|
|
2004-01-20 01:18:37 +03:00
|
|
|
acquire_sem(fAppListLock);
|
2003-02-04 03:20:15 +03:00
|
|
|
|
2004-01-20 01:18:37 +03:00
|
|
|
for(int32 i=0; i<fAppList->CountItems();i++)
|
2003-02-04 03:20:15 +03:00
|
|
|
{
|
2004-01-20 01:18:37 +03:00
|
|
|
foundapp=(ServerApp*)fAppList->ItemAt(i);
|
2005-05-07 19:56:15 +04:00
|
|
|
if(foundapp && foundapp->Title() == sig)
|
2003-02-04 03:20:15 +03:00
|
|
|
{
|
2004-01-20 01:18:37 +03:00
|
|
|
release_sem(fAppListLock);
|
2003-02-04 03:20:15 +03:00
|
|
|
return foundapp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-20 01:18:37 +03:00
|
|
|
release_sem(fAppListLock);
|
2003-02-04 03:20:15 +03:00
|
|
|
|
|
|
|
// couldn't find a match
|
|
|
|
return NULL;
|
2003-01-20 23:38:49 +03:00
|
|
|
}
|
|
|
|
|
2003-02-14 04:53:53 +03:00
|
|
|
/*!
|
|
|
|
\brief Creates a new decorator instance
|
|
|
|
\param rect Frame size
|
|
|
|
\param title Title string for the "window"
|
|
|
|
\param wlook Window look type. See Window.h
|
|
|
|
\param wfeel Window feel type. See Window.h
|
|
|
|
\param wflags Window flags. See Window.h
|
2003-02-14 14:04:01 +03:00
|
|
|
|
|
|
|
If a decorator has not been set, we use the default one packaged in with the app_server
|
|
|
|
being that we can't do anything with a window without one.
|
2003-02-14 04:53:53 +03:00
|
|
|
*/
|
2003-02-12 04:11:55 +03:00
|
|
|
Decorator *new_decorator(BRect rect, const char *title, int32 wlook, int32 wfeel,
|
|
|
|
int32 wflags, DisplayDriver *ddriver)
|
|
|
|
{
|
2003-07-12 02:30:55 +04:00
|
|
|
Decorator *dec=NULL;
|
2004-01-20 01:18:37 +03:00
|
|
|
|
|
|
|
if(!app_server->make_decorator)
|
2003-03-31 01:09:39 +04:00
|
|
|
dec=new DefaultDecorator(rect,wlook,wfeel,wflags);
|
|
|
|
else
|
|
|
|
dec=app_server->make_decorator(rect,wlook,wfeel,wflags);
|
2004-01-20 01:18:37 +03:00
|
|
|
|
2003-03-31 01:09:39 +04:00
|
|
|
gui_colorset.Lock();
|
2003-07-24 23:38:24 +04:00
|
|
|
dec->SetDriver(ddriver);
|
2003-03-31 01:09:39 +04:00
|
|
|
dec->SetColors(gui_colorset);
|
2003-07-24 23:38:24 +04:00
|
|
|
dec->SetTitle(title);
|
2003-03-31 01:09:39 +04:00
|
|
|
gui_colorset.Unlock();
|
2003-02-14 04:53:53 +03:00
|
|
|
|
2003-03-31 01:09:39 +04:00
|
|
|
return dec;
|
2003-02-12 04:11:55 +03:00
|
|
|
}
|
|
|
|
|
2003-01-27 22:43:15 +03:00
|
|
|
/*!
|
|
|
|
\brief Entry function to run the entire server
|
|
|
|
\param argc Number of command-line arguments present
|
|
|
|
\param argv String array of the command-line arguments
|
|
|
|
\return -1 if the app_server is already running, 0 if everything's OK.
|
|
|
|
*/
|
2003-01-20 23:38:49 +03:00
|
|
|
int main( int argc, char** argv )
|
|
|
|
{
|
|
|
|
// There can be only one....
|
|
|
|
if(find_port(SERVER_PORT_NAME)!=B_NAME_NOT_FOUND)
|
|
|
|
return -1;
|
|
|
|
|
2005-03-13 20:07:40 +03:00
|
|
|
srand(real_time_clock_usecs());
|
2004-01-13 03:56:36 +03:00
|
|
|
AppServer app_server;
|
|
|
|
app_server.Run();
|
2003-01-20 23:38:49 +03:00
|
|
|
return 0;
|
|
|
|
}
|