/*******************************************************************

Copyright (c) 2004 Open Mobile Alliance, Ltd.  All Rights Reserved.

This software is made available under the usage and distribution terms 
covered by the Common Public License 1.0 and by using this software you
are bound by the terms and conditions of the same.

EXCEPT AS EXPRESSLY SET FORTH IN THE COMMON PUBLIC LICENSE,
THIS PROGRAM IS PROVIDED ON AN "AS IS" BASIS, 
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, 
ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, 
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
   
Each recipient is solely responsible for determining the 
appropriateness of using and distributing this program and assumes 
all risks associated with its exercise of rights under the Common 
Public License, including but not limited to the risks and 
costs of program errors, compliance with applicable laws, 
damage to or loss of data, programs or equipment, and 
unavailability or interruption of operations.

********************************************************************/

#ifndef _SCTS_MESSAGE_H
#define _SCTS_MESSAGE_H
#include "SctsCommandElements.h"
#include "SctsTree.h"
#include "SctsErrorLog.h"

class SctsMessage;

/*************************************************************
SctsMessage Class 
**************************************************************/
class SctsMessage 
{
friend Ret_t sctsRTKHandleEndMessage(InstanceID_t id,VoidPtr_t pSession,Boolean_t final);
public:
/* Data */
	SctsTree<SctsCommand *> syncBody;
	SctsTree<SctsCommand *>::Item *currentContainer;
	SctsTree<SctsCommand *>::Item *lastCommandNotBuilt;
	SctsTree<SctsCommand *>::Item *currentCommand;
	SctsTree<SctsCommand *>::Item *lastCommandFound;
	SctsSessionContext sessionContext;
	SctsSessionContext wbxmlConverterContext;
	SctsEncoding sessionEncoding;
	int freeSize;
	bool final;
	void *uiCallbackData;
	void (*uiCallback)(void *data,SctsCommand *command,int flag,bool build);
		
/* Implementation */
	int GetFreeSize() {return freeSize;}
	void IsFinal(bool isFinal) {((SctsSyncHdr *)syncBody.GetRootItem()->data)->IsFinal(isFinal);}
	bool IsFinal() { return ((SctsSyncHdr *)syncBody.GetRootItem()->data)->IsFinal();}
	SctsCommand *FindCommand(SctsCommandType type);
	SctsCommand *FindNextCommand(SctsCommandType type=SCTS_COMMAND_COUNT);
	/* If command is 0 close the current container */
	bool InsertCommand(SctsCommand *command,bool build=true,bool closeAll=true);
	/* Used when processing status */
	SctsCommand *GetCurrentCommand();
	SctsCommand *GetHeader();
	void DeleteCurrentCommand();
	void DeleteAllUnbuilt();
	void BuildAllUnbuilt();
	SctsMessage(SctsSessionContext _sessionContext,SctsEncoding _sessionEncoding,SctsSyncHdr *_syncHdr,int maxSize,SctsSessionContext _wbxmlSessionContext=0,void *_uiCallbackData=0,void (*_uiCallback)(void *data,SctsCommand *command,int flag,bool build)=0);
	/* Ref#0019 : Command to rebuild the sync header */
	void Rebuild();
};


#endif
