Added PortMessage::ReadString and PortLink::AttachString to support BSession-style string attachments

Tweaks to startup code for BApplication
Tweaked PortQueue to utilize the BSession workaround for PortMessages
Tweaks to message protocol for BCursor


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4939 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
DarkWyrm
2003-10-04 00:55:53 +00:00
parent 9e6ef5ce51
commit 591d280e6c
5 changed files with 45 additions and 16 deletions
+13 -14
View File
@@ -52,6 +52,8 @@
#include <ObjectLocker.h>
#include <AppServerLink.h>
#include <ServerProtocol.h>
#include <PortLink.h>
#include <PortMessage.h>
// Local Includes --------------------------------------------------------------
@@ -757,24 +759,21 @@ void BApplication::InitData(const char* signature, status_t* error)
// Attach data:
// 1) port_id - receiver port of a regular app
// 2) char * - signature of the regular app
port_id srcv=create_port(100,"BApp reply port");
BSession session(srcv,fServerTo);
session.WriteInt32(AS_CREATE_APP);
session.WriteInt32(fServerTo);
session.WriteInt32(_get_object_token_(this));
session.WriteData(signature,strlen(signature)+1);
session.Sync();
port_id serverapp_port;
session.ReadInt32(&serverapp_port);
// 2) int32 - handler ID token of the app
// 3) char * - signature of the regular app
PortLink link(fServerFrom);
PortMessage pmsg;
link.SetOpCode(AS_CREATE_APP);
link.Attach<port_id>(fServerTo);
link.Attach<port_id>(_get_object_token_(this));
link.AttachString(signature);
link.FlushWithReply(&pmsg);
// Reply code: AS_CREATE_APP
// Reply data:
// 1) port_id server-side application port (fServerFrom value)
fServerFrom=serverapp_port;
delete_port(srcv);
pmsg.Read<port_id>(&fServerFrom);
}
else
fInitError=fServerTo;
+1
View File
@@ -65,6 +65,7 @@ BCursor::BCursor(const void *cursorData)
serverlink.WriteInt32(AS_CREATE_BCURSOR);
serverlink.WriteData(cursorData,68);
serverlink.WriteInt32(serverlink.GetRecvPort());
serverlink.Sync();
serverlink.ReadInt32(&m_serverToken);
}
+9 -1
View File
@@ -79,7 +79,7 @@ status_t PortLink::FlushWithReply( PortMessage *msg,bigtime_t timeout=B_INFINITE
Attach<int32>(fReceivePort);
// Flush the thing....FOOSH! :P
write_port(fSendPort, fSendCode, fSendBuffer, fSendPosition);
write_port(fSendPort, AS_SERVER_SESSION, fSendBuffer, fSendPosition);
fSendPosition = 4;
// Now we wait for the reply
@@ -126,6 +126,14 @@ status_t PortLink::Attach(const void *data, size_t size)
return B_NO_MEMORY;
}
status_t PortLink::AttachString(const char *string)
{
int16 len = (int16)strlen(string)+1;
Attach<int16>(len);
return Attach(string, len);
}
void PortLink::MakeEmpty()
{
fSendPosition=4;
+20
View File
@@ -172,3 +172,23 @@ void PortMessage::BSessionWorkaround(void)
else
is_session_msg=false;
}
status_t PortMessage::ReadString(char **string)
{
int16 len=0;
if(Read<int16>(&len)!= B_OK)
return B_ERROR;
if (len)
{
*string=new char[len];
if(Read(*string, len)!= B_OK)
{
delete *string;
*string=NULL;
}
}
return B_OK;
}
+2 -1
View File
@@ -76,7 +76,7 @@ void PortQueue::GetMessagesFromPort(bool wait_for_messages)
delete msg;
break;
}
msg->BSessionWorkaround();
_q.push(msg);
}
@@ -90,6 +90,7 @@ PortMessage *PortQueue::GetMessageFromQueue(void)
PortMessage *msg=_q.front();
_q.pop();
msg->BSessionWorkaround();
return msg;
}