1//------------------------------------------------------------------------------
2//	Copyright (c) 2001-2005, Haiku, Inc.
3//
4//	Permission is hereby granted, free of charge, to any person obtaining a
5//	copy of this software and associated documentation files (the "Software"),
6//	to deal in the Software without restriction, including without limitation
7//	the rights to use, copy, modify, merge, publish, distribute, sublicense,
8//	and/or sell copies of the Software, and to permit persons to whom the
9//	Software is furnished to do so, subject to the following conditions:
10//
11//	The above copyright notice and this permission notice shall be included in
12//	all copies or substantial portions of the Software.
13//
14//	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15//	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16//	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17//	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18//	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19//	FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20//	DEALINGS IN THE SOFTWARE.
21//
22//	File Name:		ServerApp.h
23//	Author:			DarkWyrm <bpmagic@columbus.rr.com>
24//					Adi Oanca <adioanca@myrealbox.com>
25//	Description:	Server-side BApplication counterpart
26//
27//------------------------------------------------------------------------------
28#ifndef _SERVERAPP_H_
29#define _SERVERAPP_H_
30
31#include <OS.h>
32#include <String.h>
33#include <PortLink.h>
34
35class BMessage;
36class BList;
37class DisplayDriver;
38
39namespace BPrivate {
40	class PortLink;
41};
42
43/*!
44	\class ServerApp ServerApp.h
45	\brief Counterpart to BApplication within the app_server
46*/
47class ServerApp {
48public:
49	ServerApp(port_id sendport, port_id rcvport, port_id clientLooperPort,
50		team_id clientTeamID, int32 handlerID, const char* signature);
51	virtual	~ServerApp(void);
52
53	bool Run(void);
54
55	bool IsActive(void) const { return fIsActive; }
56	void Activate(bool value);
57
58	bool PingTarget(void);
59
60	void PostMessage(int32 code);
61	void SendMessageToClient( const BMessage* msg ) const;
62
63	team_id	ClientTeamID() const;
64	thread_id MonitorThreadID() const;
65
66	const char *Title() const { return fSignature.String(); }
67
68private:
69	void DispatchMessage(int32 code, BPrivate::LinkReceiver &link);
70
71	static int32 MonitorApp(void *data);
72
73	// our BApplication's event port
74	port_id	fClientAppPort;
75	// port we receive messages from our BApplication
76	port_id	fMessagePort;
77			// TODO: find out why there is both the app port and the looper port. Do
78			// we really need both? Actually, we aren't using any of these ports,
79			// as BAppServerLink/BPortlink's messages always contain the reply port
80	// To send a message to the client, write a BMessage to this port
81	port_id	fClientLooperPort;
82
83	BString fSignature;
84
85	thread_id fMonitorThreadID;
86	team_id fClientTeamID;
87
88	BPrivate::PortLink fLink;
89
90	// TODO:
91	// - Are really Bitmaps and Pictures stored per application and not globally ?
92	// - As we reference these stuff by token, what about putting them in hash tables ?
93	BList *fSWindowList;
94
95	// TODO: Not used.
96	sem_id fLockSem;
97
98	bool fCursorHidden;
99	bool fIsActive;
100
101	// token ID of the BApplication's BHandler object.
102	// Used for BMessage target specification
103	// TODO: Is it still needed ? We aren't using it.
104	//int32 fHandlerToken;
105
106	bool fQuitting;
107};
108
109#endif	// _SERVERAPP_H_
110