ostinato/client/packetmodel.cpp
Srivats P. 84c7fe1e06 Features
- Added support for retrieving the packet capture buffer from server to client (does not work consistently however - needs investigation)
		- getCaptureBuffer() Rpc signature changed
	- RPC: Added support in Rpc Channel (client) to queue calls
	- RPC: Added support for transferring arbitrary binary data from server to client (used to get packet capture files)
		- Rpc header changed - length is now 4 bytes instead of 2; there is no rsvd field any longer

Fixes
	- RPC: Fix for the case when a msg is not received all at once over the socket
	- StreamConfigDialog: fixed display issue in packet view for combo protocols containing meta fields
	- Fixed issue with Stacked Vlan not retaining data for both CVlan and SVlan
	- Fixed incorrect payload size issue with increment/decrement frame length modes

Refactoring, Cleanup etc.
	- RPC: Minor code and TODOs cleanup
	- Server: Minor code and TODOs cleanup
	- Server: Removed unused file(s): rxtx.cpp, rxtx.h
	- Server: Replaced direct use of ProtocolList with the ProtocolListIterator
	- Common: Minor code and TODOs cleanup
	- StreamBase::frameLen() now returns the length based on the mode/min/max and the passed in streamIndex
	- AbstractProtocol interface changed for methods - protocolFrameSize(), protocolFrameOffset(), protocolFramePayloadSize() : all of them now take streamIndex as an optional param with 0 as the default value
		- Protocols implementing the above methods changed accordingly
2009-11-03 14:02:09 +00:00

221 lines
4.8 KiB
C++

#include <QHostAddress>
#include "packetmodel.h"
#include "../common/protocollistiterator.h"
#include "../common/abstractprotocol.h"
PacketModel::PacketModel(QObject *parent)
{
}
void PacketModel::setSelectedProtocols(ProtocolListIterator &iter)
{
QList<const AbstractProtocol*> currentProtocols;
iter.toFront();
while (iter.hasNext())
currentProtocols.append(iter.next());
if (mSelectedProtocols != currentProtocols)
{
mSelectedProtocols = currentProtocols;
reset();
}
}
int PacketModel::rowCount(const QModelIndex &parent) const
{
IndexId parentId;
// qDebug("in %s", __FUNCTION__);
// Parent == Invalid i.e. Invisible Root.
// ==> Children are Protocol (Top Level) Items
if (!parent.isValid())
return mSelectedProtocols.size();
// Parent - Valid Item
parentId.w = parent.internalId();
switch(parentId.ws.type)
{
case ITYP_PROTOCOL:
return mSelectedProtocols.at(parentId.ws.protocol)->frameFieldCount();
case ITYP_FIELD:
return 0;
default:
qWarning("%s: Unhandled ItemType", __FUNCTION__);
}
Q_ASSERT(1 == 0); // Unreachable code
qWarning("%s: Catch all - need to investigate", __FUNCTION__);
return 0; // catch all
}
int PacketModel::columnCount(const QModelIndex &parent) const
{
return 1;
}
QModelIndex PacketModel::index(int row, int col, const QModelIndex &parent) const
{
QModelIndex index;
IndexId id, parentId;
if (!hasIndex(row, col, parent))
goto _exit;
// Parent is Invisible Root
// Request for a Protocol Item
if (!parent.isValid())
{
id.w = 0;
id.ws.type = ITYP_PROTOCOL;
id.ws.protocol = row;
index = createIndex(row, col, id.w);
goto _exit;
}
// Parent is a Valid Item
parentId.w = parent.internalId();
id.w = parentId.w;
switch(parentId.ws.type)
{
case ITYP_PROTOCOL:
id.ws.type = ITYP_FIELD;
index = createIndex(row, col, id.w);
goto _exit;
case ITYP_FIELD:
Q_ASSERT(1 == 0); // Unreachable code
goto _exit;
default:
qWarning("%s: Unhandled ItemType", __FUNCTION__);
}
Q_ASSERT(1 == 0); // Unreachable code
_exit:
return index;
}
QModelIndex PacketModel::parent(const QModelIndex &index) const
{
QModelIndex parentIndex;
IndexId id, parentId;
if (!index.isValid())
return QModelIndex();
id.w = index.internalId();
parentId.w = id.w;
switch(id.ws.type)
{
case ITYP_PROTOCOL:
// return invalid index for invisible root
goto _exit;
case ITYP_FIELD:
parentId.ws.type = ITYP_PROTOCOL;
parentIndex = createIndex(id.ws.protocol, 0, parentId.w);
goto _exit;
default:
qWarning("%s: Unhandled ItemType", __FUNCTION__);
}
Q_ASSERT(1 == 1); // Unreachable code
_exit:
return parentIndex;
}
QVariant PacketModel::data(const QModelIndex &index, int role) const
{
IndexId id;
int fieldIdx = 0;
if (!index.isValid())
return QVariant();
id.w = index.internalId();
if (id.ws.type == ITYP_FIELD)
{
const AbstractProtocol *p = mSelectedProtocols.at(id.ws.protocol);
int n = index.row() + 1;
while (n)
{
if (!(p->fieldFlags(fieldIdx).testFlag(
AbstractProtocol::FieldIsMeta)))
n--;
fieldIdx++;
}
fieldIdx--;
}
// FIXME(HI): Relook at this completely
if (role == Qt::UserRole)
{
switch(id.ws.type)
{
case ITYP_PROTOCOL:
qDebug("*** %d/%d", id.ws.protocol, mSelectedProtocols.size());
return mSelectedProtocols.at(id.ws.protocol)->
protocolFrameValue();
case ITYP_FIELD:
return mSelectedProtocols.at(id.ws.protocol)->fieldData(
fieldIdx, AbstractProtocol::FieldFrameValue);
default:
qWarning("%s: Unhandled ItemType", __FUNCTION__);
}
return QByteArray();
}
// FIXME: Use a new enum here instead of UserRole
if (role == (Qt::UserRole+1))
{
switch(id.ws.type)
{
case ITYP_PROTOCOL:
return mSelectedProtocols.at(id.ws.protocol)->
protocolFrameValue().size();
case ITYP_FIELD:
return mSelectedProtocols.at(id.ws.protocol)->fieldData(
fieldIdx, AbstractProtocol::FieldBitSize);
default:
qWarning("%s: Unhandled ItemType", __FUNCTION__);
}
return QVariant();
}
if (role != Qt::DisplayRole)
return QVariant();
switch(id.ws.type)
{
case ITYP_PROTOCOL:
return QString("%1 (%2)")
.arg(mSelectedProtocols.at(id.ws.protocol)->shortName())
.arg(mSelectedProtocols.at(id.ws.protocol)->name());
case ITYP_FIELD:
return mSelectedProtocols.at(id.ws.protocol)->fieldData(fieldIdx,
AbstractProtocol::FieldName).toString() + QString(" : ") +
mSelectedProtocols.at(id.ws.protocol)->fieldData(fieldIdx,
AbstractProtocol::FieldTextValue).toString();
default:
qWarning("%s: Unhandled ItemType", __FUNCTION__);
}
Q_ASSERT(1 == 1); // Unreachable code
return QVariant();
}