#ifndef	_NMTYPES_H_
#define	_NMTYPES_H_
/** Copyright (C) 1995 interWAVE Communications, Inc.: All Rights Reserved. **/
/*
 * nmtypes.h: Definitions of fundamental data types used in NM classes.
 *
 * Bruce Nelson, interWAVE, 08/07/95.
 * Modified by: XChen
 */

#include <stdio.h>
#include "iwtypes.h"

/* Some message types for MsgId in IW message header.
 */
#define	NM_MSGID_IMP		0
#define	NM_MSGID_IMPSRVR_REG	1
#define	NM_MSGID_IMPSRVR_UNREG	2

#define MAX_OID_LEVELS		12
#define	MAX_STRING_LENGTH	128
#define	MAX_ARRAY_LENGTH	128
#define	MAX_ARRAY1_LENGTH	MAX_ARRAY_LENGTH
#define	MAX_ARRAY2_LENGTH	MAX_ARRAY_LENGTH
#define	MAX_ARRAY4_LENGTH	MAX_ARRAY_LENGTH
#define	MAX_ATTR_COUNT		256
#define	MAX_ACTION_COUNT	256
#define	MAX_EVENT_COUNT		256

/* Some scalar types.
 */
typedef u16 tCID;	/* class identifier */
typedef u16 tCONT;	/* container identifier */
typedef u16 tNMSTAT;	/* NM function return code: status/error */
typedef u16 tNMLEN;	/* NM message length type: always two bytes */

#define	NM_CLASS_UNDEFINED	((tCID)(65535))
#define	NM_CONTID_UNDEFINED	((tCONT)(65535))

/* Generic type for NM functions in "virtual function" table.  Note that all
 * NM functions return a non-negative status code.
 */
typedef tNMSTAT (*tNmFnP)();
typedef void (*tVdFnP)();

/* Types used to store array index/value pairs.
 */
struct ARs8
{
	u8	Index;
	s8	Value;
};
typedef struct ARs8 tARs8;
struct ARu8
{
	u8	Index;
	u8	Value;
};
typedef struct ARu8 tARu8;
struct ARs16
{
	u8	Index;
	s16	Value;
};
typedef struct ARs16 tARs16;
struct ARu16
{
	u8	Index;
	u16	Value;
};
typedef struct ARu16 tARu16;
struct ARs32
{
	u8	Index;
	s32	Value;
};
typedef struct ARs32 tARs32;
struct ARu32
{
	u8	Index;
	u32	Value;
};
typedef struct ARu32 tARu32;

/* Type used to store a class member id (e.g., attribute id).
 */
struct MID
{
	tCID	ClassId;
	u8	MemberId;
	u8	MemberType;
	tNmFnP	MemberFn;
	tVdFnP	CommitFn;
};
typedef struct MID tMID;

/* Defines for MID types.
 */
#define	MID_TYPE_UNKNOWN	0
#define	MID_TYPE_ATTR_NUM	1
#define	MID_TYPE_ATTR_ARRAY	2
#define	MID_TYPE_ATTR_STRG	3
#define	MID_TYPE_ATTR_OID	4
#define	MID_TYPE_ATTR_CID	5
#define	MID_TYPE_ACTION		14
#define	MID_TYPE_EVENT		15
#define	MID_TYPE_TYPE_MASK	0x00f
#define	MID_TYPE_NOVAL_MASK	0x010
#define	MID_TYPE_RW_MASK	0x020
#define	MID_TYPE_RO_MASK	0x030
#define	MID_TYPE_UPDATE_MASK	0x040
#define	MID_TYPE_DEBUG_MASK	0x080

/* Type used to store action info (alas, tMID not reusable enough).
 */
struct FID
{
	tCID	ActCls;
	u8	ActNum;
	u8	ParmCount;
	tCID	EvCls;
	u8	EvNum;
	tNmFnP	ActFn;
	u8*	pParmTypes;
};
typedef struct FID tFID;

/* The Dva structure (type tDva) represents a device (node) address.
 *
 * NOTICE: This is tentative.
 */
struct Dva
{
	u16	NetId;			/* network number */
	u16	NodeId;			/* node number */
};
typedef struct Dva tDva;

/* Methods operating on tDva.  (Function externs moved to bottom of file.)
 */

/* The Oid structure (type tOid) represents an object identifier.  The IxCnt
 * field must be first, since it is not explicitly marshaled, but the rest of
 * the Oid is marshaled as though it were a u16 array (of length IxCnt +
 * ((sizeof(tCONT) + sizeof(tDva)) / sizeof(u16))).  The ContId must come
 * second, both to pad to a 4-byte boundary before DvAddr and because the
 * offset of the ContId field is treated at the start of the marshaled Oid
 * data.  The Ix array must come last, since only part of it may be marshaled.
 */
struct Oid
{
	u16	IxCnt;			/* number of indexes */
	tCONT	ContId;			/* systemwide container id */
	tDva	DvAddr;			/* device address */
	u16	Ix[MAX_OID_LEVELS];	/* indexes: one per containment lvl */
};
typedef struct Oid tOid;
#define OID_NON_IX_U16_COUNT ((sizeof(tCONT) + sizeof(tDva)) / sizeof(u16))
#define OID_INIT	\
{			\
	(u16)0,		\
	(tCONT)0,	\
	{ (u16)0,	\
	  (u16)0 },	\
	{ (u16)0,	\
	  (u16)0,	\
	  (u16)0,	\
	  (u16)0,	\
	  (u16)0,	\
	  (u16)0,	\
	  (u16)0,	\
	  (u16)0,	\
	  (u16)0,	\
	  (u16)0,	\
	  (u16)0,	\
	  (u16)0 }	\
}

/* Methods operating on tOid.  (Function externs moved to bottom of file.)
 */

/* Functions that manipulate arrays.
 */
#define s8copy(pDst, pSrc, Length) \
	u8copy((u8*)(pDst), (u8*)(pSrc), (Length))
#define s16copy(pDst, pSrc, Length) \
	u16copy((u16*)(pDst), (u16*)(pSrc), (Length))
#define s32copy(pDst, pSrc, Length) \
	u32copy((u32*)(pDst), (u32*)(pSrc), (Length))

extern void DvaCopy(tDva* pDstDva, tDva* pSrcDva);
extern int  DvaEqual(tDva* pDva1, tDva* pDva2);
extern void OidCtor(tOid* pOid);
extern void OidCopy(tOid* pDstOid, tOid* pSrcOid);
extern void OidMakeChild(tOid* pDstOid, tOid* pSrcOid, tCONT DstContId,u16 DstIndex);

//extern bool GetEventName(int Cid,int Eid,char *pTempEid,char *pTempAlarmLevel);
extern bool GetMeasPara(int Cid,int Eid,int num,char *pTempPara);
extern bool GetTableName(int cid,char *pTab);

#endif /* _NMTYPES_H_ */
