Skip to content

Commit 07acf69

Browse files
committed
added:download and upload storage distributed choice function for apihelp module
1 parent 1e5fad4 commit 07acf69

File tree

8 files changed

+250
-9
lines changed

8 files changed

+250
-9
lines changed

XEngine_Source/StorageModule_APIHelp/APIHelp_Define.h

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,47 @@ extern "C" BOOL APIHelp_Distributed_RandomAddr(list<string>* pStl_ListAddr, TCHA
8383
意思:是否成功
8484
备注:
8585
*********************************************************************/
86-
extern "C" BOOL APIHelp_Distributed_FileList(list<APIHELP_LBFILEINFO>* pStl_ListParse, XSTORAGECORE_DBFILE*** pppSt_ListPacket, int* pInt_ListCount);
86+
extern "C" BOOL APIHelp_Distributed_FileList(list<APIHELP_LBFILEINFO>* pStl_ListParse, XSTORAGECORE_DBFILE*** pppSt_ListPacket, int* pInt_ListCount);
87+
/********************************************************************
88+
函数名称:APIHelp_Distributed_DLStorage
89+
函数功能:通过URLKEY得到一个对应下载地址
90+
参数.一:lpszMsgBuffer
91+
In/Out:In
92+
类型:常量字符指针
93+
可空:N
94+
意思:输入要解析的URL
95+
参数.二:pStl_ListBucket
96+
In/Out:In
97+
类型:容器指针
98+
可空:N
99+
意思:输入要解析的列表
100+
参数.三:pSt_StorageBucket
101+
In/Out:Out
102+
类型:数据结构指针
103+
可空:N
104+
意思:输出获取到的可用存储
105+
返回值
106+
类型:逻辑型
107+
意思:是否成功
108+
备注:
109+
*********************************************************************/
110+
extern "C" BOOL APIHelp_Distributed_DLStorage(LPCTSTR lpszMsgBuffer, list<XENGINE_STORAGEBUCKET>* pStl_ListBucket, XENGINE_STORAGEBUCKET* pSt_StorageBucket);
111+
/********************************************************************
112+
函数名称:APIHelp_Distributed_UPStorage
113+
函数功能:通过分布式存储列表获得一个存储地址
114+
参数.一:pStl_ListBucket
115+
In/Out:In
116+
类型:容器指针
117+
可空:N
118+
意思:输入要解析的列表
119+
参数.二:pSt_StorageBucket
120+
In/Out:Out
121+
类型:数据结构指针
122+
可空:N
123+
意思:输出获取到的可用存储
124+
返回值
125+
类型:逻辑型
126+
意思:是否成功
127+
备注:
128+
*********************************************************************/
129+
extern "C" BOOL APIHelp_Distributed_UPStorage(list<XENGINE_STORAGEBUCKET>* pStl_ListBucket, XENGINE_STORAGEBUCKET* pSt_StorageBucket);

XEngine_Source/StorageModule_APIHelp/APIHelp_Distributed/APIHelp_Distributed.cpp

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,146 @@ BOOL CAPIHelp_Distributed::APIHelp_Distributed_FileList(list<APIHELP_LBFILEINFO>
141141
*pInt_ListCount = pStl_ListParse->size();
142142
return TRUE;
143143
}
144+
/********************************************************************
145+
函数名称:APIHelp_Distributed_DLStorage
146+
函数功能:通过URLKEY得到一个对应下载地址
147+
参数.一:lpszMsgBuffer
148+
In/Out:In
149+
类型:常量字符指针
150+
可空:N
151+
意思:输入要解析的URL
152+
参数.二:pStl_ListBucket
153+
In/Out:In
154+
类型:容器指针
155+
可空:N
156+
意思:输入要解析的列表
157+
参数.三:pSt_StorageBucket
158+
In/Out:Out
159+
类型:数据结构指针
160+
可空:N
161+
意思:输出获取到的可用存储
162+
返回值
163+
类型:逻辑型
164+
意思:是否成功
165+
备注:
166+
*********************************************************************/
167+
BOOL CAPIHelp_Distributed::APIHelp_Distributed_DLStorage(LPCTSTR lpszMsgBuffer, list<XENGINE_STORAGEBUCKET>* pStl_ListBucket, XENGINE_STORAGEBUCKET* pSt_StorageBucket)
168+
{
169+
APIHelp_IsErrorOccur = FALSE;
170+
171+
if ((NULL == lpszMsgBuffer) || (NULL == pSt_StorageBucket))
172+
{
173+
APIHelp_IsErrorOccur = TRUE;
174+
APIHelp_dwErrorCode = ERROR_STORAGE_MODULE_APIHELP_PARAMENT;
175+
return FALSE;
176+
}
177+
BOOL bFound = FALSE;
178+
TCHAR tszKeyStr[128];
179+
memset(tszKeyStr, '\0', sizeof(tszKeyStr));
180+
//获得key
181+
int nLen = _tcslen(lpszMsgBuffer);
182+
for (int i = 0; i < nLen; i++)
183+
{
184+
if ('/' == lpszMsgBuffer[i])
185+
{
186+
bFound = TRUE;
187+
memcpy(tszKeyStr, lpszMsgBuffer, i);
188+
break;
189+
}
190+
}
191+
if (!bFound)
192+
{
193+
APIHelp_IsErrorOccur = TRUE;
194+
APIHelp_dwErrorCode = ERROR_STORAGE_MODULE_APIHELP_NOTFOUND;
195+
return FALSE;
196+
}
197+
bFound = FALSE;
198+
//获得对应存储
199+
for (auto stl_ListIterator = pStl_ListBucket->begin(); stl_ListIterator != pStl_ListBucket->end(); stl_ListIterator++)
200+
{
201+
if (0 == _tcsncmp(tszKeyStr, stl_ListIterator->tszBuckKey, _tcslen(tszKeyStr)))
202+
{
203+
bFound = TRUE;
204+
*pSt_StorageBucket = *stl_ListIterator;
205+
break;
206+
}
207+
}
208+
if (!bFound)
209+
{
210+
APIHelp_IsErrorOccur = TRUE;
211+
APIHelp_dwErrorCode = ERROR_STORAGE_MODULE_APIHELP_NOTFOUND;
212+
return FALSE;
213+
}
214+
return TRUE;
215+
}
216+
/********************************************************************
217+
函数名称:APIHelp_Distributed_UPStorage
218+
函数功能:通过分布式存储列表获得一个存储地址
219+
参数.一:pStl_ListBucket
220+
In/Out:In
221+
类型:容器指针
222+
可空:N
223+
意思:输入要解析的列表
224+
参数.二:pSt_StorageBucket
225+
In/Out:Out
226+
类型:数据结构指针
227+
可空:N
228+
意思:输出获取到的可用存储
229+
返回值
230+
类型:逻辑型
231+
意思:是否成功
232+
备注:
233+
*********************************************************************/
234+
BOOL CAPIHelp_Distributed::APIHelp_Distributed_UPStorage(list<XENGINE_STORAGEBUCKET>* pStl_ListBucket, XENGINE_STORAGEBUCKET* pSt_StorageBucket)
235+
{
236+
APIHelp_IsErrorOccur = FALSE;
237+
238+
if ((NULL == pStl_ListBucket) || (NULL == pSt_StorageBucket))
239+
{
240+
APIHelp_IsErrorOccur = TRUE;
241+
APIHelp_dwErrorCode = ERROR_STORAGE_MODULE_APIHELP_PARAMENT;
242+
return FALSE;
243+
}
244+
BOOL bFound = FALSE;
245+
int nLastLevel = 9999;
246+
for (auto stl_ListIterator = pStl_ListBucket->begin(); stl_ListIterator != pStl_ListBucket->end(); stl_ListIterator++)
247+
{
248+
//只处理启用的
249+
if (stl_ListIterator->bEnable)
250+
{
251+
//处理优先级
252+
if (stl_ListIterator->nLevel < nLastLevel)
253+
{
254+
int nListCount = 0;
255+
__int64u nDirCount = 0; //当前目录大小
256+
CHAR** ppListFile;
257+
SystemApi_File_EnumFile(stl_ListIterator->tszFilePath, &ppListFile, &nListCount, NULL, NULL, TRUE, 1);
258+
for (int j = 0; j < nListCount; j++)
259+
{
260+
struct __stat64 st_FStat;
261+
_stat64(stl_ListIterator->tszFilePath, &st_FStat);
262+
nDirCount += st_FStat.st_size;
263+
}
264+
BaseLib_OperatorMemory_Free((XPPPMEM)&ppListFile, nListCount);
265+
//如果当前目录大小大于设定的大小.那么忽略
266+
if (nDirCount >= APIHelp_Distributed_GetSize(stl_ListIterator->tszBuckSize))
267+
{
268+
continue;
269+
}
270+
bFound = TRUE;
271+
nLastLevel = stl_ListIterator->nLevel;
272+
*pSt_StorageBucket = *stl_ListIterator;
273+
}
274+
}
275+
}
276+
if (!bFound)
277+
{
278+
APIHelp_IsErrorOccur = TRUE;
279+
APIHelp_dwErrorCode = ERROR_STORAGE_MODULE_APIHELP_NOTFOUND;
280+
return FALSE;
281+
}
282+
return TRUE;
283+
}
144284
//////////////////////////////////////////////////////////////////////////
145285
// 保护函数
146286
//////////////////////////////////////////////////////////////////////////
@@ -199,4 +339,47 @@ BOOL CAPIHelp_Distributed::APIHelp_Distributed_FileListParse(LPCTSTR lpszMsgBuff
199339
break;
200340
}
201341
return TRUE;
342+
}
343+
/********************************************************************
344+
函数名称:APIHelp_Distributed_GetSize
345+
函数功能:获取存储设置大小
346+
参数.一:lpszMsgBuffer
347+
In/Out:In
348+
类型:常量字符指针
349+
可空:N
350+
意思:输入要获取的缓冲区
351+
返回值
352+
类型:整数型
353+
意思:获取到的大小字节
354+
备注:
355+
*********************************************************************/
356+
__int64u CAPIHelp_Distributed::APIHelp_Distributed_GetSize(LPCTSTR lpszMsgBuffer)
357+
{
358+
APIHelp_IsErrorOccur = FALSE;
359+
360+
TCHAR tszSizeStr[64];
361+
TCHAR tszUnitStr[4];
362+
363+
memset(tszSizeStr, '\0', sizeof(tszSizeStr));
364+
memset(tszUnitStr, '\0', sizeof(tszUnitStr));
365+
//分别得到数字和单位
366+
memcpy(tszSizeStr, lpszMsgBuffer - 2, _tcslen(lpszMsgBuffer) - 2);
367+
BaseLib_OperatorString_GetLastString(lpszMsgBuffer, 2, tszUnitStr);
368+
369+
__int64u nllSize = _ttoi64(tszSizeStr);
370+
//得到单位大小
371+
if (0 == _tcsncmp(tszUnitStr, _T("KB"), 2))
372+
{
373+
nllSize = nllSize * 1024;
374+
}
375+
else if (0 == _tcsncmp(tszUnitStr, _T("MB"), 2))
376+
{
377+
nllSize = nllSize * 1024 * 1024;
378+
}
379+
else if (0 == _tcsncmp(tszUnitStr, _T("GB"), 2))
380+
{
381+
nllSize = nllSize * 1024 * 1024 * 1024;
382+
}
383+
384+
return nllSize;
202385
}

