ostinato/common/streambase.cpp
Srivats P. 2ec7fb30c2 Protocol Framework basic code in place now. Cleanup pending.
- New Classes:
  o ProtocolManager - singleton with which all protocols register
  o ProtocolCollection - Aggregates all registered protocols; exports methods to work on all protocols
  o StreamBase - aggregates ProtocolCollection with Stream Core and Control; the client/server side stream classes now derive from StreamBase leading to major reduction in their code (more cleanup pending)
- AbstractProtocol now supports the additional methods
  o createInstance()
  o protocolFrameSize()
  o protocolFrameOffset(), protocolFramePayloadSize()
  o protocolId(), payloadProtocolId()
  o protocolFrameCksum(), protocolFramePayloadCksum()
  0 constructor takes an extra param - frameProtoList
- Specific protocols - eth2, llc, snap, ip4, udp, tcp now return length, protocol id and cksums correctly (tcp/udp cksum pending)
- StreamConfigDialog - protocol controls for length, cksum and protocolid are automatically updated (not fully working yet)
2009-05-10 06:27:17 +00:00

70 lines
1.5 KiB
C++

#include "streambase.h"
StreamBase::StreamBase() :
mStreamId(new OstProto::StreamId),
mCore(new OstProto::StreamCore),
mControl(new OstProto::StreamControl),
protocols(currentFrameProtocols, mCore)
{
mStreamId->set_id(0xFFFFFFFF);
}
StreamBase::~StreamBase()
{
delete mStreamId;
delete mCore;
delete mControl;
}
void StreamBase::protoDataCopyFrom(const OstProto::Stream &stream)
{
mStreamId->CopyFrom(stream.stream_id());
mCore->CopyFrom(stream.core());
mControl->CopyFrom(stream.control());
protocols.protoDataCopyFrom(stream);
setFrameProtocol(frameProtocol());
}
void StreamBase::protoDataCopyInto(OstProto::Stream &stream) const
{
stream.mutable_stream_id()->CopyFrom(*mStreamId);
stream.mutable_core()->CopyFrom(*mCore);
stream.mutable_control()->CopyFrom(*mControl);
protocols.protoDataCopyInto(stream);
}
QList<int> StreamBase::frameProtocol()
{
QList<int> protocolList;
for (int i = 0; i < mCore->frame_proto_size(); i++)
protocolList.append(mCore->frame_proto(i));
return protocolList;
}
void StreamBase::setFrameProtocol(QList<int> protocolList)
{
mCore->clear_frame_proto();
currentFrameProtocols.clear();
for (int i = 0; i < protocolList.size(); i++)
{
mCore->add_frame_proto(protocolList.at(i));
currentFrameProtocols.append(protocols.protocol(protocolList.at(i)));
}
}
AbstractProtocol* StreamBase::protocol(int protoNum)
{
return protocols.protocol(protoNum);
}
AbstractProtocol* StreamBase::protocol(QString protoName)
{
return protocols.protocol(protoName);
}