-
Notifications
You must be signed in to change notification settings - Fork 76
/
TimerWnd.cpp
109 lines (81 loc) · 2.43 KB
/
TimerWnd.cpp
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
// TimerWnd.cpp : implementation file
//
#include "stdafx.h"
#include "mushclient.h"
#include "doc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTimerWnd
CTimerWnd::CTimerWnd(CMUSHclientDoc * pDoc)
{
m_pDoc = pDoc;
m_iTimer = 0;
}
CTimerWnd::~CTimerWnd()
{
}
BEGIN_MESSAGE_MAP(CTimerWnd, CWnd)
//{{AFX_MSG_MAP(CTimerWnd)
ON_WM_TIMER()
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTimerWnd message handlers
void CTimerWnd::OnTimer(UINT nIDEvent)
{
// no queued commands - don't update status line
if (m_pDoc->m_QueuedCommandsList.IsEmpty ())
return;
while (!m_pDoc->m_QueuedCommandsList.IsEmpty ())
{
CString strCommand = m_pDoc->m_QueuedCommandsList.RemoveHead ();
char cMessageType = strCommand [0];
m_pDoc->DoSendMsg (strCommand.Mid (1),
toupper (cMessageType) == QUEUE_WITH_ECHO ||
toupper (cMessageType) == IMMEDIATE_WITH_ECHO,
cMessageType >= 'A'); // log flag
if (toupper (cMessageType) == QUEUE_WITH_ECHO ||
toupper (cMessageType) == QUEUE_WITHOUT_ECHO)
break; // if we need to wait, don't keep pulling them out
}
m_pDoc->ShowQueuedCommands (); // update status line
}
void CTimerWnd::OnDestroy()
{
if (m_iTimer)
KillTimer (m_iTimer);
CWnd::OnDestroy();
}
void CTimerWnd::ChangeTimerRate (const int iRate)
{
int iNewRate = iRate;
// make sure valid
if (iNewRate < 0)
iNewRate = 0;
if (iNewRate > 30000)
iNewRate = 30000;
// get rid of old timer
if (m_iTimer)
KillTimer (m_iTimer);
// if zero, no timer wanted
if (iNewRate)
m_iTimer = SetTimer(COMMAND_QUEUE_TIMER_ID, iNewRate, NULL);
else
{
// if no delay any more, send all outstanding lines
while (!m_pDoc->m_QueuedCommandsList.IsEmpty ())
{
CString strCommand = m_pDoc->m_QueuedCommandsList.RemoveHead ();
char cMessageType = strCommand [0];
m_pDoc->DoSendMsg (strCommand.Mid (1),
cMessageType == QUEUE_WITH_ECHO ||
cMessageType == IMMEDIATE_WITH_ECHO,
cMessageType >= 'A'); // log flag
} // end of sending all lines
}
} // end of ChangeTimerRate