XEngine_Source/StorageModule_APIHelp/APIHelp_Distributed/APIHelp_Distributed.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ class CAPIHelp_Distributed
2121
BOOL APIHelp_Distributed_IsMode(list<int>* pStl_ListMode, int nMode);
2222
BOOL APIHelp_Distributed_RandomAddr(list<string>* pStl_ListAddr, TCHAR* ptszAddr);
2323
BOOL APIHelp_Distributed_FileList(list<APIHELP_LBFILEINFO>* pStl_ListParse, XSTORAGECORE_DBFILE*** pppSt_ListPacket, int* pInt_ListCount);
24+
BOOL APIHelp_Distributed_DLStorage(LPCTSTR lpszMsgBuffer, list<XENGINE_STORAGEBUCKET>* pStl_ListBucket, XENGINE_STORAGEBUCKET* pSt_StorageBucket);
25+
BOOL APIHelp_Distributed_UPStorage(list<XENGINE_STORAGEBUCKET>* pStl_ListBucket, XENGINE_STORAGEBUCKET* pSt_StorageBucket);
2426
protected:
2527
BOOL APIHelp_Distributed_FileListParse(LPCTSTR lpszMsgBuffer, int nMsgLen, XSTORAGECORE_DBFILE* pSt_DBFile);
28+
__int64u APIHelp_Distributed_GetSize(LPCTSTR lpszMsgBuffer);
2629
private:
2730
};

XEngine_Source/StorageModule_APIHelp/APIHelp_Error.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@
1111
// History:
1212
*********************************************************************/
1313
#define ERROR_STORAGE_MODULE_APIHELP_PARAMENT 0x0030001
14-
#define ERROR_STORAGE_MODULE_APIHELP_PARSE 0x0030002
14+
#define ERROR_STORAGE_MODULE_APIHELP_PARSE 0x0030002
15+
#define ERROR_STORAGE_MODULE_APIHELP_NOTFOUND 0x0030003

XEngine_Source/StorageModule_APIHelp/StorageModule_APIHelp.def

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ EXPORTS
55

66
APIHelp_Distributed_IsMode
77
APIHelp_Distributed_RandomAddr
8-
APIHelp_Distributed_FileList
8+
APIHelp_Distributed_FileList
9+
APIHelp_Distributed_DLStorage
10+
APIHelp_Distributed_UPStorage

XEngine_Source/StorageModule_APIHelp/StorageModule_APIHelp.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
7474
<LinkIncremental>true</LinkIncremental>
7575
<IncludePath>$(XEngine_Include);$(IncludePath)</IncludePath>
76-
<LibraryPath>$(XEngine_Library);$(LibraryPath)</LibraryPath>
76+
<LibraryPath>$(XEngine_Lib32);$(LibraryPath)</LibraryPath>
7777
</PropertyGroup>
7878
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
7979
<LinkIncremental>false</LinkIncremental>

