Can get replies as PortMessages now

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3627 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
DarkWyrm 2003-06-23 13:18:39 +00:00
parent 1fe39d4d37
commit 6b76dd01f5
2 changed files with 93 additions and 1 deletions

View File

@ -8,6 +8,7 @@
#include <List.h>
class PortLinkData;
class PortMessage;
class PortLink
{
@ -31,6 +32,8 @@ public:
int8* FlushWithReply(int32 *code, status_t *status, ssize_t *buffersize,
bigtime_t timeout=B_INFINITE_TIMEOUT);
status_t FlushWithReply(PortLink::ReplyData *data,bigtime_t timeout=B_INFINITE_TIMEOUT);
status_t FlushWithReply(PortMessage *msg,bigtime_t timeout=B_INFINITE_TIMEOUT);
status_t Attach(const void *data, size_t size);
status_t Attach(int32 data);
status_t Attach(int16 data);

View File

@ -24,7 +24,8 @@
// Description: A helper class for port-based messaging
//
//------------------------------------------------------------------------------
#include "PortLink.h"
#include <PortLink.h>
#include <PortMessage.h>
#include <string.h>
#include <stdio.h>
#include <malloc.h>
@ -395,6 +396,94 @@ printf("\tFlushWithReply(): unable to assign reply port to data\n");
return B_OK;
}
status_t PortLink::FlushWithReply(PortMessage *msg,bigtime_t timeout=B_INFINITE_TIMEOUT)
{
#ifdef PLDEBUG
printf("PortLink::FlushWithReply(PortMessage*,bigtime_t)\n");
#endif
// Fires a message to the target and then waits for a reply. The target will
// receive a message with the first item being the port_id to reply to.
// Effectively, an Attach() call inlined for changes
if(!port_ok || !msg)
{
#ifdef PLDEBUG
printf("\tFlushWithReply(): invalid port\n");
#endif
return B_BAD_VALUE;
}
// create a new storage object and stash the data
PortLinkData *pld=new PortLinkData;
if(pld->Set(&replyport,sizeof(port_id))==B_OK)
{
bufferlength+=sizeof(port_id);
}
else
{
#ifdef PLDEBUG
printf("\tFlushWithReply(): unable to assign reply port to data\n");
#endif
delete pld;
return B_ERROR;
}
// Flatten() inlined to make some necessary changes
int8 *buffer=new int8[bufferlength];
int8 *bufferindex=buffer;
size_t size=0;
// attach our port_id first
memcpy(bufferindex, pld->buffer, pld->buffersize);
bufferindex += pld->buffersize;
size+=pld->buffersize;
// attach everything else
for(int i=0;i<attachlist->CountItems();i++)
{
pld=(PortLinkData*)attachlist->ItemAt(i);
memcpy(bufferindex, pld->buffer, pld->buffersize);
bufferindex += pld->buffersize;
size+=pld->buffersize;
}
// Flush the thing....FOOSH! :P
write_port(target,opcode,buffer,size);
MakeEmpty();
delete buffer;
// Now we wait for the reply
ssize_t rbuffersize;
int8 *rbuffer=NULL;
int32 rcode;
if(timeout==B_INFINITE_TIMEOUT)
{
rbuffersize=port_buffer_size(replyport);
if(rbuffersize>0)
rbuffer=(int8*)new int8[rbuffersize];
read_port(replyport,&rcode,rbuffer,rbuffersize);
}
else
{
rbuffersize=port_buffer_size_etc(replyport,0,timeout);
if(rbuffersize==B_TIMED_OUT)
return B_TIMED_OUT;
if(rbuffersize>0)
rbuffer=(int8*)new int8[rbuffersize];
read_port(replyport,&rcode,rbuffer,rbuffersize);
}
// We got this far, so we apparently have some data
msg->SetCode(rcode);
msg->SetBuffer(rbuffer,rbuffersize,false);
return B_OK;
}
status_t PortLink::Attach(const void *data, size_t size)
{
#ifdef PLDEBUG