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