From 88ec853d096d700e60f08f02d7b2d7fbd9f2930a Mon Sep 17 00:00:00 2001 From: "Srivats P." Date: Tue, 22 Apr 2014 06:03:40 +0530 Subject: [PATCH] NOX: HexDumpProtocol - separated protocol and widget as per new framework --- common/hexdump.cpp | 52 ---------------------- common/hexdump.h | 38 +++++----------- common/hexdumpconfig.cpp | 75 ++++++++++++++++++++++++++++++++ common/hexdumpconfig.h | 44 +++++++++++++++++++ common/ostproto.pro | 8 ++-- common/ostprotogui.pro | 11 +++-- common/protocolmanager.cpp | 10 +++-- common/protocolwidgetfactory.cpp | 7 +++ 8 files changed, 154 insertions(+), 91 deletions(-) create mode 100644 common/hexdumpconfig.cpp create mode 100644 common/hexdumpconfig.h diff --git a/common/hexdump.cpp b/common/hexdump.cpp index f579430..376ccf0 100644 --- a/common/hexdump.cpp +++ b/common/hexdump.cpp @@ -20,35 +20,13 @@ along with this program. If not, see #include "hexdump.h" #include "streambase.h" -#include - -HexDumpConfigForm::HexDumpConfigForm(QWidget *parent) - : QWidget(parent) -{ - setupUi(this); - - hexEdit->setFont(QFont("Courier")); - hexEdit->setOverwriteMode(false); -} - -void HexDumpConfigForm::on_hexEdit_overwriteModeChanged(bool isOverwriteMode) -{ - if (isOverwriteMode) - mode->setText(tr("Ovr")); - else - mode->setText(tr("Ins")); -} - HexDumpProtocol::HexDumpProtocol(StreamBase *stream, AbstractProtocol *parent) : AbstractProtocol(stream, parent) { - /* The configWidget is created lazily */ - configForm = NULL; } HexDumpProtocol::~HexDumpProtocol() { - delete configForm; } AbstractProtocol* HexDumpProtocol::createInstance(StreamBase *stream, @@ -231,33 +209,3 @@ int HexDumpProtocol::protocolFrameSize(int streamIndex) const return len; } -QWidget* HexDumpProtocol::configWidget() -{ - /* Lazy creation of the configWidget */ - if (configForm == NULL) - { - configForm = new HexDumpConfigForm; - loadConfigWidget(); - } - - return configForm; -} - -void HexDumpProtocol::loadConfigWidget() -{ - configWidget(); - - configForm->hexEdit->setData( - fieldData(hexDump_content, FieldValue).toByteArray()); - configForm->padUntilEnd->setChecked( - fieldData(hexDump_pad_until_end, FieldValue).toBool()); -} - -void HexDumpProtocol::storeConfigWidget() -{ - configWidget(); - - setFieldData(hexDump_content, configForm->hexEdit->data()); - setFieldData(hexDump_pad_until_end, configForm->padUntilEnd->isChecked()); -} - diff --git a/common/hexdump.h b/common/hexdump.h index f5b6932..4318192 100644 --- a/common/hexdump.h +++ b/common/hexdump.h @@ -20,10 +20,8 @@ along with this program. If not, see #ifndef _HEXDUMP_H #define _HEXDUMP_H -#include "hexdump.pb.h" -#include "ui_hexdump.h" - #include "abstractprotocol.h" +#include "hexdump.pb.h" /* HexDump Protocol Frame Format - @@ -33,18 +31,19 @@ HexDump Protocol Frame Format - +---------+---------+ */ -class HexDumpConfigForm : public QWidget, public Ui::HexDump -{ - Q_OBJECT -public: - HexDumpConfigForm(QWidget *parent = 0); -private slots: - void on_hexEdit_overwriteModeChanged(bool isOverwriteMode); -}; - class HexDumpProtocol : public AbstractProtocol { public: + enum hexDumpfield + { + // Frame Fields + hexDump_content = 0, + + // Meta Fields + hexDump_pad_until_end, + + hexDump_fieldCount + }; HexDumpProtocol(StreamBase *stream, AbstractProtocol *parent = 0); virtual ~HexDumpProtocol(); @@ -68,22 +67,7 @@ public: virtual int protocolFrameSize(int streamIndex = 0) const; - virtual QWidget* configWidget(); - virtual void loadConfigWidget(); - virtual void storeConfigWidget(); - private: OstProto::HexDump data; - HexDumpConfigForm *configForm; - enum hexDumpfield - { - // Frame Fields - hexDump_content = 0, - - // Meta Fields - hexDump_pad_until_end, - - hexDump_fieldCount - }; }; #endif diff --git a/common/hexdumpconfig.cpp b/common/hexdumpconfig.cpp new file mode 100644 index 0000000..1c057b6 --- /dev/null +++ b/common/hexdumpconfig.cpp @@ -0,0 +1,75 @@ +/* +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 "hexdumpconfig.h" +#include "hexdump.h" + +HexDumpConfigForm::HexDumpConfigForm(QWidget *parent) + : AbstractProtocolConfigForm(parent) +{ + setupUi(this); + + hexEdit->setFont(QFont("Courier")); + hexEdit->setOverwriteMode(false); +} + +HexDumpConfigForm::~HexDumpConfigForm() +{ +} + +HexDumpConfigForm* HexDumpConfigForm::createInstance() +{ + return new HexDumpConfigForm; +} + +void HexDumpConfigForm::loadWidget(AbstractProtocol *proto) +{ + hexEdit->setData( + proto->fieldData( + HexDumpProtocol::hexDump_content, + AbstractProtocol::FieldValue + ).toByteArray()); + padUntilEnd->setChecked( + proto->fieldData( + HexDumpProtocol::hexDump_pad_until_end, + AbstractProtocol::FieldValue + ).toBool()); +} + +void HexDumpConfigForm::storeWidget(AbstractProtocol *proto) +{ + proto->setFieldData( + HexDumpProtocol::hexDump_content, + hexEdit->data()); + proto->setFieldData( + HexDumpProtocol::hexDump_pad_until_end, + padUntilEnd->isChecked()); +} + +// +// ------------ private slots +// +void HexDumpConfigForm::on_hexEdit_overwriteModeChanged(bool isOverwriteMode) +{ + if (isOverwriteMode) + mode->setText(tr("Ovr")); + else + mode->setText(tr("Ins")); +} + diff --git a/common/hexdumpconfig.h b/common/hexdumpconfig.h new file mode 100644 index 0000000..b0dcfa7 --- /dev/null +++ b/common/hexdumpconfig.h @@ -0,0 +1,44 @@ +/* +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 _HEX_DUMP_CONFIG_H +#define _HEX_DUMP_CONFIG_H + +#include "abstractprotocolconfig.h" +#include "ui_hexdump.h" + +class HexDumpConfigForm : + public AbstractProtocolConfigForm, + private Ui::HexDump +{ + Q_OBJECT +public: + HexDumpConfigForm(QWidget *parent = 0); + virtual ~HexDumpConfigForm(); + + static HexDumpConfigForm* createInstance(); + + virtual void loadWidget(AbstractProtocol *proto); + virtual void storeWidget(AbstractProtocol *proto); + +private slots: + void on_hexEdit_overwriteModeChanged(bool isOverwriteMode); +}; + +#endif diff --git a/common/ostproto.pro b/common/ostproto.pro index c69e4e0..7497d0c 100644 --- a/common/ostproto.pro +++ b/common/ostproto.pro @@ -69,11 +69,11 @@ HEADERS += \ mld.h \ tcp.h \ udp.h \ - textproto.h + textproto.h \ + hexdump.h HEADERS1 += \ userscript.h \ - hexdump.h \ sample.h SOURCES = \ @@ -102,11 +102,11 @@ SOURCES += \ mld.cpp \ tcp.cpp \ udp.cpp \ - textproto.cpp + textproto.cpp \ + hexdump.cpp SOURCES1 += \ userscript.cpp \ - hexdump.cpp \ sample.cpp QMAKE_DISTCLEAN += object_script.* diff --git a/common/ostprotogui.pro b/common/ostprotogui.pro index 98596bc..3eab07e 100644 --- a/common/ostprotogui.pro +++ b/common/ostprotogui.pro @@ -1,6 +1,7 @@ TEMPLATE = lib CONFIG += qt staticlib QT += network xml +INCLUDEPATH += "../extra/qhexedit2/src" LIBS += \ -lprotobuf @@ -22,11 +23,11 @@ FORMS += \ icmp.ui \ tcp.ui \ udp.ui \ - textproto.ui + textproto.ui \ + hexdump.ui FORMS1 += \ userscript.ui \ - hexdump.ui \ sample.ui PROTOS = \ @@ -70,7 +71,8 @@ HEADERS += \ mldconfig.h \ tcpconfig.h \ udpconfig.h \ - textprotoconfig.h + textprotoconfig.h \ + hexdumpconfig.h SOURCES += \ ostprotolib.cpp \ @@ -100,7 +102,8 @@ SOURCES += \ mldconfig.cpp \ tcpconfig.cpp \ udpconfig.cpp \ - textprotoconfig.cpp + textprotoconfig.cpp \ + hexdumpconfig.cpp QMAKE_DISTCLEAN += object_script.* diff --git a/common/protocolmanager.cpp b/common/protocolmanager.cpp index 8649dc9..beda573 100644 --- a/common/protocolmanager.cpp +++ b/common/protocolmanager.cpp @@ -23,7 +23,6 @@ along with this program. If not, see #include "protocol.pb.h" #if 0 #include "userscript.h" -#include "hexdump.h" #include "sample.h" #else #include "mac.h" @@ -53,6 +52,8 @@ along with this program. If not, see #include "udp.h" // L5 Protos #include "textproto.h" +// Special Protos +#include "hexdump.h" #endif ProtocolManager *OstProtocolManager; @@ -63,9 +64,6 @@ ProtocolManager::ProtocolManager() themselves (once this is done remove the #includes for all the protocols) */ #if 0 - registerProtocol(OstProto::Protocol::kHexDumpFieldNumber, - (void*) HexDumpProtocol::createInstance); - registerProtocol(OstProto::Protocol::kUserScriptFieldNumber, (void*) UserScriptProtocol::createInstance); registerProtocol(OstProto::Protocol::kSampleFieldNumber, @@ -129,6 +127,10 @@ ProtocolManager::ProtocolManager() registerProtocol(OstProto::Protocol::kTextProtocolFieldNumber, (void*) TextProtocol::createInstance); + // Special Protocols + registerProtocol(OstProto::Protocol::kHexDumpFieldNumber, + (void*) HexDumpProtocol::createInstance); + #endif populateNeighbourProtocols(); } diff --git a/common/protocolwidgetfactory.cpp b/common/protocolwidgetfactory.cpp index 8c59eb4..927c565 100644 --- a/common/protocolwidgetfactory.cpp +++ b/common/protocolwidgetfactory.cpp @@ -46,6 +46,8 @@ along with this program. If not, see #include "udpconfig.h" // L5 Protocol Widgets #include "textprotoconfig.h" +// Special Protocol Widgets +#include "hexdumpconfig.h" ProtocolWidgetFactory *OstProtocolWidgetFactory; QMap ProtocolWidgetFactory::configWidgetFactory; @@ -137,6 +139,11 @@ ProtocolWidgetFactory::ProtocolWidgetFactory() OstProtocolWidgetFactory->registerProtocolConfigWidget( OstProto::Protocol::kTextProtocolFieldNumber, (void*) TextProtocolConfigForm::createInstance); + + // Special Protocols + OstProtocolWidgetFactory->registerProtocolConfigWidget( + OstProto::Protocol::kHexDumpFieldNumber, + (void*) HexDumpConfigForm::createInstance); } ProtocolWidgetFactory::~ProtocolWidgetFactory()