Skip to content

Commit 1217741

Browse files
committed
C接口Linux版本初步运行
1 parent ef926e4 commit 1217741

File tree

10 files changed

+95
-31
lines changed

10 files changed

+95
-31
lines changed

QuantBox_CTP_Quote/QuantBox_CTP_Quote.depend

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@
257257
<set>
258258
<string>
259259

260-
1426762120 source:/home/mep/dev/broker/oss/QuantBox_XAPI/QuantBox_CTP_Quote/main.cpp
260+
1427789621 source:/home/mep/dev/broker/oss/QuantBox_XAPI/QuantBox_CTP_Quote/main.cpp
261261
"stdafx.h"
262262
"../include/ApiHeader.h"
263263
"../include/QueueEnum.h"
@@ -277,21 +277,21 @@
277277

278278
1426762122 /home/mep/dev/broker/oss/QuantBox_XAPI/include/QueueEnum.h
279279

280-
1426762120 /home/mep/dev/broker/oss/QuantBox_XAPI/QuantBox_CTP_Quote/MdUserApi.h
280+
1427789621 /home/mep/dev/broker/oss/QuantBox_XAPI/QuantBox_CTP_Quote/MdUserApi.h
281281
"../include/ApiStruct.h"
282282
"../include/CTP/ThostFtdcMdApi.h"
283283
<set>
284284
<string>
285285
<atomic>
286286
<mutex>
287287

288-
1426762120 /home/mep/dev/broker/oss/QuantBox_XAPI/include/ApiStruct.h
288+
1427789621 /home/mep/dev/broker/oss/QuantBox_XAPI/include/ApiStruct.h
289289
"ApiDataType.h"
290290
"ApiEnum.h"
291291

292292
1426762120 /home/mep/dev/broker/oss/QuantBox_XAPI/include/ApiDataType.h
293293

294-
1426762120 /home/mep/dev/broker/oss/QuantBox_XAPI/include/ApiEnum.h
294+
1427789621 /home/mep/dev/broker/oss/QuantBox_XAPI/include/ApiEnum.h
295295

296296
1426762120 /home/mep/dev/broker/oss/QuantBox_XAPI/include/CTP/ThostFtdcMdApi.h
297297
"ThostFtdcUserApiStruct.h"
@@ -301,7 +301,7 @@
301301

302302
1426762120 /home/mep/dev/broker/oss/QuantBox_XAPI/include/CTP/ThostFtdcUserApiDataType.h
303303

304-
1426762120 source:/home/mep/dev/broker/oss/QuantBox_XAPI/QuantBox_CTP_Quote/MdUserApi.cpp
304+
1427789621 source:/home/mep/dev/broker/oss/QuantBox_XAPI/QuantBox_CTP_Quote/MdUserApi.cpp
305305
"stdafx.h"
306306
"MdUserApi.h"
307307
"../include/QueueEnum.h"
@@ -314,7 +314,7 @@
314314
<mutex>
315315
<vector>
316316

317-
1426762120 /home/mep/dev/broker/oss/QuantBox_XAPI/QuantBox_Queue/MsgQueue.h
317+
1427789621 /home/mep/dev/broker/oss/QuantBox_XAPI/QuantBox_Queue/MsgQueue.h
318318
<thread>
319319
<mutex>
320320
<cstring>

QuantBox_Queue/QuantBox_Queue.depend

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@
153153
"stdafx.h"
154154
"MsgQueue.h"
155155

156-
1426762120 source:/home/mep/dev/broker/oss/QuantBox_XAPI/QuantBox_Queue/main.cpp
156+
1427789621 source:/home/mep/dev/broker/oss/QuantBox_XAPI/QuantBox_Queue/main.cpp
157157
"stdafx.h"
158158
"MsgQueue.h"
159159
"../include/QueueHeader.h"
@@ -168,7 +168,7 @@
168168
1426762120 /home/mep/dev/broker/oss/QuantBox_XAPI/QuantBox_Queue/targetver.h
169169
<SDKDDKVer.h>
170170

