1 /* 2 * Copyright 2001-2006, Haiku. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * DarkWyrm <bpmagic@columbus.rr.com> 7 * Adrian Oanca <adioanca@cotty.iren.ro> 8 * Stephan Aßmus <superstippi@gmx.de> 9 * Stefano Ceccherini (burton666@libero.it) 10 * Axel Dörfler, axeld@pinc-software.de 11 */ 12 #ifndef SERVER_APP_H 13 #define SERVER_APP_H 14 15 16 #include "ClientMemoryAllocator.h" 17 #include "MessageLooper.h" 18 19 #include <ObjectList.h> 20 #include <TokenSpace.h> 21 22 #include <Messenger.h> 23 #include <String.h> 24 25 26 class AreaPool; 27 class BMessage; 28 class BList; 29 class Desktop; 30 class DrawingEngine; 31 class ServerPicture; 32 class ServerCursor; 33 class ServerBitmap; 34 class ServerWindow; 35 36 namespace BPrivate { 37 class PortLink; 38 }; 39 40 class ServerApp : public MessageLooper { 41 public: 42 ServerApp(Desktop* desktop, 43 port_id clientAppPort, 44 port_id clientLooperPort, 45 team_id clientTeamID, 46 int32 handlerID, 47 const char* signature); 48 virtual ~ServerApp(); 49 50 status_t InitCheck(); 51 void Quit(sem_id shutdownSemaphore = -1); 52 53 virtual bool Run(); 54 virtual port_id MessagePort() const { return fMessagePort; } 55 56 /*! 57 \brief Determines whether the application is the active one 58 \return true if active, false if not. 59 */ 60 bool IsActive(void) const { return fIsActive; } 61 void Activate(bool value); 62 63 void SendMessageToClient(BMessage* message) const; 64 65 void SetCurrentCursor(ServerCursor* cursor); 66 ServerCursor* CurrentCursor() const; 67 68 team_id ClientTeam() const; 69 const char* Signature() const { return fSignature.String(); } 70 const char* SignatureLeaf() const { return fSignature.String() + 12; } 71 72 bool AddWindow(ServerWindow* window); 73 void RemoveWindow(ServerWindow* window); 74 bool InWorkspace(int32 index) const; 75 uint32 Workspaces() const; 76 int32 InitialWorkspace() const { return fInitialWorkspace; } 77 78 int32 CountBitmaps() const; 79 ServerBitmap* FindBitmap(int32 token) const; 80 81 int32 CountPictures() const; 82 ServerPicture* CreatePicture(const ServerPicture* original = NULL); 83 ServerPicture* FindPicture(const int32& token) const; 84 bool DeletePicture(const int32& token); 85 86 Desktop* GetDesktop() const { return fDesktop; } 87 88 BPrivate::BTokenSpace& ViewTokens() { return fViewTokens; } 89 90 private: 91 virtual void _DispatchMessage(int32 code, 92 BPrivate::LinkReceiver& link); 93 virtual void _MessageLooper(); 94 virtual void _GetLooperName(char* name, size_t size); 95 status_t _CreateWindow(int32 code, 96 BPrivate::LinkReceiver& link, 97 port_id& clientReplyPort); 98 99 bool _HasWindowUnderMouse(); 100 101 port_id fMessagePort; 102 port_id fClientReplyPort; 103 // our BApplication's event port 104 105 BMessenger fHandlerMessenger; 106 port_id fClientLooperPort; 107 int32 fClientToken; 108 // To send a BMessage to the client 109 // (port + token) 110 111 Desktop* fDesktop; 112 BString fSignature; 113 team_id fClientTeam; 114 115 mutable BLocker fWindowListLock; 116 BObjectList<ServerWindow> fWindowList; 117 BPrivate::BTokenSpace fViewTokens; 118 119 int32 fInitialWorkspace; 120 121 // NOTE: Bitmaps and Pictures are stored globally, but ServerApps remember 122 // which ones they own so that they can destroy them when they quit. 123 // TODO: 124 // - As we reference these stuff by token, what about putting them in hash tables ? 125 BList fBitmapList; 126 BList fPictureList; 127 128 ServerCursor* fAppCursor; 129 ServerCursor* fViewCursor; 130 int32 fCursorHideLevel; 131 // 0 = cursor visible 132 133 bool fIsActive; 134 135 ClientMemoryAllocator fMemoryAllocator; 136 }; 137 138 #endif // SERVER_APP_H 139