2003-10-04 23:06:34 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Copyright (c) 2001-2002, OpenBeOS
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
// copy of this software and associated documentation files (the "Software"),
|
|
|
|
// to deal in the Software without restriction, including without limitation
|
|
|
|
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
// and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
// Software is furnished to do so, subject to the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
// DEALINGS IN THE SOFTWARE.
|
|
|
|
//
|
|
|
|
// File Name: PortLink.h
|
|
|
|
// Author: DarkWyrm <bpmagic@columbus.rr.com>
|
|
|
|
// Description: Class for low-overhead port-based messaging
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------------------
|
2003-08-31 21:21:49 +04:00
|
|
|
#ifndef _PORTLINK_H
|
|
|
|
#define _PORTLINK_H
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-08-31 21:21:49 +04:00
|
|
|
#include <BeBuild.h>
|
2002-07-09 16:24:59 +04:00
|
|
|
#include <OS.h>
|
2003-08-31 21:21:49 +04:00
|
|
|
|
2003-06-23 17:18:39 +04:00
|
|
|
class PortMessage;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-10-04 02:20:28 +04:00
|
|
|
class PortLink
|
|
|
|
{
|
2003-07-12 03:16:15 +04:00
|
|
|
public:
|
2003-10-04 02:20:28 +04:00
|
|
|
PortLink(port_id port);
|
|
|
|
PortLink(const PortLink &link);
|
2003-10-04 03:28:05 +04:00
|
|
|
virtual ~PortLink(void);
|
2003-10-04 02:20:28 +04:00
|
|
|
|
|
|
|
void SetOpCode(int32 code);
|
|
|
|
|
|
|
|
void SetPort(port_id port);
|
|
|
|
port_id GetPort();
|
|
|
|
|
|
|
|
status_t Flush(bigtime_t timeout = B_INFINITE_TIMEOUT);
|
|
|
|
status_t FlushWithReply(PortMessage *msg,bigtime_t timeout=B_INFINITE_TIMEOUT);
|
2003-06-23 17:18:39 +04:00
|
|
|
|
2003-10-04 02:20:28 +04:00
|
|
|
void MakeEmpty();
|
|
|
|
status_t Attach(const void *data, size_t size);
|
2003-10-04 04:52:24 +04:00
|
|
|
status_t AttachString(const char *string);
|
2003-10-04 02:20:28 +04:00
|
|
|
template <class Type> status_t Attach(Type data)
|
|
|
|
{
|
|
|
|
int32 size = sizeof(Type);
|
|
|
|
|
|
|
|
if (4096 - fSendPosition > size){
|
|
|
|
memcpy(fSendBuffer + fSendPosition, &data, size);
|
|
|
|
fSendPosition += size;
|
2003-11-14 03:21:43 +03:00
|
|
|
*fDataSize+=size;
|
2003-10-04 02:20:28 +04:00
|
|
|
return B_OK;
|
2003-07-12 03:16:15 +04:00
|
|
|
}
|
2003-10-04 02:20:28 +04:00
|
|
|
return B_NO_MEMORY;
|
|
|
|
}
|
|
|
|
|
2003-08-31 21:21:49 +04:00
|
|
|
private:
|
2003-10-04 02:20:28 +04:00
|
|
|
bool port_ok;
|
|
|
|
port_id fSendPort;
|
|
|
|
port_id fReceivePort;
|
|
|
|
char *fSendBuffer;
|
|
|
|
int32 fSendPosition;
|
|
|
|
int32 fSendCode;
|
2003-10-14 03:33:20 +04:00
|
|
|
int32 *fDataSize;
|
2002-07-09 16:24:59 +04:00
|
|
|
};
|
|
|
|
|
2003-04-14 05:56:41 +04:00
|
|
|
#endif
|