diff --git a/headers/private/app/LinkMsgReader.h b/headers/private/app/LinkMsgReader.h index c486c88032..bd0cc0f2ed 100644 --- a/headers/private/app/LinkMsgReader.h +++ b/headers/private/app/LinkMsgReader.h @@ -23,7 +23,9 @@ class LinkMsgReader { port_id Port(void) { return fReceivePort; } status_t GetNextMessage(int32 &code, bigtime_t timeout = B_INFINITE_TIMEOUT); - status_t Read(void *data, ssize_t size); + bool NeedsReply() const; + + virtual status_t Read(void *data, ssize_t size); status_t ReadString(char **string); template status_t Read(Type *data) { diff --git a/headers/private/app/PortLink.h b/headers/private/app/PortLink.h index 4c0fbb8ad3..333ff11388 100644 --- a/headers/private/app/PortLink.h +++ b/headers/private/app/PortLink.h @@ -61,7 +61,8 @@ class BPortLink { void SetReplyPort(port_id port); port_id ReplyPort(); - status_t GetNextReply(int32 &code, bigtime_t timeout = B_INFINITE_TIMEOUT); + status_t GetNextMessage(int32 &code, bigtime_t timeout = B_INFINITE_TIMEOUT); + bool NeedsReply() const; status_t Read(void *data, ssize_t size); status_t ReadString(char **string); status_t ReadRegion(BRegion *region); @@ -71,6 +72,8 @@ class BPortLink { // convenience methods status_t FlushWithReply(int32 &code); + LinkMsgReader &Reader() { return *fReader; } + LinkMsgSender &Sender() { return *fSender; } protected: LinkMsgReader *fReader; @@ -148,11 +151,17 @@ BPortLink::ReplyPort() } inline status_t -BPortLink::GetNextReply(int32 &code, bigtime_t timeout) +BPortLink::GetNextMessage(int32 &code, bigtime_t timeout) { return fReader->GetNextMessage(code, timeout); } +inline bool +BPortLink::NeedsReply() const +{ + return fReader->NeedsReply(); +} + inline status_t BPortLink::Read(void *data, ssize_t size) { diff --git a/src/kits/app/AppServerLink.cpp b/src/kits/app/AppServerLink.cpp index 273ee775f1..75a3e1311e 100644 --- a/src/kits/app/AppServerLink.cpp +++ b/src/kits/app/AppServerLink.cpp @@ -34,7 +34,6 @@ BLocker sLock; -port_id sReplyPort = -1; namespace BPrivate { @@ -44,15 +43,10 @@ BAppServerLink::BAppServerLink(void) sLock.Lock(); // if there is no be_app, we can't do a whole lot, anyway - if (be_app) + if (be_app) { SetSendPort(be_app->fServerFrom); - - // There is only one global reply port, and we create it here - // (protected by sLock) when it's not yet there - if (sReplyPort < B_OK) - sReplyPort = create_port(100, "AppServerLink reply port"); - - SetReplyPort(sReplyPort); + SetReplyPort(be_app->fServerTo); + } } @@ -65,17 +59,11 @@ BAppServerLink::~BAppServerLink() status_t BAppServerLink::FlushWithReply(int32 *code) { - status_t err; - - err = Attach(sReplyPort); - if (err < B_OK) - return err; + status_t status = Flush(B_INFINITE_TIMEOUT, true); + if (status < B_OK) + return status; - err = Flush(); - if (err < B_OK) - return err; - - return GetNextReply(*code); + return GetNextMessage(*code); } } // namespace BPrivate diff --git a/src/kits/app/LinkMsgReader.cpp b/src/kits/app/LinkMsgReader.cpp index 9b048b9587..a21ad406cf 100644 --- a/src/kits/app/LinkMsgReader.cpp +++ b/src/kits/app/LinkMsgReader.cpp @@ -102,6 +102,17 @@ LinkMsgReader::GetNextMessage(int32 &code, bigtime_t timeout) } +bool +LinkMsgReader::NeedsReply() const +{ + if (fReplySize == 0) + return false; + + message_header *header = (message_header *)(fRecvBuffer + fRecvStart); + return (header->flags & kNeedsReply) != 0; +} + + void LinkMsgReader::ResetBuffer() { diff --git a/src/kits/app/PortLink.cpp b/src/kits/app/PortLink.cpp index db71038ddc..28da5d68b6 100644 --- a/src/kits/app/PortLink.cpp +++ b/src/kits/app/PortLink.cpp @@ -92,9 +92,9 @@ BPortLink::AttachShape(BShape &shape) status_t BPortLink::FlushWithReply(int32 &code) { - status_t status = Flush(); + status_t status = Flush(B_INFINITE_TIMEOUT, true); if (status < B_OK) return status; - return GetNextReply(code); + return GetNextMessage(code); } diff --git a/src/servers/app/AppServer.cpp b/src/servers/app/AppServer.cpp index 9a7cb6f7bc..861e227da4 100644 --- a/src/servers/app/AppServer.cpp +++ b/src/servers/app/AppServer.cpp @@ -257,22 +257,16 @@ AppServer::~AppServer(void) int32 AppServer::PicassoThread(void *data) { - int32 i; - AppServer *appserver=(AppServer*)data; - ServerApp *app; - for(;;) - { - i = 0; - acquire_sem(appserver->fAppListLock); - for(;;) - { - app=(ServerApp*)appserver->fAppList->ItemAt(i++); - if(!app) + for (;;) { + acquire_sem(sAppServer->fAppListLock); + for (int32 i = 0;;) { + ServerApp *app = (ServerApp *)sAppServer->fAppList->ItemAt(i++); + if (!app) break; app->PingTarget(); } - release_sem(appserver->fAppListLock); + release_sem(sAppServer->fAppListLock); // we do this every other second so as not to suck *too* many CPU cycles snooze(1000000); } @@ -407,7 +401,7 @@ AppServer::MainLoop(void) STRACE(("info: AppServer::MainLoop listening on port %ld.\n", fMessagePort)); int32 code; - status_t err = pmsg.GetNextReply(code); + status_t err = pmsg.GetNextMessage(code); if (err < B_OK) { STRACE(("MainLoop:pmsg.GetNextReply failed\n")); continue; @@ -424,12 +418,12 @@ AppServer::MainLoop(void) case AS_SET_DECORATOR: case AS_GET_DECORATOR: case AS_R5_SET_DECORATOR: - DispatchMessage(code,pmsg); + DispatchMessage(code, pmsg); break; default: { - STRACE(("Server::MainLoop received unexpected code %ld(offset %ld)\n", - code,code-SERVER_TRUE)); + STRACE(("Server::MainLoop received unexpected code %ld (offset %ld)\n", + code, code - SERVER_TRUE)); break; } } @@ -464,19 +458,19 @@ AppServer::LoadDecorator(const char *path) status_t stat; image_id addon; - addon= load_add_on(path); - if(addon < 0) + addon = load_add_on(path); + if (addon < B_OK) return false; // As of now, we do nothing with decorator versions, but the possibility exists // that the API will change even though I cannot forsee any reason to do so. If // we *did* do anything with decorator versions, the assignment to a global would // go here. - + // Get the instantiation function - stat= get_image_symbol(addon, "instantiate_decorator", B_SYMBOL_TYPE_TEXT, (void**)&pcreatefunc); - if(stat != B_OK) - { + stat = get_image_symbol(addon, "instantiate_decorator", + B_SYMBOL_TYPE_TEXT, (void**)&pcreatefunc); + if (stat != B_OK) { unload_add_on(addon); return false; } @@ -497,33 +491,29 @@ AppServer::InitDecorators(void) { BMessage settings; - BDirectory dir,newdir; - if(dir.SetTo(SERVER_SETTINGS_DIR)==B_ENTRY_NOT_FOUND) - create_directory(SERVER_SETTINGS_DIR,0777); + BDirectory dir; + if (dir.SetTo(SERVER_SETTINGS_DIR) == B_ENTRY_NOT_FOUND) + create_directory(SERVER_SETTINGS_DIR, 0777); BString path(SERVER_SETTINGS_DIR); - path+="DecoratorSettings"; - BFile file(path.String(),B_READ_ONLY); + path += "DecoratorSettings"; + BFile file(path.String(), B_READ_ONLY); - if(file.InitCheck()==B_OK) - { - if(settings.Unflatten(&file)==B_OK) - { - BString itemtext; - if(settings.FindString("decorator",&itemtext)==B_OK) - { - path.SetTo(DECORATORS_DIR); - path+=itemtext; - if(LoadDecorator(path.String())) - return; - } + if (file.InitCheck() == B_OK + && settings.Unflatten(&file) == B_OK) { + BString itemtext; + if (settings.FindString("decorator", &itemtext) == B_OK) { + path.SetTo(DECORATORS_DIR); + path += itemtext; + if (LoadDecorator(path.String())) + return; } } // We got this far, so something must have gone wrong. We set make_decorator // to NULL so that the decorator allocation routine knows to utilize the included // default decorator instead of an addon. - make_decorator=NULL; + make_decorator = NULL; } /*! @@ -550,25 +540,26 @@ AppServer::DispatchMessage(int32 code, BPortLink &msg) // Find the necessary data team_id clientTeamID = -1; port_id clientLooperPort = -1; - port_id app_port = -1; + port_id clientReplyPort = -1; int32 htoken = B_NULL_TOKEN; - char *app_signature = NULL; + char *appSignature = NULL; - msg.Read(&app_port); + msg.Read(&clientReplyPort); msg.Read(&clientLooperPort); msg.Read(&clientTeamID); msg.Read(&htoken); - msg.ReadString(&app_signature); + if (msg.ReadString(&appSignature) != B_OK) + break; - port_id server_listen = create_port(DEFAULT_MONITOR_PORT_SIZE, app_signature); - if (server_listen < B_OK) { + port_id serverListen = create_port(DEFAULT_MONITOR_PORT_SIZE, appSignature); + if (serverListen < B_OK) { printf("No more ports left. Time to crash. Have a nice day! :)\n"); break; } - + // we let the application own the port, so that we get aware when it's gone - if (set_port_owner(server_listen, clientTeamID) < B_OK) { - delete_port(server_listen); + if (set_port_owner(serverListen, clientTeamID) < B_OK) { + delete_port(serverListen); printf("Could not transfer port ownership to client %ld!\n", clientTeamID); break; } @@ -576,21 +567,21 @@ AppServer::DispatchMessage(int32 code, BPortLink &msg) // Create the ServerApp subthread for this app acquire_sem(fAppListLock); - ServerApp *app = new ServerApp(app_port,server_listen, clientLooperPort, - clientTeamID, htoken, app_signature); + ServerApp *app = new ServerApp(clientReplyPort, serverListen, clientLooperPort, + clientTeamID, htoken, appSignature); // add the new ServerApp to the known list of ServerApps fAppList->AddItem(app); release_sem(fAppListLock); - BPortLink replylink(app_port); + BPortLink replylink(clientReplyPort); replylink.StartMessage(SERVER_TRUE); - replylink.Attach(server_listen); + replylink.Attach(serverListen); replylink.Flush(); // This is necessary because BPortLink::ReadString allocates memory - free(app_signature); + free(appSignature); break; } case AS_DELETE_APP: diff --git a/src/servers/app/RAMLinkMsgReader.cpp b/src/servers/app/RAMLinkMsgReader.cpp index 99ee5d527e..874a8e5ba7 100644 --- a/src/servers/app/RAMLinkMsgReader.cpp +++ b/src/servers/app/RAMLinkMsgReader.cpp @@ -25,8 +25,8 @@ RAMLinkMsgReader::~RAMLinkMsgReader(void) } - -void RAMLinkMsgReader::SetBuffer(int8 *buffer) +void +RAMLinkMsgReader::SetBuffer(int8 *buffer) { if(!buffer) { @@ -48,93 +48,35 @@ void RAMLinkMsgReader::SetBuffer(int8 *buffer) } -int8 *RAMLinkMsgReader::GetBuffer(void) +int8 * +RAMLinkMsgReader::GetBuffer(void) { return fBuffer; } -size_t RAMLinkMsgReader::GetBufferSize(void) +size_t +RAMLinkMsgReader::GetBufferSize(void) { return fAttachSize; } - -status_t RAMLinkMsgReader::Read(void *data, ssize_t size) +status_t +RAMLinkMsgReader::Read(void *data, ssize_t size) { - if(!fBuffer || fAttachSize==0) + if (!fBuffer || fAttachSize == 0) return B_NO_INIT; - - if(size<1) + + if (size < 1) return B_BAD_VALUE; - - if(fPosition+size > fAttachStart+fAttachSize) - { + + if (fPosition + size > fAttachStart + fAttachSize) { // read past end of buffer return B_BAD_VALUE; } - + memcpy(data, fPosition, size); - fPosition+=size; + fPosition += size; return B_OK; } - - -status_t RAMLinkMsgReader::ReadString(char **string) -{ - status_t err; - int32 len = 0; - - err = Read(&len); - if (err < B_OK) - return err; - - if (len) - { - *string = (char *)malloc(len); - if (*string == NULL) - { - fPosition -= sizeof(int32); - return B_NO_MEMORY; - } - - err = Read(*string, len); - if (err < B_OK) - { - free(*string); - *string = NULL; - fPosition -= sizeof(int32); - return err; - } - (*string)[len-1] = '\0'; - return B_OK; - } - else - { - fPosition -= sizeof(int32); - return B_ERROR; - } -} - -// "Forbidden" functions :P -status_t RAMLinkMsgReader::GetNextMessage(int32 *code, bigtime_t timeout) -{ - debugger("RAMLinkMsgReader::GetNextMessage is not permitted"); - return B_ERROR; -} - - -void RAMLinkMsgReader::SetPort(port_id port) -{ - debugger("RAMLinkMsgReader::SetPort is not permitted"); -} - - -port_id RAMLinkMsgReader::GetPort(void) -{ - debugger("RAMLinkMsgReader::GetPort is not permitted"); - return B_ERROR; -} - - diff --git a/src/servers/app/RAMLinkMsgReader.h b/src/servers/app/RAMLinkMsgReader.h index 6c3a81168f..8b9dc6dfa3 100644 --- a/src/servers/app/RAMLinkMsgReader.h +++ b/src/servers/app/RAMLinkMsgReader.h @@ -39,38 +39,24 @@ size_t buffer size [data buffer] */ -class RAMLinkMsgReader : public LinkMsgReader -{ -public: - RAMLinkMsgReader(int8 *buffer); - RAMLinkMsgReader(void); - ~RAMLinkMsgReader(void); - - void SetBuffer(int8 *buffer); - int8 *GetBuffer(void); - size_t GetBufferSize(void); - int32 Code(void) { return fCode; } - - status_t Read(void *data, ssize_t size); - status_t ReadString(char **string); - template status_t Read(Type *data) - { - return Read(data, sizeof(Type)); - } +class RAMLinkMsgReader : public LinkMsgReader { + public: + RAMLinkMsgReader(int8 *buffer); + RAMLinkMsgReader(void); + virtual ~RAMLinkMsgReader(void); - // These should never need to be called where this class is used. However, we do - // need to make debugging easier for such contexts... - status_t GetNextMessage(int32 *code, bigtime_t timeout); - void SetPort(port_id port); - port_id GetPort(void); - -protected: - - - int8 *fBuffer, *fAttachStart; - int8 *fPosition; - size_t fAttachSize; - int32 fCode; + void SetBuffer(int8 *buffer); + int8 *GetBuffer(void); + size_t GetBufferSize(void); + int32 Code(void) { return fCode; } + + virtual status_t Read(void *data, ssize_t size); + + protected: + int8 *fBuffer, *fAttachStart; + int8 *fPosition; + size_t fAttachSize; + int32 fCode; }; #endif diff --git a/src/servers/app/RootLayer.cpp b/src/servers/app/RootLayer.cpp index 3605f56fdc..007ce4ac93 100644 --- a/src/servers/app/RootLayer.cpp +++ b/src/servers/app/RootLayer.cpp @@ -208,7 +208,7 @@ RootLayer::WorkingThread(void *data) STRACE(("info: RootLayer(%s)::WorkingThread listening on port %ld.\n", oneRootLayer->GetName(), oneRootLayer->fListenPort)); for (;;) { - err = messageQueue.GetNextReply(code); + err = messageQueue.GetNextMessage(code); if (err < B_OK) { STRACE(("WorkingThread: messageQueue.GetNextReply failed\n")); continue; diff --git a/src/servers/app/ServerApp.cpp b/src/servers/app/ServerApp.cpp index 81031fa648..478eeafc94 100644 --- a/src/servers/app/ServerApp.cpp +++ b/src/servers/app/ServerApp.cpp @@ -1,35 +1,19 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2001-2005, Haiku, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// -// File Name: ServerApp.cpp -// Author: DarkWyrm -// Description: Server-side BApplication counterpart -// -//------------------------------------------------------------------------------ +/* + * Copyright 2001-2005, Haiku. + * Distributed under the terms of the MIT License. + * + * Authors: + * DarkWyrm + * Adrian Oanca + * Stephan Aßmus + * Stefano Ceccherini (burton666@libero.it) + * Axel Dörfler, axeld@pinc-software.de + */ + + #include -#include -#include #include #include -#include #include #include #include @@ -88,25 +72,24 @@ */ ServerApp::ServerApp(port_id sendport, port_id rcvport, port_id clientLooperPort, team_id clientTeamID, int32 handlerID, const char* signature) - : - fClientAppPort(sendport), - fMessagePort(rcvport), - fClientLooperPort(clientLooperPort), - fSignature(signature), - fMonitorThreadID(-1), - fClientTeamID(clientTeamID), - fMsgReader(new LinkMsgReader(fMessagePort)), - fMsgSender(new LinkMsgSender(fClientAppPort)), - fSWindowList(new BList()), - fBitmapList(new BList()), - fPictureList(new BList()), - fAppCursor(NULL), - fLockSem(create_sem(1, "ServerApp sem")), - fCursorHidden(false), - fIsActive(false), - //fHandlerToken(handlerID), - fSharedMem(new AreaPool), - fQuitting(false) + : + fClientAppPort(sendport), + fMessagePort(rcvport), + fClientLooperPort(clientLooperPort), + fSignature(signature), + fMonitorThreadID(-1), + fClientTeamID(clientTeamID), + fLink(fClientAppPort, fMessagePort), + fSWindowList(new BList()), + fBitmapList(new BList()), + fPictureList(new BList()), + fAppCursor(NULL), + fLockSem(create_sem(1, "ServerApp sem")), + fCursorHidden(false), + fIsActive(false), + //fHandlerToken(handlerID), + fSharedMem(new AreaPool), + fQuitting(false) { if (fSignature == "") fSignature = "application/x-vnd.NULL-application-signature"; @@ -137,21 +120,16 @@ ServerApp::~ServerApp(void) fQuitting = true; - for (int32 i = 0; i< fBitmapList->CountItems(); i++) + for (int32 i = 0; i< fBitmapList->CountItems(); i++) { delete static_cast(fBitmapList->ItemAt(i)); - - fBitmapList->MakeEmpty(); + } delete fBitmapList; - for (int32 i = 0; i < fPictureList->CountItems(); i++) + for (int32 i = 0; i < fPictureList->CountItems(); i++) { delete static_cast(fPictureList->ItemAt(i)); - - fPictureList->MakeEmpty(); + } delete fPictureList; - delete fMsgReader; - delete fMsgSender; - // This shouldn't be necessary -- all cursors owned by the app // should be cleaned up by RemoveAppCursors // if(fAppCursor) @@ -163,7 +141,7 @@ ServerApp::~ServerApp(void) gDesktop->ActiveRootLayer()->GetCursorManager().RemoveAppCursors(fClientTeamID); delete_sem(fLockSem); - STRACE(("#ServerApp %s:~ServerApp()\n",fSignature.String())); + STRACE(("#ServerApp %s:~ServerApp()\n", fSignature.String())); // TODO: Is this the right place for this ? // From what I've understood, this is the port created by @@ -213,10 +191,10 @@ ServerApp::PingTarget(void) { team_info tinfo; if (get_team_info(fClientTeamID,&tinfo) == B_BAD_TEAM_ID) { - fMsgSender->SetPort(gAppServerPort); - fMsgSender->StartMessage(AS_DELETE_APP); - fMsgSender->Attach(&fMonitorThreadID, sizeof(thread_id)); - fMsgSender->Flush(); + LinkMsgSender link(gAppServerPort); + link.StartMessage(AS_DELETE_APP); + link.Attach(&fMonitorThreadID, sizeof(thread_id)); + link.Flush(); return false; } return true; @@ -229,7 +207,7 @@ ServerApp::PingTarget(void) void ServerApp::PostMessage(int32 code) { - BPortLink link(fMessagePort); + LinkMsgSender link(fMessagePort); link.StartMessage(code); link.Flush(); } @@ -243,7 +221,7 @@ ServerApp::SendMessageToClient(const BMessage *msg) const { ssize_t size = msg->FlattenedSize(); char *buffer = new char[size]; - + if (msg->Flatten(buffer, size) == B_OK) write_port(fClientLooperPort, msg->what, buffer, size); else @@ -288,24 +266,24 @@ int32 ServerApp::MonitorApp(void *data) { // Message-dispatching loop for the ServerApp - + ServerApp *app = (ServerApp *)data; - LinkMsgReader msgqueue(app->fMessagePort); - + LinkMsgReader &reader = app->fLink.Reader(); + int32 code; status_t err = B_OK; - + while (!app->fQuitting) { STRACE(("info: ServerApp::MonitorApp listening on port %ld.\n", app->fMessagePort)); - err = msgqueue.GetNextMessage(code); + err = reader.GetNextMessage(code, B_INFINITE_TIMEOUT); if (err < B_OK) { STRACE(("ServerApp::MonitorApp(): GetNextMessage returned %s\n", strerror(err))); // ToDo: this should kill the app, but it doesn't work - app->fMsgSender->SetPort(gAppServerPort); - app->fMsgSender->StartMessage(AS_DELETE_APP); - app->fMsgSender->Attach(&app->fMonitorThreadID, sizeof(thread_id)); - app->fMsgSender->Flush(); + LinkMsgSender link(gAppServerPort); + link.StartMessage(AS_DELETE_APP); + link.Attach(&app->fMonitorThreadID, sizeof(thread_id)); + link.Flush(); break; } @@ -313,7 +291,7 @@ ServerApp::MonitorApp(void *data) case AS_CREATE_WINDOW: { // Create the ServerWindow to node monitor a new OBWindow - + // Attached data: // 2) BRect window frame // 3) uint32 window look @@ -333,16 +311,17 @@ ServerApp::MonitorApp(void *data) port_id sendPort = -1; port_id looperPort = -1; char *title = NULL; - - msgqueue.Read(&frame); - msgqueue.Read(&look); - msgqueue.Read(&feel); - msgqueue.Read(&flags); - msgqueue.Read(&wkspaces); - msgqueue.Read(&token); - msgqueue.Read(&sendPort); - msgqueue.Read(&looperPort); - msgqueue.ReadString(&title); + + reader.Read(&frame); + reader.Read(&look); + reader.Read(&feel); + reader.Read(&flags); + reader.Read(&wkspaces); + reader.Read(&token); + reader.Read(&sendPort); + reader.Read(&looperPort); + if (reader.ReadString(&title) != B_OK) + break; STRACE(("ServerApp %s: Got 'New Window' message, trying to do smething...\n",app->fSignature.String())); @@ -352,10 +331,10 @@ ServerApp::MonitorApp(void *data) sw->Init(frame, look, feel, flags, wkspaces); STRACE(("\nServerApp %s: New Window %s (%.1f,%.1f,%.1f,%.1f)\n", - app->fSignature.String(),title,frame.left,frame.top,frame.right,frame.bottom)); - - free(title); + app->fSignature.String(), title, frame.left, frame.top, + frame.right, frame.bottom)); + free(title); break; } case AS_QUIT_APP: @@ -365,7 +344,8 @@ ServerApp::MonitorApp(void *data) // NOT want to shut down client applications. The server can be quit o in this fashion // through the driver's interface, such as closing the ViewDriver's window. - STRACE(("ServerApp %s:Server shutdown notification received\n",app->fSignature.String())); + STRACE(("ServerApp %s:Server shutdown notification received\n", + app->fSignature.String())); // If we are using the real, accelerated version of the // DisplayDriver, we do NOT want the user to be able shut down @@ -382,21 +362,19 @@ ServerApp::MonitorApp(void *data) STRACE(("ServerApp %s: B_QUIT_REQUESTED\n",app->fSignature.String())); // Our BApplication sent us this message when it quit. // We need to ask the app_server to delete ourself. - app->fMsgSender->SetPort(gAppServerPort); - app->fMsgSender->StartMessage(AS_DELETE_APP); - app->fMsgSender->Attach(&app->fMonitorThreadID, sizeof(thread_id)); - app->fMsgSender->Flush(); + LinkMsgSender sender(gAppServerPort); + sender.StartMessage(AS_DELETE_APP); + sender.Attach(&app->fMonitorThreadID, sizeof(thread_id)); + sender.Flush(); break; } - default: - { - STRACE(("ServerApp %s: Got a Message to dispatch\n",app->fSignature.String())); - app->DispatchMessage(code, msgqueue); - break; - } - } - } // end for + default: + STRACE(("ServerApp %s: Got a Message to dispatch\n", app->fSignature.String())); + app->DispatchMessage(code, reader); + break; + } + } return 0; } @@ -412,12 +390,11 @@ ServerApp::MonitorApp(void *data) matter of casting and incrementing an index variable to access them. */ void -ServerApp::DispatchMessage(int32 code, LinkMsgReader &msg) +ServerApp::DispatchMessage(int32 code, LinkMsgReader &link) { LayerData ld; - BPortLink replylink; - - switch(code) { + + switch (code) { case AS_UPDATE_COLORS: { // NOTE: R2: Eventually we will have windows which will notify their children of changes in @@ -468,9 +445,9 @@ ServerApp::DispatchMessage(int32 code, LinkMsgReader &msg) area_info ai; int8 *msgpointer; - msg.Read(&area); - msg.Read(&offset); - msg.Read(&msgsize); + link.Read(&area); + link.Read(&offset); + link.Read(&msgsize); // Part sanity check, part get base pointer :) if (get_area_info(area, &ai) < B_OK) @@ -499,42 +476,36 @@ ServerApp::DispatchMessage(int32 code, LinkMsgReader &msg) // Attached Data: // 1) size_t requested size // 2) port_id reply_port - + size_t memsize; - port_id replyport; - - msg.Read(&memsize); - msg.Read(&replyport); - + link.Read(&memsize); + // TODO: I wonder if ACQUIRE_SERVERMEM should have a minimum size requirement? void *sharedmem = fSharedMem->GetBuffer(memsize); - - replylink.SetSendPort(replyport); + if (memsize < 1 || sharedmem == NULL) { - replylink.StartMessage(SERVER_FALSE); - replylink.Flush(); + fLink.StartMessage(SERVER_FALSE); + fLink.Flush(); break; } area_id owningArea = area_for(sharedmem); - area_info ai; - - if (owningArea == B_ERROR || get_area_info(owningArea, &ai) < B_OK) - { - replylink.StartMessage(SERVER_FALSE); - replylink.Flush(); + area_info info; + + if (owningArea == B_ERROR || get_area_info(owningArea, &info) < B_OK) { + fLink.StartMessage(SERVER_FALSE); + fLink.Flush(); break; } - - int32 areaoffset = ((int32*)sharedmem) - ((int32*)ai.address); + + int32 areaoffset = (addr_t)sharedmem - (addr_t)info.address; STRACE(("Successfully allocated shared memory of size %ld\n",memsize)); - - replylink.StartMessage(SERVER_TRUE); - replylink.Attach(owningArea); - replylink.Attach(areaoffset); - replylink.Flush(); - + + fLink.StartMessage(SERVER_TRUE); + fLink.Attach(owningArea); + fLink.Attach(areaoffset); + fLink.Flush(); break; } case AS_RELEASE_SERVERMEM: @@ -547,8 +518,8 @@ ServerApp::DispatchMessage(int32 code, LinkMsgReader &msg) area_id owningArea; int32 areaoffset; - msg.Read(&owningArea); - msg.Read(&areaoffset); + link.Read(&owningArea); + link.Read(&areaoffset); area_info areaInfo; if (owningArea < 0 || get_area_info(owningArea, &areaInfo) != B_OK) @@ -596,37 +567,36 @@ ServerApp::DispatchMessage(int32 code, LinkMsgReader &msg) // 3) int32 area pointer offset used to calculate fBasePtr // First, let's attempt to allocate the bitmap - port_id replyport = -1; - BRect r; - color_space cs; - int32 f,bpr; - screen_id s; + ServerBitmap *bitmap = NULL; + BRect frame; + color_space colorSpace; + int32 flags, bytesPerRow; + screen_id screenID; - msg.Read(&r); - msg.Read(&cs); - msg.Read(&f); - msg.Read(&bpr); - msg.Read(&s); - msg.Read(&replyport); - - ServerBitmap *sbmp = bitmapmanager->CreateBitmap(r, cs, f ,bpr, s); + link.Read(&frame); + link.Read(&colorSpace); + link.Read(&flags); + link.Read(&bytesPerRow); + if (link.Read(&screenID) == B_OK) { + bitmap = bitmapmanager->CreateBitmap(frame, colorSpace, flags, + bytesPerRow, screenID); + } - STRACE(("ServerApp %s: Create Bitmap (%.1f,%.1f,%.1f,%.1f)\n", - fSignature.String(),r.left,r.top,r.right,r.bottom)); + STRACE(("ServerApp %s: Create Bitmap (%.1fx%.1f)\n", + fSignature.String(), frame.Width(), frame.Height())); - replylink.SetSendPort(replyport); - if(sbmp) { - fBitmapList->AddItem(sbmp); - replylink.StartMessage(SERVER_TRUE); - replylink.Attach(sbmp->Token()); - replylink.Attach(sbmp->Area()); - replylink.Attach(sbmp->AreaOffset()); + if (bitmap) { + fBitmapList->AddItem(bitmap); + fLink.StartMessage(SERVER_TRUE); + fLink.Attach(bitmap->Token()); + fLink.Attach(bitmap->Area()); + fLink.Attach(bitmap->AreaOffset()); } else { // alternatively, if something went wrong, we reply with SERVER_FALSE - replylink.StartMessage(SERVER_FALSE); + fLink.StartMessage(SERVER_FALSE); } - replylink.Flush(); - + + fLink.Flush(); break; } case AS_DELETE_BITMAP: @@ -640,37 +610,33 @@ ServerApp::DispatchMessage(int32 code, LinkMsgReader &msg) // Reply Code: SERVER_TRUE if successful, // SERVER_FALSE if the buffer was already deleted or was not found - port_id replyport = -1; - int32 bmp_id; - - msg.Read(&bmp_id); - msg.Read(&replyport); - - ServerBitmap *sbmp=FindBitmap(bmp_id); - replylink.SetSendPort(replyport); - if(sbmp) { - STRACE(("ServerApp %s: Deleting Bitmap %ld\n",fSignature.String(),bmp_id)); + int32 id; + link.Read(&id); - fBitmapList->RemoveItem(sbmp); - bitmapmanager->DeleteBitmap(sbmp); - replylink.StartMessage(SERVER_TRUE); + ServerBitmap *bitmap = FindBitmap(id); + if (bitmap) { + STRACE(("ServerApp %s: Deleting Bitmap %ld\n", fSignature.String(), id)); + + fBitmapList->RemoveItem(bitmap); + bitmapmanager->DeleteBitmap(bitmap); + fLink.StartMessage(SERVER_TRUE); } else - replylink.StartMessage(SERVER_TRUE); - - replylink.Flush(); + fLink.StartMessage(SERVER_FALSE); + + fLink.Flush(); break; } case AS_CREATE_PICTURE: { // TODO: Implement AS_CREATE_PICTURE - STRACE(("ServerApp %s: Create Picture unimplemented\n",fSignature.String())); + STRACE(("ServerApp %s: Create Picture unimplemented\n", fSignature.String())); break; } case AS_DELETE_PICTURE: { // TODO: Implement AS_DELETE_PICTURE - STRACE(("ServerApp %s: Delete Picture unimplemented\n",fSignature.String())); + STRACE(("ServerApp %s: Delete Picture unimplemented\n", fSignature.String())); break; } @@ -701,9 +667,9 @@ ServerApp::DispatchMessage(int32 code, LinkMsgReader &msg) int32 index; uint32 mode; bool stick; - msg.Read(&index); - msg.Read(&mode); - msg.Read(&stick); + link.Read(&index); + link.Read(&mode); + link.Read(&stick); RootLayer *root=gDesktop->ActiveRootLayer(); Workspace *workspace=root->WorkspaceAt(index); @@ -726,7 +692,7 @@ ServerApp::DispatchMessage(int32 code, LinkMsgReader &msg) // Error-checking is done in ActivateWorkspace, so this is a safe call int32 workspace; - msg.Read(&workspace); + link.Read(&workspace); break; } @@ -764,15 +730,11 @@ ServerApp::DispatchMessage(int32 code, LinkMsgReader &msg) } case AS_QUERY_CURSOR_HIDDEN: { - STRACE(("ServerApp %s: Received IsCursorHidden request\n",fSignature.String())); + STRACE(("ServerApp %s: Received IsCursorHidden request\n", fSignature.String())); // Attached data // 1) int32 port to reply to - int32 replyport; - msg.Read(&replyport); - - replylink.SetSendPort(replyport); - replylink.StartMessage(fCursorHidden ? SERVER_TRUE : SERVER_FALSE); - replylink.Flush(); + fLink.StartMessage(fCursorHidden ? SERVER_TRUE : SERVER_FALSE); + fLink.Flush(); break; } case AS_SET_CURSOR_DATA: @@ -781,7 +743,7 @@ ServerApp::DispatchMessage(int32 code, LinkMsgReader &msg) // Attached data: 68 bytes of fAppCursor data int8 cdata[68]; - msg.Read(cdata,68); + link.Read(cdata,68); // Because we don't want an overaccumulation of these particular // cursors, we will delete them if there is an existing one. It would @@ -809,12 +771,9 @@ ServerApp::DispatchMessage(int32 code, LinkMsgReader &msg) // 3) port_id port to receive a reply. Only exists if the sync flag is true. bool sync; int32 ctoken = B_NULL_TOKEN; - port_id replyport = -1; - msg.Read(&sync); - msg.Read(&ctoken); - if(sync) - msg.Read(&replyport); + link.Read(&sync); + link.Read(&ctoken); // although this isn't pretty, ATM we have only one RootLayer. // there should be a way that this ServerApp be attached to a particular @@ -822,14 +781,12 @@ ServerApp::DispatchMessage(int32 code, LinkMsgReader &msg) ServerCursor *cursor; if ((cursor = gDesktop->ActiveRootLayer()->GetCursorManager().FindCursor(ctoken))) gDesktop->ActiveRootLayer()->GetDisplayDriver()->SetCursor(cursor); - - if(sync) - { + + if (sync) { // the application is expecting a reply, but plans to do literally nothing // with the data, so we'll just reuse the cursor token variable - replylink.SetSendPort(replyport); - replylink.StartMessage(SERVER_TRUE); - replylink.Flush(); + fLink.StartMessage(SERVER_TRUE); + fLink.Flush(); } break; } @@ -840,38 +797,34 @@ ServerApp::DispatchMessage(int32 code, LinkMsgReader &msg) // 1) 68 bytes of fAppCursor data // 2) port_id reply port - port_id replyport = -1; - int8 cdata[68]; + int8 cursorData[68]; + link.Read(cursorData, sizeof(cursorData)); - msg.Read(cdata,68); - msg.Read(&replyport); - - fAppCursor=new ServerCursor(cdata); + fAppCursor = new ServerCursor(cursorData); fAppCursor->SetOwningTeam(fClientTeamID); fAppCursor->SetAppSignature(fSignature.String()); // although this isn't pretty, ATM we have only one RootLayer. // there should be a way that this ServerApp be attached to a particular // RootLayer to know which RootLayer's cursor to modify. gDesktop->ActiveRootLayer()->GetCursorManager().AddCursor(fAppCursor); - + // Synchronous message - BApplication is waiting on the cursor's ID - replylink.SetSendPort(replyport); - replylink.StartMessage(SERVER_TRUE); - replylink.Attach(fAppCursor->ID()); - replylink.Flush(); + fLink.StartMessage(SERVER_TRUE); + fLink.Attach(fAppCursor->ID()); + fLink.Flush(); break; } case AS_DELETE_BCURSOR: { - STRACE(("ServerApp %s: Delete BCursor\n",fSignature.String())); + STRACE(("ServerApp %s: Delete BCursor\n", fSignature.String())); // Attached data: // 1) int32 token ID of the cursor to delete int32 ctoken = B_NULL_TOKEN; - msg.Read(&ctoken); - - if(fAppCursor && fAppCursor->ID()==ctoken) - fAppCursor=NULL; - + link.Read(&ctoken); + + if (fAppCursor && fAppCursor->ID() == ctoken) + fAppCursor = NULL; + // although this isn't pretty, ATM we have only one RootLayer. // there should be a way that this ServerApp be attached to a particular // RootLayer to know which RootLayer's cursor to modify. @@ -880,111 +833,81 @@ ServerApp::DispatchMessage(int32 code, LinkMsgReader &msg) } case AS_GET_SCROLLBAR_INFO: { - STRACE(("ServerApp %s: Get ScrollBar info\n",fSignature.String())); - // Attached data: - // 1) port_id reply port - synchronous message + STRACE(("ServerApp %s: Get ScrollBar info\n", fSignature.String())); + scroll_bar_info info = gDesktop->ScrollBarInfo(); - scroll_bar_info sbi=gDesktop->ScrollBarInfo(); - - port_id replyport; - msg.Read(&replyport); - - replylink.SetSendPort(replyport); - replylink.StartMessage(SERVER_TRUE); - replylink.Attach(sbi); - replylink.Flush(); + fLink.StartMessage(SERVER_TRUE); + fLink.Attach(info); + fLink.Flush(); break; } case AS_SET_SCROLLBAR_INFO: { - STRACE(("ServerApp %s: Set ScrollBar info\n",fSignature.String())); + STRACE(("ServerApp %s: Set ScrollBar info\n", fSignature.String())); // Attached Data: // 1) scroll_bar_info scroll bar info structure - scroll_bar_info sbi; - msg.Read(&sbi); - - gDesktop->SetScrollBarInfo(sbi); + scroll_bar_info info; + if (link.Read(&info) == B_OK) + gDesktop->SetScrollBarInfo(info); break; } case AS_FOCUS_FOLLOWS_MOUSE: { - STRACE(("ServerApp %s: query Focus Follow Mouse in use\n",fSignature.String())); - // Attached data: - // 1) port_id reply port - synchronous message + STRACE(("ServerApp %s: query Focus Follow Mouse in use\n", fSignature.String())); - port_id replyport; - msg.Read(&replyport); - - replylink.SetSendPort(replyport); - replylink.StartMessage(SERVER_TRUE); - replylink.Attach(gDesktop->FFMouseInUse()); - replylink.Flush(); + fLink.StartMessage(SERVER_TRUE); + fLink.Attach(gDesktop->FFMouseInUse()); + fLink.Flush(); break; } case AS_SET_FOCUS_FOLLOWS_MOUSE: { - STRACE(("ServerApp %s: Set Focus Follows Mouse in use\n",fSignature.String())); -/* // Attached Data: - // 1) scroll_bar_info scroll bar info structure - scroll_bar_info sbi; - msg.Read(&sbi); - - gDesktop->SetScrollBarInfo(sbi);*/ + STRACE(("ServerApp %s: Set Focus Follows Mouse in use\n", fSignature.String())); + // ToDo: implement me! break; } case AS_SET_MOUSE_MODE: { - STRACE(("ServerApp %s: Set Focus Follows Mouse mode\n",fSignature.String())); + STRACE(("ServerApp %s: Set Focus Follows Mouse mode\n", fSignature.String())); // Attached Data: // 1) enum mode_mouse FFM mouse mode mode_mouse mmode; - msg.Read(&mmode); - - gDesktop->SetFFMouseMode(mmode); + if (link.Read(&mmode) == B_OK) + gDesktop->SetFFMouseMode(mmode); break; } case AS_GET_MOUSE_MODE: { - STRACE(("ServerApp %s: Get Focus Follows Mouse mode\n",fSignature.String())); - // Attached data: - // 1) port_id reply port - synchronous message + STRACE(("ServerApp %s: Get Focus Follows Mouse mode\n", fSignature.String())); + mode_mouse mmode = gDesktop->FFMouseMode(); - mode_mouse mmode=gDesktop->FFMouseMode(); - - port_id replyport = -1; - msg.Read(&replyport); - - replylink.SetSendPort(replyport); - replylink.StartMessage(SERVER_TRUE); - replylink.Attach(mmode); - replylink.Flush(); + fLink.StartMessage(SERVER_TRUE); + fLink.Attach(mmode); + fLink.Flush(); break; } case AS_GET_UI_COLOR: { - STRACE(("ServerApp %s: Get UI color\n",fSignature.String())); + STRACE(("ServerApp %s: Get UI color\n", fSignature.String())); RGBColor color; int32 whichcolor; - port_id replyport = -1; - - msg.Read(&whichcolor); - msg.Read(&replyport); - + link.Read(&whichcolor); + gui_colorset.Lock(); - color=gui_colorset.AttributeToColor(whichcolor); + color = gui_colorset.AttributeToColor(whichcolor); gui_colorset.Unlock(); - - replylink.SetSendPort(replyport); - replylink.StartMessage(SERVER_TRUE); - replylink.Attach(color.GetColor32()); - replylink.Flush(); + + fLink.StartMessage(SERVER_TRUE); + fLink.Attach(color.GetColor32()); + fLink.Flush(); break; } case AS_UPDATED_CLIENT_FONTLIST: { - STRACE(("ServerApp %s: Acknowledged update of client-side font list\n",fSignature.String())); - + STRACE(("ServerApp %s: Acknowledged update of client-side font list\n", + fSignature.String())); + // received when the client-side global font list has been // refreshed fontserver->Lock(); @@ -994,95 +917,76 @@ ServerApp::DispatchMessage(int32 code, LinkMsgReader &msg) } case AS_QUERY_FONTS_CHANGED: { - FTRACE(("ServerApp %s: AS_QUERY_FONTS_CHANGED unimplemented\n",fSignature.String())); + FTRACE(("ServerApp %s: AS_QUERY_FONTS_CHANGED unimplemented\n", + fSignature.String())); // Attached Data: // 1) bool check flag - // 2) port_id reply_port - + // if just checking, just give an answer, // if not and needs updated, // sync the font list and return true else return false + fLink.StartMessage(SERVER_FALSE); + fLink.Flush(); break; } case AS_GET_FAMILY_NAME: { - FTRACE(("ServerApp %s: AS_GET_FAMILY_NAME\n",fSignature.String())); + FTRACE(("ServerApp %s: AS_GET_FAMILY_NAME\n", fSignature.String())); // Attached Data: // 1) int32 the ID of the font family to get - // 2) port_id reply port - + // Returns: // 1) font_family - name of family // 2) uint32 - flags of font family (B_IS_FIXED || B_HAS_TUNED_FONT) - int32 famid; - port_id replyport; - - msg.Read(&famid); - msg.Read(&replyport); - - replylink.SetSendPort(replyport); - + int32 id; + + link.Read(&id); + fontserver->Lock(); - FontFamily *ffamily=fontserver->GetFamily(famid); - if(ffamily) - { + FontFamily *ffamily = fontserver->GetFamily(id); + if (ffamily) { font_family fam; - sprintf(fam,"%s",ffamily->Name()); - replylink.StartMessage(SERVER_TRUE); - replylink.Attach(fam,sizeof(font_family)); - replylink.Attach(ffamily->GetFlags()); - replylink.Flush(); - } - else - { - replylink.StartMessage(SERVER_FALSE); - replylink.Flush(); - } - + strcpy(fam, ffamily->Name()); + fLink.Attach(fam, sizeof(font_family)); + fLink.Attach(ffamily->GetFlags()); + } else + fLink.StartMessage(SERVER_FALSE); + + fLink.Flush(); fontserver->Unlock(); break; } case AS_GET_STYLE_NAME: { - FTRACE(("ServerApp %s: AS_GET_STYLE_NAME\n",fSignature.String())); + FTRACE(("ServerApp %s: AS_GET_STYLE_NAME\n", fSignature.String())); // Attached Data: // 1) font_family The name of the font family // 2) int32 ID of the style to get - // 3) port_id reply port - + // Returns: // 1) font_style - name of the style // 2) uint16 - appropriate face values // 3) uint32 - flags of font style (B_IS_FIXED || B_HAS_TUNED_FONT) - + int32 styid; - port_id replyport; font_family fam; - - msg.Read(fam,sizeof(font_family)); - msg.Read(&styid); - msg.Read(&replyport); - - replylink.SetSendPort(replyport); - + + link.Read(fam,sizeof(font_family)); + link.Read(&styid); + fontserver->Lock(); - FontStyle *fstyle=fontserver->GetStyle(fam,styid); - if(fstyle) - { + FontStyle *fstyle = fontserver->GetStyle(fam, styid); + if (fstyle) { font_family sty; - sprintf(sty,"%s",fstyle->Name()); - replylink.StartMessage(SERVER_TRUE); - replylink.Attach(sty,sizeof(font_style)); - replylink.Attach(fstyle->GetFace()); - replylink.Attach(fstyle->GetFlags()); - replylink.Flush(); - } - else - { - replylink.StartMessage(SERVER_FALSE); - replylink.Flush(); - } - + strcpy(sty, fstyle->Name()); + fLink.StartMessage(SERVER_TRUE); + fLink.Attach(sty,sizeof(font_style)); + fLink.Attach(fstyle->GetFace()); + fLink.Attach(fstyle->GetFlags()); + } else + fLink.StartMessage(SERVER_FALSE); + + fLink.Flush(); fontserver->Unlock(); break; } @@ -1092,66 +996,51 @@ ServerApp::DispatchMessage(int32 code, LinkMsgReader &msg) // Attached Data: // 1) uint16 - family ID // 2) uint16 - style ID - // 3) port_id reply port - + // Returns: // 1) font_family The name of the font family // 2) font_style - name of the style uint16 famid, styid; - port_id replyport; font_family fam; font_style sty; - - msg.Read(&famid); - msg.Read(&styid); - msg.Read(&replyport); - replylink.SetSendPort(replyport); - + link.Read(&famid); + link.Read(&styid); + fontserver->Lock(); - FontStyle *fstyle=fontserver->GetStyle(famid,styid); - if(fstyle) - { - sprintf(fam,"%s",fstyle->Family()->Name()); - sprintf(sty,"%s",fstyle->Name()); - replylink.StartMessage(SERVER_TRUE); - replylink.Attach(fam,sizeof(font_family)); - replylink.Attach(sty,sizeof(font_style)); - replylink.Flush(); - } - else - { - replylink.StartMessage(SERVER_FALSE); - replylink.Flush(); - } - - fontserver->Unlock(); + FontStyle *fstyle = fontserver->GetStyle(famid, styid); + if (fstyle) { + strcpy(fam, fstyle->Family()->Name()); + strcpy(sty, fstyle->Name()); + fLink.StartMessage(SERVER_TRUE); + fLink.Attach(fam, sizeof(font_family)); + fLink.Attach(sty, sizeof(font_style)); + } else + fLink.StartMessage(SERVER_FALSE); + + fLink.Flush(); + fontserver->Unlock(); break; } case AS_GET_FONT_DIRECTION: { - FTRACE(("ServerApp %s: AS_GET_FONT_DIRECTION unimplemented\n",fSignature.String())); + FTRACE(("ServerApp %s: AS_GET_FONT_DIRECTION unimplemented\n", + fSignature.String())); // Attached Data: // 1) uint16 - family ID // 2) uint16 - style ID - // 3) port_id reply port - + // Returns: // 1) font_direction direction of font - + // NOTE: While this may be unimplemented, we can safely return // SERVER_FALSE. This will force the BFont code to default to // B_LEFT_TO_RIGHT, which is what the vast majority of fonts will be. // This will be fixed later. int32 famid, styid; - port_id replyport; - - msg.Read(&famid); - msg.Read(&styid); - msg.Read(&replyport); - - replylink.SetSendPort(replyport); + link.Read(&famid); + link.Read(&styid); /* fontserver->Lock(); FontStyle *fstyle=fontserver->GetStyle(famid,styid); @@ -1159,14 +1048,14 @@ ServerApp::DispatchMessage(int32 code, LinkMsgReader &msg) { font_direction dir=fstyle->GetDirection(); - replylink.StartMessage(SERVER_TRUE); - replylink.Attach(dir); - replylink.Flush(); + fLink.StartMessage(SERVER_TRUE); + fLink.Attach(dir); + fLink.Flush(); } else { -*/ replylink.StartMessage(SERVER_FALSE); - replylink.Flush(); +*/ fLink.StartMessage(SERVER_FALSE); + fLink.Flush(); // } // fontserver->Unlock(); @@ -1174,7 +1063,7 @@ ServerApp::DispatchMessage(int32 code, LinkMsgReader &msg) } case AS_GET_STRING_WIDTH: { - FTRACE(("ServerApp %s: AS_GET_STRING_WIDTH\n",fSignature.String())); + FTRACE(("ServerApp %s: AS_GET_STRING_WIDTH\n", fSignature.String())); // Attached Data: // 1) string String to measure // 2) int32 string length to measure @@ -1182,31 +1071,26 @@ ServerApp::DispatchMessage(int32 code, LinkMsgReader &msg) // 4) uint16 ID of style // 5) float point size of font // 6) uint8 spacing to use - // 7) port_id reply port - + // Returns: // 1) float - width of the string in pixels - char *string=NULL; + char *string = NULL; int32 length; - uint16 family,style; - float size,width=0; + uint16 family, style; + float size, width = 0; uint8 spacing; - port_id replyport; - - msg.ReadString(&string); - msg.Read(&length); - msg.Read(&family); - msg.Read(&style); - msg.Read(&size); - msg.Read(&spacing); - msg.Read(&replyport); - - replylink.SetSendPort(replyport); + + link.ReadString(&string); + link.Read(&length); + link.Read(&family); + link.Read(&style); + link.Read(&size); + link.Read(&spacing); ServerFont font; - if (length > 0 && font.SetFamilyAndStyle(family, style) == B_OK && - size > 0 && string) { + if (length > 0 && font.SetFamilyAndStyle(family, style) == B_OK + && size > 0 && string) { font.SetSize(size); font.SetSpacing(spacing); @@ -1217,378 +1101,287 @@ ServerApp::DispatchMessage(int32 code, LinkMsgReader &msg) // actually works. It is about 20 times faster! //width = font.StringWidth(string, length); - replylink.StartMessage(SERVER_TRUE); - replylink.Attach(width); - replylink.Flush(); - - } else { - replylink.StartMessage(SERVER_FALSE); - replylink.Flush(); - } - + fLink.StartMessage(SERVER_TRUE); + fLink.Attach(width); + } else + fLink.StartMessage(SERVER_FALSE); + + fLink.Flush(); free(string); - break; } case AS_GET_FONT_BOUNDING_BOX: { - FTRACE(("ServerApp %s: AS_GET_BOUNDING_BOX unimplemented\n",fSignature.String())); + FTRACE(("ServerApp %s: AS_GET_BOUNDING_BOX unimplemented\n", + fSignature.String())); // Attached Data: // 1) uint16 - family ID // 2) uint16 - style ID - // 3) port_id reply port - + // Returns: // 1) BRect - box holding entire font - + + // ToDo: implement me! + fLink.StartMessage(SERVER_FALSE); + fLink.Flush(); break; } case AS_GET_TUNED_COUNT: { - FTRACE(("ServerApp %s: AS_GET_TUNED_COUNT\n",fSignature.String())); + FTRACE(("ServerApp %s: AS_GET_TUNED_COUNT\n", fSignature.String())); // Attached Data: // 1) uint16 - family ID // 2) uint16 - style ID - // 3) port_id reply port - + // Returns: // 1) int32 - number of font strikes available int32 famid, styid; - port_id replyport; - - msg.Read(&famid); - msg.Read(&styid); - msg.Read(&replyport); - - replylink.SetSendPort(replyport); - + link.Read(&famid); + link.Read(&styid); + fontserver->Lock(); - FontStyle *fstyle=fontserver->GetStyle(famid,styid); - if(fstyle) - { - replylink.StartMessage(SERVER_TRUE); - replylink.Attach(fstyle->TunedCount()); - replylink.Flush(); - } - else - { - replylink.StartMessage(SERVER_FALSE); - replylink.Flush(); - } - + FontStyle *fstyle = fontserver->GetStyle(famid, styid); + if (fstyle) { + fLink.StartMessage(SERVER_TRUE); + fLink.Attach(fstyle->TunedCount()); + } else + fLink.StartMessage(SERVER_FALSE); + + fLink.Flush(); fontserver->Unlock(); break; } case AS_GET_TUNED_INFO: { - FTRACE(("ServerApp %s: AS_GET_TUNED_INFO unimplmemented\n",fSignature.String())); + FTRACE(("ServerApp %s: AS_GET_TUNED_INFO unimplmemented\n", + fSignature.String())); // Attached Data: // 1) uint16 - family ID // 2) uint16 - style ID // 3) uint32 - index of the particular font strike - // 4) port_id reply port - + // Returns: // 1) tuned_font_info - info on the strike specified + // ToDo: implement me! + fLink.StartMessage(SERVER_FALSE); + fLink.Flush(); break; } case AS_QUERY_FONT_FIXED: { - FTRACE(("ServerApp %s: AS_QUERY_FONT_FIXED unimplmemented\n",fSignature.String())); + FTRACE(("ServerApp %s: AS_QUERY_FONT_FIXED unimplmemented\n", + fSignature.String())); // Attached Data: // 1) uint16 - family ID // 2) uint16 - style ID - // 3) port_id reply port - + // Returns: // 1) bool - font is/is not fixed int32 famid, styid; - port_id replyport; - - msg.Read(&famid); - msg.Read(&styid); - msg.Read(&replyport); - - replylink.SetSendPort(replyport); - + link.Read(&famid); + link.Read(&styid); + fontserver->Lock(); - FontStyle *fstyle=fontserver->GetStyle(famid,styid); - if(fstyle) - { - replylink.StartMessage(SERVER_TRUE); - replylink.Attach(fstyle->IsFixedWidth()); - replylink.Flush(); - } - else - { - replylink.StartMessage(SERVER_FALSE); - replylink.Flush(); - } - + FontStyle *fstyle = fontserver->GetStyle(famid, styid); + if (fstyle) { + fLink.StartMessage(SERVER_TRUE); + fLink.Attach(fstyle->IsFixedWidth()); + } else + fLink.StartMessage(SERVER_FALSE); + + fLink.Flush(); fontserver->Unlock(); break; } case AS_SET_FAMILY_NAME: { - FTRACE(("ServerApp %s: AS_SET_FAMILY_NAME\n",fSignature.String())); + FTRACE(("ServerApp %s: AS_SET_FAMILY_NAME\n", fSignature.String())); // Attached Data: // 1) font_family - name of font family to use - // 2) port_id - reply port - + // Returns: // 1) uint16 - family ID - - port_id replyport; + font_family fam; - - msg.Read(fam,sizeof(font_family)); - msg.Read(&replyport); - - replylink.SetSendPort(replyport); - + link.Read(fam, sizeof(font_family)); + fontserver->Lock(); - FontFamily *ffam=fontserver->GetFamily(fam); - if(ffam) - { - replylink.StartMessage(SERVER_TRUE); - replylink.Attach(ffam->GetID()); - replylink.Flush(); - } - else - { - replylink.StartMessage(SERVER_FALSE); - replylink.Flush(); - } + FontFamily *ffam = fontserver->GetFamily(fam); + if (ffam) { + fLink.StartMessage(SERVER_TRUE); + fLink.Attach(ffam->GetID()); + } else + fLink.StartMessage(SERVER_FALSE); + fLink.Flush(); fontserver->Unlock(); break; } case AS_SET_FAMILY_AND_STYLE: { - FTRACE(("ServerApp %s: AS_SET_FAMILY_AND_STYLE\n",fSignature.String())); + FTRACE(("ServerApp %s: AS_SET_FAMILY_AND_STYLE\n", + fSignature.String())); // Attached Data: // 1) font_family - name of font family to use // 2) font_style - name of style in family - // 3) port_id - reply port - + // Returns: // 1) uint16 - family ID // 2) uint16 - style ID - - port_id replyport; + font_family fam; font_style sty; - - msg.Read(fam,sizeof(font_family)); - msg.Read(sty,sizeof(font_style)); - msg.Read(&replyport); - - replylink.SetSendPort(replyport); - + link.Read(fam, sizeof(font_family)); + link.Read(sty, sizeof(font_style)); + fontserver->Lock(); - FontStyle *fstyle=fontserver->GetStyle(fam,sty); - if(fstyle) - { - replylink.StartMessage(SERVER_TRUE); - replylink.Attach(fstyle->Family()->GetID()); - replylink.Attach(fstyle->GetID()); - replylink.Flush(); - } - else - { - replylink.StartMessage(SERVER_FALSE); - replylink.Flush(); - } - + FontStyle *fstyle = fontserver->GetStyle(fam, sty); + if (fstyle) { + fLink.StartMessage(SERVER_TRUE); + fLink.Attach(fstyle->Family()->GetID()); + fLink.Attach(fstyle->GetID()); + } else + fLink.StartMessage(SERVER_FALSE); + + fLink.Flush(); fontserver->Unlock(); break; } case AS_SET_FAMILY_AND_STYLE_FROM_ID: { - FTRACE(("ServerApp %s: AS_SET_FAMILY_AND_STYLE_FROM_ID\n",fSignature.String())); + FTRACE(("ServerApp %s: AS_SET_FAMILY_AND_STYLE_FROM_ID\n", + fSignature.String())); // Attached Data: // 1) uint16 - ID of font family to use // 2) uint16 - ID of style in family - // 3) port_id - reply port - + // Returns: // 1) uint16 - face of the font - - port_id replyport; + uint16 fam, sty; - - msg.Read(&fam); - msg.Read(&sty); - msg.Read(&replyport); - - replylink.SetSendPort(replyport); - + link.Read(&fam); + link.Read(&sty); + ServerFont font; - if(font.SetFamilyAndStyle(fam,sty)==B_OK) - { - replylink.StartMessage(SERVER_TRUE); - replylink.Attach(font.Face()); - replylink.Flush(); - } - else - { - replylink.StartMessage(SERVER_FALSE); - replylink.Flush(); - } - + if (font.SetFamilyAndStyle(fam, sty) == B_OK) { + fLink.StartMessage(SERVER_TRUE); + fLink.Attach(font.Face()); + } else + fLink.StartMessage(SERVER_FALSE); + + fLink.Flush(); break; } case AS_SET_FAMILY_AND_FACE: { - FTRACE(("ServerApp %s: AS_SET_FAMILY_AND_FACE unimplmemented\n",fSignature.String())); + FTRACE(("ServerApp %s: AS_SET_FAMILY_AND_FACE unimplmemented\n", + fSignature.String())); // Attached Data: // 1) font_family - name of font family to use // 2) uint16 - font face - // 3) port_id - reply port - + // Returns: // 1) uint16 - family ID // 2) uint16 - style ID // TODO: Check R5 for error condition behavior in SET_FAMILY_AND_FACE + // ToDo: implement me! + fLink.StartMessage(SERVER_FALSE); + fLink.Flush(); break; } case AS_COUNT_FONT_FAMILIES: { - FTRACE(("ServerApp %s: AS_COUNT_FONT_FAMILIES\n",fSignature.String())); - // Attached Data: - // 1) port_id - reply port - + FTRACE(("ServerApp %s: AS_COUNT_FONT_FAMILIES\n", fSignature.String())); // Returns: // 1) int32 - # of font families - port_id replyport; - - msg.Read(&replyport); - - replylink.SetSendPort(replyport); + fontserver->Lock(); - replylink.StartMessage(SERVER_TRUE); - replylink.Attach(fontserver->CountFamilies()); - replylink.Flush(); + + fLink.StartMessage(SERVER_TRUE); + fLink.Attach(fontserver->CountFamilies()); + fLink.Flush(); + fontserver->Unlock(); - break; } case AS_COUNT_FONT_STYLES: { - FTRACE(("ServerApp %s: AS_COUNT_FONT_STYLES\n",fSignature.String())); + FTRACE(("ServerApp %s: AS_COUNT_FONT_STYLES\n", fSignature.String())); // Attached Data: // 1) font_family - name of font family - // 2) port_id - reply port - + // Returns: // 1) int32 - # of font styles - port_id replyport; font_family fam; - - msg.Read(fam,sizeof(font_family)); - msg.Read(&replyport); - - replylink.SetSendPort(replyport); - + link.Read(fam,sizeof(font_family)); + fontserver->Lock(); - FontFamily *ffam=fontserver->GetFamily(fam); - if(ffam) - { - replylink.StartMessage(SERVER_TRUE); - replylink.Attach(ffam->CountStyles()); - replylink.Flush(); - } - else - { - replylink.StartMessage(SERVER_FALSE); - replylink.Flush(); - } - + FontFamily *ffam = fontserver->GetFamily(fam); + if (ffam) { + fLink.StartMessage(SERVER_TRUE); + fLink.Attach(ffam->CountStyles()); + } else + fLink.StartMessage(SERVER_FALSE); + + fLink.Flush(); fontserver->Unlock(); break; } case AS_SET_SYSFONT_PLAIN: { - FTRACE(("ServerApp %s: AS_SET_SYSFONT_PLAIN\n",fSignature.String())); - // Attached Data: - // port_id reply port - + FTRACE(("ServerApp %s: AS_SET_SYSFONT_PLAIN\n", fSignature.String())); // Returns: // 1) uint16 - family ID // 2) uint16 - style ID // 3) float - size in points // 4) uint16 - face flags // 5) uint32 - font flags - - port_id replyport; - msg.Read(&replyport); - replylink.SetSendPort(replyport); - + fontserver->Lock(); - ServerFont *sf=fontserver->GetSystemPlain(); - if(sf) - { - replylink.StartMessage(SERVER_TRUE); - replylink.Attach(sf->FamilyID()); - replylink.Attach(sf->StyleID()); - replylink.Attach(sf->Size()); - replylink.Attach(sf->Face()); - replylink.Attach(sf->Flags()); - replylink.Flush(); - } - else - { - replylink.StartMessage(SERVER_FALSE); - replylink.Flush(); - } - + ServerFont *sf = fontserver->GetSystemPlain(); + if (sf) { + fLink.StartMessage(SERVER_TRUE); + fLink.Attach(sf->FamilyID()); + fLink.Attach(sf->StyleID()); + fLink.Attach(sf->Size()); + fLink.Attach(sf->Face()); + fLink.Attach(sf->Flags()); + } else + fLink.StartMessage(SERVER_FALSE); + + fLink.Flush(); fontserver->Unlock(); - break; } case AS_GET_FONT_HEIGHT: { - FTRACE(("ServerApp %s: AS_GET_FONT_HEIGHT\n",fSignature.String())); + FTRACE(("ServerApp %s: AS_GET_FONT_HEIGHT\n", fSignature.String())); // Attached Data: // 1) uint16 family ID // 2) uint16 style ID // 3) float size - // 4) port_id reply port uint16 famid,styid; float ptsize; - port_id replyport; - - msg.Read(&famid); - msg.Read(&styid); - msg.Read(&ptsize); - msg.Read(&replyport); - - replylink.SetSendPort(replyport); - + link.Read(&famid); + link.Read(&styid); + link.Read(&ptsize); + fontserver->Lock(); - FontStyle *fstyle=fontserver->GetStyle(famid,styid); - if(fstyle) - { - replylink.StartMessage(SERVER_TRUE); - replylink.Attach(fstyle->GetHeight(ptsize)); - replylink.Flush(); - } - else - { - replylink.StartMessage(SERVER_FALSE); - replylink.Flush(); - } - + FontStyle *fstyle = fontserver->GetStyle(famid, styid); + if (fstyle) { + fLink.StartMessage(SERVER_TRUE); + fLink.Attach(fstyle->GetHeight(ptsize)); + } else + fLink.StartMessage(SERVER_FALSE); + + fLink.Flush(); fontserver->Unlock(); break; } case AS_SET_SYSFONT_BOLD: { - FTRACE(("ServerApp %s: AS_SET_SYSFONT_BOLD\n",fSignature.String())); - // Attached Data: - // port_id reply port - + FTRACE(("ServerApp %s: AS_SET_SYSFONT_BOLD\n", fSignature.String())); // Returns: // 1) uint16 - family ID // 2) uint16 - style ID @@ -1596,69 +1389,46 @@ ServerApp::DispatchMessage(int32 code, LinkMsgReader &msg) // 4) uint16 - face flags // 5) uint32 - font flags - port_id replyport; - msg.Read(&replyport); - replylink.SetSendPort(replyport); - fontserver->Lock(); - ServerFont *sf=fontserver->GetSystemBold(); - if(sf) - { - replylink.StartMessage(SERVER_TRUE); - replylink.Attach(sf->FamilyID()); - replylink.Attach(sf->StyleID()); - replylink.Attach(sf->Size()); - replylink.Attach(sf->Face()); - replylink.Attach(sf->Flags()); - replylink.Flush(); - } - else - { - replylink.StartMessage(SERVER_FALSE); - replylink.Flush(); - } - + ServerFont *sf = fontserver->GetSystemBold(); + if (sf) { + fLink.StartMessage(SERVER_TRUE); + fLink.Attach(sf->FamilyID()); + fLink.Attach(sf->StyleID()); + fLink.Attach(sf->Size()); + fLink.Attach(sf->Face()); + fLink.Attach(sf->Flags()); + } else + fLink.StartMessage(SERVER_FALSE); + + fLink.Flush(); fontserver->Unlock(); - break; } case AS_SET_SYSFONT_FIXED: { - FTRACE(("ServerApp %s: AS_SET_SYSFONT_FIXED\n",fSignature.String())); - // Attached Data: - // port_id reply port - + FTRACE(("ServerApp %s: AS_SET_SYSFONT_FIXED\n", fSignature.String())); // Returns: // 1) uint16 - family ID // 2) uint16 - style ID // 3) float - size in points // 4) uint16 - face flags // 5) uint32 - font flags - - port_id replyport; - msg.Read(&replyport); - replylink.SetSendPort(replyport); - + fontserver->Lock(); - ServerFont *sf=fontserver->GetSystemFixed(); - if(sf) - { - replylink.StartMessage(SERVER_TRUE); - replylink.Attach(sf->FamilyID()); - replylink.Attach(sf->StyleID()); - replylink.Attach(sf->Size()); - replylink.Attach(sf->Face()); - replylink.Attach(sf->Flags()); - replylink.Flush(); - } - else - { - replylink.StartMessage(SERVER_FALSE); - replylink.Flush(); - } - + ServerFont *sf = fontserver->GetSystemFixed(); + if (sf) { + fLink.StartMessage(SERVER_TRUE); + fLink.Attach(sf->FamilyID()); + fLink.Attach(sf->StyleID()); + fLink.Attach(sf->Size()); + fLink.Attach(sf->Face()); + fLink.Attach(sf->Flags()); + } else + fLink.StartMessage(SERVER_FALSE); + + fLink.Flush(); fontserver->Unlock(); - break; } case AS_GET_GLYPH_SHAPES: @@ -1673,33 +1443,28 @@ ServerApp::DispatchMessage(int32 code, LinkMsgReader &msg) // 6) uint32 - flags // 7) int32 - numChars // 8) char - chars (numChars times) - // 9) port_id - reply port - + // Returns: // 1) BShape - glyph shape // numChars times - + uint16 famid, styid; uint32 flags; float ptsize, shear, rotation; - msg.Read(&famid); - msg.Read(&styid); - msg.Read(&ptsize); - msg.Read(&shear); - msg.Read(&rotation); - msg.Read(&flags); + link.Read(&famid); + link.Read(&styid); + link.Read(&ptsize); + link.Read(&shear); + link.Read(&rotation); + link.Read(&flags); int32 numChars; - msg.Read(&numChars); + link.Read(&numChars); char charArray[numChars]; for (int32 i = 0; i < numChars; i++) - msg.Read(&charArray[i]); - - port_id replyport; - msg.Read(&replyport); - replylink.SetSendPort(replyport); + link.Read(&charArray[i]); ServerFont font; if (font.SetFamilyAndStyle(famid, styid) == B_OK) { @@ -1710,23 +1475,19 @@ ServerApp::DispatchMessage(int32 code, LinkMsgReader &msg) BShape **shapes = font.GetGlyphShapes(charArray, numChars); if (shapes) { - replylink.StartMessage(SERVER_TRUE); + fLink.StartMessage(SERVER_TRUE); for (int32 i = 0; i < numChars; i++) { - replylink.AttachShape(*shapes[i]); + fLink.AttachShape(*shapes[i]); delete shapes[i]; } - - replylink.Flush(); + delete shapes; - } else { - replylink.StartMessage(SERVER_FALSE); - replylink.Flush(); - } - } else { - replylink.StartMessage(SERVER_FALSE); - replylink.Flush(); - } - + } else + fLink.StartMessage(SERVER_FALSE); + } else + fLink.StartMessage(SERVER_FALSE); + + fLink.Flush(); break; } case AS_GET_ESCAPEMENTS: @@ -1739,40 +1500,33 @@ ServerApp::DispatchMessage(int32 code, LinkMsgReader &msg) // 4) float - rotation // 5) uint32 - flags // 6) int32 - numChars - // 7) char - char -\ both // 8) BPoint - offset -/ (numChars times) - - // 9) port_id - reply port - + // Returns: // 1) BPoint - escapement // numChars times - + uint16 famid, styid; uint32 flags; float ptsize, rotation; - - msg.Read(&famid); - msg.Read(&styid); - msg.Read(&ptsize); - msg.Read(&rotation); - msg.Read(&flags); - + + link.Read(&famid); + link.Read(&styid); + link.Read(&ptsize); + link.Read(&rotation); + link.Read(&flags); + int32 numChars; - msg.Read(&numChars); - + link.Read(&numChars); + char charArray[numChars]; BPoint offsetArray[numChars]; for (int32 i = 0; i < numChars; i++) { - msg.Read(&charArray[i]); - msg.Read(&offsetArray[i]); + link.Read(&charArray[i]); + link.Read(&offsetArray[i]); } - - port_id replyport; - msg.Read(&replyport); - replylink.SetSendPort(replyport); - + ServerFont font; if (font.SetFamilyAndStyle(famid, styid) == B_OK) { font.SetSize(ptsize); @@ -1781,22 +1535,18 @@ ServerApp::DispatchMessage(int32 code, LinkMsgReader &msg) BPoint *esc = font.GetEscapements(charArray, numChars, offsetArray); if (esc) { - replylink.StartMessage(SERVER_TRUE); + fLink.StartMessage(SERVER_TRUE); for (int32 i = 0; i < numChars; i++) { - replylink.Attach(esc[i]); + fLink.Attach(esc[i]); } - replylink.Flush(); delete esc; - } else { - replylink.StartMessage(SERVER_FALSE); - replylink.Flush(); - } - } else { - replylink.StartMessage(SERVER_FALSE); - replylink.Flush(); - } - + } else + fLink.StartMessage(SERVER_FALSE); + } else + fLink.StartMessage(SERVER_FALSE); + + fLink.Flush(); break; } case AS_GET_ESCAPEMENTS_AS_FLOATS: @@ -1816,8 +1566,6 @@ ServerApp::DispatchMessage(int32 code, LinkMsgReader &msg) // 9) int32 - numBytes // 10) char - the char buffer with size numBytes - // 11) port_id - reply port - // Returns: // 1) float - escapement buffer with numChar entries @@ -1825,36 +1573,32 @@ ServerApp::DispatchMessage(int32 code, LinkMsgReader &msg) uint32 flags; float ptsize, rotation; - msg.Read(&famid); - msg.Read(&styid); - msg.Read(&ptsize); - msg.Read(&rotation); - msg.Read(&flags); + link.Read(&famid); + link.Read(&styid); + link.Read(&ptsize); + link.Read(&rotation); + link.Read(&flags); escapement_delta delta; - msg.Read(&delta.nonspace); - msg.Read(&delta.space); + link.Read(&delta.nonspace); + link.Read(&delta.space); int32 numChars; - msg.Read(&numChars); + link.Read(&numChars); /* char charArray[numChars]; for (int32 i = 0; i < numChars; i++) { - msg.Read(&charArray[i]); + link.Read(&charArray[i]); }*/ uint32 numBytes; - msg.Read(&numBytes); + link.Read(&numBytes); char* charArray = new char[numBytes]; - msg.Read(charArray, numBytes); + link.Read(charArray, numBytes); float* escapements = new float[numChars]; // figure out escapements - port_id replyport; - msg.Read(&replyport); - replylink.SetSendPort(replyport); - ServerFont font; bool success = false; if (font.SetFamilyAndStyle(famid, styid) == B_OK) { @@ -1863,8 +1607,8 @@ ServerApp::DispatchMessage(int32 code, LinkMsgReader &msg) font.SetFlags(flags); if (font.GetEscapements(charArray, numChars, escapements, delta)) { - replylink.StartMessage(SERVER_TRUE); - replylink.Attach(escapements, numChars * sizeof(float)); + fLink.StartMessage(SERVER_TRUE); + fLink.Attach(escapements, numChars * sizeof(float)); success = true; } } @@ -1873,10 +1617,9 @@ ServerApp::DispatchMessage(int32 code, LinkMsgReader &msg) delete[] escapements; if (!success) - replylink.StartMessage(SERVER_FALSE); + fLink.StartMessage(SERVER_FALSE); - replylink.Flush(); - + fLink.Flush(); break; } /* case AS_GET_TRUNCATED_STRINGS: @@ -1902,19 +1645,19 @@ ServerApp::DispatchMessage(int32 code, LinkMsgReader &msg) float size; uint8 spacing; - msg.Read(&family); - msg.Read(&style); - msg.Read(&size); - msg.Read(&spacing); + link.Read(&family); + link.Read(&style); + link.Read(&size); + link.Read(&spacing); // params uint32 mode; float width; int32 count; - msg.Read(&mode); - msg.Read(&width); - msg.Read(&count); + link.Read(&mode); + link.Read(&width); + link.Read(&count); char** strings = NULL; @@ -1922,7 +1665,7 @@ ServerApp::DispatchMessage(int32 code, LinkMsgReader &msg) if (count > 0) { strings = new char*[count]; for (int32 i = 0; i < count; i++) { - msg.ReadString(&strings[i]); + link.ReadString(&strings[i]); } // TODO: truncate strings here ServerFont font; @@ -1933,20 +1676,15 @@ ServerApp::DispatchMessage(int32 code, LinkMsgReader &msg) } } - int32 replyport; - msg.Read(&replyport); - - replylink.SetSendPort(replyport); - if (success) { - replylink.StartMessage(SERVER_TRUE); + fLink.StartMessage(SERVER_TRUE); for (int32 i = 0; i < count; i++) { - replylink.AttachString(strings[i]); + fLink.AttachString(strings[i]); } - } else { - replylink.StartMessage(SERVER_FALSE); - } - replylink.Flush(); + } else + fLink.StartMessage(SERVER_FALSE); + + fLink.Flush(); // free used resources if (count > 0) { @@ -1966,10 +1704,10 @@ printf("ServerApp %s: AS_SCREEN_GET_MODE\n", fSignature.String()); // 2) screen_id // 3) workspace index screen_id id; - msg.Read(&id); + link.Read(&id); uint32 workspace; - msg.Read(&workspace); - + link.Read(&workspace); + // TODO: the display_mode can be different between // the various screens. // We have the screen_id and the workspace number, with these @@ -1978,16 +1716,11 @@ printf("ServerApp %s: AS_SCREEN_GET_MODE\n", fSignature.String()); gDesktop->GetDisplayDriver()->GetMode(mode); // actually this isn't still enough as different workspaces can // have different display_modes - - int32 replyport; - msg.Read(&replyport); - - replylink.SetSendPort(replyport); - replylink.StartMessage(SERVER_TRUE); - replylink.Attach(mode); - replylink.Attach(B_OK); - replylink.Flush(); - + + fLink.StartMessage(SERVER_TRUE); + fLink.Attach(mode); + fLink.Attach(B_OK); + fLink.Flush(); break; } case AS_SCREEN_SET_MODE: @@ -2000,72 +1733,59 @@ printf("ServerApp %s: AS_SCREEN_GET_MODE\n", fSignature.String()); // 4) display_mode to set // 5) 'makedefault' boolean // TODO: See above: workspaces support, etc. - + screen_id id; - msg.Read(&id); - + link.Read(&id); + uint32 workspace; - msg.Read(&workspace); - + link.Read(&workspace); + display_mode mode; - msg.Read(&mode); - + link.Read(&mode); + bool makedefault = false; - msg.Read(&makedefault); - + link.Read(&makedefault); + // TODO: Adi doesn't like this: see if // messaging is better. gDesktop->ActiveRootLayer()->Lock(); // TODO: This should return something gDesktop->GetDisplayDriver()->SetMode(mode); gDesktop->ActiveRootLayer()->Unlock(); - - int32 replyport; - msg.Read(&replyport); - - replylink.SetSendPort(replyport); - replylink.StartMessage(SERVER_TRUE); - replylink.Attach(B_OK); - replylink.Flush(); + + fLink.StartMessage(SERVER_TRUE); + fLink.Attach(B_OK); + fLink.Flush(); break; } - + case AS_SCREEN_GET_COLORMAP: { STRACE(("ServerApp %s: AS_SCREEN_GET_COLORMAP\n", fSignature.String())); - + screen_id id; - msg.Read(&id); - - int32 replyport; - msg.Read(&replyport); - - replylink.SetSendPort(replyport); - replylink.StartMessage(SERVER_TRUE); - + link.Read(&id); + + fLink.StartMessage(SERVER_TRUE); + // TODO: this doesn't seem to work. //See also comment in BPrivateScreen::BPrivateScreen() - //replylink.Attach(*SystemColorMap()); - replylink.Flush(); - + //fLink.Attach(*SystemColorMap()); + fLink.Flush(); break; } - - default: - { - printf("ServerApp %s received unhandled message code offset %s\n", fSignature.String(), - MsgCodeToBString(code).String()); - // TODO: completely broken. The reply port seems to be unkown! - // It is in the data, but the position is unkown. Man, I find - // this comm stuff really clumsy. -Stephan) - // And BTW: the client is now blocking and waiting for a reply! - /*replylink.SetSendPort(msg.GetPort()); - replylink.StartMessage(SERVER_FALSE); - replylink.Flush(); - */ + default: + printf("ServerApp %s received unhandled message code offset %s\n", + fSignature.String(), MsgCodeToBString(code).String()); + + if (link.NeedsReply()) { + // the client is now blocking and waiting for a reply! + fLink.StartMessage(SERVER_FALSE); + fLink.Flush(); + } else + puts("message doesn't need a reply!"); break; - } } } diff --git a/src/servers/app/ServerApp.h b/src/servers/app/ServerApp.h index 3356661fb3..baeacdf67e 100644 --- a/src/servers/app/ServerApp.h +++ b/src/servers/app/ServerApp.h @@ -30,6 +30,7 @@ #include #include +#include #include "FMWList.h" @@ -38,8 +39,6 @@ class BMessage; class BPortLink; class BList; class DisplayDriver; -class LinkMsgReader; -class LinkMsgSender; class ServerPicture; class ServerCursor; class ServerBitmap; @@ -92,9 +91,9 @@ public: private: void DispatchMessage(int32 code, LinkMsgReader &link); - + static int32 MonitorApp(void *data); - + // our BApplication's event port port_id fClientAppPort; // port we receive messages from our BApplication @@ -104,15 +103,14 @@ private: // as BAppServerLink/BPortlink's messages always contain the reply port // To send a message to the client, write a BMessage to this port port_id fClientLooperPort; - + BString fSignature; - + thread_id fMonitorThreadID; team_id fClientTeamID; - - LinkMsgReader *fMsgReader; - LinkMsgSender *fMsgSender; - + + BPortLink fLink; + // TODO: // - Are really Bitmaps and Pictures stored per application and not globally ? // - As we reference these stuff by token, what about putting them in hash tables ? diff --git a/src/tests/kits/app/messaging/PortLinkTest.cpp b/src/tests/kits/app/messaging/PortLinkTest.cpp index e7decfb3a9..55f4149527 100644 --- a/src/tests/kits/app/messaging/PortLinkTest.cpp +++ b/src/tests/kits/app/messaging/PortLinkTest.cpp @@ -12,7 +12,7 @@ void get_next_message(BPortLink &link, int32 expectedCode) { int32 code; - if (link.GetNextReply(code) != B_OK) { + if (link.GetNextMessage(code) != B_OK) { fprintf(stderr, "get message failed!\n"); exit(-1); } @@ -96,7 +96,7 @@ main() get_next_message(receiver, 'tst5'); int32 code; - status = receiver.GetNextReply(code, 0); + status = receiver.GetNextMessage(code, 0); if (status != B_WOULD_BLOCK) { fprintf(stderr, "reading would not block!\n"); return -1;