xref: /haiku/src/servers/app/ServerApp.h (revision 5412911f7f8ca41340b0f5cb928ed9726322ab44)
1 /*
2  * Copyright 2001-2005, 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 _SERVERAPP_H_
13 #define _SERVERAPP_H_
14 
15 
16 #include "MessageLooper.h"
17 #include "SubWindowList.h"
18 #include "BGet++.h"
19 
20 #include <ObjectList.h>
21 #include <String.h>
22 
23 
24 class AreaPool;
25 class BMessage;
26 class BList;
27 class Desktop;
28 class DrawingEngine;
29 class ServerPicture;
30 class ServerCursor;
31 class ServerBitmap;
32 class ServerWindow;
33 
34 namespace BPrivate {
35 	class PortLink;
36 };
37 
38 class ServerApp : public MessageLooper {
39 	public:
40 		ServerApp(Desktop* desktop, port_id clientAppPort,
41 			port_id clientLooperPort, team_id clientTeamID,
42 			int32 handlerID, const char* signature);
43 		virtual ~ServerApp();
44 
45 		status_t InitCheck();
46 		void Quit(sem_id shutdownSemaphore = -1);
47 
48 		virtual bool Run();
49 		virtual port_id MessagePort() const { return fMessagePort; }
50 
51 		/*!
52 			\brief Determines whether the application is the active one
53 			\return true if active, false if not.
54 		*/
55 		bool IsActive(void) const { return fIsActive; }
56 		void Activate(bool value);
57 
58 		void SendMessageToClient(const BMessage* msg) const;
59 
60 		void SetAppCursor(void);
61 
62 		team_id	ClientTeam() const;
63 		const char *Signature() const { return fSignature.String(); }
64 
65 		void RemoveWindow(ServerWindow* window);
66 
67 		int32 CountBitmaps() const;
68 		ServerBitmap *FindBitmap(int32 token) const;
69 
70 		int32 CountPictures() const;
71 		ServerPicture *FindPicture(int32 token) const;
72 
73 		AreaPool *AppAreaPool() { return &fSharedMem; }
74 
75 		Desktop* GetDesktop() const { return fDesktop; }
76 
77 		// ToDo: public?
78 		SubWindowList fAppSubWindowList;
79 
80 	private:
81 		virtual void _DispatchMessage(int32 code, BPrivate::LinkReceiver &link);
82 		virtual void _MessageLooper();
83 		virtual void _GetLooperName(char* name, size_t size);
84 
85 		port_id	fMessagePort;
86 		port_id	fClientReplyPort;
87 			// our BApplication's event port
88 
89 		port_id	fClientLooperPort;
90 		int32 fClientToken;
91 			// To send a BMessage to the client (port + token)
92 
93 		Desktop* fDesktop;
94 		BString fSignature;
95 		team_id fClientTeam;
96 
97 		BLocker fWindowListLock;
98 		BObjectList<ServerWindow> fWindowList;
99 
100 		// TODO:
101 		// - Are really Bitmaps and Pictures stored per application and not globally ?
102 		// - As we reference these stuff by token, what about putting them in hash tables ?
103 		BList fBitmapList;
104 		BList fPictureList;
105 
106 		ServerCursor *fAppCursor;
107 		bool fCursorHidden;
108 
109 		bool fIsActive;
110 
111 		AreaPool fSharedMem;
112 };
113 
114 #endif	// _SERVERAPP_H_
115