/*****************************************************************
 *****************************************************************
 ***                                                            **
 ***    (C)Copyright 2005-2006, American Megatrends Inc.        **
 ***                                                            **
 ***            All Rights Reserved.                            **
 ***                                                            **
 ***        6145-F, Northbelt Parkway, Norcross,                **
 ***                                                            **
 ***        Georgia - 30071, USA. Phone-(770)-246-8600.         **
 ***                                                            **
 *****************************************************************
 *****************************************************************
 ******************************************************************
 *
 * SELRecord.h
 * SEL record structures.
 *
 *  Author: Rama Rao Bisa<ramab@ami.com>
 *
 ******************************************************************/
#ifndef SEL_RECORD_H
#define SEL_RECORD_H

#include "com_IPMI_SEL.h"

/*** External Definitions ***/
#define VALID_RECORD        0x5A

#define MAX_RECORD_ID 		(65535)

//#define SEL_RECLAIM_HEAD_NODE(BMCInst)     g_BMCInfo[BMCInst].SELReclaimRepos.HeadeNode
//#define SEL_RECLAIM_TAIL_NODE(BMCInst)     g_BMCInfo[BMCInst].SELReclaimRepos.TailNode

//#define SEL_RECLAIM_RECORD_HEAD_NODE(BMCInst)     g_BMCInfo[BMCInst].SELReclaimRepos.HeadeRecNode
//#define SEL_RECLAIM_RECORD_TAIL_NODE(BMCInst)     g_BMCInfo[BMCInst].SELReclaimRepos.TailRecNode

//#define SEL_RECORD_ADDR(BMCInst,Var)          g_BMCInfo[BMCInst].SELReclaimRepos.pSELRecAddr[Var]
//#define SEL_PREV_RECORD_ADDR(BMCInst,Var)     g_BMCInfo[BMCInst].SELReclaimRepos.pSELRecAddr[Var].RecAddr->PrevRec
//#define SEL_NEXT_RECORD_ADDR(BMCInst,Var)     g_BMCInfo[BMCInst].SELReclaimRepos.pSELRecAddr[Var].RecAddr->NextRec

//#define SEL_MALLOC(Var)    (struct Var *)malloc(sizeof(Var))

#define SIGN_SIZE 4

//#define SEL_RECLAIM_SECTION_INFO "SELRECLAIMINFO"

//#define SEL_SIGNATURE     "signature"
//#define SEL_NUMRECORDS    "NumRecords"
//#define SEL_ADDTIMESTAMP    "AddTimeStamp"
//#define SEL_ERASETIMESTAMP    "EraseTimeStamp"
//#define SEL_LASTFILEINDEX    "LastFileIndex"
//#define SEL_MAXRECPOS    "MaxRecPos"

//#define SEL_FREE(Var)    \
//do{                      \
//    free(Var);           \
//    Var=NULL;            \
//}while(0);


#pragma pack( 1 )




/**
 * @struct SELRepository_T
 * @brief SEL Repository structure.
**/
typedef struct
{
    uint8_t       Signature [SIGN_SIZE];      /* $SDR */
    uint16_t      NumRecords;
    uint16_t      Padding;
    uint32_t      AddTimeStamp;
    uint32_t      EraseTimeStamp;
	uint16_t	FirstRecID;
	uint16_t	LastRecID;
	uint16_t	SELIndex;
    SELRec_T    *SELRecord;

}   SELRepository_T;


/* * @struct SELRecIDNode
 * @brief SELRecIDNode structure.
**/
typedef struct SELRecIDNode
{ 
    int16_t RecordID;
    struct SELRecIDNode *NextRecID;
 }SELRecIDNode;

/**
 * @struct SELEventNode
 * @brief SELEventNode structure.
**/
typedef struct SELEventNode
{
    int32_t FileIndex;
    SELRec_T SELRecord;
    struct SELEventNode *NextRec;
    struct SELEventNode *PrevRec;
 }SELEventNode;

typedef struct
{  
    int32_t RecPos;
    struct SELEventNode *RecAddr;
}SELRecAddr;

/**
 * @struct SELReclaimInfo_T
 * @brief SELReclaimInfo_T structure.
**/
typedef struct
{
    int8_t Signature[SIGN_SIZE];
    int16_t NumRecords;
    int32_t AddTimeStamp;
    int32_t EraseTimeStamp;
    int32_t LastFileIndex;
    int32_t MaxRecPos;
} SELReclaimInfo_T;

/**
 * @struct SELReclaimRepository_T
 * @brief SELReclaimRepository_T structure.
**/
typedef struct
{
/* The Node Pointer needs to be maintained
 * at the top in order to avoid structure
 * alignment issues */
    SELEventNode *HeadeNode;
    SELEventNode *TailNode;
    SELRecIDNode *HeadeRecNode;
    SELRecIDNode *TailRecNode;
    SELRecAddr *pSELRecAddr;
    SELReclaimInfo_T *pSELReclaimInfo;
} SELReclaimRepository_T;

///* SEL Reclaim Function Prototypes */
//extern int DeleteSELRecordIDHeadNode(SELRecIDNode **HeadNode,SELRecIDNode **TailNode);
//extern int DeleteSELReclaimNode(SELEventNode **HeadNode,SELEventNode **TailNode,int16_t RecordID,unsigned int *FileIndex);
//extern int AddSELRecalimNode(SELEventNode **HeadNode,SELEventNode **TailNode,SELRec_T *SELRecord,unsigned int FileIndex);
//extern int16_t GetNextReclaimRecordID(void);
//extern int FlushAddReclaimSEL(SELRec_T *SELRecord);
//extern int ReFlushDeleteReclaimSEL(int16_t RecordID);
//extern int AddSELRecordIDNode(SELRecIDNode **HeadNode,SELRecIDNode **TailNode,int16_t RecordID);
//extern int32_t GetReclaimFileSize(char *FileName);
//extern void DeleteReclaimAllSELNode(SELEventNode **HeadNode,SELEventNode **TailNode);
//extern int UpdateRecordIDList(int8_t *RecordID);
//extern int CopySELReclaimEntries(SELEventNode **HeadNode,int8_t *RecordData,int32_t NumEntriesRetrd,int32_t NumOfEntries);
//extern int LoadSELReclaimInfo( SELReclaimInfo_T *SELInfo);
//extern int SaveSELReclaimInfo( SELReclaimInfo_T *SELInfo);
//extern int CheckPreviousReclaimFile(int32_t FileIndex,int32_t FileSize,SELRec_T *pSELReclaimRec,int8_t *SELCount,char *PrevFileName);
//extern int FilterSELReclaimFiles(const struct dirent *entry);

#pragma pack( )

#endif  /* SEL_RECORD_H */
