[go: up one dir, main page]

Menu

[r369]: / trunk / VTS3 / FrameContext.cpp  Maximize  Restore  History

Download this file

238 lines (187 with data), 5.9 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
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
// FrameContext.cpp: implementation of the CFrameContext class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "VTS.h"
#include "FrameContext.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
CFrameContext* gNewFrameContext;
//
// CFrameContext::CFrameContext
//
CFrameContext::CFrameContext()
: m_pDoc(0), m_NextFrame(0)
, m_Listeners(0)
, m_PacketCount(0), m_CurrentPacket(-1)
, m_DetailCount(0), m_CurrentDetail(-1)
, m_HexStart(0), m_HexLen(0)
// , m_Packet(), m_PacketInfo( false, true ) // no summary, do detail MAD_DB
, m_PacketInfo( false, true ) // no summary, do detail
{
}
//
// CFrameContext::~CFrameContext
//
// The only thing the destructor has to do is make sure that the
// document it is bound to will not have this soon to be invalid
// object in its list.
//
CFrameContext::~CFrameContext()
{
if (m_pDoc)
m_pDoc->UnbindFrameContext( this );
}
//
// CFrameContext::AddListener
//
// There is a new listener that needs to be added to this context. In most
// cases it will be a view within a frame, but in the future it may be in
// its own frame but shares the context with other frames. It would be nice
// to double-click on a packet and open up a window with just the detail
// and hex views of the packet (in which case it would keep its own context)
// or ctrl-click on a packet to give it its own window but keep it bound to
// the window.
//
void CFrameContext::AddListener( CFrameContextListener* pListener )
{
pListener->m_NextListener = m_Listeners;
m_Listeners = pListener;
}
//
// CFrameContext::NotifyListeners
//
// Tell all the listeners that something about the frame context has changed.
// See CFrameContext::Signal for a list of the defined signals. Listeners are
// free to process or ignore the notification as they wish.
//
void CFrameContext::NotifyListeners( Signal s )
{
for (CFrameContextListener* cur = m_Listeners; cur; cur = cur->m_NextListener)
cur->ContextChange( s );
}
void CFrameContext::UpdatePrefs( void )
{
// We've called this guy to tell our listeners that some settings in their prefs
// might need to update... so go about it.
NotifyListeners( eUpdatePrefs );
}
//
// CFrameContext::SetPacketCount
//
// The packet count is in the bound database, but rather than go through the
// overhead to get the count, just keep a local copy in the context.
//
void CFrameContext::SetPacketCount( int packetCnt )
{
// skip if this context already has the correct packet count
if (packetCnt == m_PacketCount)
return;
// update the local copy
m_PacketCount = packetCnt;
// tell the listeners
NotifyListeners( eNewPacketCount );
}
//
// CFrameContext::SetCurrentPacket
//
void CFrameContext::SetCurrentPacket( int packetNum )
{
// skip it if this context is already pointing to the correct packet
if (packetNum == m_CurrentPacket)
return;
// make sure it's valid, -1 means nothing is selected
if (packetNum != -1)
if ((packetNum < 0) || (packetNum >= m_PacketCount))
return;
// update the current packet
m_CurrentPacket = packetNum; // neccessary for GetCurrentPacket to work properly
VTSPacketPtr ppkt = GetCurrentPacket();
// if (packetNum != -1) { MAD_DB
if ( ppkt != NULL )
{
// read it out of the database
//MAD_DB m_pDoc->m_pDB->ReadPacket( packetNum, m_Packet );
// set globals so name lookups have somewhere to go
//MAD_DB NetworkSniffer::SetLookupContext( m_Packet.packetHdr.packetPortID, &this->m_pDoc->m_pDB->dbNameList );
NetworkSniffer::SetLookupContext( ppkt->packetHdr.m_szPortName );
// pick the interpreter based on the protocol id
//MAD_DB m_PacketInfo.Interpret( (BACnetPIInfo::ProtocolType)m_Packet.packetHdr.packetProtocolID
// , (char *)m_Packet.packetData, m_Packet.packetLen
// );
//MAD_DB
m_PacketInfo.Interpret( (BACnetPIInfo::ProtocolType) ppkt->packetHdr.packetProtocolID, (char *) ppkt->packetData, ppkt->packetLen );
/* Added timestamp string, madanner 5/03
// add timestamp info in detail view
FILETIME locFileTime;
SYSTEMTIME st;
char theTime[16];
::FileTimeToLocalFileTime( &m_Packet.packetHdr.packetTime, &locFileTime );
::FileTimeToSystemTime( &locFileTime, &st );
sprintf( theTime, "%02d:%02d:%02d.%03d "
, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds);
*/
gCurrentInfo->detailLine[0]=new BACnetPIDetail;
sprintf(gCurrentInfo->detailLine[0]->piLine,"Timestamp : %s", ppkt->GetTimeStampString());
}
// tell the listeners that the packet changed, come and get the new contents
NotifyListeners( eNewCurrentPacket );
}
VTSPacketPtr CFrameContext::GetCurrentPacket()
{
return m_pDoc->GetPacket(m_CurrentPacket);
}
//
// CFrameContext::SetDetailCount
//
void CFrameContext::SetDetailCount( int detailCnt )
{
if (detailCnt == m_DetailCount)
return;
m_DetailCount = detailCnt;
NotifyListeners( eNewDetailCount );
}
//
// CFrameContext::SetCurrentDetail
//
void CFrameContext::SetCurrentDetail( int detailNum )
{
if (detailNum == m_CurrentDetail)
return;
if (detailNum != -1)
if ((detailNum < 0) || (detailNum >= m_DetailCount))
return;
m_CurrentDetail = detailNum;
NotifyListeners( eNewCurrentDetail );
if (detailNum != -1)
SetCurrentRange( m_PacketInfo.detailLine[detailNum]->piOffset
, m_PacketInfo.detailLine[detailNum]->piLen
);
}
//
// CFrameContext::SetCurrentRange
//
void CFrameContext::SetCurrentRange( int start, int len )
{
m_HexStart = start;
m_HexLen = len;
NotifyListeners( eNewCurrentRange );
}
//
// CFrameContextListener::CFrameContextListener
//
CFrameContextListener::CFrameContextListener()
: m_FrameContext(0), m_NextListener(0)
{
}
//
// CFrameContextListener::SetContext
//
void CFrameContextListener::SetContext( CFrameContextPtr pContext )
{
m_FrameContext = pContext;
pContext->AddListener( this );
}