// DIMEPayload.h: interface for the DIMEPayload class.
//
//
//////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2002 Robert Cunnings. All rights reserved.
//
// You may copy, modify, distribute or publish this code free of charge.
//
// NO WARRANTY: This software is provided AS IS, without warranty of any kind.
//
//////////////////////////////////////////////////////////////////////
//
// DIMEPayload class - implementation of DIME payload class. This is 
// a wrapper for an IStorage interface pointer. Data is stored in a single
// stream with an empty name.
//  
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_DIMEPAYLOAD_H__B4102C75_E26F_48DD_BB44_8FF09A76BC1E__INCLUDED_)
#define AFX_DIMEPAYLOAD_H__B4102C75_E26F_48DD_BB44_8FF09A76BC1E__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "DIMEOptions.h"
#include <string>
#include <list>
using namespace std;

#define DIME_TYPENAME_FORMAT_UNCHANGED 0x00
#define DIME_TYPENAME_FORMAT_MEDIATYPE 0x01
#define DIME_TYPENAME_FORMAT_URI 0x02
#define DIME_TYPENAME_FORMAT_UNKNOWN 0x03
#define DIME_TYPENAME_FORMAT_NONE 0x04

class DIMEPayload  
{
public:

	union Header32{
		unsigned long l;
		unsigned char c[4];
	};

	DIMEPayload();
	DIMEPayload(IStorage *pIStorage,
				const string& strId,
				const string& strType,
				unsigned long ulTNF);

	virtual ~DIMEPayload();

	unsigned long GetTNF() { return m_ulTNF; }
	const string& GetType() { return m_strType; }
	const string& GetId() { return m_strId; }
	IStorage *GetStorage() { return m_pIStorage; }
	bool OpenForRead();
	bool OpenForWrite();
	bool Read(  char *pszBuffer,
				unsigned long ulBufferSize,
				unsigned long *pulBytesRead);
	bool Write( char *pszBuffer,
				unsigned long ulBufferSize,
				unsigned long *pulBytesWritten);
	bool Close();
	unsigned long GetDataLength();
	bool GetOptions(unsigned char *pOptions, unsigned long& ulLength);
	bool SetOptions(unsigned char *pOptions, unsigned long ulLength);
	bool AddOption(DIMEOption *pOption);
	unsigned long GetOptionsLength();
	list<DIMEOption	*>& GetOptionsList() { return m_listOptions; }

protected:
	IStorage			*m_pIStorage;
	IStream				*m_pCurrentStream;
	string				m_strId;
	string				m_strType;
	unsigned long		m_ulTNF;
	list<DIMEOption	*>	m_listOptions;
};

#endif // !defined(AFX_DIMEPAYLOAD_H__B4102C75_E26F_48DD_BB44_8FF09A76BC1E__INCLUDED_)