171-
1426762120 /home/mep/dev/broker/oss/QuantBox_XAPI/QuantBox_Queue/MsgQueue.h
171+
1427789621 /home/mep/dev/broker/oss/QuantBox_XAPI/QuantBox_Queue/MsgQueue.h
172172
<thread>
173173
<mutex>
174174
<cstring>
@@ -224,7 +224,7 @@
224224
1426762120 /home/mep/dev/broker/oss/QuantBox_XAPI/include/ApiHeader.h
225225
"../include/CrossPlatform.h"
226226

227-
1426762120 source:/home/mep/dev/broker/oss/QuantBox_XAPI/QuantBox_Queue/MsgQueue.cpp
227+
1427789621 source:/home/mep/dev/broker/oss/QuantBox_XAPI/QuantBox_Queue/MsgQueue.cpp
228228
"stdafx.h"
229229
"MsgQueue.h"
230230

QuantBox_XAPI/QuantBox_XAPI.cbp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<Option compiler="clang" />
88
<Build>
99
<Target title="Debug">
10-
<Option output="bin/Debug/libQuantBox_XAPI" prefix_auto="1" extension_auto="1" />
10+
<Option output="../bin/Debug/QuantBox_XAPI" prefix_auto="1" extension_auto="1" />
1111
<Option object_output="obj/Debug/" />
1212
<Option type="3" />
1313
<Option compiler="clang" />
@@ -18,7 +18,7 @@
1818
</Compiler>
1919
</Target>
2020
<Target title="Release">
21-
<Option output="bin/Release/libQuantBox_XAPI" prefix_auto="1" extension_auto="1" />
21+
<Option output="../bin/Release/QuantBox_XAPI" prefix_auto="1" extension_auto="1" />
2222
<Option object_output="obj/Release/" />
2323
<Option type="3" />
2424
<Option compiler="clang" />
@@ -33,10 +33,20 @@
3333
</Target>
3434
</Build>
3535
<Compiler>
36-
<Add option="-Weverything" />
36+
<Add option="-Wall" />
37+
<Add option="-std=c++11" />
3738
<Add option="-fexceptions" />
39+
<Add option="-pthread" />
40+
<Add option="-fPIC" />
3841
</Compiler>
42+
<Unit filename="QuantBox_XAPI.cpp" />
43+
<Unit filename="XApiC.cpp" />
44+
<Unit filename="XApiCpp.cpp" />
45+
<Unit filename="XApiImpl.cpp" />
46+
<Unit filename="XApiImpl.h" />
3947
<Unit filename="main.cpp" />
48+
<Unit filename="stdafx.cpp" />
49+
<Unit filename="stdafx.h" />
4050
<Extensions>
4151
<code_completion />
4252
<debugger />

QuantBox_XAPI/XApiC.cpp

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,34 @@
11
#include "stdafx.h"
22

3+
#include <string.h>
34
#include "../include/XApiC.h"
4-
#include <libloaderapi.h>
55
#include "../include/QueueHeader.h"
66
#include "../include/QueueEnum.h"
77

8+
#if defined WINDOWS
9+
#include <libloaderapi.h>
10+
#else
11+
#include <dlfcn.h>
12+
#include <errno.h>
13+
#endif
14+
15+
816
void* X_LoadLib(char* libPath)
917
{
1018
if (libPath == nullptr)
1119
return nullptr;
1220

21+
#if defined WINDOWS
1322
return LoadLibraryExA(libPath, nullptr, LOAD_WITH_ALTERED_SEARCH_PATH);
23+
#else
24+
return dlopen(libPath, RTLD_LAZY);
25+
#endif
1426
}
1527

1628
char* X_GetLastError()
1729
{
18-
char szBuf[256] = {0};
30+
#if defined WINDOWS
31+
char szBuf[256] = {0};
1932
LPVOID lpMsgBuf;
2033
DWORD dw = GetLastError();
2134
FormatMessageA(
@@ -25,32 +38,44 @@ char* X_GetLastError()
2538
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
2639
(LPSTR)&lpMsgBuf,
2740
0, NULL);
28-
29-
return (char*)lpMsgBuf;
41+
return (char*)lpMsgBuf;
42+
#else
43+
extern int errno;
44+
return strerror(errno);
45+
#endif
3046
}
3147

