More testing and fixes. Removed an attachment bug.
Port capacity checking a compile-time option. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2018 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -27,9 +27,11 @@ capacity - contains the storage capacity of the target port.
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
|
|
||||||
//#define PLDEBUG
|
#define PLDEBUG
|
||||||
//#define PLD_DEBUG
|
//#define PLD_DEBUG
|
||||||
|
|
||||||
|
//#define CAPACITY_CHECKING
|
||||||
|
|
||||||
#ifdef PLDEBUG
|
#ifdef PLDEBUG
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#endif
|
#endif
|
||||||
@@ -68,6 +70,10 @@ printf("PortLink(%lu)\n",port);
|
|||||||
opcode=0;
|
opcode=0;
|
||||||
bufferlength=0;
|
bufferlength=0;
|
||||||
replyport=create_port(30,"PortLink reply port");
|
replyport=create_port(30,"PortLink reply port");
|
||||||
|
#ifdef PLDEBUG
|
||||||
|
printf("\tPort valid: %s\n",(port_ok)?"true":"false");
|
||||||
|
printf("\tReply port: %lu\n",replyport);
|
||||||
|
#endif
|
||||||
|
|
||||||
// TODO: initialize all attachments pointers to NULL
|
// TODO: initialize all attachments pointers to NULL
|
||||||
}
|
}
|
||||||
@@ -88,6 +94,13 @@ printf("PortLink(PortLink*)\n");
|
|||||||
num_attachments=0;
|
num_attachments=0;
|
||||||
replyport=create_port(30,"PortLink reply port");
|
replyport=create_port(30,"PortLink reply port");
|
||||||
|
|
||||||
|
#ifdef PLDEBUG
|
||||||
|
printf("\tOpcode: %lu\n",opcode);
|
||||||
|
printf("\tTarget port: %lu\n",target);
|
||||||
|
printf("\tCapacity: %lu\n",capacity);
|
||||||
|
printf("\tPort valid: %s\n",(port_ok)?"true":"false");
|
||||||
|
printf("\tReply port: %lu\n",replyport);
|
||||||
|
#endif
|
||||||
// TODO: initialize all attachments pointers to NULL
|
// TODO: initialize all attachments pointers to NULL
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,7 +123,11 @@ printf("~PortLink()\n");
|
|||||||
void PortLink::SetOpCode(int32 code)
|
void PortLink::SetOpCode(int32 code)
|
||||||
{
|
{
|
||||||
#ifdef PLDEBUG
|
#ifdef PLDEBUG
|
||||||
printf("PortLink::SetOpCode(%lu)\n",code);
|
printf("PortLink::SetOpCode(%c%c%c%c)\n",
|
||||||
|
(char)((code & 0xFF000000) >> 24),
|
||||||
|
(char)((code & 0x00FF0000) >> 16),
|
||||||
|
(char)((code & 0x0000FF00) >> 8),
|
||||||
|
(char)((code & 0x000000FF)) );
|
||||||
#endif
|
#endif
|
||||||
// Sets the message code. This does not change once the message is sent.
|
// Sets the message code. This does not change once the message is sent.
|
||||||
// Another call to SetOpCode() is required for such things.
|
// Another call to SetOpCode() is required for such things.
|
||||||
@@ -247,6 +264,7 @@ printf("PortLink::FlushWithReply(): bad port\n");
|
|||||||
delete buffer;
|
delete buffer;
|
||||||
|
|
||||||
// Now we wait for the reply
|
// Now we wait for the reply
|
||||||
|
buffer=NULL;
|
||||||
if(timeout==B_INFINITE_TIMEOUT)
|
if(timeout==B_INFINITE_TIMEOUT)
|
||||||
{
|
{
|
||||||
*buffersize=port_buffer_size(replyport);
|
*buffersize=port_buffer_size(replyport);
|
||||||
@@ -388,6 +406,7 @@ printf("\tAttach(): size invalid -> size=0\n");
|
|||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef CAPACITY_CHECKING
|
||||||
if(bufferlength+size>capacity)
|
if(bufferlength+size>capacity)
|
||||||
{
|
{
|
||||||
#ifdef PLDEBUG
|
#ifdef PLDEBUG
|
||||||
@@ -395,6 +414,7 @@ printf("\tAttach(): bufferlength+size > port capacity\n");
|
|||||||
#endif
|
#endif
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// create a new storage object and stash the data
|
// create a new storage object and stash the data
|
||||||
PortLinkData *pld=new PortLinkData;
|
PortLinkData *pld=new PortLinkData;
|
||||||
@@ -434,12 +454,14 @@ printf("Attach(%ld)\n",data);
|
|||||||
|
|
||||||
int32 size=sizeof(int32);
|
int32 size=sizeof(int32);
|
||||||
|
|
||||||
|
#ifdef CAPACITY_CHECKING
|
||||||
if(bufferlength+size>capacity)
|
if(bufferlength+size>capacity)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
#endif
|
||||||
|
|
||||||
// create a new storage object and stash the data
|
// create a new storage object and stash the data
|
||||||
PortLinkData *pld=new PortLinkData;
|
PortLinkData *pld=new PortLinkData;
|
||||||
if(pld->Set(&data,size))
|
if(pld->Set(&data,size)==B_OK)
|
||||||
{
|
{
|
||||||
num_attachments++;
|
num_attachments++;
|
||||||
attachments[num_attachments-1]=pld;
|
attachments[num_attachments-1]=pld;
|
||||||
@@ -463,12 +485,14 @@ printf("Attach(%d)\n",data);
|
|||||||
|
|
||||||
int32 size=sizeof(int16);
|
int32 size=sizeof(int16);
|
||||||
|
|
||||||
|
#ifdef CAPACITY_CHECKING
|
||||||
if(bufferlength+size>capacity)
|
if(bufferlength+size>capacity)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
#endif
|
||||||
|
|
||||||
// create a new storage object and stash the data
|
// create a new storage object and stash the data
|
||||||
PortLinkData *pld=new PortLinkData;
|
PortLinkData *pld=new PortLinkData;
|
||||||
if(pld->Set(&data,size))
|
if(pld->Set(&data,size)==B_OK)
|
||||||
{
|
{
|
||||||
num_attachments++;
|
num_attachments++;
|
||||||
attachments[num_attachments-1]=pld;
|
attachments[num_attachments-1]=pld;
|
||||||
@@ -492,12 +516,14 @@ printf("Attach(%d)\n",data);
|
|||||||
|
|
||||||
int32 size=sizeof(int8);
|
int32 size=sizeof(int8);
|
||||||
|
|
||||||
|
#ifdef CAPACITY_CHECKING
|
||||||
if(bufferlength+size>capacity)
|
if(bufferlength+size>capacity)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
#endif
|
||||||
|
|
||||||
// create a new storage object and stash the data
|
// create a new storage object and stash the data
|
||||||
PortLinkData *pld=new PortLinkData;
|
PortLinkData *pld=new PortLinkData;
|
||||||
if(pld->Set(&data,size))
|
if(pld->Set(&data,size)==B_OK)
|
||||||
{
|
{
|
||||||
num_attachments++;
|
num_attachments++;
|
||||||
attachments[num_attachments-1]=pld;
|
attachments[num_attachments-1]=pld;
|
||||||
@@ -521,12 +547,14 @@ printf("Attach(%f)\n",data);
|
|||||||
|
|
||||||
int32 size=sizeof(float);
|
int32 size=sizeof(float);
|
||||||
|
|
||||||
|
#ifdef CAPACITY_CHECKING
|
||||||
if(bufferlength+size>capacity)
|
if(bufferlength+size>capacity)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
#endif
|
||||||
|
|
||||||
// create a new storage object and stash the data
|
// create a new storage object and stash the data
|
||||||
PortLinkData *pld=new PortLinkData;
|
PortLinkData *pld=new PortLinkData;
|
||||||
if(pld->Set(&data,size))
|
if(pld->Set(&data,size)==B_OK)
|
||||||
{
|
{
|
||||||
num_attachments++;
|
num_attachments++;
|
||||||
attachments[num_attachments-1]=pld;
|
attachments[num_attachments-1]=pld;
|
||||||
@@ -550,12 +578,14 @@ printf("Attach(%s)\n",(data)?"true":"false");
|
|||||||
|
|
||||||
int32 size=sizeof(bool);
|
int32 size=sizeof(bool);
|
||||||
|
|
||||||
|
#ifdef CAPACITY_CHECKING
|
||||||
if(bufferlength+size>capacity)
|
if(bufferlength+size>capacity)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
#endif
|
||||||
|
|
||||||
// create a new storage object and stash the data
|
// create a new storage object and stash the data
|
||||||
PortLinkData *pld=new PortLinkData;
|
PortLinkData *pld=new PortLinkData;
|
||||||
if(pld->Set(&data,size))
|
if(pld->Set(&data,size)==B_OK)
|
||||||
{
|
{
|
||||||
num_attachments++;
|
num_attachments++;
|
||||||
attachments[num_attachments-1]=pld;
|
attachments[num_attachments-1]=pld;
|
||||||
@@ -579,12 +609,14 @@ printf("Attach(BRect(%f,%f,%f,%f))\n",data.left,data.top,data.right,data.bottom)
|
|||||||
|
|
||||||
int32 size=sizeof(BRect);
|
int32 size=sizeof(BRect);
|
||||||
|
|
||||||
|
#ifdef CAPACITY_CHECKING
|
||||||
if(bufferlength+size>capacity)
|
if(bufferlength+size>capacity)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
#endif
|
||||||
|
|
||||||
// create a new storage object and stash the data
|
// create a new storage object and stash the data
|
||||||
PortLinkData *pld=new PortLinkData;
|
PortLinkData *pld=new PortLinkData;
|
||||||
if(pld->Set(&data,size))
|
if(pld->Set(&data,size)==B_OK)
|
||||||
{
|
{
|
||||||
num_attachments++;
|
num_attachments++;
|
||||||
attachments[num_attachments-1]=pld;
|
attachments[num_attachments-1]=pld;
|
||||||
@@ -608,12 +640,14 @@ printf("Attach(BPoint(%f,%f))\n",data.x,data.y);
|
|||||||
|
|
||||||
int32 size=sizeof(BPoint);
|
int32 size=sizeof(BPoint);
|
||||||
|
|
||||||
|
#ifdef CAPACITY_CHECKING
|
||||||
if(bufferlength+size>capacity)
|
if(bufferlength+size>capacity)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
#endif
|
||||||
|
|
||||||
// create a new storage object and stash the data
|
// create a new storage object and stash the data
|
||||||
PortLinkData *pld=new PortLinkData;
|
PortLinkData *pld=new PortLinkData;
|
||||||
if(pld->Set(&data,size))
|
if(pld->Set(&data,size)==B_OK)
|
||||||
{
|
{
|
||||||
num_attachments++;
|
num_attachments++;
|
||||||
attachments[num_attachments-1]=pld;
|
attachments[num_attachments-1]=pld;
|
||||||
|
|||||||
Reference in New Issue
Block a user