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

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_ERRORLOG_H
#define _SCTS_ERRORLOG_H

#include "SctsPlatformLib.h"
#ifdef __SCTS_LOG_ERRORS__
#include "SctsThread.h"
#include "SctsTree.h"
#include "map"

#ifdef __SCTS_USING_RTK__
const char *sctsGetRTKError(int);
void sctsClearRTKError();
#endif

/*
Error logs can be created on a per-thread basis. SCTS maintains a map of
thread IDs and SctsErrorLog objects which it uses to demultiplex error
messages to the appropriate log. Errors are logged using LIFO logic. An
error log is basically a tree of error nodes each of which has a number of
associated errors. Error nodes are used to logically group errors.
*/

class SctsErrorLog
{

public:
	typedef struct nodeEntry_s
	{
		char *error;
		struct nodeEntry_s *next;
	} NodeEntry;

	class Node
	{
	public:
		NodeEntry *errors;
		char *name;
		char *desc;
		Node(char *_name,char *_desc);
		~Node();
	};

	SctsTree<Node *> nodeTree;
	void *uiData;

/* Implementation */
private:
	static std::map <int,SctsErrorLog *> errorLogs;
	static SctsMutex errorLogsLock;
	static SctsErrorLog *GetErrorLog();
	SctsTree<Node *>::Item *currentNodeTreeItem;

public:
	bool HasErrors();
	static bool Clear();
	static bool OpenNode(char *nodeName,char *nodeDesc);
	static bool AppendError(char *error);
	static bool CloseNode();
	SctsErrorLog();
	~SctsErrorLog();
};

#endif
#endif