3248
void* X_GetFunction(void* lib)
3349
{
3450
if (lib == nullptr)
3551
return nullptr;
36-
37-
return (fnOnRespone)GetProcAddress((HMODULE)lib, "XRequest");;
52+
#if defined WINDOWS
53+
return (fnOnRespone)GetProcAddress((HMODULE)lib, "XRequest");
54+
#else
55+
return static_cast<fnOnRespone*>(dlsym(lib, "XRequest"));
56+
#endif
3857
}
3958

4059
void X_FreeLib(void* lib)
4160
{
4261
if (lib == nullptr)
4362
return;
4463

64+
#if defined WINDOWS
4565
FreeLibrary((HMODULE)lib);
66+
#else
67+
dlclose(lib);
68+
#endif
4669
}
4770

4871
ApiType X_GetApiType(void* pFun)
4972
{
5073
if (pFun == nullptr)
5174
return ApiType::Nono;
5275

53-
return (ApiType)(char)((fnOnRespone)pFun)(RequestType::GetApiType, nullptr, nullptr, 0, 0, nullptr, 0, nullptr, 0, nullptr, 0);
76+
void* p = ((fnOnRespone)pFun)(RequestType::GetApiType, nullptr, nullptr, 0, 0, nullptr, 0, nullptr, 0, nullptr, 0);
77+
78+
return (ApiType)(char)(long long)(p);
5479
}
5580

5681
char* X_GetApiVersion(void* pFun)
@@ -187,4 +212,4 @@ void X_CancelQuote(void* pFun, void* pApi, OrderIDType* pIn, OrderIDType* pOut,
187212
return;
188213

189214
((fnOnRespone)pFun)(RequestType::ReqQuoteAction, pApi, nullptr, 0, 0, pIn, count, pOut, 0, nullptr, 0);
190-
}
215+
}

QuantBox_XAPI/XApiImpl.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "stdafx.h"
2+
#include <string.h>
23
#include "XApiImpl.h"
34

45
#include "../include/QueueEnum.h"
@@ -121,7 +122,7 @@ bool CXApiImpl::Init()
121122
return true;
122123
}
123124
}
124-
125+
125126
return false;
126127
}
127128

@@ -133,7 +134,7 @@ char* CXApiImpl::GetLastError()
133134
void CXApiImpl::Connect(char* szPath, ServerInfoField* pServerInfo, UserInfoField* pUserInfo, int count)
134135
{
135136
m_pApi = X_Create(m_pFun);
136-
X_Register(m_pFun, m_pApi, OnRespone, this);
137+
X_Register(m_pFun, m_pApi, (void*)OnRespone, this);
137138
X_Connect(m_pFun, m_pApi, szPath, pServerInfo, pUserInfo, count);
138139
}
139140

@@ -190,4 +191,4 @@ void CXApiImpl::SendQuote(QuoteField* pQuote, OrderIDType* pAskOut, OrderIDType*
190191
void CXApiImpl::CancelQuote(OrderIDType* pIn, OrderIDType* pOut, int count)
191192
{
192193
X_CancelQuote(m_pFun, m_pApi, pIn, pOut, count);
193-
}
194+
}

QuantBox_XAPI/stdafx.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55

66
#pragma once
77

8+
#if defined _WIN32 || WIN32 || _WINDOWS
89
#include "targetver.h"
910

1011
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
1112
// Windows Header Files:
1213
#include <windows.h>
1314

15+
#else
1416

17+
#endif // defined
1518

1619
// TODO: reference additional headers your program requires here

QuantBox_XAPI_C_Linux.workspace

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@
1212
<Project filename="QuantBox_DFITC_Level2/QuantBox_DFITC_Level2.cbp" />
1313
<Project filename="QuantBox_Femas_Quote/QuantBox_CTP_Quote.cbp" />
1414
<Project filename="QuantBox_Femas_Trade/QuantBox_Femas_Trade.cbp" />
15+
<Project filename="QuantBox_XAPI/QuantBox_XAPI.cbp" />
16+
<Project filename="QuantBox_XAPI_TEST/QuantBox_XAPI_TEST.cbp" />
1517
</Workspace>
1618
</CodeBlocks_workspace_file>

