-
Notifications
You must be signed in to change notification settings - Fork 0
/
DeltaTImeFilterContext.cpp
334 lines (255 loc) · 8.86 KB
/
DeltaTImeFilterContext.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
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
// ============================================================================
// DeltaTimeFilterContext.cpp:
// implementation of the CDeltaTimeFilterContext class.
// ============================================================================
// Copyright (c) WildPackets, Inc. 2006. All rights reserved.
#include "stdafx.h"
#include "resource.h"
#include "DeltaTimeFilterContext.h"
#include "DeltaTimeFilterPlugin.h"
#include "DeltaTimeFilterParent.h"
#include "DeltaTimeFilterTab.h"
#include "Memutil.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// CDeltaTimeFilterContext
//////////////////////////////////////////////////////////////////////
CDeltaTimeFilterContext::CDeltaTimeFilterContext(
CPeekApp* pPeekApp,
CDeltaTimeFilterPlugin* pPlugin )
: m_pPlugin( pPlugin )
{
m_LastTimeStamp = 0;
m_nOperator = 0;
m_nDeltaFilter = 0;
}
// -----------------------------------------------------------------------------
// Init
// -----------------------------------------------------------------------------
int
CDeltaTimeFilterContext::Init(
PluginCreateContextParam* ioParams )
{
CPeekContext::Init( ioParams );
if (ioParams->fContextFlags == kContextType_Global)
return 0;
HWND hTabWnd = NULL;
int nResult = DoAddTab(
_T( "DeltaTimeFilter" ),
_T( "STATIC" ),
(void**) &hTabWnd );
ASSERT( nResult == 0 );
if ( nResult != 0 ) return PLUGIN_RESULT_ERROR;
ASSERT( hTabWnd != NULL );
if ( hTabWnd == NULL ) return PLUGIN_RESULT_ERROR;
AFX_MANAGE_STATE( AfxGetStaticModuleState() );
// Subclass the static window Peek created.
#undef SubclassWindow // The compiler picks up this macro
m_TabParent.SubclassWindow( hTabWnd ); // instead of this function.
// Create a dialog to be embedded in the Parent window. The Parent window will delete it.
m_pTab = new CDeltaTimeFilterTab;
ASSERT( m_pTab != NULL );
if ( m_pTab == NULL ) return PLUGIN_RESULT_ERROR;
SetCapturing( FALSE );
m_pTab->SetContext( this );
m_pTab->Create( IDD_DeltaTimeFilter_TAB, &m_TabParent );
m_TabParent.SetChild( m_pTab );
m_pTab->ShowWindow( SW_SHOW );
return PLUGIN_RESULT_SUCCESS;
}
// -----------------------------------------------------------------------------
// Term
// -----------------------------------------------------------------------------
int
CDeltaTimeFilterContext::Term( )
{
CPeekContext::Term();
return PLUGIN_RESULT_SUCCESS;
}
// -----------------------------------------------------------------------------
// OnReset
// -----------------------------------------------------------------------------
int
CDeltaTimeFilterContext::OnReset(
PluginResetParam* ioParams )
{
return PLUGIN_RESULT_SUCCESS;
}
// -----------------------------------------------------------------------------
// OnStartCapture
// -----------------------------------------------------------------------------
int
CDeltaTimeFilterContext::OnStartCapture(
PluginStartCaptureParam* ioParams )
{
SetCapturing( TRUE );
return PLUGIN_RESULT_SUCCESS;
}
// -----------------------------------------------------------------------------
// OnStopCapture
// -----------------------------------------------------------------------------
int
CDeltaTimeFilterContext::OnStopCapture(
PluginStopCaptureParam* ioParams )
{
SetCapturing( FALSE );
return PLUGIN_RESULT_SUCCESS;
}
// -----------------------------------------------------------------------------
// OnProcessPacket
// -----------------------------------------------------------------------------
int
CDeltaTimeFilterContext::OnProcessPacket(
PluginProcessPacketParam* ioParams )
{
USES_CONVERSION;
return PLUGIN_RESULT_SUCCESS;
}
// -----------------------------------------------------------------------------
// OnGetPacketString
// -----------------------------------------------------------------------------
int
CDeltaTimeFilterContext::OnGetPacketString(
PluginGetPacketStringParam* ioParams )
{
return PLUGIN_RESULT_SUCCESS;
}
// -----------------------------------------------------------------------------
// OnApply
// -----------------------------------------------------------------------------
int
CDeltaTimeFilterContext::OnApply(
PluginApplyParam* ioParams )
{
if ( ioParams->fCommand == kApplyMsg_Start ) return PLUGIN_RESULT_SUCCESS;
if ( ioParams->fCommand == kApplyMsg_End ) return PLUGIN_RESULT_SUCCESS;
if ( ioParams->fCommand != kApplyMsg_Packet ) return -1;
if ( ioParams->fPacket == NULL ) return -1;
return PLUGIN_RESULT_SUCCESS;
}
// -----------------------------------------------------------------------------
// OnSelect
// -----------------------------------------------------------------------------
int
CDeltaTimeFilterContext::OnSelect(
PluginSelectParam* ioParams )
{
return PLUGIN_RESULT_SUCCESS;
}
// -----------------------------------------------------------------------------
// OnPacketsLoaded
// -----------------------------------------------------------------------------
int
CDeltaTimeFilterContext::OnPacketsLoaded(
PluginPacketsLoadedParam* /* ioParams */ )
{
return PLUGIN_RESULT_SUCCESS;
}
// -----------------------------------------------------------------------------
// OnSummary
// -----------------------------------------------------------------------------
int
CDeltaTimeFilterContext::OnSummary(
PluginSummaryParam* ioParams )
{
return PLUGIN_RESULT_SUCCESS;
}
// -----------------------------------------------------------------------------
// OnFilter
// -----------------------------------------------------------------------------
#define kLessThan 0
#define kGreaterThan 1
int
CDeltaTimeFilterContext::OnFilter(
PluginFilterParam* ioParams )
{
USES_CONVERSION;
int ret = PLUGIN_PACKET_REJECT;
if (m_LastTimeStamp == 0 || m_LastTimeStamp > ioParams->fPacket->fTimeStamp)
{
TCHAR buffer[1025];
int i = m_pTab->m_DeltaTimeCtrl.GetLine(0, buffer);
if (i == 0)
{
ioParams->fBytesAccepted = ioParams->fPacket->fPacketLength;
ret = PLUGIN_PACKET_ACCEPT;
}
buffer[i] = 0;
UInt64 nDeltaFilter = static_cast<UInt64>(_ttoi64(buffer));
m_nDeltaFilter = nDeltaFilter *= 1000000;
int nOperator = m_pTab->m_OperatorCtrl.GetCheck();
m_nOperator = (nOperator == 1) ? kLessThan : kGreaterThan;
m_LastTimeStamp = 0;
ret = PLUGIN_PACKET_REJECT;
}
else
{
UInt64 nDeltaTime = ioParams->fPacket->fTimeStamp - m_LastTimeStamp;
if (m_nOperator == kLessThan && nDeltaTime < m_nDeltaFilter )
{
ioParams->fBytesAccepted = ioParams->fPacket->fPacketLength;
ret = PLUGIN_PACKET_ACCEPT;
}
else
if (m_nOperator == kGreaterThan && nDeltaTime > m_nDeltaFilter )
{
ioParams->fBytesAccepted = ioParams->fPacket->fPacketLength;
ret = PLUGIN_PACKET_ACCEPT;
}
}
m_LastTimeStamp = ioParams->fPacket->fTimeStamp;
return ret;
}
// -----------------------------------------------------------------------------
// OnGetPacketAnalysis
// -----------------------------------------------------------------------------
// Called when a packet needs to be displayed in the main packet list. Plug-ins
// will only get packets which correspond the the ProtoSpecs they supplied
// during Load (in GetSupportedProtoSpecs).
int
CDeltaTimeFilterContext::OnGetPacketAnalysis(
PluginGetPacketStringParam* ioParams )
{
return PLUGIN_RESULT_SUCCESS;
}
// -----------------------------------------------------------------------------
// OnDecodePacket
// -----------------------------------------------------------------------------
int
CDeltaTimeFilterContext::OnDecodePacket(
PluginDecodePacketParam* /*ioParams*/ )
{
return PLUGIN_RESULT_SUCCESS;
}
// -----------------------------------------------------------------------------
// OnProcessPluginMessage
// -----------------------------------------------------------------------------
int
CDeltaTimeFilterContext::OnProcessPluginMessage(
PluginProcessPluginMessageParam* /*ioParams*/ )
{
return PLUGIN_RESULT_SUCCESS;
}
// -----------------------------------------------------------------------------
// OnHandleNotify
// -----------------------------------------------------------------------------
int
CDeltaTimeFilterContext::OnHandleNotify(
PluginHandleNotifyParam* /*ioParams*/ )
{
// TODO: Add code here to handle notifications.
return PLUGIN_RESULT_SUCCESS;
}
// -----------------------------------------------------------------------------
// ListenToMessage
// -----------------------------------------------------------------------------
void
CDeltaTimeFilterContext::ListenToMessage( UInt32 inMessage, void* ioParam )
{
ASSERT(m_pTab);
if (m_pTab == NULL) return;
}