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>
|
2004-07-30 19:10:19 +04:00
|
|
|
// Pahtz <pahtz@yahoo.com.au>
|
|
|
|
// Description: Class for low-overhead port-based messaging
|
2003-10-04 23:06:34 +04:00
|
|
|
//
|
|
|
|
//------------------------------------------------------------------------------
|
2003-08-31 21:21:49 +04:00
|
|
|
#ifndef _PORTLINK_H
|
|
|
|
#define _PORTLINK_H
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
#include <OS.h>
|
2003-08-31 21:21:49 +04:00
|
|
|
|
2004-07-30 19:10:19 +04:00
|
|
|
/*
|
|
|
|
Error checking rules: (for if you don't want to check every return code)
|
|
|
|
|
|
|
|
Calling EndMessage() is optional, implied by Flush() or StartMessage().
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
*/
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2005-04-30 00:41:21 +04:00
|
|
|
class LinkMsgReader;
|
|
|
|
class LinkMsgSender;
|
2004-07-30 19:10:19 +04:00
|
|
|
class BPortLink
|
2003-10-04 02:20:28 +04:00
|
|
|
{
|
2003-07-12 03:16:15 +04:00
|
|
|
public:
|
2004-07-30 19:10:19 +04:00
|
|
|
BPortLink(port_id send = -1, port_id reply = -1);
|
|
|
|
virtual ~BPortLink();
|
2003-10-04 02:20:28 +04:00
|
|
|
|
2004-07-30 19:10:19 +04:00
|
|
|
status_t StartMessage(int32 code);
|
|
|
|
void CancelMessage();
|
|
|
|
status_t EndMessage();
|
2003-10-04 02:20:28 +04:00
|
|
|
|
|
|
|
status_t Flush(bigtime_t timeout = B_INFINITE_TIMEOUT);
|
2004-07-30 19:10:19 +04:00
|
|
|
|
|
|
|
void SetSendPort(port_id port);
|
|
|
|
port_id GetSendPort();
|
2004-10-14 05:18:38 +04:00
|
|
|
|
2004-07-30 19:10:19 +04:00
|
|
|
void SetReplyPort(port_id port);
|
|
|
|
port_id GetReplyPort();
|
2004-01-13 02:58:04 +03:00
|
|
|
|
2004-07-30 19:10:19 +04:00
|
|
|
status_t Attach(const void *data, ssize_t size);
|
2003-10-04 04:52:24 +04:00
|
|
|
status_t AttachString(const char *string);
|
2005-01-22 12:48:10 +03:00
|
|
|
status_t AttachRegion(const BRegion ®ion);
|
2005-04-01 11:29:04 +04:00
|
|
|
status_t AttachShape(BShape &shape);
|
2004-07-30 19:10:19 +04:00
|
|
|
template <class Type> status_t Attach(const Type& data)
|
2003-10-04 02:20:28 +04:00
|
|
|
{
|
2004-07-30 19:10:19 +04:00
|
|
|
return Attach(&data, sizeof(Type));
|
2003-10-04 02:20:28 +04:00
|
|
|
}
|
2004-07-30 19:10:19 +04:00
|
|
|
|
|
|
|
status_t GetNextReply(int32 *code, bigtime_t timeout = B_INFINITE_TIMEOUT);
|
|
|
|
status_t Read(void *data, ssize_t size);
|
|
|
|
status_t ReadString(char **string);
|
2005-01-22 12:48:10 +03:00
|
|
|
status_t ReadRegion(BRegion *region);
|
2005-04-01 11:29:04 +04:00
|
|
|
status_t ReadShape(BShape *shape);
|
2004-10-14 05:18:38 +04:00
|
|
|
template <class T> status_t Read(T *data)
|
2004-07-30 19:10:19 +04:00
|
|
|
{
|
2005-04-30 00:41:21 +04:00
|
|
|
return Read(data,sizeof(T));
|
2004-07-30 19:10:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2004-10-14 05:18:38 +04:00
|
|
|
LinkMsgReader *fReader;
|
|
|
|
LinkMsgSender *fSender;
|
2002-07-09 16:24:59 +04:00
|
|
|
};
|
|
|
|
|
2003-04-14 05:56:41 +04:00
|
|
|
#endif
|