Struct modified.
This commit is contained in:
parent
a7b6538bac
commit
14ec30b0be
@ -1,5 +1,5 @@
|
|||||||
#ifndef BLOCK_EXPAND_H
|
#ifndef block_expand_h
|
||||||
#define BLOCK_EXPAND_H
|
#define block_expand_h
|
||||||
|
|
||||||
|
|
||||||
#endif /* block_expand_h */
|
#endif /* block_expand_h */
|
||||||
|
5
include/block/block_print.h
Normal file
5
include/block/block_print.h
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#ifndef block_print_h
|
||||||
|
#define block_print_h
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* block_print_h */
|
@ -11,12 +11,13 @@
|
|||||||
*/
|
*/
|
||||||
typedef struct block{
|
typedef struct block{
|
||||||
uint64_t size;
|
uint64_t size;
|
||||||
|
uint64_t m_size;
|
||||||
uint32_t carve;
|
uint32_t carve;
|
||||||
void *data;
|
void *data;
|
||||||
#ifdef id_enable
|
#ifdef id_enable
|
||||||
SID *s_id;//栈节点的ID
|
SID *s_id;//栈节点的ID
|
||||||
#endif
|
#endif
|
||||||
} SNode;
|
} Block;
|
||||||
|
|
||||||
|
|
||||||
#endif /* block_type_h */
|
#endif /* block_type_h */
|
||||||
|
@ -1,285 +1,7 @@
|
|||||||
#ifndef communicate_h
|
#ifndef communicate_h
|
||||||
#define communicate_h
|
#define communicate_h
|
||||||
|
|
||||||
/*
|
#include <communicate/communicate_type.h>
|
||||||
*文件头信息的管理及操作的结构
|
|
||||||
*/
|
|
||||||
typedef struct file_head{
|
|
||||||
char head_test[18];//数据文件头部的验证信息
|
|
||||||
uint32_t data_num;//数据文件中的标准数据结构的数目
|
|
||||||
}F_HEAD;
|
|
||||||
|
|
||||||
/*
|
|
||||||
*数据文件的管理及操作的结构
|
|
||||||
*/
|
|
||||||
typedef struct data_file{
|
|
||||||
FILE *fp;//数据文件
|
|
||||||
F_HEAD *pf_head;//数据文件头
|
|
||||||
List *pf_stdlst;//数据文件的标志数据结构的储存链表
|
|
||||||
}D_FILE;
|
|
||||||
|
|
||||||
/*
|
|
||||||
*标准数据结构的管理及操作的结构
|
|
||||||
*/
|
|
||||||
typedef struct standard_data_blocks{
|
|
||||||
uint16_t type;//数据块的类型
|
|
||||||
uint32_t location;//数据块在数据文件中的定位
|
|
||||||
char *sid;//数据块的ID
|
|
||||||
_Bool if_data;//数据块是否赋值
|
|
||||||
unsigned int blocks_num;//数据块字节大小
|
|
||||||
char *buff;//指向数据块储存值内存空间的指针
|
|
||||||
}STD_BLOCKS;
|
|
||||||
|
|
||||||
/*
|
|
||||||
*标准数据结构中数据块的连接关系的管理及操作的结构
|
|
||||||
*/
|
|
||||||
typedef struct standard_data_connection{
|
|
||||||
uint32_t location;//数据块链接关系结构在文件中的定位
|
|
||||||
char *f_sid;//前一个数据块的ID
|
|
||||||
char *s_sid;//后一个数据块的ID
|
|
||||||
}STD_CTN;
|
|
||||||
|
|
||||||
/*
|
|
||||||
*标准数据结构头的管理及操作的结构
|
|
||||||
*/
|
|
||||||
typedef struct standard_data_head{
|
|
||||||
uint32_t data_blk_num;//数据块的数目
|
|
||||||
uint32_t data_ctn_num;//数据块链接关系结构的数目
|
|
||||||
}STD_HEAD;
|
|
||||||
|
|
||||||
/*
|
|
||||||
*标准数据结构的管理及操作的结构
|
|
||||||
*/
|
|
||||||
typedef struct standard_data{
|
|
||||||
SID *s_id;//标准数据结构的ID
|
|
||||||
int read_data;//标准数据结构是否已经读取完整
|
|
||||||
uint16_t type;//标准数据结构所对应的类型
|
|
||||||
uint32_t size;//标准数据结构在数据文件中的大小
|
|
||||||
uint32_t location;//标准数据结构的头在数据文件中的定位
|
|
||||||
_Bool lock;//标准数据文件是否被锁住
|
|
||||||
List *pd_blocklst;//数据块储存链表
|
|
||||||
List *pd_ctnlst;//数据块连接关系结构的储存链表
|
|
||||||
}STD_DATA;
|
|
||||||
|
|
||||||
/*
|
|
||||||
*消息的管理及操作的结构
|
|
||||||
*/
|
|
||||||
typedef struct message{
|
|
||||||
SID *p_sid;//消息的ID
|
|
||||||
time_t time;//消息的产生时间
|
|
||||||
char titile[16];//消息标题
|
|
||||||
unsigned long size;//消息的大小
|
|
||||||
char content[0];//消息的正文
|
|
||||||
}MSG;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/************************************************
|
|
||||||
相关结构体初始化: 初始化相关结构体有关函数
|
|
||||||
************************************************/
|
|
||||||
|
|
||||||
/*
|
|
||||||
*以写的方式初始化数据文件管理结构
|
|
||||||
*参数: route指示数据文件路径
|
|
||||||
*返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL.
|
|
||||||
*/
|
|
||||||
extern D_FILE *initDataFileForWrite(char *route);
|
|
||||||
|
|
||||||
/*
|
|
||||||
*以读的方式初始化数据文件管理结构
|
|
||||||
*参数: route指示数据文件路径
|
|
||||||
*返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL.
|
|
||||||
*/
|
|
||||||
extern D_FILE *initDataFileForRead(char *route);
|
|
||||||
|
|
||||||
/*
|
|
||||||
*初始化数据块管理结构
|
|
||||||
*参数: type指示数据块储存数据的数据类型,data_size指示数据块储存数据的大小
|
|
||||||
*返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL.
|
|
||||||
*/
|
|
||||||
extern STD_BLOCKS *initStandardDBlocks(SID *p_sid, uint16_t type, uint32_t data_size);
|
|
||||||
|
|
||||||
/*
|
|
||||||
*初始化数据块链接关系管理结构
|
|
||||||
*参数: f_sid指示第一个数据块的SID,s_sid指示第二个数据块的SID.
|
|
||||||
*返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL.
|
|
||||||
*/
|
|
||||||
extern STD_CTN *initStandardDConnection(SID *f_sid, SID *s_sid);
|
|
||||||
|
|
||||||
/*
|
|
||||||
*初始化标准数据结构管理结构
|
|
||||||
*参数: type指示标准数据结构所储存的数据结构的数据类型, s_id指示所储存的数据结构的ID,
|
|
||||||
若s_id为NULL,则另外分配一个ID.为了方便管理,标准数据结构必须有ID.
|
|
||||||
*返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL.
|
|
||||||
*/
|
|
||||||
extern STD_DATA *initStandardData(uint16_t type, SID *s_id);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/************************************************
|
|
||||||
相关结构体的组织: 组织相关结构体有关函数
|
|
||||||
************************************************/
|
|
||||||
|
|
||||||
/*
|
|
||||||
*为数据块添加数据
|
|
||||||
*参数: data为指向所添加数据所在内存空间的指针
|
|
||||||
*返回: 处理成功则返回0,不成功则返回-1.
|
|
||||||
*/
|
|
||||||
extern int dataForStandardDBlock(STD_BLOCKS *p_stdb,void *data);
|
|
||||||
|
|
||||||
/*
|
|
||||||
*为数据文件添加标准数据结构
|
|
||||||
*返回: 处理成功则返回0,不成功则返回-1.
|
|
||||||
*/
|
|
||||||
extern int dataFileAddStandardData(D_FILE *p_dfile, STD_DATA *p_std);
|
|
||||||
|
|
||||||
/*
|
|
||||||
*为标准数据结构添加数据块
|
|
||||||
*参数: type指示所添加数据的数据类型, data为指向所添加数据所在内存空间的指针, data_size指示所添加数据的大小
|
|
||||||
*返回: 处理成功则返回0,不成功则返回-1.
|
|
||||||
*/
|
|
||||||
extern int standardDataAddBlock(STD_DATA *p_std, SID *p_sid ,uint16_t type, void *data, uint32_t data_size);
|
|
||||||
|
|
||||||
/*
|
|
||||||
*为标准数据结构添加数据块链接关系结构体
|
|
||||||
*参数: f_sid指示第一个数据块的SID,s_sid指示第二个数据块的SID.
|
|
||||||
*返回: 处理成功则返回0,不成功则返回-1.
|
|
||||||
*/
|
|
||||||
extern int standardDataAddConnection(STD_DATA *p_std, SID *f_sid, SID *s_sid);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/************************************************
|
|
||||||
数据文件管理结构的整体写入与读出: 对数据文件管理结构的操作
|
|
||||||
************************************************/
|
|
||||||
|
|
||||||
/*
|
|
||||||
*将数据文件管理结构写入到相关数据文件中,以储存.
|
|
||||||
*返回: 处理成功则返回0,不成功则返回-1.
|
|
||||||
*/
|
|
||||||
extern int dataFileWriteIn(D_FILE *p_dfile);
|
|
||||||
|
|
||||||
/*
|
|
||||||
*将相关数据文件中的内容,读出到数据文件管理结构中,等待操作.
|
|
||||||
*返回: 处理成功则返回0,不成功则返回-1.
|
|
||||||
*/
|
|
||||||
extern int dataFileReadOut(D_FILE *p_dfile);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/************************************************
|
|
||||||
相关结构的释放操作: 释放相关结构体所占内存空间的相关函数
|
|
||||||
************************************************/
|
|
||||||
|
|
||||||
/*
|
|
||||||
*释放数据块所占内存空间
|
|
||||||
*返回: 处理成功则返回0,不成功则返回-1.
|
|
||||||
*/
|
|
||||||
extern int releaseSTDBlocks(STD_BLOCKS *p_stdb);
|
|
||||||
|
|
||||||
/*
|
|
||||||
*释放标准数据结构管理结构所占的内存空间
|
|
||||||
*返回: 处理成功则返回0,不成功则返回-1.
|
|
||||||
*/
|
|
||||||
extern int releaseStandardData(STD_DATA *p_std);
|
|
||||||
|
|
||||||
/*
|
|
||||||
*释放数据块链接关系管理结构所占的内存空间
|
|
||||||
*返回: 处理成功则返回0,不成功则返回-1.
|
|
||||||
*/
|
|
||||||
extern int releaseSTDConnection(STD_CTN *p_stdc);
|
|
||||||
|
|
||||||
/*
|
|
||||||
*释放数据文件管理结构所占的内存空间
|
|
||||||
*返回: 处理成功则返回0,不成功则返回-1.
|
|
||||||
*/
|
|
||||||
extern int releaseDFile(D_FILE *p_file);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/************************************************
|
|
||||||
结构类型的转换: 其他数据结构与标准数据结构的转换相关函数
|
|
||||||
************************************************/
|
|
||||||
|
|
||||||
/*
|
|
||||||
*将链表转化为标准数据结构
|
|
||||||
*返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL.
|
|
||||||
*/
|
|
||||||
extern STD_DATA *listToSTD(List *);
|
|
||||||
|
|
||||||
/*
|
|
||||||
*将标准数据结构转换成链表
|
|
||||||
*返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL.
|
|
||||||
*/
|
|
||||||
extern List *standardDataToList(STD_DATA *);
|
|
||||||
|
|
||||||
//STD_DATA *stackToSTD(Stack *);
|
|
||||||
|
|
||||||
//STD_DATA *treeToSTD(Tree *);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/************************************************
|
|
||||||
标准数据结构的随机存取: 标准数据结构的随机存取相关函数
|
|
||||||
************************************************/
|
|
||||||
|
|
||||||
/*
|
|
||||||
*读取数据文件的简略信息,为随机存取准备必要信息
|
|
||||||
*说明: 该函数只会在数据文件管理结构中建立一个框架,不会读入实际的数据块以及数据块链接关系.
|
|
||||||
*返回: 处理成功则返回0,不成功则返回-1.
|
|
||||||
*/
|
|
||||||
extern int readDataFileInfo(D_FILE *p_dfile);
|
|
||||||
|
|
||||||
/*
|
|
||||||
*读取数据文件中的特定标准数据结构
|
|
||||||
*参数: p_std为指向框架中的相关标准数据所在内存空间的指针
|
|
||||||
*返回: 处理成功则返回0,不成功则返回-1.
|
|
||||||
*/
|
|
||||||
extern int readStandardData(D_FILE *p_dfile, STD_DATA *p_std);
|
|
||||||
|
|
||||||
/*
|
|
||||||
*读取数据文件中的特定标准数据结构中的数据块
|
|
||||||
*返回: 处理成功则返回0,不成功则返回-1.
|
|
||||||
*/
|
|
||||||
extern int readSTDBlocks(STD_BLOCKS *p_stdb);
|
|
||||||
|
|
||||||
/*
|
|
||||||
*读取文件头,检验文件是否为数据文件
|
|
||||||
*返回: 处理成功则返回0,不成功则返回-1.
|
|
||||||
*/
|
|
||||||
extern int checkIfDataFile(D_FILE *p_dfile);
|
|
||||||
|
|
||||||
/*
|
|
||||||
*通过标准数据结构的ID,在数据文件中读入特定的标准数据结构
|
|
||||||
*返回: 处理成功则返回0,不成功则返回-1.
|
|
||||||
*/
|
|
||||||
extern int readStandardDataBySid(D_FILE *p_dfile, SID *p_sid);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/************************************************
|
|
||||||
标准数据结构信息: 获取标准数据结构信息相关函数
|
|
||||||
************************************************/
|
|
||||||
|
|
||||||
/*
|
|
||||||
*打印标准数据结构信息
|
|
||||||
*/
|
|
||||||
extern void printStandardData(void *value);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
269
include/communicate/communicate_file.h
Normal file
269
include/communicate/communicate_file.h
Normal file
@ -0,0 +1,269 @@
|
|||||||
|
#ifndef communicate_file_h
|
||||||
|
#define communicate_file_h
|
||||||
|
|
||||||
|
#include <communicate/communicate_type.h>
|
||||||
|
|
||||||
|
/************************************************
|
||||||
|
相关结构体初始化: 初始化相关结构体有关函数
|
||||||
|
************************************************/
|
||||||
|
|
||||||
|
/*
|
||||||
|
*以写的方式初始化数据文件管理结构
|
||||||
|
*参数: route指示数据文件路径
|
||||||
|
*返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL.
|
||||||
|
*/
|
||||||
|
extern D_FILE *initDataFileForWrite(char *route);
|
||||||
|
|
||||||
|
/*
|
||||||
|
*以读的方式初始化数据文件管理结构
|
||||||
|
*参数: route指示数据文件路径
|
||||||
|
*返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL.
|
||||||
|
*/
|
||||||
|
extern D_FILE *initDataFileForRead(char *route);
|
||||||
|
|
||||||
|
/*
|
||||||
|
*初始化数据块管理结构
|
||||||
|
*参数: type指示数据块储存数据的数据类型,data_size指示数据块储存数据的大小
|
||||||
|
*返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL.
|
||||||
|
*/
|
||||||
|
extern STD_BLOCKS *initStandardDBlocks(SID *p_sid, uint16_t type, uint32_t data_size);
|
||||||
|
|
||||||
|
/*
|
||||||
|
*初始化数据块链接关系管理结构
|
||||||
|
*参数: f_sid指示第一个数据块的SID,s_sid指示第二个数据块的SID.
|
||||||
|
*返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL.
|
||||||
|
*/
|
||||||
|
extern STD_CTN *initStandardDConnection(SID *f_sid, SID *s_sid);
|
||||||
|
|
||||||
|
/*
|
||||||
|
*初始化标准数据结构管理结构
|
||||||
|
*参数: type指示标准数据结构所储存的数据结构的数据类型, s_id指示所储存的数据结构的ID,
|
||||||
|
若s_id为NULL,则另外分配一个ID.为了方便管理,标准数据结构必须有ID.
|
||||||
|
*返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL.
|
||||||
|
*/
|
||||||
|
extern STD_DATA *initStandardData(uint16_t type, SID *s_id);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/************************************************
|
||||||
|
相关结构体的组织: 组织相关结构体有关函数
|
||||||
|
************************************************/
|
||||||
|
|
||||||
|
/*
|
||||||
|
*为数据块添加数据
|
||||||
|
*参数: data为指向所添加数据所在内存空间的指针
|
||||||
|
*返回: 处理成功则返回0,不成功则返回-1.
|
||||||
|
*/
|
||||||
|
extern int dataForStandardDBlock(STD_BLOCKS *p_stdb,void *data);
|
||||||
|
|
||||||
|
/*
|
||||||
|
*为数据文件添加标准数据结构
|
||||||
|
*返回: 处理成功则返回0,不成功则返回-1.
|
||||||
|
*/
|
||||||
|
extern int dataFileAddStandardData(D_FILE *p_dfile, STD_DATA *p_std);
|
||||||
|
|
||||||
|
/*
|
||||||
|
*为标准数据结构添加数据块
|
||||||
|
*参数: type指示所添加数据的数据类型, data为指向所添加数据所在内存空间的指针, data_size指示所添加数据的大小
|
||||||
|
*返回: 处理成功则返回0,不成功则返回-1.
|
||||||
|
*/
|
||||||
|
extern int standardDataAddBlock(STD_DATA *p_std, SID *p_sid ,uint16_t type, void *data, uint32_t data_size);
|
||||||
|
|
||||||
|
/*
|
||||||
|
*为标准数据结构添加数据块链接关系结构体
|
||||||
|
*参数: f_sid指示第一个数据块的SID,s_sid指示第二个数据块的SID.
|
||||||
|
*返回: 处理成功则返回0,不成功则返回-1.
|
||||||
|
*/
|
||||||
|
extern int standardDataAddConnection(STD_DATA *p_std, SID *f_sid, SID *s_sid);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/************************************************
|
||||||
|
数据文件管理结构的整体写入与读出: 对数据文件管理结构的操作
|
||||||
|
************************************************/
|
||||||
|
|
||||||
|
/*
|
||||||
|
*将数据文件管理结构写入到相关数据文件中,以储存.
|
||||||
|
*返回: 处理成功则返回0,不成功则返回-1.
|
||||||
|
*/
|
||||||
|
extern int dataFileWriteIn(D_FILE *p_dfile);
|
||||||
|
|
||||||
|
/*
|
||||||
|
*将相关数据文件中的内容,读出到数据文件管理结构中,等待操作.
|
||||||
|
*返回: 处理成功则返回0,不成功则返回-1.
|
||||||
|
*/
|
||||||
|
extern int dataFileReadOut(D_FILE *p_dfile);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/************************************************
|
||||||
|
相关结构的释放操作: 释放相关结构体所占内存空间的相关函数
|
||||||
|
************************************************/
|
||||||
|
|
||||||
|
/*
|
||||||
|
*释放数据块所占内存空间
|
||||||
|
*返回: 处理成功则返回0,不成功则返回-1.
|
||||||
|
*/
|
||||||
|
extern int releaseSTDBlocks(STD_BLOCKS *p_stdb);
|
||||||
|
|
||||||
|
/*
|
||||||
|
*释放标准数据结构管理结构所占的内存空间
|
||||||
|
*返回: 处理成功则返回0,不成功则返回-1.
|
||||||
|
*/
|
||||||
|
extern int releaseStandardData(STD_DATA *p_std);
|
||||||
|
|
||||||
|
/*
|
||||||
|
*释放数据块链接关系管理结构所占的内存空间
|
||||||
|
*返回: 处理成功则返回0,不成功则返回-1.
|
||||||
|
*/
|
||||||
|
extern int releaseSTDConnection(STD_CTN *p_stdc);
|
||||||
|
|
||||||
|
/*
|
||||||
|
*释放数据文件管理结构所占的内存空间
|
||||||
|
*返回: 处理成功则返回0,不成功则返回-1.
|
||||||
|
*/
|
||||||
|
extern int releaseDFile(D_FILE *p_file);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/************************************************
|
||||||
|
结构类型的转换: 其他数据结构与标准数据结构的转换相关函数
|
||||||
|
************************************************/
|
||||||
|
|
||||||
|
/*
|
||||||
|
*将链表转化为标准数据结构
|
||||||
|
*返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL.
|
||||||
|
*/
|
||||||
|
extern STD_DATA *listToSTD(List *);
|
||||||
|
|
||||||
|
/*
|
||||||
|
*将标准数据结构转换成链表
|
||||||
|
*返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL.
|
||||||
|
*/
|
||||||
|
extern List *standardDataToList(STD_DATA *);
|
||||||
|
|
||||||
|
//STD_DATA *stackToSTD(Stack *);
|
||||||
|
|
||||||
|
//STD_DATA *treeToSTD(Tree *);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/************************************************
|
||||||
|
标准数据结构的随机存取: 标准数据结构的随机存取相关函数
|
||||||
|
************************************************/
|
||||||
|
|
||||||
|
/*
|
||||||
|
*读取数据文件的简略信息,为随机存取准备必要信息
|
||||||
|
*说明: 该函数只会在数据文件管理结构中建立一个框架,不会读入实际的数据块以及数据块链接关系.
|
||||||
|
*返回: 处理成功则返回0,不成功则返回-1.
|
||||||
|
*/
|
||||||
|
extern int readDataFileInfo(D_FILE *p_dfile);
|
||||||
|
|
||||||
|
/*
|
||||||
|
*读取数据文件中的特定标准数据结构
|
||||||
|
*参数: p_std为指向框架中的相关标准数据所在内存空间的指针
|
||||||
|
*返回: 处理成功则返回0,不成功则返回-1.
|
||||||
|
*/
|
||||||
|
extern int readStandardData(D_FILE *p_dfile, STD_DATA *p_std);
|
||||||
|
|
||||||
|
/*
|
||||||
|
*读取数据文件中的特定标准数据结构中的数据块
|
||||||
|
*返回: 处理成功则返回0,不成功则返回-1.
|
||||||
|
*/
|
||||||
|
extern int readSTDBlocks(STD_BLOCKS *p_stdb);
|
||||||
|
|
||||||
|
/*
|
||||||
|
*读取文件头,检验文件是否为数据文件
|
||||||
|
*返回: 处理成功则返回0,不成功则返回-1.
|
||||||
|
*/
|
||||||
|
extern int checkIfDataFile(D_FILE *p_dfile);
|
||||||
|
|
||||||
|
/*
|
||||||
|
*通过标准数据结构的ID,在数据文件中读入特定的标准数据结构
|
||||||
|
*返回: 处理成功则返回0,不成功则返回-1.
|
||||||
|
*/
|
||||||
|
extern int readStandardDataBySid(D_FILE *p_dfile, SID *p_sid);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/************************************************
|
||||||
|
标准数据结构信息: 获取标准数据结构信息相关函数
|
||||||
|
************************************************/
|
||||||
|
|
||||||
|
/*
|
||||||
|
*打印标准数据结构信息
|
||||||
|
*/
|
||||||
|
extern void printStandardData(void *value);
|
||||||
|
|
||||||
|
/*
|
||||||
|
*计算标准数据结构在文件中占用的空间,以字节为单位.
|
||||||
|
*/
|
||||||
|
uint32_t calStandardData(STD_DATA *p_std);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/************************************************
|
||||||
|
相关回调函数声明
|
||||||
|
************************************************/
|
||||||
|
|
||||||
|
/*
|
||||||
|
*数据文件管理结构中标准数据结构管理结构的简略信息的写入函数
|
||||||
|
*/
|
||||||
|
__CALLBACK_STATE(StandardDataInfoWrite);
|
||||||
|
|
||||||
|
/*
|
||||||
|
*数据文件管理结构中标准数据结构管理结构的内容的写入函数
|
||||||
|
*/
|
||||||
|
__CALLBACK_STATE(StandardDataWrite);
|
||||||
|
|
||||||
|
/*
|
||||||
|
*标准数据结构管理结构中的数据块链接关系管理结构的写入函数
|
||||||
|
*/
|
||||||
|
__CALLBACK_STATE(StandardDConnectionWrite);
|
||||||
|
|
||||||
|
/*
|
||||||
|
*标准数据结构管理结构中的数据块管理结构的写入函数
|
||||||
|
*/
|
||||||
|
__CALLBACK_STATE(StandardDBlockWrite);
|
||||||
|
|
||||||
|
/*
|
||||||
|
*数据文件管理结构的读出函数的回调函数声明
|
||||||
|
*/
|
||||||
|
__CALLBACK_STATE(dataFileReadOut);
|
||||||
|
|
||||||
|
/*
|
||||||
|
*计算数据块链接关系在文件中的大小
|
||||||
|
*/
|
||||||
|
__CALLBACK_STATE(calStandardDataCTN);
|
||||||
|
|
||||||
|
/*
|
||||||
|
*计算数据块在文件中的大小
|
||||||
|
*/
|
||||||
|
__CALLBACK_STATE(calStandardDataBLK);
|
||||||
|
|
||||||
|
/*
|
||||||
|
*将标准数据结构转换成链表的回调函数
|
||||||
|
*/
|
||||||
|
__CALLBACK_STATE(StandardDataToList);
|
||||||
|
|
||||||
|
/*
|
||||||
|
*通过标准数据结构的ID,在数据文件中读入特定的标准数据结构函数的回调函数
|
||||||
|
*/
|
||||||
|
__CALLBACK_STATE(findStandardDataBySid);
|
||||||
|
|
||||||
|
#endif /* communicate_file_h */
|
77
include/communicate/communicate_type.h
Normal file
77
include/communicate/communicate_type.h
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
#ifndef communicate_type_h
|
||||||
|
#define communicate_type_h
|
||||||
|
|
||||||
|
#include<type.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
*文件头信息的管理及操作的结构
|
||||||
|
*/
|
||||||
|
typedef struct file_head{
|
||||||
|
char head_test[18];//数据文件头部的验证信息
|
||||||
|
uint32_t data_num;//数据文件中的标准数据结构的数目
|
||||||
|
}F_HEAD;
|
||||||
|
|
||||||
|
/*
|
||||||
|
*数据文件的管理及操作的结构
|
||||||
|
*/
|
||||||
|
typedef struct data_file{
|
||||||
|
FILE *fp;//数据文件
|
||||||
|
F_HEAD *pf_head;//数据文件头
|
||||||
|
List *pf_stdlst;//数据文件的标志数据结构的储存链表
|
||||||
|
}D_FILE;
|
||||||
|
|
||||||
|
/*
|
||||||
|
*标准数据结构的管理及操作的结构
|
||||||
|
*/
|
||||||
|
typedef struct standard_data_blocks{
|
||||||
|
uint16_t type;//数据块的类型
|
||||||
|
uint32_t location;//数据块在数据文件中的定位
|
||||||
|
char *sid;//数据块的ID
|
||||||
|
_Bool if_data;//数据块是否赋值
|
||||||
|
unsigned int blocks_num;//数据块字节大小
|
||||||
|
char *buff;//指向数据块储存值内存空间的指针
|
||||||
|
}STD_BLOCKS;
|
||||||
|
|
||||||
|
/*
|
||||||
|
*标准数据结构中数据块的连接关系的管理及操作的结构
|
||||||
|
*/
|
||||||
|
typedef struct standard_data_connection{
|
||||||
|
uint32_t location;//数据块链接关系结构在文件中的定位
|
||||||
|
char *f_sid;//前一个数据块的ID
|
||||||
|
char *s_sid;//后一个数据块的ID
|
||||||
|
}STD_CTN;
|
||||||
|
|
||||||
|
/*
|
||||||
|
*标准数据结构头的管理及操作的结构
|
||||||
|
*/
|
||||||
|
typedef struct standard_data_head{
|
||||||
|
uint32_t data_blk_num;//数据块的数目
|
||||||
|
uint32_t data_ctn_num;//数据块链接关系结构的数目
|
||||||
|
}STD_HEAD;
|
||||||
|
|
||||||
|
/*
|
||||||
|
*标准数据结构的管理及操作的结构
|
||||||
|
*/
|
||||||
|
typedef struct standard_data{
|
||||||
|
SID *s_id;//标准数据结构的ID
|
||||||
|
int read_data;//标准数据结构是否已经读取完整
|
||||||
|
uint16_t type;//标准数据结构所对应的类型
|
||||||
|
uint32_t size;//标准数据结构在数据文件中的大小
|
||||||
|
uint32_t location;//标准数据结构的头在数据文件中的定位
|
||||||
|
_Bool lock;//标准数据文件是否被锁住
|
||||||
|
List *pd_blocklst;//数据块储存链表
|
||||||
|
List *pd_ctnlst;//数据块连接关系结构的储存链表
|
||||||
|
}STD_DATA;
|
||||||
|
|
||||||
|
/*
|
||||||
|
*消息的管理及操作的结构
|
||||||
|
*/
|
||||||
|
typedef struct message{
|
||||||
|
SID *p_sid;//消息的ID
|
||||||
|
time_t time;//消息的产生时间
|
||||||
|
char titile[16];//消息标题
|
||||||
|
unsigned long size;//消息的大小
|
||||||
|
char content[0];//消息的正文
|
||||||
|
}MSG;
|
||||||
|
|
||||||
|
#endif /* communicate_type_h */
|
@ -166,12 +166,12 @@
|
|||||||
/*
|
/*
|
||||||
*若快速声明回调函数则使用该宏
|
*若快速声明回调函数则使用该宏
|
||||||
*参数: name为回调函数名.*/
|
*参数: name为回调函数名.*/
|
||||||
#define __CALLBACK_STATE(name) static List *_do##name(unsigned int, void *, List *)
|
#define __CALLBACK_STATE(name) List *_do##name(unsigned int, void *, List *)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*若快速定义回调函数则使用该宏
|
*若快速定义回调函数则使用该宏
|
||||||
*参数: name为回调函数名.*/
|
*参数: name为回调函数名.*/
|
||||||
#define __CALLBACK_DEFINE(name) static List *_do##name(unsigned int type, void *value, List *expand_resources)
|
#define __CALLBACK_DEFINE(name) List *_do##name(unsigned int type, void *value, List *expand_resources)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*若传递回调函数指针则使用该宏
|
*若传递回调函数指针则使用该宏
|
||||||
|
@ -5,330 +5,8 @@
|
|||||||
#include <list/list_expand.h>
|
#include <list/list_expand.h>
|
||||||
#include <list/list_expand_1.h>
|
#include <list/list_expand_1.h>
|
||||||
#include <communicate/communicate.h>
|
#include <communicate/communicate.h>
|
||||||
|
#include <communicate/communicate_file.h>
|
||||||
|
|
||||||
/*
|
|
||||||
*计算标准数据结构在文件中占用的空间,以字节为单位.
|
|
||||||
*/
|
|
||||||
static uint32_t calStandardData(STD_DATA *p_std);
|
|
||||||
|
|
||||||
/*
|
|
||||||
*数据文件管理结构中标准数据结构管理结构的简略信息的写入函数
|
|
||||||
*/
|
|
||||||
__CALLBACK_STATE(StandardDataInfoWrite);
|
|
||||||
|
|
||||||
/*
|
|
||||||
*数据文件管理结构中标准数据结构管理结构的内容的写入函数
|
|
||||||
*/
|
|
||||||
__CALLBACK_STATE(StandardDataWrite);
|
|
||||||
|
|
||||||
/*
|
|
||||||
*标准数据结构管理结构中的数据块链接关系管理结构的写入函数
|
|
||||||
*/
|
|
||||||
__CALLBACK_STATE(StandardDConnectionWrite);
|
|
||||||
|
|
||||||
/*
|
|
||||||
*标准数据结构管理结构中的数据块管理结构的写入函数
|
|
||||||
*/
|
|
||||||
__CALLBACK_STATE(StandardDBlockWrite);
|
|
||||||
|
|
||||||
/*
|
|
||||||
*数据文件管理结构的读出函数的回调函数声明
|
|
||||||
*/
|
|
||||||
__CALLBACK_STATE(dataFileReadOut);
|
|
||||||
|
|
||||||
/*
|
|
||||||
*计算数据块链接关系在文件中的大小
|
|
||||||
*/
|
|
||||||
__CALLBACK_STATE(calStandardDataCTN);
|
|
||||||
|
|
||||||
/*
|
|
||||||
*计算数据块在文件中的大小
|
|
||||||
*/
|
|
||||||
__CALLBACK_STATE(calStandardDataBLK);
|
|
||||||
|
|
||||||
/*
|
|
||||||
*将标准数据结构转换成链表的回调函数
|
|
||||||
*/
|
|
||||||
__CALLBACK_STATE(StandardDataToList);
|
|
||||||
|
|
||||||
/*
|
|
||||||
*通过标准数据结构的ID,在数据文件中读入特定的标准数据结构函数的回调函数
|
|
||||||
*/
|
|
||||||
__CALLBACK_STATE(findStandardDataBySid);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
STD_BLOCKS *initStandardDBlocks(SID *p_sid, uint16_t type, uint32_t data_size){
|
|
||||||
STD_BLOCKS *p_stdb = (STD_BLOCKS *)malloc(sizeof(STD_BLOCKS));
|
|
||||||
if(p_sid != NULL){
|
|
||||||
p_stdb->sid = s_idToASCIIString(p_sid);
|
|
||||||
}
|
|
||||||
else p_stdb->sid = NULL;
|
|
||||||
p_stdb->if_data = 0;
|
|
||||||
p_stdb->location = 0;
|
|
||||||
uint32_t blocks_num = (uint32_t)(data_size/sizeof(char));
|
|
||||||
p_stdb->blocks_num = blocks_num;
|
|
||||||
p_stdb->type = type;
|
|
||||||
p_stdb->buff = (char *)malloc(sizeof(char) * blocks_num);
|
|
||||||
return p_stdb;
|
|
||||||
}
|
|
||||||
|
|
||||||
int dataForStandardDBlock(STD_BLOCKS *p_stdb,void *data){
|
|
||||||
char *t_data = (char *)data;
|
|
||||||
/*unsigned int data_size = sizeof(data);*/
|
|
||||||
for(int i = 0; i < p_stdb->blocks_num; i++){
|
|
||||||
p_stdb->buff[i] = t_data[i];
|
|
||||||
}
|
|
||||||
p_stdb->if_data = 1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
STD_CTN *initStandardDConnection(SID *f_sid, SID *s_sid){
|
|
||||||
STD_CTN *p_stdc = (STD_CTN *)malloc(sizeof(STD_CTN));
|
|
||||||
p_stdc->f_sid = s_idToASCIIString(f_sid);
|
|
||||||
p_stdc->s_sid = s_idToASCIIString(s_sid);
|
|
||||||
p_stdc->location = 0;
|
|
||||||
return p_stdc;
|
|
||||||
}
|
|
||||||
|
|
||||||
STD_DATA *initStandardData(uint16_t type, SID *s_id){
|
|
||||||
STD_DATA *p_std = (STD_DATA *)malloc(sizeof(STD_DATA));
|
|
||||||
p_std->pd_blocklst = initList(0);
|
|
||||||
p_std->pd_ctnlst = initList(0);
|
|
||||||
p_std->lock = 0;
|
|
||||||
p_std->type = type;
|
|
||||||
p_std->size = 0;
|
|
||||||
p_std->location = 0;
|
|
||||||
p_std->read_data = 0;
|
|
||||||
|
|
||||||
if(s_id == NULL) p_std->s_id = getS_id(STANDARD_DATA, 2);
|
|
||||||
else p_std->s_id = copyS_id(s_id);
|
|
||||||
setSidToASCIIString(p_std->s_id);
|
|
||||||
return p_std;
|
|
||||||
}
|
|
||||||
|
|
||||||
int standardDataAddBlock(STD_DATA *p_std, SID *p_sid ,uint16_t type, void *data, uint32_t data_size){
|
|
||||||
if (p_std->lock) return -1;
|
|
||||||
STD_BLOCKS *p_stdb = initStandardDBlocks(p_sid, type,data_size);
|
|
||||||
dataForStandardDBlock(p_stdb, data);
|
|
||||||
insertInTail(p_std->pd_blocklst, nodeWithPointer(p_stdb,0));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int standardDataAddConnection(STD_DATA *p_std, SID *f_sid, SID *s_sid){
|
|
||||||
if (p_std->lock) return -1;
|
|
||||||
STD_CTN *p_stdb = initStandardDConnection(f_sid, s_sid);
|
|
||||||
insertInTail(p_std->pd_ctnlst, nodeWithPointer(p_stdb,0));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
D_FILE *initDataFileForWrite(char *route){
|
|
||||||
D_FILE *p_dfile = (D_FILE *)malloc(sizeof(D_FILE));
|
|
||||||
p_dfile->fp = fopen(route, "wb");
|
|
||||||
p_dfile->pf_head = (F_HEAD *)malloc(sizeof(F_HEAD));
|
|
||||||
strcpy(p_dfile->pf_head->head_test,"ZESTDLIB_STDDFILE");
|
|
||||||
p_dfile->pf_head->data_num = 0;
|
|
||||||
p_dfile->pf_stdlst = initList(0);
|
|
||||||
return p_dfile;
|
|
||||||
}
|
|
||||||
|
|
||||||
D_FILE *initDataFileForRead(char *route){
|
|
||||||
D_FILE *p_dfile = (D_FILE *)malloc(sizeof(D_FILE));
|
|
||||||
p_dfile->fp = fopen(route, "rb");
|
|
||||||
p_dfile->pf_head = (F_HEAD *)malloc(sizeof(F_HEAD));
|
|
||||||
p_dfile->pf_head->data_num = 0;
|
|
||||||
p_dfile->pf_stdlst = initList(0);
|
|
||||||
return p_dfile;
|
|
||||||
}
|
|
||||||
|
|
||||||
int dataFileAddStandardData(D_FILE *p_dfile, STD_DATA *p_std){
|
|
||||||
insertInTail(p_dfile->pf_stdlst, nodeWithPointer(p_std,0));
|
|
||||||
p_dfile->pf_head->data_num = (uint32_t)p_dfile->pf_stdlst->length;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int dataFileWriteIn(D_FILE *p_dfile){
|
|
||||||
|
|
||||||
fwrite(p_dfile->pf_head->head_test, sizeof(char), 18, p_dfile->fp);
|
|
||||||
fwrite(&p_dfile->pf_head->data_num, sizeof(uint32_t), 1, p_dfile->fp);
|
|
||||||
fwrite("STDINFO", sizeof(char), 8, p_dfile->fp);
|
|
||||||
listThrough(p_dfile->pf_stdlst, __CALLBACK_CALL(StandardDataInfoWrite), __SEND_ARG("%p", p_dfile->fp));
|
|
||||||
fwrite("STDLST", sizeof(char), 7, p_dfile->fp);
|
|
||||||
listThrough(p_dfile->pf_stdlst, __CALLBACK_CALL(StandardDataWrite), __SEND_ARG("%p", p_dfile->fp));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
__CALLBACK_DEFINE(StandardDataInfoWrite){
|
|
||||||
FILE *fp = __ARGS_P(0, FILE);
|
|
||||||
STD_DATA *p_std = __VALUE(STD_DATA *);
|
|
||||||
fwrite(p_std->s_id->decrypt_str, sizeof(char), SID_LEN, fp);
|
|
||||||
fwrite(&p_std->type, sizeof(uint16_t), 1, fp);
|
|
||||||
uint32_t std_size = calStandardData(p_std);
|
|
||||||
p_std->size = std_size;
|
|
||||||
fwrite(&std_size, sizeof(uint32_t), 1, fp);
|
|
||||||
return __CRETURN__;
|
|
||||||
}
|
|
||||||
|
|
||||||
__CALLBACK_DEFINE(StandardDataWrite){
|
|
||||||
FILE *fp = __ARGS_P(0, FILE);
|
|
||||||
STD_DATA *p_std = __VALUE(STD_DATA *);
|
|
||||||
fwrite("STD", sizeof(char), 4, fp);
|
|
||||||
fwrite(p_std->s_id->decrypt_str, sizeof(char), SID_LEN, fp);
|
|
||||||
fwrite(&p_std->pd_ctnlst->length, sizeof(uint32_t), 1, fp);
|
|
||||||
fwrite(&p_std->pd_blocklst->length, sizeof(uint32_t), 1, fp);
|
|
||||||
listThrough(p_std->pd_ctnlst, __CALLBACK_CALL(StandardDConnectionWrite), __SEND_ARG("%p", fp));
|
|
||||||
listThrough(p_std->pd_blocklst, __CALLBACK_CALL(StandardDBlockWrite), __SEND_ARG("%p", fp));
|
|
||||||
return __CRETURN__;
|
|
||||||
}
|
|
||||||
|
|
||||||
__CALLBACK_DEFINE(StandardDConnectionWrite){
|
|
||||||
FILE *fp = __ARGS_P(0, FILE);
|
|
||||||
STD_CTN *p_stdc = __VALUE(STD_CTN *);
|
|
||||||
fwrite(p_stdc->f_sid, sizeof(char), SID_LEN, fp);
|
|
||||||
fwrite(p_stdc->s_sid, sizeof(char), SID_LEN, fp);
|
|
||||||
return __CRETURN__;
|
|
||||||
}
|
|
||||||
|
|
||||||
__CALLBACK_DEFINE(StandardDBlockWrite){
|
|
||||||
STD_BLOCKS *p_stdb = value;
|
|
||||||
FILE *fp = __ARGS_P(0, FILE);
|
|
||||||
unsigned long blocks_num = p_stdb->blocks_num;
|
|
||||||
int if_sid = 0;
|
|
||||||
if(p_stdb->sid != NULL){
|
|
||||||
if_sid = 1;
|
|
||||||
fwrite(&if_sid, sizeof(int), 1, fp);
|
|
||||||
fwrite(p_stdb->sid, sizeof(char), SID_LEN, fp);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
fwrite(&if_sid, sizeof(int), 1, fp);
|
|
||||||
}
|
|
||||||
fwrite(&p_stdb->type, sizeof(uint16_t), 1, fp);
|
|
||||||
fwrite(&blocks_num, sizeof(uint32_t), 1, fp);
|
|
||||||
fwrite(p_stdb->buff, sizeof(char), p_stdb->blocks_num, fp);
|
|
||||||
return __CRETURN__;
|
|
||||||
}
|
|
||||||
|
|
||||||
STD_DATA *listToSTD(List *p_list){
|
|
||||||
Node *p_node = p_list->head;
|
|
||||||
STD_DATA *p_std = NULL;
|
|
||||||
if (p_list->s_id != NULL){
|
|
||||||
p_std = initStandardData(LIST,p_list->s_id);
|
|
||||||
}
|
|
||||||
else p_std = initStandardData(LIST, NULL);
|
|
||||||
while (p_node != NULL) {
|
|
||||||
if(p_node->type == HOLE) continue;
|
|
||||||
uint32_t data_size = 0;
|
|
||||||
if(p_node->type == INT) data_size = sizeof(int);
|
|
||||||
else if (p_node->type == DOUBLE) data_size = sizeof(double);
|
|
||||||
else if (p_node->type == STRING) data_size = (uint32_t)strlen((char *)p_node->value) + 1;
|
|
||||||
else data_size = sizeof(void *);
|
|
||||||
standardDataAddBlock(p_std, p_node->s_id, p_node->type, p_node->value, data_size);
|
|
||||||
p_node = p_node->next;
|
|
||||||
}
|
|
||||||
return p_std;
|
|
||||||
}
|
|
||||||
|
|
||||||
int dataFileReadOut(D_FILE *p_dfile){
|
|
||||||
if(!readDataFileInfo(p_dfile)){
|
|
||||||
listThrough(p_dfile->pf_stdlst, __CALLBACK_CALL(dataFileReadOut), __SEND_ARG("%p", p_dfile));
|
|
||||||
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
__CALLBACK_DEFINE(dataFileReadOut){
|
|
||||||
D_FILE *p_dfile = __ARGS_P(0, D_FILE);
|
|
||||||
readStandardData(p_dfile, __VALUE(STD_DATA *));
|
|
||||||
return __CRETURN__;
|
|
||||||
}
|
|
||||||
|
|
||||||
int releaseSTDConnection(STD_CTN *p_stdc){
|
|
||||||
free(p_stdc->f_sid);
|
|
||||||
free(p_stdc->s_sid);
|
|
||||||
free(p_stdc);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int releaseSTDBlocks(STD_BLOCKS *p_stdb){
|
|
||||||
free(p_stdb->buff);
|
|
||||||
free(p_stdb->sid);
|
|
||||||
free(p_stdb);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int releaseStandardData(STD_DATA *p_std){
|
|
||||||
releaseListForCustom(p_std->pd_blocklst, (int (*)(void *))releaseSTDBlocks);
|
|
||||||
releaseListForCustom(p_std->pd_ctnlst, (int (*)(void *))releaseSTDConnection);
|
|
||||||
freeS_id(p_std->s_id);
|
|
||||||
free(p_std);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int releaseDFile(D_FILE *p_dfile){
|
|
||||||
releaseListForCustom(p_dfile->pf_stdlst, (int (*)(void *))releaseStandardData);
|
|
||||||
fclose(p_dfile->fp);
|
|
||||||
free(p_dfile->pf_head);
|
|
||||||
free(p_dfile);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
List *standardDataToList(STD_DATA *p_std){
|
|
||||||
List *p_list = initList(0);
|
|
||||||
listThrough(p_std->pd_blocklst, __CALLBACK_CALL(StandardDataToList), __SEND_ARG("%p", p_list));
|
|
||||||
return p_list;
|
|
||||||
}
|
|
||||||
|
|
||||||
__CALLBACK_DEFINE(StandardDataToList){
|
|
||||||
List *p_list = __ARGS_P(0, List);
|
|
||||||
STD_BLOCKS *p_stdb = __VALUE(STD_BLOCKS *);
|
|
||||||
Node *p_node = initNode(0);
|
|
||||||
p_node->s_id = setS_idWithString(p_stdb->sid);
|
|
||||||
p_node->type = p_stdb->type;
|
|
||||||
p_node->value = malloc(sizeof(p_stdb->blocks_num));
|
|
||||||
memcpy(p_node->value, p_stdb->buff, sizeof(p_stdb->blocks_num));
|
|
||||||
insertInTail(p_list, p_node);
|
|
||||||
return __CRETURN__;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t calStandardData(STD_DATA *p_std){
|
|
||||||
List *rtn_lst = NULL;
|
|
||||||
uint32_t size = 4 + sizeof(unsigned long long) * 2;
|
|
||||||
if(p_std->s_id != NULL) size += SID_LEN * sizeof(char);
|
|
||||||
rtn_lst = listThrough(p_std->pd_ctnlst, __CALLBACK_CALL(calStandardDataCTN), __SEND_ARG("%d", size));
|
|
||||||
if(rtn_lst != NULL){
|
|
||||||
size = __RTN_ARGS(rtn_lst, 0, uint32_t);
|
|
||||||
releaseList(rtn_lst);
|
|
||||||
}
|
|
||||||
rtn_lst = listThrough(p_std->pd_blocklst, __CALLBACK_CALL(calStandardDataBLK), __SEND_ARG("%d", size));
|
|
||||||
if(rtn_lst != NULL){
|
|
||||||
size = __RTN_ARGS(rtn_lst, 0, uint32_t);
|
|
||||||
releaseList(rtn_lst);
|
|
||||||
}
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
__CALLBACK_DEFINE(calStandardDataCTN){
|
|
||||||
uint32_t size = __ARGS(0, uint32_t);
|
|
||||||
size += 64;
|
|
||||||
//unsigned long long temp = __NOW_INDEX;
|
|
||||||
if(__NOW_INDEX == __LIST_LEN - 1){
|
|
||||||
__RETURN("%ull", size);
|
|
||||||
}
|
|
||||||
return __CRETURN__;
|
|
||||||
}
|
|
||||||
|
|
||||||
__CALLBACK_DEFINE(calStandardDataBLK){
|
|
||||||
uint32_t size = __ARGS(0, uint32_t);
|
|
||||||
STD_BLOCKS *p_stdb = __VALUE(STD_BLOCKS *);
|
|
||||||
if(p_stdb->sid != NULL) size += SID_LEN + sizeof(int32_t);
|
|
||||||
else size += sizeof(int32_t);
|
|
||||||
size += p_stdb->blocks_num + sizeof(uint16_t) + sizeof(uint32_t);
|
|
||||||
//unsigned long long temp = __NOW_INDEX;
|
|
||||||
if(__NOW_INDEX == __LIST_LEN - 1){
|
|
||||||
return __RETURN("%ull", size);
|
|
||||||
}
|
|
||||||
return __CRETURN__;
|
|
||||||
}
|
|
||||||
|
|
||||||
MSG *createMessage(char *title, void *data, unsigned long data_size){
|
MSG *createMessage(char *title, void *data, unsigned long data_size){
|
||||||
MSG *p_msg = malloc(sizeof(MSG) + data_size);
|
MSG *p_msg = malloc(sizeof(MSG) + data_size);
|
||||||
@ -372,112 +50,3 @@ MSG *createMessage(char *title, void *data, unsigned long data_size){
|
|||||||
close(client_sockfd);
|
close(client_sockfd);
|
||||||
return -1;
|
return -1;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
int readDataFileInfo(D_FILE *p_dfile){
|
|
||||||
if(checkIfDataFile(p_dfile)){
|
|
||||||
uint32_t std_num = 0,std_size;
|
|
||||||
uint16_t std_type = VOID;
|
|
||||||
char info_begin[INFO_TEST_LEN], s_id[SID_LEN];
|
|
||||||
uint32_t location = 0;
|
|
||||||
fread(&std_num, sizeof(uint32_t), 1, p_dfile->fp);
|
|
||||||
fread(info_begin, sizeof(char),INFO_TEST_LEN,p_dfile->fp);
|
|
||||||
location += INFO_TEST_LEN + sizeof(uint32_t) + FILE_TSET_LEN;
|
|
||||||
if(!strcmp(info_begin, "STDINFO")){
|
|
||||||
location += std_num * 45 + 7;
|
|
||||||
for(int i = 0; i < std_num; i++){
|
|
||||||
fread(s_id, sizeof(char), SID_LEN, p_dfile->fp);
|
|
||||||
fread(&std_type, sizeof(uint16_t), 1, p_dfile->fp);
|
|
||||||
fread(&std_size, sizeof(uint32_t), 1, p_dfile->fp);
|
|
||||||
SID *temp_sid = setS_idWithString(s_id);
|
|
||||||
STD_DATA *p_std = initStandardData(std_type,temp_sid);
|
|
||||||
freeS_id(temp_sid);
|
|
||||||
p_std->size = std_size;
|
|
||||||
p_std->type = std_type;
|
|
||||||
p_std->location = location;
|
|
||||||
dataFileAddStandardData(p_dfile, p_std);
|
|
||||||
location += std_size;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int readStandardData(D_FILE *p_dfile,STD_DATA *p_std){
|
|
||||||
char s_id[SID_LEN],std_text[STD_TEXT_LEN];
|
|
||||||
fseek(p_dfile->fp, p_std->location, SEEK_SET);
|
|
||||||
fread(std_text, sizeof(char), STD_TEXT_LEN, p_dfile->fp);
|
|
||||||
if(strcmp(std_text, "STD")) return -1;
|
|
||||||
fread(s_id, sizeof(char), SID_LEN, p_dfile->fp);
|
|
||||||
|
|
||||||
if(!strcmp(s_id, p_std->s_id->decrypt_str)){
|
|
||||||
uint32_t ctn_num = 0, blk_num = 0;
|
|
||||||
fread(&ctn_num, sizeof(uint32_t), 1, p_dfile->fp);
|
|
||||||
fread(&blk_num, sizeof(uint32_t), 1, p_dfile->fp);
|
|
||||||
for(int i = 0; i < ctn_num; i++){
|
|
||||||
SID *fs_id = NULL, *ss_id = NULL;
|
|
||||||
char t_sid[SID_LEN];
|
|
||||||
fread(t_sid, sizeof(char), SID_LEN, p_dfile->fp);
|
|
||||||
fs_id = setS_idWithString(t_sid);
|
|
||||||
fread(t_sid, sizeof(char), SID_LEN, p_dfile->fp);
|
|
||||||
ss_id = setS_idWithString(t_sid);
|
|
||||||
standardDataAddConnection(p_std, fs_id, ss_id);
|
|
||||||
freeS_id(fs_id);
|
|
||||||
freeS_id(ss_id);
|
|
||||||
}
|
|
||||||
for(int i = 0; i < blk_num; i++){
|
|
||||||
int if_sid = 0;
|
|
||||||
uint16_t type = VOID;
|
|
||||||
uint32_t blk_size = 0;
|
|
||||||
char t_sid[SID_LEN];
|
|
||||||
fread(&if_sid, sizeof(int32_t), 1, p_dfile->fp);
|
|
||||||
if(if_sid){
|
|
||||||
fread(t_sid, sizeof(char), SID_LEN, p_dfile->fp);
|
|
||||||
}
|
|
||||||
fread(&type, sizeof(int32_t), 1, p_dfile->fp);
|
|
||||||
fread(&blk_size, sizeof(uint32_t), 1, p_dfile->fp);
|
|
||||||
char *buff = malloc(sizeof(char) * blk_size);
|
|
||||||
fread(buff, sizeof(char), blk_size, p_dfile->fp);
|
|
||||||
SID *sb_sid = NULL;
|
|
||||||
if (if_sid) setS_idWithString(t_sid);
|
|
||||||
standardDataAddBlock(p_std, sb_sid, type, buff, blk_size);
|
|
||||||
free(buff);
|
|
||||||
freeS_id(sb_sid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
p_std->read_data = 1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int checkIfDataFile(D_FILE *p_dfile){
|
|
||||||
char test_info[FILE_TSET_LEN];
|
|
||||||
fread(test_info, sizeof(char), FILE_TSET_LEN, p_dfile->fp);
|
|
||||||
strcpy(p_dfile->pf_head->head_test, test_info);
|
|
||||||
if(!strcmp(test_info, "ZESTDLIB_STDDFILE"))return 1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void printStandardData(void *value){
|
|
||||||
STD_DATA *p_std = (STD_DATA *)value;
|
|
||||||
printf("SID:%s\n",p_std->s_id->decrypt_str);
|
|
||||||
printf("Loaction:%u\n",p_std->location);
|
|
||||||
printf("Size:%u\n",p_std->size);
|
|
||||||
printf("Ctn number:%llu\n",p_std->pd_ctnlst->length);
|
|
||||||
printf("Blk number:%llu\n",p_std->pd_blocklst->length);
|
|
||||||
}
|
|
||||||
|
|
||||||
int readStandardDataBySid(D_FILE *p_dfile, SID *p_sid){
|
|
||||||
List *rtn = listThrough(p_dfile->pf_stdlst, __CALLBACK_CALL(findStandardDataBySid), __SEND_ARG("%p", p_sid));
|
|
||||||
//STD_DATA *p_std = __RTN_ARGS_P(rtn, 0, STD_DATA);
|
|
||||||
releaseList(rtn);
|
|
||||||
//if(p_std != NULL) readStandardData(p_dfile, p_std);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
__CALLBACK_DEFINE(findStandardDataBySid){
|
|
||||||
SID *t_sid = __ARGS_P(0, SID);
|
|
||||||
STD_DATA *p_std = __VALUE(STD_DATA *);
|
|
||||||
if(simFitS_id(p_std->s_id, t_sid)){
|
|
||||||
return __RETURN("%p", p_std);
|
|
||||||
}
|
|
||||||
return __CRETURN__;
|
|
||||||
}
|
|
||||||
|
49
src/communicate/dfile/dfile_in.c
Normal file
49
src/communicate/dfile/dfile_in.c
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#include <id/id.h>
|
||||||
|
#include <list/list.h>
|
||||||
|
#include <list/list_expand.h>
|
||||||
|
#include <list/list_expand_1.h>
|
||||||
|
#include <communicate/communicate_file.h>
|
||||||
|
|
||||||
|
|
||||||
|
int dataFileReadOut(D_FILE *p_dfile){
|
||||||
|
if(!readDataFileInfo(p_dfile)){
|
||||||
|
listThrough(p_dfile->pf_stdlst, __CALLBACK_CALL(dataFileReadOut), __SEND_ARG("%p", p_dfile));
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
__CALLBACK_DEFINE(dataFileReadOut){
|
||||||
|
D_FILE *p_dfile = __ARGS_P(0, D_FILE);
|
||||||
|
readStandardData(p_dfile, __VALUE(STD_DATA *));
|
||||||
|
return __CRETURN__;
|
||||||
|
}
|
||||||
|
|
||||||
|
int readDataFileInfo(D_FILE *p_dfile){
|
||||||
|
if(checkIfDataFile(p_dfile)){
|
||||||
|
uint32_t std_num = 0,std_size;
|
||||||
|
uint16_t std_type = VOID;
|
||||||
|
char info_begin[INFO_TEST_LEN], s_id[SID_LEN];
|
||||||
|
uint32_t location = 0;
|
||||||
|
fread(&std_num, sizeof(uint32_t), 1, p_dfile->fp);
|
||||||
|
fread(info_begin, sizeof(char),INFO_TEST_LEN,p_dfile->fp);
|
||||||
|
location += INFO_TEST_LEN + sizeof(uint32_t) + FILE_TSET_LEN;
|
||||||
|
if(!strcmp(info_begin, "STDINFO")){
|
||||||
|
location += std_num * 45 + 7;
|
||||||
|
for(int i = 0; i < std_num; i++){
|
||||||
|
fread(s_id, sizeof(char), SID_LEN, p_dfile->fp);
|
||||||
|
fread(&std_type, sizeof(uint16_t), 1, p_dfile->fp);
|
||||||
|
fread(&std_size, sizeof(uint32_t), 1, p_dfile->fp);
|
||||||
|
SID *temp_sid = setS_idWithString(s_id);
|
||||||
|
STD_DATA *p_std = initStandardData(std_type,temp_sid);
|
||||||
|
freeS_id(temp_sid);
|
||||||
|
p_std->size = std_size;
|
||||||
|
p_std->type = std_type;
|
||||||
|
p_std->location = location;
|
||||||
|
dataFileAddStandardData(p_dfile, p_std);
|
||||||
|
location += std_size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
13
src/communicate/dfile/dfile_info.c
Normal file
13
src/communicate/dfile/dfile_info.c
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#include <id/id.h>
|
||||||
|
#include <list/list.h>
|
||||||
|
#include <list/list_expand.h>
|
||||||
|
#include <list/list_expand_1.h>
|
||||||
|
#include <communicate/communicate_file.h>
|
||||||
|
|
||||||
|
int checkIfDataFile(D_FILE *p_dfile){
|
||||||
|
char test_info[FILE_TSET_LEN];
|
||||||
|
fread(test_info, sizeof(char), FILE_TSET_LEN, p_dfile->fp);
|
||||||
|
strcpy(p_dfile->pf_head->head_test, test_info);
|
||||||
|
if(!strcmp(test_info, "ZESTDLIB_STDDFILE"))return 1;
|
||||||
|
return 0;
|
||||||
|
}
|
24
src/communicate/dfile/dfile_init.c
Normal file
24
src/communicate/dfile/dfile_init.c
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#include <id/id.h>
|
||||||
|
#include <list/list.h>
|
||||||
|
#include <list/list_expand.h>
|
||||||
|
#include <list/list_expand_1.h>
|
||||||
|
#include <communicate/communicate_file.h>
|
||||||
|
|
||||||
|
D_FILE *initDataFileForWrite(char *route){
|
||||||
|
D_FILE *p_dfile = (D_FILE *)malloc(sizeof(D_FILE));
|
||||||
|
p_dfile->fp = fopen(route, "wb");
|
||||||
|
p_dfile->pf_head = (F_HEAD *)malloc(sizeof(F_HEAD));
|
||||||
|
strcpy(p_dfile->pf_head->head_test,"ZESTDLIB_STDDFILE");
|
||||||
|
p_dfile->pf_head->data_num = 0;
|
||||||
|
p_dfile->pf_stdlst = initList(0);
|
||||||
|
return p_dfile;
|
||||||
|
}
|
||||||
|
|
||||||
|
D_FILE *initDataFileForRead(char *route){
|
||||||
|
D_FILE *p_dfile = (D_FILE *)malloc(sizeof(D_FILE));
|
||||||
|
p_dfile->fp = fopen(route, "rb");
|
||||||
|
p_dfile->pf_head = (F_HEAD *)malloc(sizeof(F_HEAD));
|
||||||
|
p_dfile->pf_head->data_num = 0;
|
||||||
|
p_dfile->pf_stdlst = initList(0);
|
||||||
|
return p_dfile;
|
||||||
|
}
|
11
src/communicate/dfile/dfile_insert.c
Normal file
11
src/communicate/dfile/dfile_insert.c
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#include <id/id.h>
|
||||||
|
#include <list/list.h>
|
||||||
|
#include <list/list_expand.h>
|
||||||
|
#include <list/list_expand_1.h>
|
||||||
|
#include <communicate/communicate_file.h>
|
||||||
|
|
||||||
|
int dataFileAddStandardData(D_FILE *p_dfile, STD_DATA *p_std){
|
||||||
|
insertInTail(p_dfile->pf_stdlst, nodeWithPointer(p_std,0));
|
||||||
|
p_dfile->pf_head->data_num = (uint32_t)p_dfile->pf_stdlst->length;
|
||||||
|
return 0;
|
||||||
|
}
|
15
src/communicate/dfile/dfile_out.c
Normal file
15
src/communicate/dfile/dfile_out.c
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#include <id/id.h>
|
||||||
|
#include <list/list.h>
|
||||||
|
#include <list/list_expand.h>
|
||||||
|
#include <list/list_expand_1.h>
|
||||||
|
#include <communicate/communicate_file.h>
|
||||||
|
|
||||||
|
int dataFileWriteIn(D_FILE *p_dfile){
|
||||||
|
fwrite(p_dfile->pf_head->head_test, sizeof(char), 18, p_dfile->fp);
|
||||||
|
fwrite(&p_dfile->pf_head->data_num, sizeof(uint32_t), 1, p_dfile->fp);
|
||||||
|
fwrite("STDINFO", sizeof(char), 8, p_dfile->fp);
|
||||||
|
listThrough(p_dfile->pf_stdlst, __CALLBACK_CALL(StandardDataInfoWrite), __SEND_ARG("%p", p_dfile->fp));
|
||||||
|
fwrite("STDLST", sizeof(char), 7, p_dfile->fp);
|
||||||
|
listThrough(p_dfile->pf_stdlst, __CALLBACK_CALL(StandardDataWrite), __SEND_ARG("%p", p_dfile->fp));
|
||||||
|
return 0;
|
||||||
|
}
|
13
src/communicate/dfile/dfile_release.c
Normal file
13
src/communicate/dfile/dfile_release.c
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#include <id/id.h>
|
||||||
|
#include <list/list.h>
|
||||||
|
#include <list/list_expand.h>
|
||||||
|
#include <list/list_expand_1.h>
|
||||||
|
#include <communicate/communicate_file.h>
|
||||||
|
|
||||||
|
int releaseDFile(D_FILE *p_dfile){
|
||||||
|
releaseListForCustom(p_dfile->pf_stdlst, (int (*)(void *))releaseStandardData);
|
||||||
|
fclose(p_dfile->fp);
|
||||||
|
free(p_dfile->pf_head);
|
||||||
|
free(p_dfile);
|
||||||
|
return 0;
|
||||||
|
}
|
14
src/communicate/std/std_find.c
Normal file
14
src/communicate/std/std_find.c
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#include <id/id.h>
|
||||||
|
#include <list/list.h>
|
||||||
|
#include <list/list_expand.h>
|
||||||
|
#include <list/list_expand_1.h>
|
||||||
|
#include <communicate/communicate_file.h>
|
||||||
|
|
||||||
|
__CALLBACK_DEFINE(findStandardDataBySid){
|
||||||
|
SID *t_sid = __ARGS_P(0, SID);
|
||||||
|
STD_DATA *p_std = __VALUE(STD_DATA *);
|
||||||
|
if(simFitS_id(p_std->s_id, t_sid)){
|
||||||
|
return __RETURN("%p", p_std);
|
||||||
|
}
|
||||||
|
return __CRETURN__;
|
||||||
|
}
|
59
src/communicate/std/std_in.c
Normal file
59
src/communicate/std/std_in.c
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
#include <id/id.h>
|
||||||
|
#include <list/list.h>
|
||||||
|
#include <list/list_expand.h>
|
||||||
|
#include <list/list_expand_1.h>
|
||||||
|
#include <communicate/communicate_file.h>
|
||||||
|
|
||||||
|
int readStandardData(D_FILE *p_dfile,STD_DATA *p_std){
|
||||||
|
char s_id[SID_LEN],std_text[STD_TEXT_LEN];
|
||||||
|
fseek(p_dfile->fp, p_std->location, SEEK_SET);
|
||||||
|
fread(std_text, sizeof(char), STD_TEXT_LEN, p_dfile->fp);
|
||||||
|
if(strcmp(std_text, "STD")) return -1;
|
||||||
|
fread(s_id, sizeof(char), SID_LEN, p_dfile->fp);
|
||||||
|
|
||||||
|
if(!strcmp(s_id, p_std->s_id->decrypt_str)){
|
||||||
|
uint32_t ctn_num = 0, blk_num = 0;
|
||||||
|
fread(&ctn_num, sizeof(uint32_t), 1, p_dfile->fp);
|
||||||
|
fread(&blk_num, sizeof(uint32_t), 1, p_dfile->fp);
|
||||||
|
for(int i = 0; i < ctn_num; i++){
|
||||||
|
SID *fs_id = NULL, *ss_id = NULL;
|
||||||
|
char t_sid[SID_LEN];
|
||||||
|
fread(t_sid, sizeof(char), SID_LEN, p_dfile->fp);
|
||||||
|
fs_id = setS_idWithString(t_sid);
|
||||||
|
fread(t_sid, sizeof(char), SID_LEN, p_dfile->fp);
|
||||||
|
ss_id = setS_idWithString(t_sid);
|
||||||
|
standardDataAddConnection(p_std, fs_id, ss_id);
|
||||||
|
freeS_id(fs_id);
|
||||||
|
freeS_id(ss_id);
|
||||||
|
}
|
||||||
|
for(int i = 0; i < blk_num; i++){
|
||||||
|
int if_sid = 0;
|
||||||
|
uint16_t type = VOID;
|
||||||
|
uint32_t blk_size = 0;
|
||||||
|
char t_sid[SID_LEN];
|
||||||
|
fread(&if_sid, sizeof(int32_t), 1, p_dfile->fp);
|
||||||
|
if(if_sid){
|
||||||
|
fread(t_sid, sizeof(char), SID_LEN, p_dfile->fp);
|
||||||
|
}
|
||||||
|
fread(&type, sizeof(int32_t), 1, p_dfile->fp);
|
||||||
|
fread(&blk_size, sizeof(uint32_t), 1, p_dfile->fp);
|
||||||
|
char *buff = malloc(sizeof(char) * blk_size);
|
||||||
|
fread(buff, sizeof(char), blk_size, p_dfile->fp);
|
||||||
|
SID *sb_sid = NULL;
|
||||||
|
if (if_sid) setS_idWithString(t_sid);
|
||||||
|
standardDataAddBlock(p_std, sb_sid, type, buff, blk_size);
|
||||||
|
free(buff);
|
||||||
|
freeS_id(sb_sid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
p_std->read_data = 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int readStandardDataBySid(D_FILE *p_dfile, SID *p_sid){
|
||||||
|
List *rtn = listThrough(p_dfile->pf_stdlst, __CALLBACK_CALL(findStandardDataBySid), __SEND_ARG("%p", p_sid));
|
||||||
|
//STD_DATA *p_std = __RTN_ARGS_P(rtn, 0, STD_DATA);
|
||||||
|
releaseList(rtn);
|
||||||
|
//if(p_std != NULL) readStandardData(p_dfile, p_std);
|
||||||
|
return 0;
|
||||||
|
}
|
44
src/communicate/std/std_info.c
Normal file
44
src/communicate/std/std_info.c
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
#include <id/id.h>
|
||||||
|
#include <list/list.h>
|
||||||
|
#include <list/list_expand.h>
|
||||||
|
#include <list/list_expand_1.h>
|
||||||
|
#include <communicate/communicate_file.h>
|
||||||
|
|
||||||
|
uint32_t calStandardData(STD_DATA *p_std){
|
||||||
|
List *rtn_lst = NULL;
|
||||||
|
uint32_t size = 4 + sizeof(unsigned long long) * 2;
|
||||||
|
if(p_std->s_id != NULL) size += SID_LEN * sizeof(char);
|
||||||
|
rtn_lst = listThrough(p_std->pd_ctnlst, __CALLBACK_CALL(calStandardDataCTN), __SEND_ARG("%d", size));
|
||||||
|
if(rtn_lst != NULL){
|
||||||
|
size = __RTN_ARGS(rtn_lst, 0, uint32_t);
|
||||||
|
releaseList(rtn_lst);
|
||||||
|
}
|
||||||
|
rtn_lst = listThrough(p_std->pd_blocklst, __CALLBACK_CALL(calStandardDataBLK), __SEND_ARG("%d", size));
|
||||||
|
if(rtn_lst != NULL){
|
||||||
|
size = __RTN_ARGS(rtn_lst, 0, uint32_t);
|
||||||
|
releaseList(rtn_lst);
|
||||||
|
}
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
__CALLBACK_DEFINE(calStandardDataBLK){
|
||||||
|
uint32_t size = __ARGS(0, uint32_t);
|
||||||
|
STD_BLOCKS *p_stdb = __VALUE(STD_BLOCKS *);
|
||||||
|
if(p_stdb->sid != NULL) size += SID_LEN + sizeof(int32_t);
|
||||||
|
else size += sizeof(int32_t);
|
||||||
|
size += p_stdb->blocks_num + sizeof(uint16_t) + sizeof(uint32_t);
|
||||||
|
//unsigned long long temp = __NOW_INDEX;
|
||||||
|
if(__NOW_INDEX == __LIST_LEN - 1){
|
||||||
|
return __RETURN("%ull", size);
|
||||||
|
}
|
||||||
|
return __CRETURN__;
|
||||||
|
}
|
||||||
|
|
||||||
|
void printStandardData(void *value){
|
||||||
|
STD_DATA *p_std = (STD_DATA *)value;
|
||||||
|
printf("SID:%s\n",p_std->s_id->decrypt_str);
|
||||||
|
printf("Loaction:%u\n",p_std->location);
|
||||||
|
printf("Size:%u\n",p_std->size);
|
||||||
|
printf("Ctn number:%llu\n",p_std->pd_ctnlst->length);
|
||||||
|
printf("Blk number:%llu\n",p_std->pd_blocklst->length);
|
||||||
|
}
|
31
src/communicate/std/std_init.c
Normal file
31
src/communicate/std/std_init.c
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#include <id/id.h>
|
||||||
|
#include <list/list.h>
|
||||||
|
#include <list/list_expand.h>
|
||||||
|
#include <list/list_expand_1.h>
|
||||||
|
#include <communicate/communicate_file.h>
|
||||||
|
|
||||||
|
STD_CTN *initStandardDConnection(SID *f_sid, SID *s_sid){
|
||||||
|
STD_CTN *p_stdc = (STD_CTN *)malloc(sizeof(STD_CTN));
|
||||||
|
p_stdc->f_sid = s_idToASCIIString(f_sid);
|
||||||
|
p_stdc->s_sid = s_idToASCIIString(s_sid);
|
||||||
|
p_stdc->location = 0;
|
||||||
|
return p_stdc;
|
||||||
|
}
|
||||||
|
|
||||||
|
STD_DATA *initStandardData(uint16_t type, SID *s_id){
|
||||||
|
STD_DATA *p_std = (STD_DATA *)malloc(sizeof(STD_DATA));
|
||||||
|
p_std->pd_blocklst = initList(0);
|
||||||
|
p_std->pd_ctnlst = initList(0);
|
||||||
|
p_std->lock = 0;
|
||||||
|
p_std->type = type;
|
||||||
|
p_std->size = 0;
|
||||||
|
p_std->location = 0;
|
||||||
|
p_std->read_data = 0;
|
||||||
|
|
||||||
|
if(s_id == NULL) p_std->s_id = getS_id(STANDARD_DATA, 2);
|
||||||
|
else p_std->s_id = copyS_id(s_id);
|
||||||
|
setSidToASCIIString(p_std->s_id);
|
||||||
|
return p_std;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
20
src/communicate/std/std_insert.c
Normal file
20
src/communicate/std/std_insert.c
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#include <id/id.h>
|
||||||
|
#include <list/list.h>
|
||||||
|
#include <list/list_expand.h>
|
||||||
|
#include <list/list_expand_1.h>
|
||||||
|
#include <communicate/communicate_file.h>
|
||||||
|
|
||||||
|
int standardDataAddBlock(STD_DATA *p_std, SID *p_sid ,uint16_t type, void *data, uint32_t data_size){
|
||||||
|
if (p_std->lock) return -1;
|
||||||
|
STD_BLOCKS *p_stdb = initStandardDBlocks(p_sid, type,data_size);
|
||||||
|
dataForStandardDBlock(p_stdb, data);
|
||||||
|
insertInTail(p_std->pd_blocklst, nodeWithPointer(p_stdb,0));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int standardDataAddConnection(STD_DATA *p_std, SID *f_sid, SID *s_sid){
|
||||||
|
if (p_std->lock) return -1;
|
||||||
|
STD_CTN *p_stdb = initStandardDConnection(f_sid, s_sid);
|
||||||
|
insertInTail(p_std->pd_ctnlst, nodeWithPointer(p_stdb,0));
|
||||||
|
return 0;
|
||||||
|
}
|
29
src/communicate/std/std_out.c
Normal file
29
src/communicate/std/std_out.c
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#include <id/id.h>
|
||||||
|
#include <list/list.h>
|
||||||
|
#include <list/list_expand.h>
|
||||||
|
#include <list/list_expand_1.h>
|
||||||
|
#include <communicate/communicate_file.h>
|
||||||
|
|
||||||
|
|
||||||
|
__CALLBACK_DEFINE(StandardDataInfoWrite){
|
||||||
|
FILE *fp = __ARGS_P(0, FILE);
|
||||||
|
STD_DATA *p_std = __VALUE(STD_DATA *);
|
||||||
|
fwrite(p_std->s_id->decrypt_str, sizeof(char), SID_LEN, fp);
|
||||||
|
fwrite(&p_std->type, sizeof(uint16_t), 1, fp);
|
||||||
|
uint32_t std_size = calStandardData(p_std);
|
||||||
|
p_std->size = std_size;
|
||||||
|
fwrite(&std_size, sizeof(uint32_t), 1, fp);
|
||||||
|
return __CRETURN__;
|
||||||
|
}
|
||||||
|
|
||||||
|
__CALLBACK_DEFINE(StandardDataWrite){
|
||||||
|
FILE *fp = __ARGS_P(0, FILE);
|
||||||
|
STD_DATA *p_std = __VALUE(STD_DATA *);
|
||||||
|
fwrite("STD", sizeof(char), 4, fp);
|
||||||
|
fwrite(p_std->s_id->decrypt_str, sizeof(char), SID_LEN, fp);
|
||||||
|
fwrite(&p_std->pd_ctnlst->length, sizeof(uint32_t), 1, fp);
|
||||||
|
fwrite(&p_std->pd_blocklst->length, sizeof(uint32_t), 1, fp);
|
||||||
|
listThrough(p_std->pd_ctnlst, __CALLBACK_CALL(StandardDConnectionWrite), __SEND_ARG("%p", fp));
|
||||||
|
listThrough(p_std->pd_blocklst, __CALLBACK_CALL(StandardDBlockWrite), __SEND_ARG("%p", fp));
|
||||||
|
return __CRETURN__;
|
||||||
|
}
|
13
src/communicate/std/std_relaese.c
Normal file
13
src/communicate/std/std_relaese.c
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#include <id/id.h>
|
||||||
|
#include <list/list.h>
|
||||||
|
#include <list/list_expand.h>
|
||||||
|
#include <list/list_expand_1.h>
|
||||||
|
#include <communicate/communicate_file.h>
|
||||||
|
|
||||||
|
int releaseStandardData(STD_DATA *p_std){
|
||||||
|
releaseListForCustom(p_std->pd_blocklst, (int (*)(void *))releaseSTDBlocks);
|
||||||
|
releaseListForCustom(p_std->pd_ctnlst, (int (*)(void *))releaseSTDConnection);
|
||||||
|
freeS_id(p_std->s_id);
|
||||||
|
free(p_std);
|
||||||
|
return 0;
|
||||||
|
}
|
6
src/communicate/stdb/stdb_in.c
Normal file
6
src/communicate/stdb/stdb_in.c
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#include <id/id.h>
|
||||||
|
#include <list/list.h>
|
||||||
|
#include <list/list_expand.h>
|
||||||
|
#include <list/list_expand_1.h>
|
||||||
|
#include <communicate/communicate_file.h>
|
||||||
|
|
30
src/communicate/stdb/stdb_init.c
Normal file
30
src/communicate/stdb/stdb_init.c
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#include <id/id.h>
|
||||||
|
#include <list/list.h>
|
||||||
|
#include <list/list_expand.h>
|
||||||
|
#include <list/list_expand_1.h>
|
||||||
|
#include <communicate/communicate_file.h>
|
||||||
|
|
||||||
|
STD_BLOCKS *initStandardDBlocks(SID *p_sid, uint16_t type, uint32_t data_size){
|
||||||
|
STD_BLOCKS *p_stdb = (STD_BLOCKS *)malloc(sizeof(STD_BLOCKS));
|
||||||
|
if(p_sid != NULL){
|
||||||
|
p_stdb->sid = s_idToASCIIString(p_sid);
|
||||||
|
}
|
||||||
|
else p_stdb->sid = NULL;
|
||||||
|
p_stdb->if_data = 0;
|
||||||
|
p_stdb->location = 0;
|
||||||
|
uint32_t blocks_num = (uint32_t)(data_size/sizeof(char));
|
||||||
|
p_stdb->blocks_num = blocks_num;
|
||||||
|
p_stdb->type = type;
|
||||||
|
p_stdb->buff = (char *)malloc(sizeof(char) * blocks_num);
|
||||||
|
return p_stdb;
|
||||||
|
}
|
||||||
|
|
||||||
|
int dataForStandardDBlock(STD_BLOCKS *p_stdb,void *data){
|
||||||
|
char *t_data = (char *)data;
|
||||||
|
/*unsigned int data_size = sizeof(data);*/
|
||||||
|
for(int i = 0; i < p_stdb->blocks_num; i++){
|
||||||
|
p_stdb->buff[i] = t_data[i];
|
||||||
|
}
|
||||||
|
p_stdb->if_data = 1;
|
||||||
|
return 0;
|
||||||
|
}
|
24
src/communicate/stdb/stdb_out.c
Normal file
24
src/communicate/stdb/stdb_out.c
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#include <id/id.h>
|
||||||
|
#include <list/list.h>
|
||||||
|
#include <list/list_expand.h>
|
||||||
|
#include <list/list_expand_1.h>
|
||||||
|
#include <communicate/communicate_file.h>
|
||||||
|
|
||||||
|
__CALLBACK_DEFINE(StandardDBlockWrite){
|
||||||
|
STD_BLOCKS *p_stdb = value;
|
||||||
|
FILE *fp = __ARGS_P(0, FILE);
|
||||||
|
unsigned long blocks_num = p_stdb->blocks_num;
|
||||||
|
int if_sid = 0;
|
||||||
|
if(p_stdb->sid != NULL){
|
||||||
|
if_sid = 1;
|
||||||
|
fwrite(&if_sid, sizeof(int), 1, fp);
|
||||||
|
fwrite(p_stdb->sid, sizeof(char), SID_LEN, fp);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
fwrite(&if_sid, sizeof(int), 1, fp);
|
||||||
|
}
|
||||||
|
fwrite(&p_stdb->type, sizeof(uint16_t), 1, fp);
|
||||||
|
fwrite(&blocks_num, sizeof(uint32_t), 1, fp);
|
||||||
|
fwrite(p_stdb->buff, sizeof(char), p_stdb->blocks_num, fp);
|
||||||
|
return __CRETURN__;
|
||||||
|
}
|
12
src/communicate/stdb/stdb_release.c
Normal file
12
src/communicate/stdb/stdb_release.c
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#include <id/id.h>
|
||||||
|
#include <list/list.h>
|
||||||
|
#include <list/list_expand.h>
|
||||||
|
#include <list/list_expand_1.h>
|
||||||
|
#include <communicate/communicate_file.h>
|
||||||
|
|
||||||
|
int releaseSTDBlocks(STD_BLOCKS *p_stdb){
|
||||||
|
free(p_stdb->buff);
|
||||||
|
free(p_stdb->sid);
|
||||||
|
free(p_stdb);
|
||||||
|
return 0;
|
||||||
|
}
|
14
src/communicate/stdc/stdc_in.c
Normal file
14
src/communicate/stdc/stdc_in.c
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#include <id/id.h>
|
||||||
|
#include <list/list.h>
|
||||||
|
#include <list/list_expand.h>
|
||||||
|
#include <list/list_expand_1.h>
|
||||||
|
#include <communicate/communicate_file.h>
|
||||||
|
|
||||||
|
|
||||||
|
__CALLBACK_DEFINE(StandardDConnectionWrite){
|
||||||
|
FILE *fp = __ARGS_P(0, FILE);
|
||||||
|
STD_CTN *p_stdc = __VALUE(STD_CTN *);
|
||||||
|
fwrite(p_stdc->f_sid, sizeof(char), SID_LEN, fp);
|
||||||
|
fwrite(p_stdc->s_sid, sizeof(char), SID_LEN, fp);
|
||||||
|
return __CRETURN__;
|
||||||
|
}
|
15
src/communicate/stdc/stdc_info.c
Normal file
15
src/communicate/stdc/stdc_info.c
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#include <id/id.h>
|
||||||
|
#include <list/list.h>
|
||||||
|
#include <list/list_expand.h>
|
||||||
|
#include <list/list_expand_1.h>
|
||||||
|
#include <communicate/communicate_file.h>
|
||||||
|
|
||||||
|
__CALLBACK_DEFINE(calStandardDataCTN){
|
||||||
|
uint32_t size = __ARGS(0, uint32_t);
|
||||||
|
size += 64;
|
||||||
|
//unsigned long long temp = __NOW_INDEX;
|
||||||
|
if(__NOW_INDEX == __LIST_LEN - 1){
|
||||||
|
__RETURN("%ull", size);
|
||||||
|
}
|
||||||
|
return __CRETURN__;
|
||||||
|
}
|
6
src/communicate/stdc/stdc_init.c
Normal file
6
src/communicate/stdc/stdc_init.c
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#include <id/id.h>
|
||||||
|
#include <list/list.h>
|
||||||
|
#include <list/list_expand.h>
|
||||||
|
#include <list/list_expand_1.h>
|
||||||
|
#include <communicate/communicate_file.h>
|
||||||
|
|
6
src/communicate/stdc/stdc_out.c
Normal file
6
src/communicate/stdc/stdc_out.c
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#include <id/id.h>
|
||||||
|
#include <list/list.h>
|
||||||
|
#include <list/list_expand.h>
|
||||||
|
#include <list/list_expand_1.h>
|
||||||
|
#include <communicate/communicate_file.h>
|
||||||
|
|
12
src/communicate/stdc/stdc_release.c
Normal file
12
src/communicate/stdc/stdc_release.c
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#include <id/id.h>
|
||||||
|
#include <list/list.h>
|
||||||
|
#include <list/list_expand.h>
|
||||||
|
#include <list/list_expand_1.h>
|
||||||
|
#include <communicate/communicate_file.h>
|
||||||
|
|
||||||
|
int releaseSTDConnection(STD_CTN *p_stdc){
|
||||||
|
free(p_stdc->f_sid);
|
||||||
|
free(p_stdc->s_sid);
|
||||||
|
free(p_stdc);
|
||||||
|
return 0;
|
||||||
|
}
|
25
src/communicate/stdcvt/stcvt_in.c
Normal file
25
src/communicate/stdcvt/stcvt_in.c
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#include <id/id.h>
|
||||||
|
#include <list/list.h>
|
||||||
|
#include <list/list_expand.h>
|
||||||
|
#include <list/list_expand_1.h>
|
||||||
|
#include <communicate/communicate_file.h>
|
||||||
|
|
||||||
|
STD_DATA *listToSTD(List *p_list){
|
||||||
|
Node *p_node = p_list->head;
|
||||||
|
STD_DATA *p_std = NULL;
|
||||||
|
if (p_list->s_id != NULL){
|
||||||
|
p_std = initStandardData(LIST,p_list->s_id);
|
||||||
|
}
|
||||||
|
else p_std = initStandardData(LIST, NULL);
|
||||||
|
while (p_node != NULL) {
|
||||||
|
if(p_node->type == HOLE) continue;
|
||||||
|
uint32_t data_size = 0;
|
||||||
|
if(p_node->type == INT) data_size = sizeof(int);
|
||||||
|
else if (p_node->type == DOUBLE) data_size = sizeof(double);
|
||||||
|
else if (p_node->type == STRING) data_size = (uint32_t)strlen((char *)p_node->value) + 1;
|
||||||
|
else data_size = sizeof(void *);
|
||||||
|
standardDataAddBlock(p_std, p_node->s_id, p_node->type, p_node->value, data_size);
|
||||||
|
p_node = p_node->next;
|
||||||
|
}
|
||||||
|
return p_std;
|
||||||
|
}
|
23
src/communicate/stdcvt/stdcvt_out.c
Normal file
23
src/communicate/stdcvt/stdcvt_out.c
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#include <id/id.h>
|
||||||
|
#include <list/list.h>
|
||||||
|
#include <list/list_expand.h>
|
||||||
|
#include <list/list_expand_1.h>
|
||||||
|
#include <communicate/communicate_file.h>
|
||||||
|
|
||||||
|
List *standardDataToList(STD_DATA *p_std){
|
||||||
|
List *p_list = initList(0);
|
||||||
|
listThrough(p_std->pd_blocklst, __CALLBACK_CALL(StandardDataToList), __SEND_ARG("%p", p_list));
|
||||||
|
return p_list;
|
||||||
|
}
|
||||||
|
|
||||||
|
__CALLBACK_DEFINE(StandardDataToList){
|
||||||
|
List *p_list = __ARGS_P(0, List);
|
||||||
|
STD_BLOCKS *p_stdb = __VALUE(STD_BLOCKS *);
|
||||||
|
Node *p_node = initNode(0);
|
||||||
|
p_node->s_id = setS_idWithString(p_stdb->sid);
|
||||||
|
p_node->type = p_stdb->type;
|
||||||
|
p_node->value = malloc(sizeof(p_stdb->blocks_num));
|
||||||
|
memcpy(p_node->value, p_stdb->buff, sizeof(p_stdb->blocks_num));
|
||||||
|
insertInTail(p_list, p_node);
|
||||||
|
return __CRETURN__;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user