-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSampleDialogSettingConnection.cpp
More file actions
384 lines (339 loc) · 9.52 KB
/
SampleDialogSettingConnection.cpp
File metadata and controls
384 lines (339 loc) · 9.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
#include "stdafx.h"
#include "SampleDialogSettingConnection.h"
//#include "ConnectionApi.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
enum SampleSettingConnectionIds
{
listBoxConnectionId = 10000,
connectionIdsCount
};
SampleDialogSettingConnection::SampleDialogSettingConnection(TakionMainWnd* mainWnd, TakionSettingTabDialog* parentTab):
BaseDialogSetting(mainWnd, parentTab, "Connection"),
m_ListBoxConnection(true)
{
m_ListBoxConnection.SetSelectable(false);
int x = 0;
int y = 0;
int width = 200;
int listBoxHeight = 58;
// int xc = x + hgap;
AddListBoxIndirect(nullptr, WS_VISIBLE | WS_TABSTOP | WS_BORDER | LBS_NOTIFY | LBS_SORT | LBS_OWNERDRAWFIXED | LBS_NOINTEGRALHEIGHT | WS_VSCROLL, 0, x, y, width, listBoxHeight, listBoxConnectionId);
}
HWND SampleDialogSettingConnection::GetFirstTabControl() const
{
return m_ListBoxConnection.m_hWnd;
}
void SampleDialogSettingConnection::UpdateSettings()
{
// BaseDialogSetting::UpdateSettings();
}
void SampleDialogSettingConnection::UpdateControls()
{
// TD_GetNewAccountObservable().AddObserver(this);
// TD_GetAdminObservable().AddObserver(this);
}
void SampleDialogSettingConnection::BeforeDestroy()
{
TD_GetNewAccountObservable().RemoveObserver(this);
TD_GetAdminObservable().RemoveObserver(this);
BaseDialogSetting::BeforeDestroy();
}
void SampleDialogSettingConnection::Leaving()
{
// TD_GetNewAccountObservable().RemoveObserver(this);
// TD_GetAdminObservable().RemoveObserver(this);
}
BOOL SampleDialogSettingConnection::OnInitDialog()
{
TD_GetNewAccountObservable().AddObserver(this);
TD_GetAdminObservable().AddObserver(this);
BOOL ret = BaseDialogSetting::OnInitDialog();
UpdateConnections();
/*
TakionIterator* iterator = TD_CreateAccountIterator();
Account* account;
TD_LockAccountStorage();
iterator->Reset();
while(account = (Account*)TD_GetNextAccount(iterator))
{
m_ComboBoxAccount.AddString((const char*)account);
}
TD_UnlockAccountStorage();
delete iterator;
m_ComboBoxAccount.SetCurSel(0);
*/
return ret;
}
void SampleDialogSettingConnection::DoDataExchange(CDataExchange* pDX)
{
BaseDialogSetting::DoDataExchange(pDX);
DDX_Control(pDX, listBoxConnectionId, m_ListBoxConnection);
}
BEGIN_MESSAGE_MAP(SampleDialogSettingConnection, BaseDialogSetting)
ON_WM_CTLCOLOR()
ON_LBN_SELCHANGE(listBoxConnectionId, OnSelchangeConnection)
END_MESSAGE_MAP()
void SampleDialogSettingConnection::OnSelchangeConnection()
{
}
void SampleDialogSettingConnection::UpdateConnections()
{
m_ListBoxConnection.ResetContent();
const ActiveConnection* connection;
TakionIterator* iterator = TD_CreateActiveConnectionIterator();
iterator->Reset();
while(connection = TD_GetNextActiveConnection(iterator))
{
m_ListBoxConnection.AddString((const char*)new ConnectionItem(nullptr, connection->GetIpInvAddress(), connection->GetPort(), "", connection->GetName(), connection->GetConnectionDataType(), connection->isConnected()));//it->second.c_str()));
}
delete iterator;
// OnSelchangeConnection();
}
HBRUSH SampleDialogSettingConnection::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
/*
switch(pWnd->GetDlgCtrlID())
{
case editSymbolId:
if(m_symbol.empty())
{
pDC->SetBkMode(TRANSPARENT);
return *m_takionVisual->GetWarningBrush();
}
break;
}
*/
return BaseDialogSetting::OnCtlColor(pDC, pWnd, nCtlColor);
}
void SampleDialogSettingConnection::Notify(const Message* message, const Observable* from, const Message* info)
{
switch(message->m_type)
{
case TM_NEW_ORDER:
// DisplayNewOrder(((const TMsgOrder*)message)->m_order);
break;
/*
case TM_ORDER_UPDATE:
break;
*/
case TM_DEAD_ORDER:
// DisplayCanceledOrder(((const TMsgOrder*)message)->m_order);
break;
case TM_NEW_EXECUTION:
// DisplayExecution(((const TMsgExecution*)message)->m_execution);
break;
case TM_AUTO_ACTION:
/*
if(&TD_GetAdminObservable() == from && info && info->m_type == TM_UPDATED_ACCOUNT)
{
Account* account = ((TMsgUpdatedAccount*)info)->m_account;
if(account == m_currentAccount)// || config->m_showAutoActionForAllAccounts.GetValue())
{
const TMsgAutoAction* msg = (const TMsgAutoAction*)message;
DisplayAutoAction(account, msg->m_symbol, msg->m_close, msg->m_loss, msg->m_constraint);//, unsigned int uintValue, unsigned int uintConstraint)
}
}
*/
break;
case M_TEXT:
{
// const TMsgText* msg = (const TMsgText*)message;
// DisplayAdminBroadcastMessage((const char*)msg + sizeof(TMsgText));
}
break;
case TS_NEW_ACCOUNT:
if(info && info->m_type == TM_NEW_ACCOUNT)
{
TMsgNewAccountObject* msg = (TMsgNewAccountObject*)info;
Account* account = msg->m_account;
// m_ComboBoxAccount.AddString((const char*)account);
}
break;
case TM_NEW_ACCOUNT:
{
TMsgNewAccountObject* msg = (TMsgNewAccountObject*)message;
Account* account = msg->m_account;
// m_ComboBoxAccount.AddString((const char*)account);
}
break;
case TM_UPDATED_ACCOUNT://TM_ACCOUNT_UPDATE:
// UpdateAccount(((TMsgAccount*)message)->m_account);
break;
case TM_ACCOUNT_DELETE:
{
Account* account = ((const TMsgAccountDelete*)message)->m_account;
/*
ClearAccountOrders(account);
int found = m_ComboBoxAccount.FindItem(account);
if(found >= 0)
{
const int sel = m_ComboBoxAccount.GetCurSel();
m_ComboBoxAccount.DeleteString(found);
if(sel >= 0)
{
const unsigned int count = m_ComboBoxAccount.GetItemCount();
if(count > 0)
{
if((unsigned int)sel >= count)
{
m_ComboBoxAccount.SetCurSel(count - 1);
}
}
}
OnSelchangeAccount();
}
*/
}
break;
case TM_DELETE_ALL_ACCOUNTS:
// ClearStocks();
// m_ComboBoxAccount.ResetContent();
// m_ComboBoxAccount.AddString(nullptr);
break;
#ifndef TAKION_NO_OPTIONS
case TM_DELETE_ALL_FUTURE_ACCOUNTS:
break;
#endif
case M_RESP_MD_LOGON:
// UpdateMarketDataEntitlements();
break;
case TS_LOGIN_RESP:
if(info && info->m_type == TM_NEW_ACCOUNT)
{
TMsgNewAccountObject* msg = (TMsgNewAccountObject*)info;
Account* account = msg->m_account;
/*
if(m_ComboBoxAccount.FindItem(account) < 0)
{
m_ComboBoxAccount.AddString((const char*)account);
}
*/
}
break;
case TS_ACCOUNT_POSITION_RESP:
if(info && info->m_type == TM_UPDATED_ACCOUNT)
{
TMsgUpdatedAccount* msg = (TMsgUpdatedAccount*)info;
Account* account = msg->m_account;
/*
SendAccountPositionCost(account);
if(account == m_currentAccount)
{
CurrentAccountLoaded();
}
if(from != (Observable*)account)
{
AccountLoaded(account);
}
*/
}
break;
case TS_ACCOUNT_EXEC_HISTORY_COMPLETE:
if(info && info->m_type == TM_UPDATED_ACCOUNT)
{
TMsgUpdatedAccount* msg = (TMsgUpdatedAccount*)info;
Account* account = msg->m_account;
/*
int sel = m_ComboBoxAccount.GetCurSel();
if(sel >= 0)
{
if(account == (Account*)m_ComboBoxAccount.GetItemDataPtr(sel))
{
}
}
*/
}
break;
case TM_DISCONNECTED:
if(info && info->m_type == TM_CONNECTION_OBJECT)
{
const TMsgConnectionObject* msg = (const TMsgConnectionObject*)info;
const Connection* connection = msg->m_connection;
UpdateConnection(connection, false);
/*
if(connection == TD_GetMarketSorterConnection())
{
}
else if(connection == TD_GetMarketDataConnection())
{
}
else if(connection == TD_GetExecutorConnection())
{
}
*/
}
break;
case TM_CONNECTED:
if(info && info->m_type == TM_CONNECTION_OBJECT)
{
// const TMsgConnected* msg = (const TMsgConnected*)message;
// ConnectionConnected(msg->m_ipAddress, msg->m_port, msg->m_ipBindAddress, msg->m_bindPort, msg->m_connectionName);
const TMsgConnectionObject* msg = (const TMsgConnectionObject*)info;
const Connection* connection = msg->m_connection;
UpdateConnection(connection, true);
/*
if(connection == TD_GetMarketSorterConnection())
{
}
else if(connection == TD_GetMarketDataConnection())
{
}
else if(connection == TD_GetExecutorConnection())
{
}
*/
}
break;
case TM_MARKET_STATUS:
{
}
break;
case TM_NEXT_DAY_STARTED:
{
// NextDayStarted(((const TMsgNextDayStarted*)message)->m_date);
}
break;
case TM_MARKET_SORTER_LOADED:
// MarketSorterLoaded();
break;
case TM_MARKET_SORTER_CLEANUP:
// MarketSorterCleanup();
break;
case TM_DATA_THREAD_BUFFER_OVERFLOW:
// PostMessage(WM_USER + 500, ((const TMsgDataThreadBufferOverflow*)message)->m_threadId, 0);
break;
}
}
void SampleDialogSettingConnection::UpdateConnection(const Connection* connection, bool connected)
{
/*
enum ConnectionDataType : unsigned char
{
CDT_MARKET_DATA,
CDT_EXECUTOR,
CDT_MARKET_SORTER,
CDT_COUNT
};
*/
unsigned int dataType = connection->GetConnectionDataType();
ConnectionItem* item;
for(unsigned int i = 0, end = m_ListBoxConnection.GetItemCount(); i < end; ++i)
{
item = (ConnectionItem*)m_ListBoxConnection.GetItemDataPtr(i);
if(dataType == item->GetDataType())
{
if(item->isConnected() != connected)
{
item->SetConnected(connected);
m_ListBoxConnection.InvalidateItem(i);
return;
}
}
}
if(connected)
{
m_ListBoxConnection.AddString((const char*)new ConnectionItem(nullptr, connection->GetIpInvAddress(), connection->GetPort(), "", connection->GetName(), connection->GetConnectionDataType(), connected));//it->second.c_str()));
}
}