
#ifndef __MSG_ERROR_H__
#define __MSG_ERROR_H__

#include "cstring.h"

#ifdef WIN32
#ifdef V2_DLL_EXPORTS
#define V2_DLL_API __declspec(dllexport)
#else
#define V2_DLL_API __declspec(dllimport)
#endif
#else
#define V2_DLL_API
#endif

#define MA_MAX_ERR_CODE		50

#define MA_OK				 	0
// flow errors
#define MA_ER_NO_DATA			-1		// no data

// control errors
#define MA_ER_OUTOF_MEM			-11		// memory error
#define MA_ER_PARAM_NULL		-12		// parameter is NULL
#define MA_ER_TAGDIC_OTHER		-13		// other tag dictionary error
#define MA_ER_BAD_TAGNUM		-14		// out of tagnum boundary
#define MA_ER_BAD_MSGNUM		-15		// out of msgnum boundary
#define MA_ER_BAD_SUBMSG		-16		// out of submsg boundary
#define MA_ER_BAD_TAGTYPE		-17		// invalid tag type
#define MA_ER_NOTDEF_TAG		-18		// not defined tag dictionary
#define MA_ER_NOTDEF_MSG		-19		// not defined msg dictionary
#define MA_ER_NO_TAG_MSGDIC		-20		// not defined tag in msg dictionary
#define MA_ER_XML_PARSE			-21		// XML parsing failed
#define MA_ER_DUP_MSGNUM		-22		// duplicated msgnum defined
#define MA_ER_DUP_TAGNUM		-23		// duplicated tagnum defined
#define MA_ER_ASSERT_FMT		-24		// invalid assert expression format
#define MA_ER_RESTRICT_FMT		-25		// invalid restriction expression format
#define MA_ER_XERCES_INIT		-26		// Xerces Initialize error
#define MA_ER_OUTOF_BOUND		-27		// out of index boundary in array
#define MA_ER_BAD_SVC_MSG		-28		// invalid input message of service
#define MA_ER_IMPORT_DIC		-29		// import dictionary error
#define MA_ER_BAD_STMT_ID		-30		// undefined statment id
#define MA_ER_JSON_PARSE		-31		// JSON parsing failed
#define MA_ER_FILE_NOT_FOUND	-32		// File not found
#define MA_ER_ADAPTOR_FAIL		-33		// Socket error
#define MA_ER_INVALID_CONFIG	-34		// Config file error
#define MA_ER_NOT_INITIALIZED	-35		// Not Initialized
#define MA_ER_DIC_LOADING		-36		// Dictionary loading failed

#define DEBUG_STEP()     fprintf(stdout, "STEP : %d lines at %s\n", __LINE__, __FILE__)

extern V2_DLL_API const char *MA_GetErrorStr(int p_iCode);

class V2_DLL_API CLastError
{
public:
	CLastError();
	~CLastError();
	char *GetLastError(void);

protected:
	void SetLastError(int p_iCode, const char *p_szFormat, ...);

private:
	struct Error {
		int iCode;
		CString sInfo;
	} *m_pErr;
};

#endif	// __MSG_ERROR_H__
