Numerous messaging fixes to coincide with the recent updates to PortLink, BSession, PortQueue, and PortMessage

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4940 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
DarkWyrm
2003-10-04 00:56:43 +00:00
parent 591d280e6c
commit e90ddf96b4
3 changed files with 70 additions and 65 deletions
+49 -45
View File
@@ -210,7 +210,7 @@ int32 AppServer::PollerThread(void *data)
for(;;) for(;;)
{ {
if(!mousequeue.MessagesWaiting()) if(!mousequeue.MessagesWaiting())
mousequeue.GetMessagesFromPort(true); // wait for a message to come into the port mousequeue.GetMessagesFromPort(true);
else else
mousequeue.GetMessagesFromPort(false); mousequeue.GetMessagesFromPort(false);
@@ -229,7 +229,6 @@ int32 AppServer::PollerThread(void *data)
{ {
if(!msg->Buffer()) if(!msg->Buffer())
break; break;
// ServerWindow::HandleMouseEvent(msg->Code(),(int8*)msg->Buffer());
ServerWindow::HandleMouseEvent(msg); ServerWindow::HandleMouseEvent(msg);
break; break;
} }
@@ -242,10 +241,15 @@ int32 AppServer::PollerThread(void *data)
// 2) float - x coordinate of mouse click // 2) float - x coordinate of mouse click
// 3) float - y coordinate of mouse click // 3) float - y coordinate of mouse click
// 4) int32 - buttons down // 4) int32 - buttons down
// We're using
index=(int8*)msg->Buffer(); index=(int8*)msg->Buffer();
if(!index) if(!index)
break; break;
// Skip past the message code packaged in the BSession-style message
index += sizeof(int32);
// Time sent is not necessary for cursor processing. // Time sent is not necessary for cursor processing.
index += sizeof(int64); index += sizeof(int64);
@@ -258,7 +262,6 @@ int32 AppServer::PollerThread(void *data)
if(appserver->_driver) if(appserver->_driver)
{ {
appserver->_driver->MoveCursorTo(tempx,tempy); appserver->_driver->MoveCursorTo(tempx,tempy);
// ServerWindow::HandleMouseEvent(msg->Code(),(int8*)msg->Buffer());
ServerWindow::HandleMouseEvent(msg); ServerWindow::HandleMouseEvent(msg);
} }
break; break;
@@ -333,20 +336,13 @@ thread_id AppServer::Run(void)
//! Main message-monitoring loop for the regular message port - no input messages! //! Main message-monitoring loop for the regular message port - no input messages!
void AppServer::MainLoop(void) void AppServer::MainLoop(void)
{ {
int32 msgcode; PortMessage pmsg;
int8 *msgbuffer=NULL;
ssize_t buffersize,bytesread;
for(;;) for(;;)
{ {
buffersize=port_buffer_size(_messageport); if(pmsg.ReadFromPort(_messageport)==B_OK)
if(buffersize>0)
msgbuffer=new int8[buffersize];
bytesread=read_port(_messageport,&msgcode,msgbuffer,buffersize);
if (bytesread != B_BAD_PORT_ID && bytesread != B_TIMED_OUT && bytesread != B_WOULD_BLOCK)
{ {
switch(msgcode) switch(pmsg.Code())
{ {
case AS_CREATE_APP: case AS_CREATE_APP:
case AS_DELETE_APP: case AS_DELETE_APP:
@@ -354,20 +350,18 @@ void AppServer::MainLoop(void)
case B_QUIT_REQUESTED: case B_QUIT_REQUESTED:
case AS_UPDATED_CLIENT_FONTLIST: case AS_UPDATED_CLIENT_FONTLIST:
case AS_QUERY_FONTS_CHANGED: case AS_QUERY_FONTS_CHANGED:
DispatchMessage(msgcode,msgbuffer); DispatchMessage(&pmsg);
break; break;
default: default:
{ {
printf("Server::MainLoop received unexpected code %ld\n",msgcode); printf("Server::MainLoop received unexpected code %ld\n",pmsg.Code());
break; break;
} }
} }
} }
if(buffersize>0) if(pmsg.Code()==AS_DELETE_APP || (pmsg.Code()==B_QUIT_REQUESTED && DISPLAYDRIVER!=HWDRIVER))
delete msgbuffer;
if(msgcode==AS_DELETE_APP || msgcode==B_QUIT_REQUESTED && DISPLAYDRIVER!=HWDRIVER)
{ {
if(_quitting_server==true && _applist->CountItems()==0) if(_quitting_server==true && _applist->CountItems()==0)
break; break;
@@ -458,25 +452,30 @@ void AppServer::InitDecorators(void)
\param buffer Attachement buffer for the message. \param buffer Attachement buffer for the message.
*/ */
void AppServer::DispatchMessage(int32 code, int8 *buffer) void AppServer::DispatchMessage(PortMessage *msg)
{ {
int8 *index=buffer; switch(msg->Code())
switch(code)
{ {
case AS_CREATE_APP: case AS_CREATE_APP:
{ {
// Create the ServerApp to node monitor a new BApplication // Create the ServerApp to node monitor a new BApplication
// Attached data: // Attached data:
// 1) port_id - port to reply to // 1) port_id - receiver port of a regular app
// 2) port_id - receiver port of a regular app // 2) int32 - handler token of the regular app
// 3) char * - signature of the regular app // 2) char * - signature of the regular app
// 3) port_id - port to reply to
// Find the necessary data // Find the necessary data
port_id reply_port=*((port_id*)index); index+=sizeof(port_id); port_id reply_port;
port_id app_port=*((port_id*)index); index+=sizeof(port_id); port_id app_port;
int32 htoken=*((int32*)index); index+=sizeof(int32); int32 htoken;
char *app_signature=(char *)index; char *app_signature;
msg->Read<int32>(&app_port);
msg->Read<int32>(&htoken);
msg->ReadString(&app_signature);
msg->Read<int32>(&reply_port);
// Create the ServerApp subthread for this app // Create the ServerApp subthread for this app
acquire_sem(_applist_lock); acquire_sem(_applist_lock);
@@ -497,12 +496,13 @@ void AppServer::DispatchMessage(int32 code, int8 *buffer)
_p_active_app=newapp; _p_active_app=newapp;
_active_app=_applist->CountItems()-1; _active_app=_applist->CountItems()-1;
PortLink *replylink=new PortLink(reply_port); PortLink replylink(reply_port);
replylink->SetOpCode(AS_SET_SERVER_PORT); replylink.SetOpCode(AS_SET_SERVER_PORT);
replylink->Attach<int32>(newapp->_receiver); replylink.Attach<int32>(newapp->_receiver);
replylink->Flush(); replylink.Flush();
delete replylink; // This is necessary because PortLink::ReadString allocates memory
delete app_signature;
release_sem(_active_lock); release_sem(_active_lock);
@@ -519,7 +519,8 @@ void AppServer::DispatchMessage(int32 code, int8 *buffer)
int32 i, appnum=_applist->CountItems(); int32 i, appnum=_applist->CountItems();
ServerApp *srvapp; ServerApp *srvapp;
thread_id srvapp_id=*((thread_id*)buffer); thread_id srvapp_id;
msg->Read<thread_id>(&srvapp_id);
// Run through the list of apps and nuke the proper one // Run through the list of apps and nuke the proper one
for(i=0;i<appnum;i++) for(i=0;i<appnum;i++)
@@ -580,11 +581,12 @@ void AppServer::DispatchMessage(int32 code, int8 *buffer)
bool needs_update=fontserver->FontsNeedUpdated(); bool needs_update=fontserver->FontsNeedUpdated();
fontserver->Unlock(); fontserver->Unlock();
PortLink *pl=new PortLink(*((port_id*)index)); // Seeing how the client merely wants an answer, we'll skip the PortLink
pl->SetOpCode( (needs_update)?SERVER_TRUE:SERVER_FALSE ); // and all its overhead and just write the code to port.
pl->Flush(); port_id replyport;
delete pl; msg->Read<port_id>(&replyport);
write_port(replyport, (needs_update)?SERVER_TRUE:SERVER_FALSE, NULL,0);
break; break;
} }
case AS_GET_SCREEN_MODE: case AS_GET_SCREEN_MODE:
@@ -601,13 +603,15 @@ void AppServer::DispatchMessage(int32 code, int8 *buffer)
// 2) int32 height // 2) int32 height
// 3) int depth // 3) int depth
PortLink *replylink=new PortLink(*((port_id*)index)); port_id replyport;
replylink->SetOpCode(AS_GET_SCREEN_MODE); msg->Read<port_id>(&replyport);
replylink->Attach<int16>(_driver->GetWidth());
replylink->Attach<int16>(_driver->GetHeight()); PortLink replylink(replyport);
replylink->Attach<int16>(_driver->GetDepth()); replylink.SetOpCode(AS_GET_SCREEN_MODE);
replylink->Flush(); replylink.Attach<int16>(_driver->GetWidth());
delete replylink; replylink.Attach<int16>(_driver->GetHeight());
replylink.Attach<int16>(_driver->GetDepth());
replylink.Flush();
break; break;
} }
case B_QUIT_REQUESTED: case B_QUIT_REQUESTED:
+2 -1
View File
@@ -16,6 +16,7 @@ class ServerApp;
class DisplayDriver; class DisplayDriver;
class CursorManager; class CursorManager;
class BitmapManager; class BitmapManager;
class PortMessage;
/*! /*!
\class AppServer AppServer.h \class AppServer AppServer.h
@@ -40,7 +41,7 @@ public:
void MainLoop(void); void MainLoop(void);
bool LoadDecorator(const char *path); bool LoadDecorator(const char *path);
void InitDecorators(void); void InitDecorators(void);
void DispatchMessage(int32 code, int8 *buffer); void DispatchMessage(PortMessage *msg);
void Broadcast(int32 code); void Broadcast(int32 code);
void HandleKeyMessage(int32 code, int8 *buffer); void HandleKeyMessage(int32 code, int8 *buffer);
ServerApp *FindApp(const char *sig); ServerApp *FindApp(const char *sig);
+17 -17
View File
@@ -253,7 +253,7 @@ int32 ServerApp::MonitorApp(void *data)
// Message-dispatching loop for the ServerApp // Message-dispatching loop for the ServerApp
int32 msgCode; int32 msgCode;
app->ses = new BSession( app->_receiver, 0L ); app->ses=new BSession( app->_receiver, 0L );
for(;;) for(;;)
{ {
@@ -420,12 +420,12 @@ void ServerApp::_DispatchMessage(int32 code)
// Allocate a bitmap for an application // Allocate a bitmap for an application
// Attached Data: // Attached Data:
// 1) port_id reply port // 1) BRect bounds
// 2) BRect bounds // 2) color_space space
// 3) color_space space // 3) int32 bitmap_flags
// 4) int32 bitmap_flags // 4) int32 bytes_per_row
// 5) int32 bytes_per_row // 5) int32 screen_id::id
// 6) int32 screen_id::id // 6) port_id reply port
// Reply Code: SERVER_TRUE // Reply Code: SERVER_TRUE
// Reply Data: // Reply Data:
@@ -440,12 +440,12 @@ void ServerApp::_DispatchMessage(int32 code)
int32 f,bpr; int32 f,bpr;
screen_id s; screen_id s;
ses->ReadInt32(&replyport);
ses->ReadRect(&r); ses->ReadRect(&r);
ses->ReadData(&cs,sizeof(color_space)); ses->ReadData(&cs,sizeof(color_space));
ses->ReadInt32(&f); ses->ReadInt32(&f);
ses->ReadInt32(&bpr); ses->ReadInt32(&bpr);
ses->ReadData(&s,sizeof(screen_id)); ses->ReadData(&s,sizeof(screen_id));
ses->ReadInt32(&replyport);
ServerBitmap *sbmp=bitmapmanager->CreateBitmap(r,cs,f,bpr,s); ServerBitmap *sbmp=bitmapmanager->CreateBitmap(r,cs,f,bpr,s);
@@ -475,16 +475,16 @@ void ServerApp::_DispatchMessage(int32 code)
// Delete a bitmap's allocated memory // Delete a bitmap's allocated memory
// Attached Data: // Attached Data:
// 1) int32 reply port // 1) int32 token
// 2) int32 token // 2) int32 reply port
// Reply Code: SERVER_TRUE if successful, // Reply Code: SERVER_TRUE if successful,
// SERVER_FALSE if the buffer was already deleted or was not found // SERVER_FALSE if the buffer was already deleted or was not found
port_id replyport; port_id replyport;
int32 bmp_id; int32 bmp_id;
ses->ReadInt32(&replyport);
ses->ReadInt32(&bmp_id); ses->ReadInt32(&bmp_id);
ses->ReadInt32(&replyport);
ServerBitmap *sbmp=_FindBitmap(bmp_id); ServerBitmap *sbmp=_FindBitmap(bmp_id);
if(sbmp) if(sbmp)
@@ -634,23 +634,23 @@ void ServerApp::_DispatchMessage(int32 code)
case AS_CREATE_BCURSOR: case AS_CREATE_BCURSOR:
{ {
// Attached data: // Attached data:
// 1) port_id reply port // 1) 68 bytes of _appcursor data
// 2) 68 bytes of _appcursor data // 2) port_id reply port
port_id replyport; port_id replyport;
int8 cdata[68]; int8 cdata[68];
ses->ReadInt32(&replyport);
ses->ReadData(cdata,68); ses->ReadData(cdata,68);
ses->ReadInt32(&replyport);
_appcursor=new ServerCursor(cdata); _appcursor=new ServerCursor(cdata);
_appcursor->SetAppSignature(_signature.String()); _appcursor->SetAppSignature(_signature.String());
cursormanager->AddCursor(_appcursor); cursormanager->AddCursor(_appcursor);
// Synchronous message - BApplication is waiting on the cursor's ID // Synchronous message - BApplication is waiting on the cursor's ID
BSession replysession(0,replyport); PortLink link(replyport);
replysession.WriteInt32(_appcursor->ID()); link.Attach<int32>(_appcursor->ID());
replysession.Sync(); link.Flush();
break; break;
} }
case AS_DELETE_BCURSOR: case AS_DELETE_BCURSOR: