NOX: 802.3 - Separated protocol and widget as per new framework

This commit is contained in:
Srivats P. 2014-03-14 07:03:44 +05:30
parent bdc1252b95
commit e6fa745b81
8 changed files with 125 additions and 70 deletions

View File

@ -1,5 +1,5 @@
/*
Copyright (C) 2010 Srivats P.
Copyright (C) 2010-2014 Srivats P.
This file is part of "Ostinato"
@ -18,28 +18,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
*/
#include "dot3.h"
#include "streambase.h"
#include <QHostAddress>
#include <QIntValidator>
#include <qendian.h>
Dot3ConfigForm::Dot3ConfigForm(QWidget *parent)
: QWidget(parent)
{
setupUi(this);
leLength->setValidator(new QIntValidator(0, 16384, this));
}
Dot3Protocol::Dot3Protocol(StreamBase *stream, AbstractProtocol *parent)
: AbstractProtocol(stream, parent)
{
configForm = NULL;
}
Dot3Protocol::~Dot3Protocol()
{
delete configForm;
}
AbstractProtocol* Dot3Protocol::createInstance(StreamBase *stream,
@ -76,7 +62,7 @@ QString Dot3Protocol::shortName() const
return QString("802.3");
}
int Dot3Protocol::fieldCount() const
int Dot3Protocol::fieldCount() const
{
return dot3_fieldCount;
}
@ -92,6 +78,7 @@ AbstractProtocol::FieldFlags Dot3Protocol::fieldFlags(int index) const
case dot3_length:
break;
// Meta fields
case dot3_is_override_length:
flags &= ~FrameField;
flags |= MetaField;
@ -207,33 +194,3 @@ int Dot3Protocol::protocolFrameVariableCount() const
{
return protocolFramePayloadVariableCount();
}
QWidget* Dot3Protocol::configWidget()
{
if (configForm == NULL)
{
configForm = new Dot3ConfigForm;
loadConfigWidget();
}
return configForm;
}
void Dot3Protocol::loadConfigWidget()
{
configWidget();
configForm->cbOverrideLength->setChecked(
fieldData(dot3_is_override_length, FieldValue).toBool());
configForm->leLength->setText(
fieldData(dot3_length, FieldValue).toString());
}
void Dot3Protocol::storeConfigWidget()
{
configWidget();
setFieldData(dot3_is_override_length,
configForm->cbOverrideLength->isChecked());
setFieldData(dot3_length,configForm->leLength->text());
}

View File

@ -1,5 +1,5 @@
/*
Copyright (C) 2010 Srivats P.
Copyright (C) 2010-2014 Srivats P.
This file is part of "Ostinato"
@ -21,22 +21,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#define _DOT3_H
#include "abstractprotocol.h"
#include "dot3.pb.h"
#include "ui_dot3.h"
class Dot3ConfigForm : public QWidget, public Ui::dot3
{
Q_OBJECT
public:
Dot3ConfigForm(QWidget *parent = 0);
};
class Dot3Protocol : public AbstractProtocol
{
private:
OstProto::Dot3 data;
Dot3ConfigForm *configForm;
public:
enum Dot3field
{
dot3_length,
@ -47,7 +36,6 @@ private:
dot3_fieldCount
};
public:
Dot3Protocol(StreamBase *stream, AbstractProtocol *parent = 0);
virtual ~Dot3Protocol();
@ -72,9 +60,8 @@ public:
virtual bool isProtocolFrameValueVariable() const;
virtual int protocolFrameVariableCount() const;
virtual QWidget* configWidget();
virtual void loadConfigWidget();
virtual void storeConfigWidget();
private:
OstProto::Dot3 data;
};
#endif

63
common/dot3config.cpp Normal file
View File

@ -0,0 +1,63 @@
/*
Copyright (C) 2010-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/>
*/
#include "dot3config.h"
#include "dot3.h"
#include <QIntValidator>
Dot3ConfigForm::Dot3ConfigForm(QWidget *parent)
: AbstractProtocolConfigForm(parent)
{
setupUi(this);
leLength->setValidator(new QIntValidator(0, 16384, this));
}
Dot3ConfigForm::~Dot3ConfigForm()
{
}
Dot3ConfigForm* Dot3ConfigForm::createInstance()
{
return new Dot3ConfigForm;
}
void Dot3ConfigForm::loadWidget(AbstractProtocol *proto)
{
cbOverrideLength->setChecked(
proto->fieldData(
Dot3Protocol::dot3_is_override_length,
AbstractProtocol::FieldValue
).toBool());
leLength->setText(
proto->fieldData(
Dot3Protocol::dot3_length,
AbstractProtocol::FieldValue
).toString());
}
void Dot3ConfigForm::storeWidget(AbstractProtocol *proto)
{
proto->setFieldData(
Dot3Protocol::dot3_is_override_length,
cbOverrideLength->isChecked());
proto->setFieldData(
Dot3Protocol::dot3_length,
leLength->text());
}

