1/*
2 * Copyright 2005, Ingo Weinhold <bonefish@cs.tu-berlin.de>.
3 * All rights reserved. Distributed under the terms of the MIT License.
4 */
5
6#ifndef _BOOT_NET_CHAIN_BUFFER_H
7#define _BOOT_NET_CHAIN_BUFFER_H
8
9#include <SupportDefs.h>
10
11class ChainBuffer {
12public:
13
14	ChainBuffer(void *data = 0, uint32 size = 0, ChainBuffer *next = NULL,
15		bool freeData = false);
16	~ChainBuffer();
17
18	void *Data() const			{ return fData; }
19	uint32 Size() const			{ return fSize; }
20	uint32 TotalSize() const	{ return fTotalSize; }
21
22	ChainBuffer *Next() const	{ return fNext; }
23	ChainBuffer *DetachNext();
24
25	void Append(ChainBuffer *next);
26
27	void Flatten(void *_buffer) const;
28
29private:
30// TODO: Implement Create() and Delete(). Make new and delete operators private.
31	enum {
32		CHAIN_BUFFER_HEAD			= 0x1,
33		CHAIN_BUFFER_EMBEDDED_DATA	= 0x2,
34		CHAIN_BUFFER_FREE_DATA		= 0x4,
35		CHAIN_BUFFER_ON_STACK		= 0x8,
36	};
37
38	void _Init(void *data, uint32 size, ChainBuffer *next, uint32 flags);
39	void _Destroy();
40
41	uint32		fFlags:4;
42	uint32		fSize:14;
43	uint32		fTotalSize:14;
44	void		*fData;
45	ChainBuffer	*fNext;
46	uint8		fBuffer[0];
47};
48
49#endif	// _BOOT_NET_CHAIN_BUFFER_H
50