#ifndef _UMAP_ERROR_H_
#define _UMAP_ERROR_H_

#ifdef __cplusplus
extern          "C" {
#endif

#include "wp_wddi.h"
#include "wls.h"
#include "umap.h"
#include "umap_ipc_struct.h"

extern WP_CHAR *WLS_error_name[];

enum UMAP_Error
{
	UMAP_OK = 0,
	UMAP_ERR_INDEX_ALREADY_EXIST = 1000,
	UMAP_ERR_INDEX_NOTEXIST,
	UMAP_ERR_WPCMALLOC,
	UMAP_ERR_ROWSTATUS_INCORRECT,
	UMAP_ERR_NOTSUPPORT,
	UMAP_ERR_CREATE_NOTSUPPORT,
	UMAP_ERR_DELETE_NOTSUPPORT,
	UMAP_ERR_SET_NOTSUPPORT,
	UMAP_ERR_GET_NOTSUPPORT,
	UMAP_ERR_GETNEXT_NOTSUPPORT,
	UMAP_ERR_ENTRY_INUSING, //this entry has another binding
	UMAP_ERR_UNDEFINED = (WP_ERR_IW_GLOBAL_UNDEFINED | 0xFC000000),
	UMAP_ERR = 0xFFFF
};

//#define UMAP_ERR_UNDEFINED (WP_ERR_IW_GLOBAL_UNDEFINED | 0xFC000000)

#define UMAP_CHECK_WLS(x) \
	{ \
		WP_status y=x; \
		if((WP_U32)y == WLS_OK) \
		{ \
			UMAP_TRACE("WLS_OK\n"); \
  			ret = UMAP_OK; \
		} \
		else if ((WP_U32)y < WLS_ERR_LAST) \
		{ \
			sprintf(pRetMsg->data.u.u_string,"UMAP Fail in file:%s, line:%d, wls_error_name:%s\n",	__FILE__,__LINE__,WLS_error_name[y]); \
  			pRetMsg->data.Result = y;ret = UMAP_ERR; \
	  		UMAP_TRACE("status = %d,WLS_error_name[y] = %s\n",y,WLS_error_name[y]); \
		} \
		else if (WP_ERROR_P(y)) \
		{ \
			sprintf(pRetMsg->data.u.u_string,"UMAP Fail in file:%s, line:%d, wp_error_name:%s\n", __FILE__,__LINE__,WP_error_name[WP_ERROR(y)]); \
  			pRetMsg->data.Result = WP_ERROR(y);ret = UMAP_ERR; \
	  		UMAP_TRACE("WP_ERROR_P(y) = %d,WP_error_name[WP_ERROR(y)] = %s\n",WP_ERROR_P(y),WP_error_name[WP_ERROR(y)]); \
  		} \
  		else \
  		{ \
			sprintf(pRetMsg->data.u.u_string,"UMAP Fail in file:%s, line:%d\n", __FILE__,__LINE__); \
  			pRetMsg->data.Result = UMAP_ERR;ret = UMAP_ERR; \
  		} \
  	}

#define UMAP_CHECK_WLS_RETURN(x) \
	{ \
		WP_status y=x; \
		if((WP_U32)y == WLS_OK) \
		{ \
			UMAP_TRACE("WLS_OK\n"); \
			return UMAP_OK; \
		} \
		else if ((WP_U32)y < WLS_ERR_LAST) \
		{ \
			sprintf(pRetMsg->data.u.u_string,"UMAP Fail in file:%s, line:%d, wls_error_name:%s\n",	__FILE__,__LINE__,WLS_error_name[y]); \
  			pRetMsg->data.Result = y; \
	  		UMAP_TRACE("status = %d,WLS_error_name[y] = %s\n",y,WLS_error_name[y]); \
	  		return UMAP_ERR; \
		} \
		else if (WP_ERROR_P(y)) \
		{ \
			sprintf(pRetMsg->data.u.u_string,"UMAP Fail in file:%s, line:%d, wp_error_name:%s\n", __FILE__,__LINE__,WP_error_name[WP_ERROR(y)]); \
  			pRetMsg->data.Result = WP_ERROR(y); \
	  		UMAP_TRACE("WP_ERROR_P(y) = %d,WP_error_name[WP_ERROR(y)] = %s\n",WP_ERROR_P(y),WP_error_name[WP_ERROR(y)]); \
	  		return UMAP_ERR; \
  		} \
  		else \
  		{ \
			sprintf(pRetMsg->data.u.u_string,"UMAP Fail in file:%s, line:%d\n", __FILE__,__LINE__); \
  			pRetMsg->data.Result = UMAP_ERR;return UMAP_ERR; \
  		} \
  	}
  	
#define UMAP_CHECK_WLS_ERR_RETURN(x) \
	{ \
		WP_status y=x; \
		if((WP_U32)y == WLS_OK) \
		{ \
			UMAP_TRACE("WLS_OK\n"); \
			ret = UMAP_OK; \
		} \
		else if ((WP_U32)y < WLS_ERR_LAST) \
		{ \
			sprintf(pRetMsg->data.u.u_string,"UMAP Fail in file:%s, line:%d, wls_error_name:%s\n",	__FILE__,__LINE__,WLS_error_name[y]); \
  			pRetMsg->data.Result = y; \
	  		UMAP_TRACE("status = %d,WLS_error_name[y] = %s\n",y,WLS_error_name[y]); \
	  		return UMAP_ERR; \
		} \
		else if (WP_ERROR_P(y)) \
		{ \
			sprintf(pRetMsg->data.u.u_string,"UMAP Fail in file:%s, line:%d, wp_error_name:%s\n", __FILE__,__LINE__,WP_error_name[WP_ERROR(y)]); \
  			pRetMsg->data.Result = WP_ERROR(y); \
	  		UMAP_TRACE("WP_ERROR_P(y) = %d,WP_error_name[WP_ERROR(y)] = %s\n",WP_ERROR_P(y),WP_error_name[WP_ERROR(y)]); \
	  		return UMAP_ERR; \
  		} \
  		else \
  		{ \
			sprintf(pRetMsg->data.u.u_string,"UMAP Fail in file:%s, line:%d\n", __FILE__,__LINE__); \
  			pRetMsg->data.Result = UMAP_ERR;return UMAP_ERR; \
  		} \
  	}  	


#define UMAP_RETURN_ERROR(x) \
   { \
	   sprintf(pRetMsg->data.u.u_string,"umap Fail in file:%s, line:%d, umap_error:%d\n",__FILE__,__LINE__,x); \
	   pRetMsg->data.Result = x; \
	   return UMAP_ERR; \
   }

#define UMAP_RETURN_OK {pRetMsg->data.Result = UMAP_OK;return UMAP_OK;}

#ifdef __cplusplus
}
#endif

#endif

