From 38c17d5e5bcc87c25dfb5a369bcb782cacf63d64 Mon Sep 17 00:00:00 2001 From: "Srivats P." Date: Thu, 27 Mar 2014 09:56:57 +0530 Subject: [PATCH] NOX: SNAP - Separated protocl and widget as per new framework --- common/abstractprotocolconfig.h | 14 ++++++ common/ostproto.pro | 4 +- common/ostprotogui.pro | 4 +- common/protocolmanager.cpp | 6 +-- common/protocolwidgetfactory.cpp | 4 ++ common/snap.cpp | 52 --------------------- common/snap.h | 18 ++------ common/snapconfig.cpp | 78 ++++++++++++++++++++++++++++++++ common/snapconfig.h | 41 +++++++++++++++++ 9 files changed, 148 insertions(+), 73 deletions(-) create mode 100644 common/snapconfig.cpp create mode 100644 common/snapconfig.h diff --git a/common/abstractprotocolconfig.h b/common/abstractprotocolconfig.h index e6023ec..ba2f9b7 100644 --- a/common/abstractprotocolconfig.h +++ b/common/abstractprotocolconfig.h @@ -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 diff --git a/common/ostproto.pro b/common/ostproto.pro index 63524f4..5840244 100644 --- a/common/ostproto.pro +++ b/common/ostproto.pro @@ -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 \ diff --git a/common/ostprotogui.pro b/common/ostprotogui.pro index 7a90fe4..2d6efc8 100644 --- a/common/ostprotogui.pro +++ b/common/ostprotogui.pro @@ -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.* diff --git a/common/protocolmanager.cpp b/common/protocolmanager.cpp index d385d0e..fb06818 100644 --- a/common/protocolmanager.cpp +++ b/common/protocolmanager.cpp @@ -22,7 +22,6 @@ along with this program. If not, see #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 #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); diff --git a/common/protocolwidgetfactory.cpp b/common/protocolwidgetfactory.cpp index e3bf662..1f153c7 100644 --- a/common/protocolwidgetfactory.cpp +++ b/common/protocolwidgetfactory.cpp @@ -28,6 +28,7 @@ along with this program. If not, see #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, diff --git a/common/snap.cpp b/common/snap.cpp index bdb80c3..6e7e7cc 100644 --- a/common/snap.cpp +++ b/common/snap.cpp @@ -17,28 +17,17 @@ You should have received a copy of the GNU General Public License along with this program. If not, see */ -#include -#include - #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)); -} diff --git a/common/snap.h b/common/snap.h index daba802..bf3a349 100644 --- a/common/snap.h +++ b/common/snap.h @@ -23,20 +23,10 @@ along with this program. If not, see #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 diff --git a/common/snapconfig.cpp b/common/snapconfig.cpp new file mode 100644 index 0000000..e594b57 --- /dev/null +++ b/common/snapconfig.cpp @@ -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 +*/ + +#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())); +} diff --git a/common/snapconfig.h b/common/snapconfig.h new file mode 100644 index 0000000..9d230e3 --- /dev/null +++ b/common/snapconfig.h @@ -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 +*/ + +#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