XEngine_Source/StorageModule_APIHelp/pch.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,12 @@ extern "C" BOOL APIHelp_Distributed_RandomAddr(list<string>*pStl_ListAddr, TCHAR
4040
extern "C" BOOL APIHelp_Distributed_FileList(list<APIHELP_LBFILEINFO>*pStl_ListParse, XSTORAGECORE_DBFILE * **pppSt_ListPacket, int* pInt_ListCount)
4141
{
4242
return m_APIDistributed.APIHelp_Distributed_FileList(pStl_ListParse, pppSt_ListPacket, pInt_ListCount);
43+
}
44+
extern "C" BOOL APIHelp_Distributed_DLStorage(LPCTSTR lpszMsgBuffer, list<XENGINE_STORAGEBUCKET>*pStl_ListBucket, XENGINE_STORAGEBUCKET * pSt_StorageBucket)
45+
{
46+
return m_APIDistributed.APIHelp_Distributed_DLStorage(lpszMsgBuffer, pStl_ListBucket, pSt_StorageBucket);
47+
}
48+
extern "C" BOOL APIHelp_Distributed_UPStorage(list<XENGINE_STORAGEBUCKET>*pStl_ListBucket, XENGINE_STORAGEBUCKET * pSt_StorageBucket)
49+
{
50+
return m_APIDistributed.APIHelp_Distributed_UPStorage(pStl_ListBucket, pSt_StorageBucket);
4351
}

XEngine_Source/StorageModule_APIHelp/pch.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ using namespace std;
3232
#include <XEngine_Include/XEngine_BaseLib/BaseLib_Error.h>
3333
#include <XEngine_Include/XEngine_HelpComponents/DataBase_Define.h>
3434
#include <XEngine_Include/XEngine_HelpComponents/DataBase_Error.h>
35+
#include <XEngine_Include/XEngine_SystemSdk/ProcFile_Define.h>
36+
#include <XEngine_Include/XEngine_SystemSdk/SystemApi_Define.h>
37+
#include <XEngine_Include/XEngine_SystemSdk/SystemApi_Error.h>
3538
#include "../XStorage_Protocol.h"
39+
#include "../StorageModule_Config/Config_Define.h"
3640
#include "../XEngine_StorageComponents/XStorage_SQLPacket/SQLPacket_Define.h"
3741
#include "APIHelp_Define.h"
3842
#include "APIHelp_Error.h"
@@ -51,9 +55,6 @@ extern BOOL APIHelp_IsErrorOccur;
5155
extern DWORD APIHelp_dwErrorCode;
5256

5357
#ifdef _WINDOWS
54-
#ifdef _WIN64
55-
#pragma comment(lib,"x64/XEngine_BaseLib/XEngine_BaseLib")
56-
#else
57-
#pragma comment(lib,"x86/XEngine_BaseLib/XEngine_BaseLib")
58-
#endif
58+
#pragma comment(lib,"XEngine_BaseLib/XEngine_BaseLib")
59+
#pragma comment(lib,"XEngine_SystemSdk/XEngine_SystemApi")
5960
#endif

0 commit comments

Comments
 (0)