-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathRTDFileThread.cpp
More file actions
103 lines (90 loc) · 2.88 KB
/
RTDFileThread.cpp
File metadata and controls
103 lines (90 loc) · 2.88 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
/******************************************************************************
*
* File: RTDFileThread.cpp
*
* Date: February 5, 2001
*
* Description: This file contains the definition of the methods for the
* thread that feeds data to the RealTimeData server. Currently, this thread
* simply feeds back the current system time.
*
* Modifications:
******************************************************************************/
#include "windows.h"
#include "windowsx.h"
#include "RTDFileThread.h"
#pragma warning(disable:4100)
IRTDUpdateEvent* pRTDUpdate = NULL;
DWORD WINAPI RTDFileThread( LPVOID pMarshalStream)
{
CoInitialize( NULL );
DWORD dwRetVal = 0;
HRESULT hr = S_OK;
//Retrieve the RTDUpdate object
hr = CoGetInterfaceAndReleaseStream( (IStream*)pMarshalStream,
IID_IRTDUpdateEvent, (void**)&pRTDUpdate );
//Set the heartbeat interval to a little more than our timer interval
if (pRTDUpdate != NULL){
pRTDUpdate->AddRef();
hr = pRTDUpdate->put_HeartbeatInterval( 1200 );
//Initiate a timer
UINT timerID = SetTimer( NULL, 0, 1000, NULL );
//Spin a message loop so the thread stays alive, and can receive commands
//from the parent thread.
dwRetVal = MessageLoop();
//Kill the timer
KillTimer( NULL, timerID );
//Clean up the RTDUpdate object
pRTDUpdate->Release();
}
CoUninitialize();
//All done...
return dwRetVal;
}
/******************************************************************************
* MessageLoop -- This method controls a standard Windows message loop.
* Parameters: none
* Returns: the status code from GetMessage.
******************************************************************************/
WPARAM MessageLoop()
{
MSG msg;
HRESULT hr;
//Only WM_QUIT causes GetMessage to return 0.
while (GetMessage( &msg, NULL, 0, 0)){
//switch on the message id
switch( msg.message ){
case WM_TIMER:
hr = pRTDUpdate->UpdateNotify();
break;
case WM_COMMAND:
HANDLE_WM_COMMAND(msg.hwnd, msg.wParam, msg.lParam, ThreadOnCommand);
break;
default:
break;
}
}
return msg.wParam;
}
/******************************************************************************
* ThreadOnCommand -- This method handles the WM_COMMAND messages.
* Parameters: hWnd -- handle to the window that received the message
* id -- the command that was received
* hwndCtl
* codeNotify
* Returns: none
******************************************************************************/
void ThreadOnCommand(HWND hWnd, int id, HWND hwndCtl, UINT codeNotify)
{
HRESULT hr = S_OK;
//switch on the command
switch( id ){
case WM_TERMINATE:
hr = pRTDUpdate->Disconnect();
case WM_SILENTTERMINATE:
PostQuitMessage( hr );
break;
default:
break;
}
}