Major API improvements by Pahtz
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8518 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
e47269fa21
commit
d0021b64bc
@ -35,7 +35,6 @@
|
|||||||
// System Includes -------------------------------------------------------------
|
// System Includes -------------------------------------------------------------
|
||||||
|
|
||||||
// Project Includes ------------------------------------------------------------
|
// Project Includes ------------------------------------------------------------
|
||||||
#include <Session.h>
|
|
||||||
#include <OS.h>
|
#include <OS.h>
|
||||||
#include <PortLink.h>
|
#include <PortLink.h>
|
||||||
|
|
||||||
@ -48,11 +47,12 @@
|
|||||||
|
|
||||||
namespace BPrivate {
|
namespace BPrivate {
|
||||||
|
|
||||||
class BAppServerLink : public PortLink
|
class BAppServerLink : public BPortLink
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BAppServerLink(void);
|
BAppServerLink(void);
|
||||||
~BAppServerLink(void);
|
~BAppServerLink(void);
|
||||||
|
status_t FlushWithReply(int32 *code);
|
||||||
private:
|
private:
|
||||||
port_id receiver;
|
port_id receiver;
|
||||||
};
|
};
|
||||||
@ -61,10 +61,3 @@ private:
|
|||||||
|
|
||||||
#endif //APPSERVERLINK_H
|
#endif //APPSERVERLINK_H
|
||||||
|
|
||||||
/*
|
|
||||||
* $Log $
|
|
||||||
*
|
|
||||||
* $Id $
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
@ -21,58 +21,93 @@
|
|||||||
//
|
//
|
||||||
// File Name: PortLink.h
|
// File Name: PortLink.h
|
||||||
// Author: DarkWyrm <bpmagic@columbus.rr.com>
|
// Author: DarkWyrm <bpmagic@columbus.rr.com>
|
||||||
// Description: Class for low-overhead packet-style port-based messaging
|
// Pahtz <pahtz@yahoo.com.au>
|
||||||
|
// Description: Class for low-overhead port-based messaging
|
||||||
//
|
//
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
#ifndef _PORTLINK_H
|
#ifndef _PORTLINK_H
|
||||||
#define _PORTLINK_H
|
#define _PORTLINK_H
|
||||||
|
|
||||||
#include <BeBuild.h>
|
|
||||||
#include <OS.h>
|
#include <OS.h>
|
||||||
#include "Session.h"
|
|
||||||
|
|
||||||
class PortMessage;
|
/*
|
||||||
|
Error checking rules: (for if you don't want to check every return code)
|
||||||
|
|
||||||
|
Calling EndMessage() is optional, implied by Flush() or StartMessage().
|
||||||
|
|
||||||
class PortLink
|
If you are sending just one message you only need to test Flush() == B_OK
|
||||||
|
|
||||||
|
If you are buffering multiple messages without calling Flush() you must
|
||||||
|
check EndMessage() == B_OK, or the last Attach() for each message. Check
|
||||||
|
Flush() at the end.
|
||||||
|
|
||||||
|
If you are reading, check the last Read() or ReadString() you perform.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
class BPortLink
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PortLink(port_id port);
|
BPortLink(port_id send = -1, port_id reply = -1);
|
||||||
PortLink(const PortLink &link);
|
virtual ~BPortLink();
|
||||||
virtual ~PortLink(void);
|
|
||||||
|
|
||||||
void SetOpCode(int32 code);
|
status_t StartMessage(int32 code);
|
||||||
|
void CancelMessage();
|
||||||
void SetPort(port_id port);
|
status_t EndMessage();
|
||||||
port_id GetPort();
|
|
||||||
|
|
||||||
status_t Flush(bigtime_t timeout = B_INFINITE_TIMEOUT);
|
status_t Flush(bigtime_t timeout = B_INFINITE_TIMEOUT);
|
||||||
status_t FlushWithReply(PortMessage *msg,bigtime_t timeout=B_INFINITE_TIMEOUT);
|
|
||||||
status_t FlushToSession();
|
// see BPrivate::BAppServerLink which inherits from BPortLink
|
||||||
|
//status_t FlushWithReply(int32 *code);
|
||||||
|
|
||||||
void MakeEmpty();
|
void SetSendPort(port_id port);
|
||||||
status_t Attach(const void *data, size_t size);
|
port_id GetSendPort();
|
||||||
|
void SetReplyPort(port_id port);
|
||||||
|
port_id GetReplyPort();
|
||||||
|
|
||||||
|
status_t Attach(const void *data, ssize_t size);
|
||||||
status_t AttachString(const char *string);
|
status_t AttachString(const char *string);
|
||||||
template <class Type> status_t Attach(Type data)
|
template <class Type> status_t Attach(const Type& data)
|
||||||
{
|
{
|
||||||
int32 size = sizeof(Type);
|
return Attach(&data, sizeof(Type));
|
||||||
|
}
|
||||||
|
|
||||||
if ( (SESSION_BUFFER_SIZE*4) - fSendPosition > size){
|
status_t GetNextReply(int32 *code, bigtime_t timeout = B_INFINITE_TIMEOUT);
|
||||||
memcpy(fSendBuffer + fSendPosition, &data, size);
|
status_t Read(void *data, ssize_t size);
|
||||||
fSendPosition += size;
|
status_t ReadString(char **string);
|
||||||
*fDataSize+=size;
|
template <class Type> status_t Read(Type *data)
|
||||||
return B_OK;
|
{
|
||||||
}
|
return Read(data, sizeof(Type));
|
||||||
return B_NO_MEMORY;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
bool fPortValid;
|
status_t FlushCompleted(ssize_t newbuffersize);
|
||||||
|
status_t ReadFromPort(bigtime_t timeout);
|
||||||
|
status_t AdjustReplyBuffer(bigtime_t timeout);
|
||||||
|
void ResetReplyBuffer();
|
||||||
|
|
||||||
port_id fSendPort;
|
port_id fSendPort;
|
||||||
port_id fReceivePort;
|
port_id fReceivePort;
|
||||||
|
|
||||||
char *fSendBuffer;
|
char *fSendBuffer;
|
||||||
int32 fSendPosition;
|
char *fRecvBuffer;
|
||||||
int32 fSendCode;
|
|
||||||
int32 *fDataSize;
|
int32 fSendPosition; //current append position
|
||||||
|
int32 fRecvPosition; //current read position
|
||||||
|
|
||||||
|
int32 fSendStart; //start of current message
|
||||||
|
int32 fRecvStart; //start of current message
|
||||||
|
|
||||||
|
int32 fSendBufferSize;
|
||||||
|
int32 fRecvBufferSize;
|
||||||
|
|
||||||
|
int32 fSendCount; //number of completed messages in buffer
|
||||||
|
|
||||||
|
int32 fDataSize; //size of data in recv buffer
|
||||||
|
int32 fReplySize; //size of current reply message
|
||||||
|
|
||||||
|
status_t fWriteError; //Attach failed for current message
|
||||||
|
status_t fReadError; //Read failed for current message
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user