2009-09-23 09:53:26 -05:00
|
|
|
#ifndef _COMBO_PROTOCOL_H
|
|
|
|
#define _COMBO_PROTOCOL_H
|
|
|
|
|
|
|
|
#include "abstractprotocol.h"
|
|
|
|
|
2009-10-14 10:16:56 -05:00
|
|
|
template <int protoNumber, class ProtoA, class ProtoB>
|
2009-09-23 09:53:26 -05:00
|
|
|
class ComboProtocol : public AbstractProtocol
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
ProtoA *protoA;
|
|
|
|
ProtoB *protoB;
|
|
|
|
QWidget *configForm;
|
|
|
|
|
|
|
|
public:
|
2009-10-14 10:16:56 -05:00
|
|
|
ComboProtocol(StreamBase *stream, AbstractProtocol *parent = 0)
|
|
|
|
: AbstractProtocol(stream, parent)
|
2009-09-23 09:53:26 -05:00
|
|
|
{
|
2009-10-14 10:16:56 -05:00
|
|
|
protoA = new ProtoA(stream, this);
|
|
|
|
protoB = new ProtoB(stream, this);
|
|
|
|
protoA->next = protoB;
|
|
|
|
protoB->prev = protoA;
|
2009-09-23 09:53:26 -05:00
|
|
|
configForm = NULL;
|
2009-10-14 10:16:56 -05:00
|
|
|
|
|
|
|
qDebug("%s: protoNumber = %d, %p <--> %p", __FUNCTION__,
|
|
|
|
protoNumber, protoA, protoB);
|
2009-09-23 09:53:26 -05:00
|
|
|
}
|
2009-10-14 10:16:56 -05:00
|
|
|
|
2009-09-23 09:53:26 -05:00
|
|
|
virtual ~ComboProtocol()
|
|
|
|
{
|
2009-10-14 10:16:56 -05:00
|
|
|
if (configForm)
|
|
|
|
{
|
|
|
|
protoA->configWidget()->setParent(0);
|
|
|
|
protoB->configWidget()->setParent(0);
|
|
|
|
delete configForm;
|
|
|
|
}
|
2009-09-23 09:53:26 -05:00
|
|
|
delete protoA;
|
|
|
|
delete protoB;
|
|
|
|
}
|
|
|
|
|
2009-10-14 10:16:56 -05:00
|
|
|
static ComboProtocol* createInstance(StreamBase *stream,
|
|
|
|
AbstractProtocol *parent)
|
2009-09-23 09:53:26 -05:00
|
|
|
{
|
2009-10-14 10:16:56 -05:00
|
|
|
return new ComboProtocol<protoNumber, ProtoA, ProtoB>(stream, parent);
|
2009-09-23 09:53:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual quint32 protocolNumber() const
|
|
|
|
{
|
2009-10-14 10:16:56 -05:00
|
|
|
return protoNumber;
|
2009-09-23 09:53:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void protoDataCopyInto(OstProto::Protocol &protocol) const
|
|
|
|
{
|
2009-10-14 10:16:56 -05:00
|
|
|
protoA->protoDataCopyInto(protocol);
|
|
|
|
protoB->protoDataCopyInto(protocol);
|
|
|
|
protocol.mutable_protocol_id()->set_id(protocolNumber());
|
2009-09-23 09:53:26 -05:00
|
|
|
}
|
2009-10-14 10:16:56 -05:00
|
|
|
|
2009-09-23 09:53:26 -05:00
|
|
|
virtual void protoDataCopyFrom(const OstProto::Protocol &protocol)
|
|
|
|
{
|
2009-10-14 10:16:56 -05:00
|
|
|
if (protocol.protocol_id().id() == protocolNumber())
|
|
|
|
{
|
|
|
|
OstProto::Protocol proto;
|
|
|
|
|
|
|
|
// NOTE: To use protoX->protoDataCopyFrom() we need to arrange
|
|
|
|
// so that it sees its own protocolNumber() - but since the
|
|
|
|
// input param 'protocol' is 'const', we make a copy first
|
|
|
|
|
|
|
|
proto.CopyFrom(protocol);
|
|
|
|
|
|
|
|
proto.mutable_protocol_id()->set_id(protoA->protocolNumber());
|
|
|
|
protoA->protoDataCopyFrom(proto);
|
|
|
|
|
|
|
|
proto.mutable_protocol_id()->set_id(protoB->protocolNumber());
|
|
|
|
protoB->protoDataCopyFrom(proto);
|
|
|
|
}
|
2009-09-23 09:53:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual QString name() const
|
|
|
|
{
|
|
|
|
return protoA->name() + "/" + protoB->name();
|
|
|
|
}
|
|
|
|
virtual QString shortName() const
|
|
|
|
{
|
|
|
|
return protoA->shortName() + "/" + protoB->shortName();
|
|
|
|
}
|
|
|
|
|
2009-11-13 10:00:57 -06:00
|
|
|
virtual ProtocolIdType protocolIdType() const
|
|
|
|
{
|
|
|
|
return protoB->protocolIdType();
|
|
|
|
}
|
|
|
|
|
2009-09-23 09:53:26 -05:00
|
|
|
virtual quint32 protocolId(ProtocolIdType type) const
|
|
|
|
{
|
|
|
|
return protoA->protocolId(type);
|
|
|
|
}
|
|
|
|
//quint32 payloadProtocolId(ProtocolIdType type) const;
|
|
|
|
|
|
|
|
virtual int fieldCount() const
|
|
|
|
{
|
|
|
|
return protoA->fieldCount() + protoB->fieldCount();
|
|
|
|
}
|
|
|
|
//virtual int metaFieldCount() const;
|
|
|
|
//int frameFieldCount() const;
|
|
|
|
|
|
|
|
virtual FieldFlags fieldFlags(int index) const
|
|
|
|
{
|
2009-10-14 10:16:56 -05:00
|
|
|
int cnt = protoA->fieldCount();
|
|
|
|
|
|
|
|
if (index < cnt)
|
2009-09-23 09:53:26 -05:00
|
|
|
return protoA->fieldFlags(index);
|
|
|
|
else
|
2009-10-14 10:16:56 -05:00
|
|
|
return protoB->fieldFlags(index - cnt);
|
2009-09-23 09:53:26 -05:00
|
|
|
}
|
|
|
|
virtual QVariant fieldData(int index, FieldAttrib attrib,
|
|
|
|
int streamIndex = 0) const
|
|
|
|
{
|
2009-10-14 10:16:56 -05:00
|
|
|
int cnt = protoA->fieldCount();
|
|
|
|
|
|
|
|
if (index < cnt)
|
|
|
|
return protoA->fieldData(index, attrib, streamIndex);
|
2009-09-23 09:53:26 -05:00
|
|
|
else
|
2009-10-14 10:16:56 -05:00
|
|
|
return protoB->fieldData(index - cnt, attrib, streamIndex);
|
2009-09-23 09:53:26 -05:00
|
|
|
}
|
|
|
|
virtual bool setFieldData(int index, const QVariant &value,
|
|
|
|
FieldAttrib attrib = FieldValue)
|
|
|
|
{
|
2009-10-14 10:16:56 -05:00
|
|
|
int cnt = protoA->fieldCount();
|
|
|
|
|
|
|
|
if (index < cnt)
|
|
|
|
return protoA->setFieldData(index, value, attrib);
|
2009-09-23 09:53:26 -05:00
|
|
|
else
|
2009-10-14 10:16:56 -05:00
|
|
|
return protoB->setFieldData(index - cnt, value, attrib);
|
2009-09-23 09:53:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
QByteArray protocolFrameValue(int streamIndex = 0,
|
|
|
|
bool forCksum = false) const;
|
|
|
|
virtual int protocolFrameSize() const;
|
|
|
|
int protocolFrameOffset() const;
|
|
|
|
int protocolFramePayloadSize() const;
|
2009-11-13 10:00:57 -06:00
|
|
|
#endif
|
2009-09-23 09:53:26 -05:00
|
|
|
|
2009-11-13 10:00:57 -06:00
|
|
|
virtual bool isProtocolFrameValueVariable() const
|
|
|
|
{
|
|
|
|
return (protoA->isProtocolFrameValueVariable()
|
|
|
|
|| protoB->isProtocolFrameValueVariable());
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool isProtocolFrameSizeVariable() const
|
|
|
|
{
|
|
|
|
return (protoA->isProtocolFrameSizeVariable()
|
|
|
|
|| protoB->isProtocolFrameSizeVariable());
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
2009-09-23 09:53:26 -05:00
|
|
|
virtual quint32 protocolFrameCksum(int streamIndex = 0,
|
|
|
|
CksumType cksumType = CksumIp) const;
|
|
|
|
quint32 protocolFrameHeaderCksum(int streamIndex = 0,
|
|
|
|
CksumType cksumType = CksumIp) const;
|
|
|
|
quint32 protocolFramePayloadCksum(int streamIndex = 0,
|
|
|
|
CksumType cksumType = CksumIp) const;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
virtual QWidget* configWidget()
|
|
|
|
{
|
|
|
|
if (configForm == NULL)
|
|
|
|
{
|
2009-10-14 10:16:56 -05:00
|
|
|
QVBoxLayout *layout = new QVBoxLayout;
|
2009-09-23 09:53:26 -05:00
|
|
|
|
|
|
|
configForm = new QWidget;
|
|
|
|
layout->addWidget(protoA->configWidget());
|
|
|
|
layout->addWidget(protoB->configWidget());
|
2009-10-14 10:16:56 -05:00
|
|
|
layout->setSpacing(0);
|
|
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
2009-09-23 09:53:26 -05:00
|
|
|
configForm->setLayout(layout);
|
|
|
|
}
|
|
|
|
return configForm;
|
|
|
|
}
|
|
|
|
virtual void loadConfigWidget()
|
|
|
|
{
|
|
|
|
protoA->loadConfigWidget();
|
|
|
|
protoB->loadConfigWidget();
|
|
|
|
}
|
|
|
|
virtual void storeConfigWidget()
|
|
|
|
{
|
|
|
|
protoA->storeConfigWidget();
|
|
|
|
protoB->storeConfigWidget();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|