app_server: fix test-app_server for launch_daemon changes

* Make test-app_server work again in a launch_daemon environment

* test_registrar gets a separate signature and port name again so the
  host system can distinguish it from the system registrar

* AppServer is normally a BServer now, however, there can't be two
  BApplications in one team. A class TestServerLoopAdapter is added,
  which becomes the base class of AppServer instead of BServer when
  compiling for libbe_test. It's an adapter class which looks towards
  AppServer as it if was a BServer, but internally it is derived from
  MessageLooper (like the old AppServer before the transition to
  BServer).

  This way, AppServer can stay a BServer in normal builds and it also
  avoids having to use too many #ifdefs to distinguish the two
  versions.
This commit is contained in:
Julian Harnath
2015-08-23 01:00:32 +02:00
parent 801b5d2119
commit e3d7394869
17 changed files with 381 additions and 16 deletions
+8 -1
View File
@@ -23,7 +23,14 @@ namespace BPrivate {
extern const char* kRAppLooperPortName;
#define B_REGISTRAR_SIGNATURE "application/x-vnd.haiku-registrar"
#ifndef HAIKU_TARGET_PLATFORM_LIBBE_TEST
# define B_REGISTRAR_SIGNATURE "application/x-vnd.haiku-registrar"
# define B_REGISTRAR_PORT_NAME "system:roster"
#else
# define B_REGISTRAR_SIGNATURE "application/x-vnd.test-registrar"
# define B_REGISTRAR_PORT_NAME "haiku-test:roster"
#endif
#define B_REGISTRAR_AUTHENTICATION_PORT_NAME "auth"
+4
View File
@@ -16,6 +16,10 @@
#include <SupportDefs.h>
#ifdef HAIKU_TARGET_PLATFORM_LIBBE_TEST
# define SERVER_PORT_NAME "haiku-test:app_server"
#endif
#if TEST_MODE
# define SERVER_INPUT_PORT "haiku-test:input port"
#endif
+60
View File
@@ -176,6 +176,9 @@ is_app_showing_modal_window(team_id team)
}
#ifndef HAIKU_TARGET_PLATFORM_LIBBE_TEST
/*! Creates a connection with the desktop.
*/
status_t
@@ -208,4 +211,61 @@ create_desktop_connection(ServerLink* link, const char* name, int32 capacity)
}
#else // HAIKU_TARGET_PLATFORM_LIBBE_TEST
static port_id sServerPort = -1;
port_id
get_app_server_port()
{
if (sServerPort < 0) {
// No need for synchronization - in the worst case, we'll call
// find_port() twice.
sServerPort = find_port(SERVER_PORT_NAME);
}
return sServerPort;
}
/*! Creates a connection with the desktop.
*/
status_t
create_desktop_connection(ServerLink* link, const char* name, int32 capacity)
{
port_id serverPort = get_app_server_port();
if (serverPort < 0)
return serverPort;
// Create the port so that the app_server knows where to send messages
port_id clientPort = create_port(capacity, name);
if (clientPort < 0)
return clientPort;
link->SetTo(serverPort, clientPort);
link->StartMessage(AS_GET_DESKTOP);
link->Attach<port_id>(clientPort);
link->Attach<int32>(getuid());
link->AttachString(getenv("TARGET_SCREEN"));
link->Attach<int32>(AS_PROTOCOL_VERSION);
int32 code;
if (link->FlushWithReply(code) != B_OK || code != B_OK) {
link->SetSenderPort(-1);
return B_ERROR;
}
link->Read<port_id>(&serverPort);
link->SetSenderPort(serverPort);
return B_OK;
}
#endif // HAIKU_TARGET_PLATFORM_LIBBE_TEST
} // namespace BPrivate
+13 -2
View File
@@ -2604,9 +2604,10 @@ BRoster::_InitMessenger()
DBG(OUT("BRoster::InitMessengers()\n"));
// find the registrar port
#ifndef HAIKU_TARGET_PLATFORM_LIBBE_TEST
BMessage data;
if (BLaunchRoster().GetData("application/x-vnd.Haiku-registrar", data)
== B_OK) {
if (BLaunchRoster().GetData(B_REGISTRAR_SIGNATURE, data) == B_OK) {
port_id port = data.GetInt32("port", -1);
team_id team = data.GetInt32("team", -1);
if (port >= 0) {
@@ -2616,6 +2617,16 @@ BRoster::_InitMessenger()
B_PREFERRED_TOKEN);
}
}
#else
port_id rosterPort = find_port(B_REGISTRAR_PORT_NAME);
port_info info;
if (rosterPort >= 0 && get_port_info(rosterPort, &info) == B_OK) {
DBG(OUT(" found roster port\n"));
BMessenger::Private(fMessenger).SetTo(info.team, rosterPort,
B_PREFERRED_TOKEN);
}
#endif
DBG(OUT("BRoster::InitMessengers() done\n"));
}
+6 -2
View File
@@ -48,7 +48,8 @@ uint32 gAppServerSIMDFlags = 0;
*/
AppServer::AppServer(status_t* status)
:
BServer("application/x-vnd.Haiku-app_server", "picasso", -1, false, status),
SERVER_BASE("application/x-vnd.Haiku-app_server", "picasso", -1, false,
status),
fDesktopLock("AppServerDesktopLock")
{
openlog("app_server", 0, LOG_DAEMON);
@@ -153,7 +154,10 @@ AppServer::QuitRequested()
wait_for_thread(thread, &status);
}
return BServer::QuitRequested();
delete this;
exit(0);
return SERVER_BASE::QuitRequested();
#else
return false;
#endif
+11 -3
View File
@@ -15,7 +15,6 @@
#include <Locker.h>
#include <ObjectList.h>
#include <OS.h>
#include <Server.h>
#include <String.h>
#include <Window.h>
@@ -23,12 +22,21 @@
#include "ServerConfig.h"
#ifndef HAIKU_TARGET_PLATFORM_LIBBE_TEST
# include <Server.h>
# define SERVER_BASE BServer
#else
# include "TestServerLoopAdapter.h"
# define SERVER_BASE TestServerLoopAdapter
#endif
class ServerApp;
class BitmapManager;
class Desktop;
class AppServer : public BServer {
class AppServer : public SERVER_BASE {
public:
AppServer(status_t* status);
virtual ~AppServer();
@@ -39,7 +47,7 @@ public:
private:
Desktop* _CreateDesktop(uid_t userID,
const char* targetScreen);
Desktop* _FindDesktop(uid_t userID,
virtual Desktop* _FindDesktop(uid_t userID,
const char* targetScreen);
void _LaunchInputServer();
+2 -2
View File
@@ -154,9 +154,9 @@ MessageLooper::_MessageLooper()
Lock();
if (code == kMsgQuitLooper) {
if (code == kMsgQuitLooper)
Quit();
} else
else
_DispatchMessage(code, receiver);
Unlock();
+121
View File
@@ -0,0 +1,121 @@
/*
* Copyright 2001-2015, Haiku, Inc.
* Distributed under the terms of the MIT license.
*
* Authors:
* DarkWyrm <bpmagic@columbus.rr.com>
* Axel Dörfler, axeld@pinc-software.de
* Stephan Aßmus <superstippi@gmx.de>
* Christian Packmann
* Julian Harnath <julian.harnath@rwth-aachen.de>
*/
#include "TestServerLoopAdapter.h"
#include "Desktop.h"
#include "ServerConfig.h"
#include "ServerProtocol.h"
#include <PortLink.h>
#include <stdio.h>
//#define DEBUG_SERVER
#ifdef DEBUG_SERVER
# include <stdio.h>
# define STRACE(x) printf x
#else
# define STRACE(x) ;
#endif
TestServerLoopAdapter::TestServerLoopAdapter(const char* signature,
const char*, port_id, bool, status_t* outError)
:
MessageLooper("test-app_server"),
fMessagePort(_CreatePort())
{
fLink.SetReceiverPort(fMessagePort);
*outError = B_OK;
}
TestServerLoopAdapter::~TestServerLoopAdapter()
{
}
bool
TestServerLoopAdapter::Run()
{
rename_thread(find_thread(NULL), "picasso");
_message_thread((void*)this);
return true;
}
void
TestServerLoopAdapter::_DispatchMessage(int32 code,
BPrivate::LinkReceiver& link)
{
switch (code) {
case AS_GET_DESKTOP:
{
port_id replyPort = 0;
link.Read<port_id>(&replyPort);
int32 userID = -1;
link.Read<int32>(&userID);
char* targetScreen = NULL;
link.ReadString(&targetScreen);
int32 version = -1;
link.Read<int32>(&version);
BMessage message(AS_GET_DESKTOP);
message.AddInt32("user", userID);
message.AddInt32("version", version);
message.AddString("target", targetScreen);
MessageReceived(&message);
// AppServer will try to send a reply, we just let that fail
// since we can find out the port by getting the desktop instance
// ourselves
free(targetScreen);
Desktop* desktop = _FindDesktop(userID, targetScreen);
BPrivate::LinkSender reply(replyPort);
if (desktop != NULL) {
reply.StartMessage(B_OK);
reply.Attach<port_id>(desktop->MessagePort());
} else
reply.StartMessage(B_ERROR);
reply.Flush();
break;
}
case B_QUIT_REQUESTED:
{
QuitRequested();
break;
}
default:
STRACE(("Server::MainLoop received unexpected code %" B_PRId32 " "
"(offset %" B_PRId32 ")\n", code, code - SERVER_TRUE));
break;
}
}
port_id
TestServerLoopAdapter::_CreatePort()
{
port_id port = create_port(DEFAULT_MONITOR_PORT_SIZE, SERVER_PORT_NAME);
if (port < B_OK)
debugger("test-app_server could not create message port");
return port;
}
+51
View File
@@ -0,0 +1,51 @@
/*
* Copyright 2001-2015, Haiku, Inc.
* Distributed under the terms of the MIT license.
*
* Authors:
* DarkWyrm <bpmagic@columbus.rr.com>
* Axel Dörfler, axeld@pinc-software.de
* Julian Harnath, <julian.harnath@rwth-aachen.de>
*/
#ifndef TEST_SERVER_LOOP_ADAPTER_H
#define TEST_SERVER_LOOP_ADAPTER_H
#include "MessageLooper.h"
class BMessage;
class Desktop;
class TestServerLoopAdapter : public MessageLooper {
public:
TestServerLoopAdapter(const char* signature,
const char* looperName, port_id port,
bool initGui, status_t* outError);
virtual ~TestServerLoopAdapter();
// MessageLooper interface
virtual port_id MessagePort() const { return fMessagePort; }
virtual bool Run();
// BApplication interface
virtual void MessageReceived(BMessage* message) = 0;
virtual bool QuitRequested() { return true; }
private:
// MessageLooper interface
virtual void _DispatchMessage(int32 code,
BPrivate::LinkReceiver &link);
virtual Desktop* _FindDesktop(uid_t userID,
const char* targetScreen) = 0;
port_id _CreatePort();
private:
port_id fMessagePort;
};
#endif // TEST_SERVER_LOOP_ADAPTER_H
@@ -694,7 +694,8 @@ DWindowHWInterface::SetMode(const display_mode& mode)
// has not been created either, but we need one to display
// a real BWindow in the test environment.
// be_app->Run() needs to be called in another thread
BApplication* app = new BApplication("application/x-vnd.haiku-app-server");
BApplication* app = new BApplication(
"application/x-vnd.Haiku-test-app_server");
app->Unlock();
thread_id appThread = spawn_thread(run_app_thread, "app thread",
+2 -1
View File
@@ -483,7 +483,8 @@ ViewHWInterface::SetMode(const display_mode& mode)
// has not been created either, but we need one to display
// a real BWindow in the test environment.
// be_app->Run() needs to be called in another thread
BApplication* app = new BApplication("application/x-vnd.haiku-app-server");
BApplication* app = new BApplication(
"application/x-vnd.Haiku-test-app_server");
app->Unlock();
thread_id appThread = spawn_thread(run_app_thread, "app thread",
+1 -1
View File
@@ -2,7 +2,7 @@
* app_server.rdef
*/
resource app_signature "application/x-vnd.Haiku-app-server";
resource app_signature "application/x-vnd.Haiku-test-app_server";
resource app_flags B_EXCLUSIVE_LAUNCH ;
+1 -1
View File
@@ -57,7 +57,7 @@ static const bigtime_t kRosterSanityEventInterval = 1000000LL;
*/
Registrar::Registrar(status_t* _error)
:
BServer(B_REGISTRAR_SIGNATURE, "system:roster", -1, false, _error),
BServer(B_REGISTRAR_SIGNATURE, B_REGISTRAR_PORT_NAME, -1, false, _error),
fRoster(NULL),
fClipboardHandler(NULL),
fMIMEManager(NULL),
+1
View File
@@ -127,6 +127,7 @@ SharedLibrary libtestappserver.so :
ProfileMessageSupport.cpp
EventDispatcher.cpp
EventStream.cpp
TestServerLoopAdapter.cpp
MessageLooper.cpp
# Decorator
+1 -1
View File
@@ -110,7 +110,7 @@ Server test_registrar
libstorage_kit_mime.a
be localestub [ TargetLibstdc++ ]
:
registrar.rdef
test_registrar.rdef
;
if $(TARGET_PLATFORM) = libbe_test {
@@ -53,7 +53,7 @@ main(int argc, char* argv[])
while (get_next_thread_info(teamInfo.team, &threadCookie, &threadInfo)
== B_OK) {
// search for the roster thread
if (!strcmp(threadInfo.name, "_roster_thread_")) {
if (!strcmp(threadInfo.name, "roster")) {
port_id port = find_port("haiku-test:roster");
port_info portInfo;
if (get_port_info(port, &portInfo) == B_OK
@@ -0,0 +1,96 @@
/*
* registrar.rdef
*/
resource app_signature "application/x-vnd.test-registrar";
resource app_flags B_EXCLUSIVE_LAUNCH | B_BACKGROUND_APP;
/* the registrar's application flags are actually
* ignored.
* The actually used flags are set in TRoster::Init().
*/
resource app_version {
major = 1,
middle = 0,
minor = 0,
variety = B_APPV_ALPHA,
internal = 0,
short_info = "registrar",
long_info = "registrar ©2005-2008 Haiku Inc."
};
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
resource vector_icon array {
$"6E6369660704006B0500020006023BB8A43D8642BF898E3DBC1F4BAE5447805C"
$"00E3AD00FFBC8F05020106023D66A73B07B6B9BEF73C1A2B48379549C4DE3D76"
$"9564FF536E4402000602B898C93319083A5C163FF4CC4AB5EA4451BB00B58A00"
$"FF8565030200060236EEF83B80F5BF3E743AB74A4B669742DBD600FFEFC0FFFF"
$"DE7C05FF0D0A044D5B585B59594D530A0626484C5B4E594E32282626270A0426"
$"484C5B4C3426270A0448542A452A2C48370A042C442C2D2A2C2A450A044C5B4E"
$"594E324C340A04282626274C344E320A042A45485448512C4408023133313C08"
$"023534353E08023936394008023D373D4208022E344040090A00010010011584"
$"00040A0101011001178400040A020102000A030103000A040104000A04010500"
$"0A050106000A050107000A06050C0B0A0908100117820004"
};
#else
resource large_icon array {
$"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
$"FFFFFFFFFF000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
$"FFFFFFFF00D9D9D90000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
$"FFFFFFFF00D98383D9D90000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
$"FFFFFFFF00D900008383D9D90000FFFFFFFFFFFFFFFFFF00000000FFFFFFFFFF"
$"FFFFFFFF00D9008F00008383D9D9000000000000FFFF003FD9D9D90000FFFFFF"
$"FFFFFFFF00D9008F8F8F00008383D9D900003F3F00003FD9D9D9D9D9D90000FF"
$"FFFFFFFF00D9008F3F8F8F8F00008383D9D900003F3FAAAAD9D9D9D9D9D98300"
$"FFFFFFFF00D9003F3F8F3F8F8F8F00008383D9D900008383AAAAD9D9D983AA00"
$"FFFFFFFF00D9008F3F3F3F8F3F8F8F8F00008383D9D900003F3FAAAA83AAAA00"
$"FFFFFFFF00D9008F3F8F3F8F3F8F8F8F8F8F00008383D9D900D93F3FAAAAAA00"
$"FFFFFFFF00D9008F3F8F3F3F3F8F8F8F8F8F8F8F000083AA00D9D9D983AA0111"
$"FFFFFFFF00D9008F8F8F3F8F3F8F8F8F8F8F8F8F8F0083AA00D9D9D9D9AA0017"
$"FFFFFFFF00D9008F8F8F8F8F3F3F8F8F8F8F8F8F8F0083AA00D9D9D9D9830011"
$"FFFFFFFF00D9008F8F8F8F8F8F8F3F8F8F8F8F8F8F0083AA00D9D9D983AA0111"
$"FFFFFFFF00D900008F8F8F8F8F8F8F8F8F8F8F8F8F0083AA00D9D983AA001111"
$"FFFFFFFF0000838300008F8F8F8F8F8F8F8F8F8F8F0083AA00D983AA001111FF"
$"FFFFFFFFFF000000838300008F8F8F8F8F8F8F8F8F0083AA0083AA001111FFFF"
$"FFFFFFFF003FD9830000838300008F8F8F8F8F8F8F0083AA00AA001111FFFFFF"
$"FFFFFF003FD98383001E0000838300008F8F8F8F8F0083AA00001111FFFFFFFF"
$"FFFF003FD98383031ED9D9830000838300008F8F8F0083AA001111FFFFFFFFFF"
$"FF003FD98383003FD9D98383003F0000838300008F0083AA0011FFFFFFFFFFFF"
$"003FD98383003FD9D98383003FD9D9D900008383000083AA0011FFFFFFFFFFFF"
$"00D98383003FD9D98383003FD9D98383003F0000838383AA0011FFFFFFFFFFFF"
$"FF0000003FD9D98383003FD9D98383003FD98383000083001111FFFFFFFFFFFF"
$"FFFF003FD9D98383003FD9D98383003FD98383001111001111FFFFFFFFFFFFFF"
$"FFFF00D9838306003FD9D98383003FD98383001111FFFFFFFFFFFFFFFFFFFFFF"
$"FFFFFF0000001000D9D98383003FD98383001111FFFFFFFFFFFFFFFFFFFFFFFF"
$"FFFFFFFFFFFFFFFF000000003FD98300001111FFFFFFFFFFFFFFFFFFFFFFFFFF"
$"FFFFFFFFFFFFFFFFFFFFFFFF000000111111FFFFFFFFFFFFFFFFFFFFFFFFFFFF"
$"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
$"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
};
resource mini_icon array {
$"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
$"FFFF000000FFFFFFFFFFFFFFFFFFFFFF"
$"FF03D9D9D90000FFFFFFFF0000FFFFFF"
$"FF03D9B6B6D9D900000000D9D90000FF"
$"FF03D9B669B6B6D9D90000AAAAD98300"
$"FF03D9B6116868B6B6D9D9003FAAAA00"
$"FF03D9B68F681B8FB683AA00D9D9AA00"
$"FF03D9B68F181B8FB683AA003FD9AA01"
$"FF03D9B6B68F188FB683AA00D9830011"
$"FF03038383B6B68FB683AA00830011FF"
$"FF00D933048383B6B683AA000011FFFF"
$"00D98300D90303838383AA0011FFFFFF"
$"008300D98300D90303030011FFFFFFFF"
$"FF00D98300D900D9830011FFFFFFFFFF"
$"FFFF0000000000000011FFFFFFFFFFFF"
$"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
};
#endif // HAIKU_TARGET_PLATFORM_HAIKU