haiku/src/servers/app/ServerApp.h
Stephan Aßmus f592fcef43 stippi + bonefish:
Fixed race conditions when a ServerApp or ServerWindow is created. The 
reply to the client that the object has been created successfully was 
sent in the thread creating it. Preempted at the wrong time (right after 
writing the message to the port) could lead to the object's thread using 
the link at the same time, which would screw up all subsequent 
communication via that link.
This fixes the problem that mimeset would sometimes fail when building 
Haiku in Haiku (can't find the ticket). It probably also fixes #2331, 
and the bug that sometimes when a window is opened (Terminal, crash 
alert, shutdown window, etc.) it would come up with huge width/height 
and tiny other dimension (can't find the ticket).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26192 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-07-01 15:47:56 +00:00

138 lines
3.6 KiB
C++

/*
* Copyright 2001-2006, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* DarkWyrm <bpmagic@columbus.rr.com>
* Adrian Oanca <adioanca@cotty.iren.ro>
* Stephan Aßmus <superstippi@gmx.de>
* Stefano Ceccherini (burton666@libero.it)
* Axel Dörfler, axeld@pinc-software.de
*/
#ifndef SERVER_APP_H
#define SERVER_APP_H
#include "ClientMemoryAllocator.h"
#include "MessageLooper.h"
#include <ObjectList.h>
#include <TokenSpace.h>
#include <Messenger.h>
#include <String.h>
class AreaPool;
class BMessage;
class BList;
class Desktop;
class DrawingEngine;
class ServerPicture;
class ServerCursor;
class ServerBitmap;
class ServerWindow;
namespace BPrivate {
class PortLink;
};
class ServerApp : public MessageLooper {
public:
ServerApp(Desktop* desktop,
port_id clientAppPort,
port_id clientLooperPort,
team_id clientTeamID,
int32 handlerID,
const char* signature);
virtual ~ServerApp();
status_t InitCheck();
void Quit(sem_id shutdownSemaphore = -1);
virtual port_id MessagePort() const { return fMessagePort; }
/*!
\brief Determines whether the application is the active one
\return true if active, false if not.
*/
bool IsActive(void) const { return fIsActive; }
void Activate(bool value);
void SendMessageToClient(BMessage* message) const;
void SetCurrentCursor(ServerCursor* cursor);
ServerCursor* CurrentCursor() const;
team_id ClientTeam() const;
const char* Signature() const { return fSignature.String(); }
const char* SignatureLeaf() const { return fSignature.String() + 12; }
bool AddWindow(ServerWindow* window);
void RemoveWindow(ServerWindow* window);
bool InWorkspace(int32 index) const;
uint32 Workspaces() const;
int32 InitialWorkspace() const { return fInitialWorkspace; }
int32 CountBitmaps() const;
ServerBitmap* FindBitmap(int32 token) const;
int32 CountPictures() const;
ServerPicture* CreatePicture(const ServerPicture* original = NULL);
ServerPicture* FindPicture(const int32& token) const;
bool DeletePicture(const int32& token);
Desktop* GetDesktop() const { return fDesktop; }
BPrivate::BTokenSpace& ViewTokens() { return fViewTokens; }
private:
virtual void _DispatchMessage(int32 code,
BPrivate::LinkReceiver& link);
virtual void _MessageLooper();
virtual void _GetLooperName(char* name, size_t size);
status_t _CreateWindow(int32 code,
BPrivate::LinkReceiver& link,
port_id& clientReplyPort);
bool _HasWindowUnderMouse();
port_id fMessagePort;
port_id fClientReplyPort;
// our BApplication's event port
BMessenger fHandlerMessenger;
port_id fClientLooperPort;
int32 fClientToken;
// To send a BMessage to the client
// (port + token)
Desktop* fDesktop;
BString fSignature;
team_id fClientTeam;
mutable BLocker fWindowListLock;
BObjectList<ServerWindow> fWindowList;
BPrivate::BTokenSpace fViewTokens;
int32 fInitialWorkspace;
// NOTE: Bitmaps and Pictures are stored globally, but ServerApps remember
// which ones they own so that they can destroy them when they quit.
// TODO:
// - As we reference these stuff by token, what about putting them in hash tables ?
BList fBitmapList;
BList fPictureList;
ServerCursor* fAppCursor;
ServerCursor* fViewCursor;
int32 fCursorHideLevel;
// 0 = cursor visible
bool fIsActive;
ClientMemoryAllocator fMemoryAllocator;
};
#endif // SERVER_APP_H