NOX: HexDumpProtocol - separated protocol and widget as per new framework

This commit is contained in:
Srivats P. 2014-04-22 06:03:40 +05:30
parent bacee5dd18
commit 88ec853d09
8 changed files with 154 additions and 91 deletions

View File

@ -20,35 +20,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "hexdump.h" #include "hexdump.h"
#include "streambase.h" #include "streambase.h"
#include <qendian.h>
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) HexDumpProtocol::HexDumpProtocol(StreamBase *stream, AbstractProtocol *parent)
: AbstractProtocol(stream, parent) : AbstractProtocol(stream, parent)
{ {
/* The configWidget is created lazily */
configForm = NULL;
} }
HexDumpProtocol::~HexDumpProtocol() HexDumpProtocol::~HexDumpProtocol()
{ {
delete configForm;
} }
AbstractProtocol* HexDumpProtocol::createInstance(StreamBase *stream, AbstractProtocol* HexDumpProtocol::createInstance(StreamBase *stream,
@ -231,33 +209,3 @@ int HexDumpProtocol::protocolFrameSize(int streamIndex) const
return len; 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());
}

View File

@ -20,10 +20,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#ifndef _HEXDUMP_H #ifndef _HEXDUMP_H
#define _HEXDUMP_H #define _HEXDUMP_H
#include "hexdump.pb.h"
#include "ui_hexdump.h"
#include "abstractprotocol.h" #include "abstractprotocol.h"
#include "hexdump.pb.h"
/* /*
HexDump Protocol Frame Format - 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 class HexDumpProtocol : public AbstractProtocol
{ {
public: public:
enum hexDumpfield
{
// Frame Fields
hexDump_content = 0,
// Meta Fields
hexDump_pad_until_end,
hexDump_fieldCount
};
HexDumpProtocol(StreamBase *stream, AbstractProtocol *parent = 0); HexDumpProtocol(StreamBase *stream, AbstractProtocol *parent = 0);
virtual ~HexDumpProtocol(); virtual ~HexDumpProtocol();
@ -68,22 +67,7 @@ public:
virtual int protocolFrameSize(int streamIndex = 0) const; virtual int protocolFrameSize(int streamIndex = 0) const;
virtual QWidget* configWidget();
virtual void loadConfigWidget();
virtual void storeConfigWidget();
private: private:
OstProto::HexDump data; OstProto::HexDump data;
HexDumpConfigForm *configForm;
enum hexDumpfield
{
// Frame Fields
hexDump_content = 0,
// Meta Fields
hexDump_pad_until_end,
hexDump_fieldCount
};
}; };
#endif #endif

75
common/hexdumpconfig.cpp Normal file
View File

@ -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 <http://www.gnu.org/licenses/>
*/
#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"));
}

44
common/hexdumpconfig.h Normal file
View File

@ -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 <http://www.gnu.org/licenses/>
*/
#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

View File

@ -69,11 +69,11 @@ HEADERS += \
mld.h \ mld.h \
tcp.h \ tcp.h \
udp.h \ udp.h \
textproto.h textproto.h \
hexdump.h
HEADERS1 += \ HEADERS1 += \
userscript.h \ userscript.h \
hexdump.h \
sample.h sample.h
SOURCES = \ SOURCES = \
@ -102,11 +102,11 @@ SOURCES += \
mld.cpp \ mld.cpp \
tcp.cpp \ tcp.cpp \
udp.cpp \ udp.cpp \
textproto.cpp textproto.cpp \
hexdump.cpp
SOURCES1 += \ SOURCES1 += \
userscript.cpp \ userscript.cpp \
hexdump.cpp \
sample.cpp sample.cpp
QMAKE_DISTCLEAN += object_script.* QMAKE_DISTCLEAN += object_script.*

View File

