-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathBidInfoMonitor.h
40 lines (33 loc) · 1018 Bytes
/
BidInfoMonitor.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
#pragma once
struct BidMessage
{
enum Phase {UnknowPhase = 0, NonBidPhase, FirstPhase, ModifyPhase};
Phase phase;
int serverTime;
int endTime;
int tradeablePrice;
std::wstring notification;
BidMessage() : phase(UnknowPhase), serverTime(0), endTime(0), tradeablePrice(0) {}
};
typedef void(*ReceivedBidMsg) (const BidMessage& bidMsg, void *arg);
class BidInfoMonitor
{
public:
BidInfoMonitor(ReceivedBidMsg printBidMsgFunc, void *receivedBidMsgArg)
: m_workThread(NULL)
, m_divert(NULL)
, m_receivedBidMsgFunc(printBidMsgFunc)
, m_receivedBidMsgArg(receivedBidMsgArg)
{}
~BidInfoMonitor() { Stop(); }
void ThreadFunc();
bool Start(const wchar_t *ip1, int port1, const wchar_t *ip2, int port2);
bool Stop();
bool isWorking() { return m_workThread && m_divert.load(); }
private:
void *m_workThread;
std::atomic<void*> m_divert;
ReceivedBidMsg m_receivedBidMsgFunc;
void *m_receivedBidMsgArg;
BidMessage m_bidMessage;
};