QuantBox_XAPI_TEST/QuantBox_XAPI_TEST.cbp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<Option compiler="clang" />
88
<Build>
99
<Target title="Debug">
10-
<Option output="bin/Debug/QuantBox_XAPI_TEST" prefix_auto="1" extension_auto="1" />
10+
<Option output="../bin/Debug/QuantBox_XAPI_TEST" prefix_auto="1" extension_auto="1" />
1111
<Option object_output="obj/Debug/" />
1212
<Option type="1" />
1313
<Option compiler="clang" />
@@ -16,7 +16,7 @@
1616
</Compiler>
1717
</Target>
1818
<Target title="Release">
19-
<Option output="bin/Release/QuantBox_XAPI_TEST" prefix_auto="1" extension_auto="1" />
19+
<Option output="../bin/Release/QuantBox_XAPI_TEST" prefix_auto="1" extension_auto="1" />
2020
<Option object_output="obj/Release/" />
2121
<Option type="1" />
2222
<Option compiler="clang" />
@@ -29,10 +29,19 @@
2929
</Target>
3030
</Build>
3131
<Compiler>
32-
<Add option="-Weverything" />
32+
<Add option="-Wall" />
33+
<Add option="-std=c++11" />
3334
<Add option="-fexceptions" />
3435
</Compiler>
35-
<Unit filename="main.cpp" />
36+
<Linker>
37+
<Add library="QuantBox_XAPI" />
38+
<Add library="dl" />
39+
<Add directory="../bin/Debug" />
40+
</Linker>
41+
<Unit filename="QuantBox_XAPI_TEST.cpp" />
42+
<Unit filename="stdafx.cpp" />
43+
<Unit filename="stdafx.h" />
44+
<Unit filename="targetver.h" />
3645
<Extensions>
3746
<code_completion />
3847
<debugger />

QuantBox_XAPI_TEST/QuantBox_XAPI_TEST.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22
//
33

44
#include "stdafx.h"
5+
6+
#if defined WINDOWS
57
#include <Windows.h>
8+
#endif
69

10+
#include <string.h>
711
#include "../include/XApiCpp.h"
812

913
#ifdef _WIN64
@@ -44,12 +48,12 @@ class CXSpiImpl :public CXSpi
4448
virtual void OnRspQryHistoricalBars(BarField* pBars, int size1, HistoricalDataRequestField* pRequest, int size2, bool bIsLast){};
4549
};
4650

47-
int _tmain(int argc, _TCHAR* argv[])
51+
int main(int argc, char* argv[])
4852
{
4953
CXSpiImpl* p = new CXSpiImpl();
5054
char DLLPath1[250] = "C:\\Program Files\\SmartQuant Ltd\\OpenQuant 2014\\XAPI\\CTP\\x86\\QuantBox_CTP_Quote.dll";
5155
char DLLPath2[250] = "C:\\Program Files\\SmartQuant Ltd\\OpenQuant 2014\\XAPI\\CTP\\x86\\QuantBox_CTP_Trade.dll";
52-
56+
5357
ServerInfoField m_ServerInfo1 = { 0 };
5458
ServerInfoField m_ServerInfo2 = { 0 };
5559
UserInfoField m_UserInfo = { 0 };
@@ -101,7 +105,7 @@ int _tmain(int argc, _TCHAR* argv[])
101105
pOrder->Qty = 1;
102106
pOrder->Type = OrderType::Limit;
103107
pOrder->Side = OrderSide::Buy;
104-
108+
105109
pApi2->SendOrder(pOrder, &Out, 1);
106110

107111
printf("%s\r\n", Out);

QuantBox_XAPI_TEST/stdafx.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,21 @@
55

66
#pragma once
77

8+
#if defined _WIN32 || WIN32 || _WINDOWS
89
#include "targetver.h"
910

10-
#include <stdio.h>
11+
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
12+
// Windows Header Files:
13+
#include <windows.h>
1114
#include <tchar.h>
1215

16+
#else
17+
18+
#endif // defined
19+
20+
#include <stdio.h>
21+
22+
1323

1424

1525
// TODO: reference additional headers your program requires here

0 commit comments

Comments
 (0)