NOX: HexDumpProtocol - separated protocol and widget as per new framework
This commit is contained in:
parent
bacee5dd18
commit
88ec853d09
@ -20,35 +20,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
#include "hexdump.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)
|
||||
: 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());
|
||||
}
|
||||
|
||||
|
@ -20,10 +20,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
#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
|
||||
|
75
common/hexdumpconfig.cpp
Normal file
75
common/hexdumpconfig.cpp
Normal 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
44
common/hexdumpconfig.h
Normal 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
|
@ -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.*
|
||||
|
@ -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.*
|
||||
|
||||
|
@ -23,7 +23,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
#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 <http://www.gnu.org/licenses/>
|
||||
#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();
|
||||
}
|
||||
|
@ -46,6 +46,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
#include "udpconfig.h"
|
||||
// L5 Protocol Widgets
|
||||
#include "textprotoconfig.h"
|
||||
// Special Protocol Widgets
|
||||
#include "hexdumpconfig.h"
|
||||
|
||||
ProtocolWidgetFactory *OstProtocolWidgetFactory;
|
||||
QMap<int, void*> 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()
|
||||
|
Loading…
Reference in New Issue
Block a user