@ -1,6 +1,7 @@
TEMPLATE = lib TEMPLATE = lib
CONFIG += qt staticlib CONFIG += qt staticlib
QT += network xml QT += network xml
INCLUDEPATH += "../extra/qhexedit2/src"
LIBS += \ LIBS += \
-lprotobuf -lprotobuf
@ -22,11 +23,11 @@ FORMS += \
icmp.ui \ icmp.ui \
tcp.ui \ tcp.ui \
udp.ui \ udp.ui \
textproto.ui textproto.ui \
hexdump.ui
FORMS1 += \ FORMS1 += \
userscript.ui \ userscript.ui \
hexdump.ui \
sample.ui sample.ui
PROTOS = \ PROTOS = \
@ -70,7 +71,8 @@ HEADERS += \
mldconfig.h \ mldconfig.h \
tcpconfig.h \ tcpconfig.h \
udpconfig.h \ udpconfig.h \
textprotoconfig.h textprotoconfig.h \
hexdumpconfig.h
SOURCES += \ SOURCES += \
ostprotolib.cpp \ ostprotolib.cpp \
@ -100,7 +102,8 @@ SOURCES += \
mldconfig.cpp \ mldconfig.cpp \
tcpconfig.cpp \ tcpconfig.cpp \
udpconfig.cpp \ udpconfig.cpp \
textprotoconfig.cpp textprotoconfig.cpp \
hexdumpconfig.cpp
QMAKE_DISTCLEAN += object_script.* QMAKE_DISTCLEAN += object_script.*

View File

@ -23,7 +23,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "protocol.pb.h" #include "protocol.pb.h"
#if 0 #if 0
#include "userscript.h" #include "userscript.h"
#include "hexdump.h"
#include "sample.h" #include "sample.h"
#else #else
#include "mac.h" #include "mac.h"
@ -53,6 +52,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "udp.h" #include "udp.h"
// L5 Protos // L5 Protos
#include "textproto.h" #include "textproto.h"
// Special Protos
#include "hexdump.h"
#endif #endif
ProtocolManager *OstProtocolManager; ProtocolManager *OstProtocolManager;
@ -63,9 +64,6 @@ ProtocolManager::ProtocolManager()
themselves (once this is done remove the #includes for all the protocols) themselves (once this is done remove the #includes for all the protocols)
*/ */
#if 0 #if 0
registerProtocol(OstProto::Protocol::kHexDumpFieldNumber,
(void*) HexDumpProtocol::createInstance);
registerProtocol(OstProto::Protocol::kUserScriptFieldNumber, registerProtocol(OstProto::Protocol::kUserScriptFieldNumber,
(void*) UserScriptProtocol::createInstance); (void*) UserScriptProtocol::createInstance);
registerProtocol(OstProto::Protocol::kSampleFieldNumber, registerProtocol(OstProto::Protocol::kSampleFieldNumber,
@ -129,6 +127,10 @@ ProtocolManager::ProtocolManager()
registerProtocol(OstProto::Protocol::kTextProtocolFieldNumber, registerProtocol(OstProto::Protocol::kTextProtocolFieldNumber,
(void*) TextProtocol::createInstance); (void*) TextProtocol::createInstance);
// Special Protocols
registerProtocol(OstProto::Protocol::kHexDumpFieldNumber,
(void*) HexDumpProtocol::createInstance);
#endif #endif
populateNeighbourProtocols(); populateNeighbourProtocols();
} }

View File

@ -46,6 +46,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "udpconfig.h" #include "udpconfig.h"
// L5 Protocol Widgets // L5 Protocol Widgets
#include "textprotoconfig.h" #include "textprotoconfig.h"
// Special Protocol Widgets
#include "hexdumpconfig.h"
ProtocolWidgetFactory *OstProtocolWidgetFactory; ProtocolWidgetFactory *OstProtocolWidgetFactory;
QMap<int, void*> ProtocolWidgetFactory::configWidgetFactory; QMap<int, void*> ProtocolWidgetFactory::configWidgetFactory;
@ -137,6 +139,11 @@ ProtocolWidgetFactory::ProtocolWidgetFactory()
OstProtocolWidgetFactory->registerProtocolConfigWidget( OstProtocolWidgetFactory->registerProtocolConfigWidget(
OstProto::Protocol::kTextProtocolFieldNumber, OstProto::Protocol::kTextProtocolFieldNumber,
(void*) TextProtocolConfigForm::createInstance); (void*) TextProtocolConfigForm::createInstance);
// Special Protocols
OstProtocolWidgetFactory->registerProtocolConfigWidget(
OstProto::Protocol::kHexDumpFieldNumber,
(void*) HexDumpConfigForm::createInstance);
} }
ProtocolWidgetFactory::~ProtocolWidgetFactory() ProtocolWidgetFactory::~ProtocolWidgetFactory()