Fix templates for PortLink & PortMessage
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3960 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
78cc8d1a5a
commit
5c54c7191a
@ -7,9 +7,26 @@
|
||||
#include <Rect.h>
|
||||
#include <List.h>
|
||||
|
||||
class PortLinkData;
|
||||
class PortMessage;
|
||||
|
||||
/*!
|
||||
\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:
|
||||
PortLinkData(void);
|
||||
~PortLinkData(void);
|
||||
status_t Set(const void *data, size_t size);
|
||||
char *buffer;
|
||||
size_t buffersize;
|
||||
};
|
||||
|
||||
|
||||
class PortLink
|
||||
{
|
||||
public:
|
||||
@ -35,7 +52,29 @@ public:
|
||||
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);
|
||||
template <class Type> status_t Attach(Type data)
|
||||
{
|
||||
int32 size=sizeof(Type);
|
||||
|
||||
#ifdef CAPACITY_CHECKING
|
||||
if(bufferlength+size>capacity)
|
||||
return B_NO_MEMORY;
|
||||
#endif
|
||||
|
||||
// create a new storage object and stash the data
|
||||
PortLinkData *pld=new PortLinkData;
|
||||
if(pld->Set(&data,size)==B_OK)
|
||||
{
|
||||
attachlist->AddItem(pld);
|
||||
bufferlength+=size;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pld;
|
||||
return B_ERROR;
|
||||
}
|
||||
return B_OK;
|
||||
}
|
||||
void MakeEmpty(void);
|
||||
protected:
|
||||
void FlattenData(int8 **buffer,int32 *size);
|
||||
|
@ -48,7 +48,23 @@ public:
|
||||
ssize_t BufferSize(void) { return _buffersize; }
|
||||
|
||||
status_t Read(void *data, ssize_t size);
|
||||
template <class Type> status_t Read(Type *data);
|
||||
template <class Type> status_t Read(Type *data)
|
||||
{
|
||||
int32 size = sizeof(Type);
|
||||
|
||||
if(!data)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
if( !_buffer ||
|
||||
(_buffersize < size) ||
|
||||
(_index+size > _buffer+_buffersize) )
|
||||
return B_NO_MEMORY;
|
||||
|
||||
*data=*((Type*)_index);
|
||||
_index+=size;
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
void Rewind(void);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user