-
Notifications
You must be signed in to change notification settings - Fork 163
/
Copy pathMsgShim.h
179 lines (156 loc) · 6.65 KB
/
MsgShim.h
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
/************************************************************************
* Copyright(c) 2010, One Unified. All rights reserved. *
* email: [email protected] *
* *
* This file is provided as is WITHOUT ANY WARRANTY *
* without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* *
* This software may not be used nor distributed without proper license *
* agreement. *
* *
* See the file LICENSE.txt for redistribution information. *
************************************************************************/
#pragma once
// 2010/05/27 translates IQFeed events to Win API Messages for cross thread consumption
#include "IQfeed.h"
namespace ou { // One Unified
namespace tf { // TradeFrame
namespace iqfeed { // IQFeed
template <typename T>
class MsgShim: public IQFeed<MsgShim<T> > {
friend IQFeed<MsgShim<T> >;
public:
typedef typename IQFeed<MsgShim<T> > inherited_t;
typedef typename inherited_t::linebuffer_t linebuffer_t;
// pre-initialized message ids for messages delivered to and accepted by external caller
struct structMessageDestinations { //
T* owner; // owner object to which message is sent (PostMessage needs to be implemented)
UINT msgConnected;
UINT msgSendComplete;
UINT msgDisconnected;
UINT msgError; // not currently forwarded
UINT msgMessageUpdate;
UINT msgMessageSummary;
UINT msgMessageNews;
UINT msgMessageFundamental;
UINT msgMessageTime;
UINT msgMessageSystem;
structMessageDestinations( void )
: owner( NULL ), msgConnected( 0 ), msgSendComplete( 0 ), msgDisconnected( 0 ), msgError( 0 ),
msgMessageUpdate( 0 ), msgMessageSummary( 0 ), msgMessageNews( 0 ), msgMessageFundamental( 0 ), msgMessageTime( 0 ), msgMessageSystem( 0 )
{};
structMessageDestinations( T* owner_, UINT msgConnected_, UINT msgSendComplete_, UINT msgDisconnected_, UINT msgError_,
UINT msgMessageUpdate_, UINT msgMessageSummary_, UINT msgMessageNews_, UINT msgMessageFundamental_, UINT msgMessageTime_, UINT msgMessageSystem_ )
: owner( owner_ ), msgConnected( msgConnected_ ), msgSendComplete( msgSendComplete_ ), msgDisconnected( msgDisconnected_ ), msgError( msgError_ ),
msgMessageUpdate( msgMessageUpdate_ ), msgMessageSummary( msgMessageSummary_ ), msgMessageNews( msgMessageNews_ ),
msgMessageFundamental( msgMessageFundamental_ ), msgMessageTime( msgMessageTime_ ), msgMessageSystem( msgMessageSystem_ )
{
BOOST_ASSERT( NULL != owner_ );
};
};
MsgShim( const structMessageDestinations& MessageDestinations)
: m_structMessageDestinations( MessageDestinations ) {
assert( NULL != MessageDestinations.owner );
};
~MsgShim( void ) {};
protected:
// CRTP callbacks
void OnIQFeedConnected( void ) {
if ( 0 != m_structMessageDestinations.msgConnected ) {
m_structMessageDestinations.owner->PostMessage( m_structMessageDestinations.msgConnected );
}
}
void OnIQFeedDisconnected( void ) {
if ( 0 != m_structMessageDestinations.msgDisconnected ) {
m_structMessageDestinations.owner->PostMessage( m_structMessageDestinations.msgDisconnected );
}
}
void OnIQFeedError( size_t e ) {
if ( 0 != m_structMessageDestinations.msgError ) {
m_structMessageDestinations.owner->PostMessage( m_structMessageDestinations.msgError, e );
}
}
void OnIQFeedSendDone( void ) {
if ( 0 != m_structMessageDestinations.msgSendComplete ) {
m_structMessageDestinations.owner->PostMessage( m_structMessageDestinations.msgSendComplete );
}
}
void OnIQFeedUpdateMessage( linebuffer_t* pBuffer, IQFUpdateMessage* pMsg ) {
if ( 0 != m_structMessageDestinations.msgMessageUpdate ) {
m_structMessageDestinations.owner->PostMessage(
m_structMessageDestinations.msgMessageUpdate,
reinterpret_cast<WPARAM>( pBuffer ),
reinterpret_cast<LPARAM>( pMsg )
);
}
else {
UpdateDone( pBuffer, pMsg );
}
}
void OnIQFeedSummaryMessage( linebuffer_t* pBuffer, IQFSummaryMessage* pMsg ) {
if ( 0 != m_structMessageDestinations.msgMessageSummary ) {
m_structMessageDestinations.owner->PostMessage(
m_structMessageDestinations.msgMessageSummary,
reinterpret_cast<WPARAM>( pBuffer ),
reinterpret_cast<LPARAM>( pMsg )
);
}
else {
SummaryDone( pBuffer, pMsg );
}
}
void OnIQFeedNewsMessage( linebuffer_t* pBuffer, IQFNewsMessage* pMsg ) {
if ( 0 != m_structMessageDestinations.msgMessageNews ) {
m_structMessageDestinations.owner->PostMessage(
m_structMessageDestinations.msgMessageNews,
reinterpret_cast<WPARAM>( pBuffer ),
reinterpret_cast<LPARAM>( pMsg )
);
}
else {
NewsDone( pBuffer, pMsg );
}
}
void OnIQFeedFundamentalMessage( linebuffer_t* pBuffer, IQFFundamentalMessage* pMsg ) {
if ( 0 != m_structMessageDestinations.msgMessageFundamental ) {
m_structMessageDestinations.owner->PostMessage(
m_structMessageDestinations.msgMessageFundamental,
reinterpret_cast<WPARAM>( pBuffer ),
reinterpret_cast<LPARAM>( pMsg )
);
}
else {
FundamentalDone( pBuffer, pMsg );
}
}
void OnIQFeedTimeMessage( linebuffer_t* pBuffer, IQFTimeMessage* pMsg ) {
if ( 0 != m_structMessageDestinations.msgMessageTime ) {
m_structMessageDestinations.owner->PostMessage(
m_structMessageDestinations.msgMessageTime,
reinterpret_cast<WPARAM>( pBuffer ),
reinterpret_cast<LPARAM>( pMsg )
);
}
else {
TimeDone( pBuffer, pMsg );
}
}
void OnIQFeedSystemMessage( linebuffer_t* pBuffer, IQFSystemMessage* pMsg ) {
if ( 0 != m_structMessageDestinations.msgMessageSystem ) {
m_structMessageDestinations.owner->PostMessage(
m_structMessageDestinations.msgMessageSystem,
reinterpret_cast<WPARAM>( pBuffer ),
reinterpret_cast<LPARAM>( pMsg )
);
}
else {
SystemDone( pBuffer, pMsg );
}
}
private:
structMessageDestinations m_structMessageDestinations;
};
} // namespace iqfeed
} // namespace tf
} // namespace ou