Skip to content

Commit 771c003

Browse files
committed
added:db configure for configure module
1 parent 77c2e43 commit 771c003

File tree

7 files changed

+91
-4
lines changed

7 files changed

+91
-4
lines changed

XEngine_Release/XEngine_Config/XEngine_Config.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
"LogLeave":32
2424
},
2525
"XSql":{
26-
"SQLAddr":"192.168.1.10",
26+
"SQLAddr":"42.194.178.57",
2727
"SQLPort":3306,
2828
"SQLUser":"root",
29-
"SQLPass":"123123aa"
29+
"SQLPass":"123123Qyt"
3030
},
3131
"XPass":{
3232
"nTimeout":2,
@@ -36,6 +36,7 @@
3636
"tszPassLogout":""
3737
},
3838
"XVer":[
39+
"3.7.0.1001 Build20230423",
3940
"3.6.0.1001 Build20230222",
4041
"3.5.0.1001 Build20230106",
4142
"3.4.0.1001 Build20221110",
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"MQUser":{
3+
"UserTime":{
4+
"bPubClear":false
5+
}
6+
}
7+
}

XEngine_Source/MQCore_ConfigModule/Config_Define.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
//////////////////////////////////////////////////////////////////////////
1414
// 导出的数据结构
1515
//////////////////////////////////////////////////////////////////////////
16-
typedef struct tag_XEngine_ServerConfig
16+
typedef struct
1717
{
1818
XCHAR tszIPAddr[128];
1919
XCHAR tszTopic[128];
@@ -62,6 +62,16 @@ typedef struct tag_XEngine_ServerConfig
6262
list<tstring> *pStl_ListStorage;
6363
}st_XVer;
6464
}XENGINE_SERVERCONFIG;
65+
typedef struct
66+
{
67+
struct
68+
{
69+
struct
70+
{
71+
bool bPubClear;
72+
}st_UserTime;
73+
}st_MQUser;
74+
}MESSAGEQUEUE_DBCONFIG;
6575
//////////////////////////////////////////////////////////////////////////
6676
// 导出函数定义
6777
//////////////////////////////////////////////////////////////////////////
@@ -70,3 +80,4 @@ extern "C" XLONG Config_GetLastError(int *pInt_ErrorCode = NULL);
7080
/* 文件配置读取 */
7181
/************************************************************************/
7282
extern "C" bool Config_Json_File(LPCXSTR lpszConfigFile,XENGINE_SERVERCONFIG *pSt_ServerConfig);
83+
extern "C" bool Config_Json_DBFile(LPCXSTR lpszConfigFile, MESSAGEQUEUE_DBCONFIG* pSt_DBConfig);

XEngine_Source/MQCore_ConfigModule/Config_Json/Config_Json.cpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,65 @@ bool CConfig_Json::Config_Json_File(LPCXSTR lpszConfigFile,XENGINE_SERVERCONFIG
145145
}
146146
return true;
147147
}
148+
bool CConfig_Json::Config_Json_DBFile(LPCXSTR lpszConfigFile, MESSAGEQUEUE_DBCONFIG* pSt_DBConfig)
149+
{
150+
Config_IsErrorOccur = false;
151+
152+
if ((NULL == lpszConfigFile) || (NULL == pSt_DBConfig))
153+
{
154+
Config_IsErrorOccur = true;
155+
Config_dwErrorCode = ERROR_MQ_MODULE_CONFIG_JSON_PARAMENT;
156+
return false;
157+
}
158+
JSONCPP_STRING st_JsonError;
159+
Json::Value st_JsonRoot;
160+
Json::CharReaderBuilder st_JsonBuilder;
161+
162+
FILE* pSt_File = _xtfopen(lpszConfigFile, _X("rb"));
163+
if (NULL == pSt_File)
164+
{
165+
Config_IsErrorOccur = true;
166+
Config_dwErrorCode = ERROR_MQ_MODULE_CONFIG_JSON_PARAMENT;
167+
return false;
168+
}
169+
int nCount = 0;
170+
XCHAR tszMsgBuffer[4096];
171+
while (1)
172+
{
173+
int nRet = fread(tszMsgBuffer + nCount, 1, 2048, pSt_File);
174+
if (nRet <= 0)
175+
{
176+
break;
177+
}
178+
nCount += nRet;
179+
}
180+
fclose(pSt_File);
181+
182+
std::unique_ptr<Json::CharReader> const pSt_JsonReader(st_JsonBuilder.newCharReader());
183+
if (!pSt_JsonReader->parse(tszMsgBuffer, tszMsgBuffer + nCount, &st_JsonRoot, &st_JsonError))
184+
{
185+
Config_IsErrorOccur = true;
186+
Config_dwErrorCode = ERROR_MQ_MODULE_CONFIG_JSON_PARSE;
187+
return false;
188+
}
189+
190+
if (st_JsonRoot["MQUser"].empty())
191+
{
192+
Config_IsErrorOccur = true;
193+
Config_dwErrorCode = ERROR_MQ_MODULE_CONFIG_JSON_XMAX;
194+
return false;
195+
}
196+
Json::Value st_JsonUser = st_JsonRoot["MQUser"];
197+
198+
if (st_JsonUser["UserTime"].empty())
199+
{
200+
Config_IsErrorOccur = true;
201+
Config_dwErrorCode = ERROR_MQ_MODULE_CONFIG_JSON_XMAX;
202+
return false;
203+
}
204+
Json::Value st_JsonUserTime = st_JsonUser["UserTime"];
205+
206+
pSt_DBConfig->st_MQUser.st_UserTime.bPubClear = st_JsonUserTime["bPubClear"].asBool();
207+
208+
return true;
209+
}

XEngine_Source/MQCore_ConfigModule/Config_Json/Config_Json.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ class CConfig_Json
1818
~CConfig_Json();
1919
public:
2020
bool Config_Json_File(LPCXSTR lpszConfigFile,XENGINE_SERVERCONFIG *pSt_ServerConfig);
21+
bool Config_Json_DBFile(LPCXSTR lpszConfigFile, MESSAGEQUEUE_DBCONFIG *pSt_DBConfig);
2122
};

XEngine_Source/MQCore_ConfigModule/MQCore_ConfigModule.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ LIBRARY
33
EXPORTS
44
Config_GetLastError
55

6-
Config_Json_File
6+
Config_Json_File
7+
Config_Json_DBFile

XEngine_Source/MQCore_ConfigModule/pch.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,7 @@ extern "C" bool Config_Json_File(LPCXSTR lpszConfigFile, XENGINE_SERVERCONFIG *
3333
{
3434
return m_ConfigJson.Config_Json_File(lpszConfigFile, pSt_ServerConfig);
3535
}
36+
extern "C" bool Config_Json_DBFile(LPCXSTR lpszConfigFile, MESSAGEQUEUE_DBCONFIG * pSt_DBConfig)
37+
{
38+
return m_ConfigJson.Config_Json_DBFile(lpszConfigFile, pSt_DBConfig);
39+
}

0 commit comments

Comments
 (0)