#ifndef __LDP_H__
#define __LDP_H__

#include <net/ethernet.h>

#include "debug.h"

#include "dy_utils/dy_common.h"
#include "dy_utils/dy_ds.h"
#include "dy_utils/dy_ipc.h"
#include "dy_utils/modbus_utils.h"
#include "dy_utils/period_service.h"
#include "dy_utils/hash_intptr.h"

#ifndef OK
#define OK (0)
#endif

#ifndef ERROR
#define ERROR (-1)
#endif

#ifndef LOCAL
#define LOCAL static
#endif

#ifndef TRUE
#define TRUE                1
#endif

#ifndef FALSE
#define FALSE               0
#endif

typedef int STATUS;

typedef int BOOL;

#define MAX_IFNAME_LENGTH 		64

#define DEV_V3_LAN_NAME	"wan"

#define DATA_LOCK_INIT(data)		pthread_mutex_init(&((data).mutex), NULL)
#define DATA_LOCK(data)			pthread_mutex_lock(&((data).mutex))
#define DATA_UNLOCK(data)			pthread_mutex_unlock(&((data).mutex))
#define DATA_LOCK_DESTROY(data)	pthread_mutex_destroy(&((data).mutex))

size_t strlcpy(char *dst, const char *src, size_t n);

#define dstrlcpy(des, src, n) \
	do \
	{\
		if (strlcpy(des, src, n) >= (n)) \
		{\
			DPRINT_ERR("chm_strlcpy overflowing : the des is not large enough\n"); \
		}\
	}while (0)

#define dcalloc(nmemb, size) \
	( \
	{ \
		void *p = NULL; \
		p = calloc((nmemb), (size)); \
		if (p) \
		{ \
			DPRINT_DBG("calloc mem, p = %p, size = %zd bytes\n", p, (nmemb) * (size)); \
		}  \
		p; \
	} \
	) 

#define dfree(p) \
	do \
	{\
		if (p) \
		{ \
			DPRINT_DBG("free mem, p = %p\n", p); \
			free(p); \
			p = NULL; \
		} \
	}while (0)


#endif