41
common/dot3config.h Normal file
View File

@ -0,0 +1,41 @@
/*
Copyright (C) 2010-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 _DOT3_CONFIG_H
#define _DOT3_CONFIG_H
#include "abstractprotocolconfig.h"
#include "ui_dot3.h"
class Dot3ConfigForm :
public AbstractProtocolConfigForm,
private Ui::dot3
{
Q_OBJECT
public:
Dot3ConfigForm(QWidget *parent = 0);
virtual ~Dot3ConfigForm();
static Dot3ConfigForm* createInstance();
virtual void loadWidget(AbstractProtocol *proto);
virtual void storeWidget(AbstractProtocol *proto);
};
#endif

View File

@ -47,11 +47,11 @@ HEADERS = \
HEADERS += \
mac.h \
payload.h \
dot3.h \
eth2.h \
ip6.h
HEADERS1 += \
dot3.h \
llc.h \
snap.h \
dot2llc.h \
@ -89,11 +89,11 @@ SOURCES = \
SOURCES += \
mac.cpp \
payload.cpp \
dot3.cpp \
eth2.cpp \
ip6.cpp
SOURCES1 += \
dot3.cpp \
llc.cpp \
snap.cpp \
vlan.cpp \

View File

@ -10,11 +10,11 @@ FORMS = \
FORMS += \
mac.ui \
payload.ui \
dot3.ui \
eth2.ui \
ip6.ui \
FORMS1 += \
dot3.ui \
llc.ui \
snap.ui \
vlan.ui \
@ -48,6 +48,7 @@ HEADERS += \
protocolwidgetfactory.h \
macconfig.h \
payloadconfig.h \
dot3config.h \
eth2config.h \
ip6config.h
@ -65,6 +66,7 @@ SOURCES += \
protocolwidgetfactory.cpp \
macconfig.cpp \
payloadconfig.cpp \
dot3config.cpp \
eth2config.cpp \
ip6config.cpp

View File

@ -22,7 +22,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "protocol.pb.h"
#if 0
#include "dot3.h"
#include "llc.h"
#include "snap.h"
#include "dot2llc.h"
@ -47,6 +46,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#else
#include "mac.h"
#include "payload.h"
#include "dot3.h"
#include "eth2.h"
#include "ip6.h"
#endif
@ -59,8 +59,6 @@ ProtocolManager::ProtocolManager()
themselves (once this is done remove the #includes for all the protocols)
*/
#if 0
registerProtocol(OstProto::Protocol::kDot3FieldNumber,
(void*) Dot3Protocol::createInstance);
registerProtocol(OstProto::Protocol::kLlcFieldNumber,
(void*) LlcProtocol::createInstance);
registerProtocol(OstProto::Protocol::kSnapFieldNumber,
@ -116,6 +114,8 @@ ProtocolManager::ProtocolManager()
registerProtocol(OstProto::Protocol::kPayloadFieldNumber,
(void*) PayloadProtocol::createInstance);
registerProtocol(OstProto::Protocol::kDot3FieldNumber,
(void*) Dot3Protocol::createInstance);
registerProtocol(OstProto::Protocol::kEth2FieldNumber,
(void*) Eth2Protocol::createInstance);
registerProtocol(OstProto::Protocol::kIp6FieldNumber,
@ -185,7 +185,8 @@ AbstractProtocol* ProtocolManager::createProtocol(int protoNumber,
Q_ASSERT_X(pc != NULL,
__FUNCTION__,
numberToNameMap.value(protoNumber).toAscii().constData());
QString("No Protocol Creator registered for protocol %1")
.arg(protoNumber).toAscii().constData());
p = (*pc)(stream, parent);

View File

@ -21,6 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "macconfig.h"
#include "payloadconfig.h"
#include "dot3config.h"
#include "eth2config.h"
#include "ip6config.h"
@ -40,6 +41,9 @@ ProtocolWidgetFactory::ProtocolWidgetFactory()
OstProto::Protocol::kPayloadFieldNumber,
(void*) PayloadConfigForm::createInstance);
OstProtocolWidgetFactory->registerProtocolConfigWidget(
OstProto::Protocol::kDot3FieldNumber,
(void*) Dot3ConfigForm::createInstance);
OstProtocolWidgetFactory->registerProtocolConfigWidget(
OstProto::Protocol::kEth2FieldNumber,
(void*) Eth2ConfigForm::createInstance);