NOX: ComboProtocol - Separated protocol and widget as per framework; VlanStack - separated protocol and widget using the refactored ComboProtocol
This commit is contained in:
parent
e1cfd39786
commit
70937bd4a4
@ -28,7 +28,6 @@ class ComboProtocol : public AbstractProtocol
|
||||
protected:
|
||||
ProtoA *protoA;
|
||||
ProtoB *protoB;
|
||||
QWidget *configForm;
|
||||
|
||||
public:
|
||||
ComboProtocol(StreamBase *stream, AbstractProtocol *parent = 0)
|
||||
@ -38,7 +37,6 @@ public:
|
||||
protoB = new ProtoB(stream, this);
|
||||
protoA->next = protoB;
|
||||
protoB->prev = protoA;
|
||||
configForm = NULL;
|
||||
|
||||
qDebug("%s: protoNumber = %d, %p <--> %p", __FUNCTION__,
|
||||
protoNumber, protoA, protoB);
|
||||
@ -46,12 +44,6 @@ public:
|
||||
|
||||
virtual ~ComboProtocol()
|
||||
{
|
||||
if (configForm)
|
||||
{
|
||||
protoA->configWidget()->setParent(0);
|
||||
protoB->configWidget()->setParent(0);
|
||||
delete configForm;
|
||||
}
|
||||
delete protoA;
|
||||
delete protoB;
|
||||
}
|
||||
@ -192,32 +184,7 @@ public:
|
||||
quint32 protocolFramePayloadCksum(int streamIndex = 0,
|
||||
CksumType cksumType = CksumIp) const;
|
||||
#endif
|
||||
|
||||
virtual QWidget* configWidget()
|
||||
{
|
||||
if (configForm == NULL)
|
||||
{
|
||||
QVBoxLayout *layout = new QVBoxLayout;
|
||||
|
||||
configForm = new QWidget;
|
||||
layout->addWidget(protoA->configWidget());
|
||||
layout->addWidget(protoB->configWidget());
|
||||
layout->setSpacing(0);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
configForm->setLayout(layout);
|
||||
}
|
||||
return configForm;
|
||||
}
|
||||
virtual void loadConfigWidget()
|
||||
{
|
||||
protoA->loadConfigWidget();
|
||||
protoB->loadConfigWidget();
|
||||
}
|
||||
virtual void storeConfigWidget()
|
||||
{
|
||||
protoA->storeConfigWidget();
|
||||
protoB->storeConfigWidget();
|
||||
}
|
||||
template <int protocolNumber, class FormA, class FormB, class ProtocolA, class ProtocolB> friend class ComboProtocolConfigForm;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
100
common/comboprotocolconfig.h
Normal file
100
common/comboprotocolconfig.h
Normal file
@ -0,0 +1,100 @@
|
||||
/*
|
||||
Copyright (C) 2010 Srivats P.
|
||||
|
||||
This file is part of "Ostinato"
|
||||
|
||||
This is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#ifndef _COMBO_PROTOCOL_CONFIG_H
|
||||
#define _COMBO_PROTOCOL_CONFIG_H
|
||||
|
||||
#include "abstractprotocolconfig.h"
|
||||
#include "comboprotocol.h"
|
||||
|
||||
template <int protoNumber,
|
||||
class FormA, class FormB,
|
||||
class ProtoA, class ProtoB>
|
||||
class ComboProtocolConfigForm :
|
||||
public AbstractProtocolConfigForm
|
||||
{
|
||||
public:
|
||||
ComboProtocolConfigForm(QWidget *parent = 0)
|
||||
: AbstractProtocolConfigForm(parent)
|
||||
{
|
||||
QVBoxLayout *layout = new QVBoxLayout;
|
||||
|
||||
formA = new FormA(this);
|
||||
formB = new FormB(this);
|
||||
|
||||
layout->addWidget(formA);
|
||||
layout->addWidget(formB);
|
||||
layout->setSpacing(0);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
setLayout(layout);
|
||||
|
||||
qDebug("%s: protoNumber = %d, %p <--> %p", __FUNCTION__,
|
||||
protoNumber, formA, formB);
|
||||
}
|
||||
|
||||
virtual ~ComboProtocolConfigForm()
|
||||
{
|
||||
formA->setParent(0);
|
||||
formB->setParent(0);
|
||||
|
||||
delete formA;
|
||||
delete formB;
|
||||
}
|
||||
|
||||
static ComboProtocolConfigForm* createInstance()
|
||||
{
|
||||
return new ComboProtocolConfigForm<protoNumber,
|
||||
FormA, FormB, ProtoA, ProtoB>;
|
||||
}
|
||||
|
||||
virtual void loadWidget(AbstractProtocol *proto)
|
||||
{
|
||||
class ComboProtocol<protoNumber, ProtoA, ProtoB> *comboProto =
|
||||
dynamic_cast<ComboProtocol<protoNumber, ProtoA, ProtoB>*>(proto);
|
||||
|
||||
Q_ASSERT_X(comboProto != NULL,
|
||||
QString("ComboProtocolConfigForm{%1}::loadWidget()")
|
||||
.arg(protoNumber).toAscii().constData(),
|
||||
QString("Protocol{%1} is not a instance of ComboProtocol")
|
||||
.arg(proto->protocolNumber()).toAscii().constData());
|
||||
|
||||
formA->loadWidget(comboProto->protoA);
|
||||
formB->loadWidget(comboProto->protoB);
|
||||
}
|
||||
virtual void storeWidget(AbstractProtocol *proto)
|
||||
{
|
||||
class ComboProtocol<protoNumber, ProtoA, ProtoB> *comboProto =
|
||||
dynamic_cast<ComboProtocol<protoNumber, ProtoA, ProtoB>*>(proto);
|
||||
|
||||
Q_ASSERT_X(comboProto != NULL,
|
||||
QString("ComboProtocolConfigForm{%1}::loadWidget()")
|
||||
.arg(protoNumber).toAscii().constData(),
|
||||
QString("Protocol{%1} is not a instance of ComboProtocol")
|
||||
.arg(proto->protocolNumber()).toAscii().constData());
|
||||
|
||||
formA->storeWidget(comboProto->protoA);
|
||||
formB->storeWidget(comboProto->protoB);
|
||||
}
|
||||
|
||||
protected:
|
||||
FormA *formA;
|
||||
FormB *formB;
|
||||
};
|
||||
|
||||
#endif
|
@ -50,6 +50,7 @@ HEADERS += \
|
||||
dot3.h \
|
||||
vlan.h \
|
||||
svlan.h \
|
||||
vlanstack.h \
|
||||
eth2.h \
|
||||
ip6.h
|
||||
|
||||
@ -58,7 +59,6 @@ HEADERS1 += \
|
||||
snap.h \
|
||||
dot2llc.h \
|
||||
dot2snap.h \
|
||||
vlanstack.h \
|
||||
arp.h \
|
||||
ip4.h \
|
||||
ipv4addressdelegate.h \
|
||||
|
@ -45,11 +45,13 @@ HEADERS = \
|
||||
|
||||
HEADERS += \
|
||||
abstractprotocolconfig.h \
|
||||
comboprotocolconfig.h \
|
||||
protocolwidgetfactory.h \
|
||||
macconfig.h \
|
||||
payloadconfig.h \
|
||||
vlanconfig.h \
|
||||
svlanconfig.h \
|
||||
vlanstackconfig.h \
|
||||
dot3config.h \
|
||||
eth2config.h \
|
||||
ip6config.h
|
||||
|
@ -26,7 +26,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
#include "snap.h"
|
||||
#include "dot2llc.h"
|
||||
#include "dot2snap.h"
|
||||
#include "vlanstack.h"
|
||||
#include "arp.h"
|
||||
#include "ip4.h"
|
||||
#include "ip6over4.h"
|
||||
@ -48,6 +47,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
#include "dot3.h"
|
||||
#include "vlan.h"
|
||||
#include "svlan.h"
|
||||
#include "vlanstack.h"
|
||||
#include "eth2.h"
|
||||
#include "ip6.h"
|
||||
#endif
|
||||
@ -69,9 +69,6 @@ ProtocolManager::ProtocolManager()
|
||||
registerProtocol(OstProto::Protocol::kDot2SnapFieldNumber,
|
||||
(void*) Dot2SnapProtocol::createInstance);
|
||||
|
||||
registerProtocol(OstProto::Protocol::kVlanStackFieldNumber,
|
||||
(void*) VlanStackProtocol::createInstance);
|
||||
|
||||
registerProtocol(OstProto::Protocol::kArpFieldNumber,
|
||||
(void*) ArpProtocol::createInstance);
|
||||
registerProtocol(OstProto::Protocol::kIp4FieldNumber,
|
||||
@ -118,6 +115,8 @@ ProtocolManager::ProtocolManager()
|
||||
(void*) VlanProtocol::createInstance);
|
||||
registerProtocol(OstProto::Protocol::kSvlanFieldNumber,
|
||||
(void*) SVlanProtocol::createInstance);
|
||||
registerProtocol(OstProto::Protocol::kVlanStackFieldNumber,
|
||||
(void*) VlanStackProtocol::createInstance);
|
||||
|
||||
registerProtocol(OstProto::Protocol::kEth2FieldNumber,
|
||||
(void*) Eth2Protocol::createInstance);
|
||||
|
@ -24,6 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
#include "dot3config.h"
|
||||
#include "vlanconfig.h"
|
||||
#include "svlanconfig.h"
|
||||
#include "vlanstackconfig.h"
|
||||
#include "eth2config.h"
|
||||
#include "ip6config.h"
|
||||
|
||||
@ -53,6 +54,9 @@ ProtocolWidgetFactory::ProtocolWidgetFactory()
|
||||
OstProtocolWidgetFactory->registerProtocolConfigWidget(
|
||||
OstProto::Protocol::kSvlanFieldNumber,
|
||||
(void*) SVlanConfigForm::createInstance);
|
||||
OstProtocolWidgetFactory->registerProtocolConfigWidget(
|
||||
OstProto::Protocol::kVlanStackFieldNumber,
|
||||
(void*) VlanStackConfigForm::createInstance);
|
||||
|
||||
OstProtocolWidgetFactory->registerProtocolConfigWidget(
|
||||
OstProto::Protocol::kEth2FieldNumber,
|
||||
|
38
common/vlanstackconfig.h
Normal file
38
common/vlanstackconfig.h
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
Copyright (C) 2014 Srivats P.
|
||||
|
||||
This file is part of "Ostinato"
|
||||
|
||||
This is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#ifndef _VLAN_STACK_CONFIG_H
|
||||
#define _VLAN_STACK_CONFIG_H
|
||||
|
||||
#include "comboprotocolconfig.h"
|
||||
|
||||
#include "svlanconfig.h"
|
||||
#include "vlanconfig.h"
|
||||
#include "svlan.h"
|
||||
#include "vlan.h"
|
||||
|
||||
#include "protocol.pb.h"
|
||||
|
||||
typedef ComboProtocolConfigForm <
|
||||
OstProto::Protocol::kVlanStackFieldNumber,
|
||||
SVlanConfigForm, VlanConfigForm,
|
||||
SVlanProtocol, VlanProtocol
|
||||
> VlanStackConfigForm;
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user