PortLink now uses a fixed buffer. Its base class is.... BSession...
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4424 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,88 +1,58 @@
|
|||||||
#ifndef _PORTLINK_H_
|
#ifndef _PORTLINK_H
|
||||||
#define _PORTLINK_H_
|
#define _PORTLINK_H
|
||||||
|
|
||||||
#include <Errors.h>
|
|
||||||
|
#include <BeBuild.h>
|
||||||
#include <OS.h>
|
#include <OS.h>
|
||||||
#include <SupportDefs.h>
|
|
||||||
#include <Rect.h>
|
#include "Session.h"
|
||||||
#include <List.h>
|
|
||||||
|
|
||||||
class PortMessage;
|
class PortMessage;
|
||||||
|
|
||||||
/*!
|
class PortLink : public BSession{
|
||||||
\class PortLinkData PortLink.cpp
|
|
||||||
\brief Internal data storage class
|
|
||||||
|
|
||||||
PortLinkData objects serve to hold attached data whilst it is waiting to be Flattened()
|
|
||||||
and then Flushed(). There is no need for this to be used outside the PortLink class.
|
|
||||||
*/
|
|
||||||
class PortLinkData
|
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
PortLinkData(void);
|
class ReplyData
|
||||||
~PortLinkData(void);
|
|
||||||
status_t Set(const void *data, size_t size);
|
|
||||||
char *buffer;
|
|
||||||
size_t buffersize;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class PortLink
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
class ReplyData
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
ReplyData(void) { code=0; buffersize=0; buffer=NULL; }
|
|
||||||
~ReplyData(void) { if(buffer) delete buffer; }
|
|
||||||
int32 code;
|
|
||||||
ssize_t buffersize;
|
|
||||||
int8 *buffer;
|
|
||||||
};
|
|
||||||
PortLink(port_id port);
|
|
||||||
PortLink(const PortLink &link);
|
|
||||||
~PortLink(void);
|
|
||||||
void SetOpCode(int32 code);
|
|
||||||
void SetPort(port_id port);
|
|
||||||
port_id GetPort(void);
|
|
||||||
status_t Flush(bigtime_t timeout=B_INFINITE_TIMEOUT);
|
|
||||||
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);
|
|
||||||
template <class Type> status_t Attach(Type data)
|
|
||||||
{
|
{
|
||||||
int32 size=sizeof(Type);
|
public:
|
||||||
|
ReplyData(void) { code=0; buffersize=0; buffer=NULL; }
|
||||||
|
~ReplyData(void) { if(buffer) delete buffer; }
|
||||||
|
|
||||||
|
int32 code;
|
||||||
|
ssize_t buffersize;
|
||||||
|
int8 *buffer;
|
||||||
|
};
|
||||||
|
|
||||||
|
PortLink( port_id port );
|
||||||
|
PortLink( const PortLink &link );
|
||||||
|
virtual ~PortLink() { }
|
||||||
|
|
||||||
#ifdef CAPACITY_CHECKING
|
void SetOpCode( int32 code );
|
||||||
if(bufferlength+size>capacity)
|
void SetPort( port_id port );
|
||||||
return B_NO_MEMORY;
|
port_id GetPort();
|
||||||
#endif
|
status_t Flush( bigtime_t timeout = B_INFINITE_TIMEOUT );
|
||||||
|
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 );
|
||||||
|
|
||||||
// create a new storage object and stash the data
|
status_t Attach(const void *data, size_t size);
|
||||||
PortLinkData *pld=new PortLinkData;
|
void MakeEmpty();
|
||||||
if(pld->Set(&data,size)==B_OK)
|
template <class Type> status_t Attach(Type data)
|
||||||
{
|
{
|
||||||
attachlist->AddItem(pld);
|
int32 size = sizeof(Type);
|
||||||
bufferlength+=size;
|
|
||||||
|
if (4096 - fSendPosition > size){
|
||||||
|
memcpy(fSendBuffer + fSendPosition, &data, size);
|
||||||
|
fSendPosition += size;
|
||||||
|
return B_OK;
|
||||||
}
|
}
|
||||||
else
|
return B_NO_MEMORY;
|
||||||
{
|
|
||||||
delete pld;
|
|
||||||
return B_ERROR;
|
|
||||||
}
|
|
||||||
return B_OK;
|
|
||||||
}
|
}
|
||||||
void MakeEmpty(void);
|
|
||||||
protected:
|
private:
|
||||||
void FlattenData(int8 **buffer,int32 *size);
|
bool port_ok;
|
||||||
port_id target, replyport;
|
|
||||||
int32 opcode;
|
|
||||||
uint32 bufferlength,capacity;
|
|
||||||
bool port_ok;
|
|
||||||
BList *attachlist;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//extern _IMPEXP_BE _PortLink_ *main_session;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user