NOX: SNAP - Separated protocl and widget as per new framework

This commit is contained in:
Srivats P. 2014-03-27 09:56:57 +05:30
parent 4608edf771
commit 38c17d5e5b
9 changed files with 148 additions and 73 deletions

View File

@ -78,6 +78,20 @@ public:
{
// Do nothing!
}
/*!
Convenience Method - can be used by storeConfigWidget() implementations
*/
uint hexStrToUInt(QString text, bool *ok=NULL)
{
bool isOk;
uint a_uint = text.remove(QChar(' ')).toUInt(&isOk, 16);
if (ok)
*ok = isOk;
return a_uint;
}
};
#endif

View File

@ -54,10 +54,10 @@ HEADERS += \
dot3.h \
llc.h \
dot2llc.h \
snap.h \
ip6.h
HEADERS1 += \
snap.h \
dot2snap.h \
arp.h \
ip4.h \
@ -94,10 +94,10 @@ SOURCES += \
eth2.cpp \
dot3.cpp \
llc.cpp \
snap.cpp \
ip6.cpp
SOURCES1 += \
snap.cpp \
arp.cpp \
ip4.cpp \
icmp.cpp \

View File

@ -14,10 +14,10 @@ FORMS += \
eth2.ui \
dot3.ui \
llc.ui \
snap.ui \
ip6.ui \
FORMS1 += \
snap.ui \
arp.ui \
ip4.ui \
icmp.ui \
@ -56,6 +56,7 @@ HEADERS += \
dot3config.h \
llcconfig.h \
dot2llcconfig.h \
snapconfig.h \
ip6config.h
SOURCES += \
@ -76,6 +77,7 @@ SOURCES += \
eth2config.cpp \
dot3config.cpp \
llcconfig.cpp \
snapconfig.cpp \
ip6config.cpp
QMAKE_DISTCLEAN += object_script.*

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 "snap.h"
#include "dot2snap.h"
#include "arp.h"
#include "ip4.h"
@ -48,6 +47,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "dot3.h"
#include "llc.h"
#include "dot2llc.h"
#include "snap.h"
#include "eth2.h"
#include "ip6.h"
#endif
@ -60,8 +60,6 @@ ProtocolManager::ProtocolManager()
themselves (once this is done remove the #includes for all the protocols)
*/
#if 0
registerProtocol(OstProto::Protocol::kSnapFieldNumber,
(void*) SnapProtocol::createInstance);
registerProtocol(OstProto::Protocol::kDot2SnapFieldNumber,
(void*) Dot2SnapProtocol::createInstance);
@ -119,6 +117,8 @@ ProtocolManager::ProtocolManager()
(void*) LlcProtocol::createInstance);
registerProtocol(OstProto::Protocol::kDot2LlcFieldNumber,
(void*) Dot2LlcProtocol::createInstance);
registerProtocol(OstProto::Protocol::kSnapFieldNumber,
(void*) SnapProtocol::createInstance);
registerProtocol(OstProto::Protocol::kIp6FieldNumber,
(void*) Ip6Protocol::createInstance);

View File

