You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

515 lines
17 KiB
C

2 years ago
/******************************************************************************************
*
* : m.j.y
2 years ago
*
* Pgc--
2 years ago
*
* $Log: Profile_Hash.h,v $
* Revision 1.2 2006/08/04 03:37:33 zhuzhenhua
* no message
*
* Revision 1.1.2.1 2006/07/28 07:54:02 zhuzhenhua
* no message
*
* Revision 1.4 2003/07/14 01:56:23 scada
* 使def
2 years ago
*
* Revision 1.3 2003/06/05 03:56:16 jehu
* doxgen
2 years ago
*
* Revision 1.2 2002/12/04 07:47:36 scada
* for NT
*
* Revision 1.1.1.1 2002/08/21 07:16:37 harold
* temporarily import
*
* Revision 1.14 2002/06/03 10:07:04 mhorse
*
2 years ago
*
* Revision 1.13 2002/03/20 03:40:02 harold
* no message
*
* Revision 1.1.1.1 2002/03/15 13:43:18 harold
* no message
*
* Revision 1.1.1.1 2002/03/15 08:17:08 harold
* no message
*
* Revision 1.12 2002/01/23 05:27:39 harold
* no message
*
* Revision 1.11 2002/01/23 02:39:57 harold
* test_function
*
* Revision 1.10 2002/01/22 08:54:26 harold
* modify2002-01-22-16:46
*
* Revision 1.9 2002/01/21 12:58:49 harold
* no message
*
* Revision 1.8 2002/01/21 04:52:41 harold
* no message
*
* Revision 1.7 2002/01/18 12:56:14 harold
* revise errno
*
* Revision 1.6 1997/03/29 12:49:05 harold
* revise bug in read/write/listsec function
*
* Revision 1.5 2002/01/18 01:08:03 harold
* revise bugs in write/close/listsec function
*
* Revision 1.4 2002/01/16 09:49:41 harold
* no message
*
* Revision 1.3 2002/01/16 08:13:41 harold
* no message
*
* Revision 1.2 2002/01/09 09:42:40 harold
* no message
*
*
******************************************************************************************/
#ifndef profile_hashisdjfidsxxxxxxxxxxxxxijpsijfspo
#define profile_hashisdjfidsxxxxxxxxxxxxxijpsijfspo
/*!
* \if developer_doc
* \file
*
* \brief Pgc--
2 years ago
*
* id: $Id: Profile_Hash.h,v 1.2 2006/08/04 03:37:33 zhuzhenhua Exp $
*
* \author prcharold@sina.com.cn develop1@szscada.com
2 years ago
* \endif
*/
//#include <util/util.h>
#include <string.h>
#include <stdio.h>
#ifndef _WIN32
2 years ago
// #include <sys/time.h>
#else
2 years ago
#include <winsock.h>
#include <time.h>
#endif //OS_LINUX
2 years ago
#include "global_errno.h"
#include "typedef.h"
//#include "basetype.h"
#include "harximoban.h"
/*!
* \if by_group
* \addtogroup grp_config_rw
* @{
* \endif
*/
/*!
* ,
2 years ago
*/
#define MAX_CONF_LINE_L (1024)
//!< 定义每行(注释行的字符个数无限制)允许的最大字符个数, 包括换行符号'\r\n'及null字符
2 years ago
#define MAX_CHAR_LINE (MAX_CONF_LINE_L)
#ifndef PATH_MAX
#define PATH_MAX 260
#endif
#define MAX_PATH 260
//!< 定义存储文件路径的字符串数组的大小
2 years ago
#define MAX_PATH_NUM (MAX_PATH)
//在重新生成配置文件时,是否将'\r\n'作为行结束标志
2 years ago
//#define REWRITEFILE_ADDCHAR_13
//!< 设置缓冲区的最大段数
2 years ago
#define MAX_SEC_NUM 2500
//!< 设置缓冲区的每一段的最大项目个数
2 years ago
#define MAX_ITEM_NUM 30
//!< 定义初始化缓冲区容纳项目的个数
2 years ago
#define INITCACHE_ITEM_NUM 5000
//!< 缓冲区增大时的递增项目的个数
2 years ago
#define RESIZE_ITEM_NUM 5000
//!< 定义在一个进程中允许同时打开的配置文件缓冲句柄的个数
2 years ago
#define MAX_PROFILEHANDLE_NUM 50
//!< 定义配置文件缓冲句柄
2 years ago
typedef pgc32 HPROFILE;
//!< 保存注释的链表
2 years ago
typedef struct tagMemoChain
{
pgcchar *szMemo;
tagMemoChain * NextNode;
} SMemoChain;
//!< 缓冲项的结构
2 years ago
typedef struct tagItemInCache
{
pgcchar szItemName[MAX_CHAR_LINE];
pgcchar szItemVal[MAX_CHAR_LINE];
pgcchar szSecName[MAX_CHAR_LINE];
PGCBOOL valid;
PGCBOOL bIsSecName;
SMemoChain *memo;
tagItemInCache()
{
memset(this, 0, sizeof(*this));
}
} SItemInCache;
//!< 项目位置链表结构
2 years ago
typedef struct tagItemSequence
{
pgc32 iPos;
tagItemSequence *NextNode;
tagItemSequence()
{
memset(this, 0, sizeof(*this));
}
} SItemSequence;
//!< 定义存储句柄对应的信息的结构
2 years ago
typedef struct tagProfileHanleInfo
{
FILE *fstream;
//!< 保存配置文件全路径名
2 years ago
pgcchar szPathName[MAX_PATH_NUM];
//!< 配置文件上一次被修改的时间
2 years ago
timeval tLastModify;
//!< 哈希表指针
2 years ago
TChainHash<SItemInCache> *pHashTable;
//!< 行位置链表头指针
2 years ago
SItemSequence *pSequence;
//!< 行位置链表当前指针
2 years ago
SItemSequence *pCurSeq;
//!< 缓冲区数组入口
2 years ago
SItemInCache* pCacheEntry;
//!< 段总数
2 years ago
pgc32 CurSecNum;
//!< 当前缓冲区能容纳的项目个数
2 years ago
pgc32 CurItemCount;
//!< 已经使用的项目个数
2 years ago
pgc32 CurUseItems;
//!< 当前文件中的行数
2 years ago
pgc32 CurLines;
tagProfileHanleInfo()
{
memset(this, 0, sizeof(*this));
}
} SProfileHanleInfo;
/*!
* \brief , .
2 years ago
*
* \param pindex --[in]
* \param count --[in] pindex, pindex[0] -- pindex[count - 1]
* \param pphash_of_index --[in] pindex, , , 使.
2 years ago
*
* \retval SUCCESS --
* \retval --
2 years ago
*
*/
pgc32 profile_build_hash_index ( SItemInCache * pindex,
pgc32 count,
TChainHash<SItemInCache> ** pphash_of_index );
/*!
* \brief
2 years ago
*
* \param pindex_base --[in]
* \param phash_of_index --[in]
* \param szSecName --[in]
* \param szItemName --[in]
2 years ago
*
* \retval --
* \retval -1 --
2 years ago
*/
pgc32 profile_search_sequence ( SItemInCache **pindex_base,
TChainHash<SItemInCache> *phash_of_index,
pgcchar *szSecName,
pgcchar *szItemName);
/*!
* \brief
2 years ago
*
* \param szLine --[in]
2 years ago
*
* \retval PGCTRUE
* \retval PGCFALSE
2 years ago
*/
PGCBOOL LineIsMark(pgcchar *szLine);
/*!
* \brief
2 years ago
*
* \param szString --[in]
2 years ago
*
* \retval
* \retval NULL
2 years ago
*/
pgcchar* FindSecTail(pgcchar *szString);
/*!
* \brief
2 years ago
*
* \param szString --[in]
* \param szRevBuffer --[out]
* \param iBufferLength --[in]
2 years ago
*
* \retval PGCTRUE
* \retval PGCFALSE
2 years ago
*/
PGCBOOL DigSecName(const pgcchar *szString, pgcchar *szRevBuffer, pgc32 iBufferLength);
/*!
* \brief
2 years ago
*
* \param szString --[in]
* \param szItemName --[in]
* \param szItemVal --[out]
* \param iBufferLength --[in]
2 years ago
*
* \retval PGCTRUE
* \retval PGCFALSE
2 years ago
*/
PGCBOOL DigItemContent( pgcchar *szString, pgcchar *szItemName, pgcchar *szItemVal, pgc32 iBufferLength);
/*!
* \brief
2 years ago
*
* \param psHead --[in]
* \param iPos --[in]
2 years ago
*
* \retval PGCTRUE
* \retval PGCFALSE
2 years ago
*/
PGCBOOL AddNode(SItemSequence * &psHead, pgc32 iPos);
/*!
* \brief
2 years ago
*
* \param hProfile --[in]
2 years ago
*/
void ReleaseProfileCache(HPROFILE hProfile);
/*!
* \brief
2 years ago
*
* \param hProfile --[in]
2 years ago
*
* \retval SUCCESS
* \retval
2 years ago
*/
pgc32 ReWriteProfile(HPROFILE hProfile);
/*!
* \brief
2 years ago
*
* \param hProfile --[in]
2 years ago
*
* \retval SUCCESS
* \retval
2 years ago
*/
pgc32 ProcessCreateCache(HPROFILE hProfile);
//-----------------------------------------------------------------------------------------
/*!
*\verbatim
//以下为应用接口
2 years ago
******************************************************************************************
*
* : m.j.y
2 years ago
*
* Pgc--使
2 years ago
*
******************************************************************************************
*\endverbaim
*/
/*!
* \brief
2 years ago
*
* \param szProfileName --[in]
* \param phfile --[out]
2 years ago
*
* \retval SUCCESS --
* \retval
* \retval ERROR_CONF_NOHANDLE --
* \retval ERROR_FOPEN --
* \retval ERROR_FREAD --
* \retval ERROR_CONF_CREATEHASH --
* \retval ERROR_MEMORY_ALLOC --
2 years ago
*/
int create_profile_cache(pgcchar *szProfileName, int *phfile);
/*!
* \brief
2 years ago
*
* .
2 years ago
*
* \param hProfile --[in]
2 years ago
*
* \retval SUCCESS --
* \retval
* \retval ERROR_CONF_INVALIDHANDLE --
2 years ago
*/
int close_profile_handle(HPROFILE hProfile);
/*!
* \brief
2 years ago
*
* :lpAppName lpKeyName
* lpReturnedString
* (pdwSize)
* ('\0')pdwSize
* lpDefault lpReturnedString;
* lpReturnedString1
* ('\0')pdwSize
2 years ago
*
* \param lpAppName --[in]
* \param lpDefault --[in] lpReturnedString
* \param lpReturnedString --[out]
* \param pdwSize --[in][out] ('\0')
* \param hProfile --[in]
2 years ago
*
* \retval SUCCESS -- lpReturnedString
* SUCCESS
* \retval ERROR_CONF_REVBUFFER -- ,,
* ERROR_CONF_REVBUFFER
* \retval SUCCESS_CONF_DEFCOPY -- lpDefaultlpDefaultlpReturnedString
* lpDefaultlpDefault [ 1]
* \retval ERROR_CONF_INVALIDHANDLE --
* \retval ERROR_FAIL --
2 years ago
*/
int get_pgcprofile_string(
const pgcchar * lpAppName, // points to section name
const pgcchar * lpKeyName, // point to key name
const pgcchar * lpDefault, // point to default string
pgcchar * lpReturnedString, // point to destination buffer
pgcu32 * pdwSize, // point to size of destination buffer
HPROFILE hProfile // point to initialization filename
);
/*!
* \brief
2 years ago
*
* : lpAppName lpKeyName
* lpString
* ,
* SUCCESS;bInsertItem
* bInsertItem
* SUCCESS; bInsertItemERROR_FAIL
2 years ago
*
* \param lpAppName --[in]
* \param lpKeyName --[in]
* \param lpString --[in]
* \param hProfile --[in]
* \param bInsertItem --[in] PGCTRUE-PGCFALSE-
2 years ago
*
* \retval SUCCESS(0) -- lpString
* ,SUCCESS
* \retval ERROR_FWRITE --
* \retval ERROR_CONF_INVALIDHANDLE --
* \retval ERROR_FAIL --
2 years ago
*/
int write_pgcprofile_string(
const pgcchar * lpAppName, // point to section name
const pgcchar * lpKeyName, // point to key name
const pgcchar * lpString, // point to string to add
HPROFILE hProfile, // handle to Profile Cache
PGCBOOL bInsertItem
);
/*!
* \brief
2 years ago
*
* pdwSize
*
* 1\02\0......\0\0
2 years ago
*
* \param lpszReturnBuffer --[out]
* \param pdwSize --[in][out]
* \param nSecNum --[out]
2 years ago
* \param hProfile --[in] handle to Profile Cache
*
* \retval SUCCESS --
* \retval --
2 years ago
*/
int get_pgcprofile_secnames(
pgcchar * lpszReturnBuffer, // address of return buffer
pgcu32 * pdwSize, // size of return buffer
pgcu32 *nSecNum,
HPROFILE hProfile // handle to Profile Cache
);
/*!
* \brief
2 years ago
*
*
2 years ago
*
* \param lpAppName --[in]
* \param lpKeyName --[in]
* \param hProfile --[in]
2 years ago
*
* \retval SUCCESS --
* \retval --
2 years ago
*/
int del_pgcprofile_key( const pgcchar * lpAppName, // point to section name
const pgcchar * lpKeyName, // point to key name
HPROFILE hProfile // point to initialization filename
);
/*!
* \brief
2 years ago
*
*
*
2 years ago
*
* \param lpAppName --[in]
* \param hProfile --[in]
2 years ago
*
* \retval SUCCESS --
* \retval --
2 years ago
*/
int del_pgcprofile_sec( const pgcchar * lpAppName,
HPROFILE hProfile
);
/*!
* \brief ,
2 years ago
*
* \param ptv1 --[in] 1
* \param ptv2 --[in] 2
* \param ptv_abs_delta --[out] , 0.
2 years ago
*
* \retval 0 -- ptv1 () ptv2
* \retval 0 -- ptv1 () ptv2
* \retval 0 -- ptv1 () ptv2
2 years ago
*/
int timeval_compare (
const timeval * ptv1,
const timeval * ptv2,
timeval * ptv_abs_delta = 0 );
/*!
* \if by_group
* @}
* \endif
*/
#endif