

#ifndef _HISTORY_DB_H
#define _HISTORY_DB_H

#define ADD_MULTIPLE_FILE_WR_FUN   // be modified by Jack.Liu on 2020/06/24--13:41:53  

#define FILE_NAME_NUM  (64*2)

enum  FileWRType_
{
     FIRST_INT_FIRST_OUT_TYPE=0,   //单文件先入先出读写
     ALL_LIST_NUM_REPLACE_TYPE,    //单文件总条数数据替换
     MULTIPLE_FILE_WR_TYPE,        //多文件读写操作
     //TODO: add paramter

     FILE_WR_ERROR_TYPE,
};



typedef struct 
{
	//需初始化
	char fileName[64];			//保存文件名称
	char dirName[64];			//文件保存目录,为空默认值app/HISTORY/DB_INFO
	DWORD listMax;				//链表最大数
	DWORD listSize;				//单个链表大小
	
	DWORD fileTatal;			//文件总数
	DWORD fileTableSize;		//文件头信息

	//运行参数
	struct file *  fd;			//文件句柄
	DWORD listNum;				//当前链表个数
	DWORD listNewNum;			//未读取个数,此变量写操作时需要做互锁处理
	DWORD listWp;				//链表写指针

	BYTE  fileWRType;           //文件读写类型
    BYTE  fileWp;               //文件链表指针 0～（fileTatal-1）指向当前的文件位置
	
} fileInfo;

struct DataListFileInfo_
{
    char fileName[64];			//保存文件名称
    char ReserveOpt[16];        //预留
    char SumValue;
};
typedef  struct DataListFileInfo_  DataListFileInfoType;
 



int initListData(fileInfo *list);
DWORD readListData(fileInfo *list,DWORD readNum,BYTE *buf);
void writeListData(fileInfo *list,BYTE *buf);
DWORD readNewListData(fileInfo *list,BYTE *buf);
extern int ReplaceListData(fileInfo *list,int replaceNum,BYTE *buf);
int DelListFile(fileInfo *list);

extern int GetMultipleFileNameInfo(fileInfo* list,DWORD fileNum,DataListFileInfoType* DataListFileInfo);
extern int UpdateMultipleFileNameInfo(fileInfo* list,DWORD fileNum,DataListFileInfoType* DataListFileInfo);
extern int GetDataListFileTitleInfo(fileInfo* list,DWORD fileNum,char* TitleData);
extern int UpdateDataListFileTitleInfo(fileInfo* list,DWORD fileNum,char* TitleData);
extern int CreateNewMultipleFileDataList(fileInfo *list,char* DataListName);
extern int DelMultipleListFile(fileInfo *list,char* FileName);
extern int  GetCurMultipleFileNumPos(fileInfo *list,DWORD* FilePos);
extern int DelAllListDataFile(fileInfo *list);

#endif