@ -28,6 +28,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "dot3config.h"
#include "llcconfig.h"
#include "dot2llcconfig.h"
#include "snapconfig.h"
#include "ip6config.h"
ProtocolWidgetFactory *OstProtocolWidgetFactory;
@ -68,6 +69,9 @@ ProtocolWidgetFactory::ProtocolWidgetFactory()
OstProtocolWidgetFactory->registerProtocolConfigWidget(
OstProto::Protocol::kDot2LlcFieldNumber,
(void*) Dot2LlcConfigForm::createInstance);
OstProtocolWidgetFactory->registerProtocolConfigWidget(
OstProto::Protocol::kSnapFieldNumber,
(void*) SnapConfigForm::createInstance);
OstProtocolWidgetFactory->registerProtocolConfigWidget(
OstProto::Protocol::kIp6FieldNumber,

View File

@ -17,28 +17,17 @@ 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 <qendian.h>
#include <QHostAddress>
#include "snap.h"
quint32 kStdOui = 0x000000;
SnapConfigForm::SnapConfigForm(QWidget *parent)
: QWidget(parent)
{
setupUi(this);
}
SnapProtocol::SnapProtocol(StreamBase *stream, AbstractProtocol *parent)
: AbstractProtocol(stream, parent)
{
configForm = NULL;
}
SnapProtocol::~SnapProtocol()
{
delete configForm;
}
AbstractProtocol* SnapProtocol::createInstance(StreamBase *stream,
@ -264,44 +253,3 @@ bool SnapProtocol::setFieldData(int index, const QVariant &value,
return isOk;
}
QWidget* SnapProtocol::configWidget()
{
if (configForm == NULL)
{
configForm = new SnapConfigForm;
loadConfigWidget();
}
return configForm;
}
void SnapProtocol::loadConfigWidget()
{
configWidget();
configForm->cbOverrideOui->setChecked(
fieldData(snap_is_override_oui, FieldValue).toBool());
configForm->leOui->setText(uintToHexStr(
fieldData(snap_oui, FieldValue).toUInt(), 3));
configForm->cbOverrideType->setChecked(
fieldData(snap_is_override_type, FieldValue).toBool());
configForm->leType->setText(uintToHexStr(
fieldData(snap_type, FieldValue).toUInt(), 2));
}
void SnapProtocol::storeConfigWidget()
{
bool isOk;
configWidget();
setFieldData(snap_is_override_oui,
configForm->cbOverrideOui->isChecked());
setFieldData(snap_oui, configForm->leOui->text().remove(QChar(' '))
.toUInt(&isOk, BASE_HEX));
setFieldData(snap_is_override_type,
configForm->cbOverrideType->isChecked());
setFieldData(snap_type, configForm->leType->text().remove(QChar(' '))
.toUInt(&isOk, BASE_HEX));
}

View File

@ -23,20 +23,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "abstractprotocol.h"
#include "snap.pb.h"
#include "ui_snap.h"
class SnapConfigForm : public QWidget, public Ui::snap
{
Q_OBJECT
public:
SnapConfigForm(QWidget *parent = 0);
};
class SnapProtocol : public AbstractProtocol
{
private:
OstProto::Snap data;
SnapConfigForm *configForm;
public:
enum snapfield
{
snap_oui = 0,
@ -49,7 +39,6 @@ private:
snap_fieldCount
};
public:
SnapProtocol(StreamBase *stream, AbstractProtocol *parent = 0);
virtual ~SnapProtocol();
@ -74,9 +63,8 @@ public:
virtual bool setFieldData(int index, const QVariant &value,
FieldAttrib attrib = FieldValue);
virtual QWidget* configWidget();
virtual void loadConfigWidget();
virtual void storeConfigWidget();
private:
OstProto::Snap data;
};
#endif

78
common/snapconfig.cpp Normal file
View File

@ -0,0 +1,78 @@
/*
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/>
*/
#include "snapconfig.h"
#include "snap.h"
SnapConfigForm::SnapConfigForm(QWidget *parent)
: AbstractProtocolConfigForm(parent)
{
setupUi(this);
}
SnapConfigForm::~SnapConfigForm()
{
}
SnapConfigForm* SnapConfigForm::createInstance()
{
return new SnapConfigForm;
}
void SnapConfigForm::loadWidget(AbstractProtocol *proto)
{
cbOverrideOui->setChecked(
proto->fieldData(
SnapProtocol::snap_is_override_oui,
AbstractProtocol::FieldValue
).toBool());
leOui->setText(uintToHexStr(
proto->fieldData(
SnapProtocol::snap_oui,
AbstractProtocol::FieldValue
).toUInt(), 3));
cbOverrideType->setChecked(
proto->fieldData(
SnapProtocol::snap_is_override_type,
AbstractProtocol::FieldValue
).toBool());
leType->setText(uintToHexStr(
proto->fieldData(
SnapProtocol::snap_type,
AbstractProtocol::FieldValue
).toUInt(), 2));
}
void SnapConfigForm::storeWidget(AbstractProtocol *proto)
{
proto->setFieldData(
SnapProtocol::snap_is_override_oui,
cbOverrideOui->isChecked());
proto->setFieldData(
SnapProtocol::snap_oui,
hexStrToUInt(leOui->text()));
proto->setFieldData(
SnapProtocol::snap_is_override_type,
cbOverrideType->isChecked());
proto->setFieldData(
SnapProtocol::snap_type,
hexStrToUInt(leType->text()));
}

41
common/snapconfig.h Normal file
View File

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