NOX: Framework to separate the protocol widgets from the protocol. Changes in client to use the new framework. Changes may not compile

This commit is contained in:
Srivats P. 2014-03-11 06:16:41 +05:30
parent 925697dfcc
commit cabd6ad096
17 changed files with 441 additions and 150 deletions

View File

@ -20,6 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "mainwindow.h"
#include "../common/ostprotolib.h"
#include "../common/protocolmanager.h"
#include "../common/protocolwidgetfactory.h"
#include "settings.h"
#include <QApplication>
@ -31,6 +32,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
extern const char* version;
extern const char* revision;
extern ProtocolManager *OstProtocolManager;
extern ProtocolWidgetFactory *OstProtocolWidgetFactory;
QSettings *appSettings;
QMainWindow *mainWindow;
@ -58,6 +60,7 @@ int main(int argc, char* argv[])
app.setProperty("revision", revision);
OstProtocolManager = new ProtocolManager();
OstProtocolWidgetFactory = new ProtocolWidgetFactory();
/* (Portable Mode) If we have a .ini file in the same directory as the
executable, we use that instead of the platform specific location

View File

@ -100,14 +100,21 @@ MainWindow::MainWindow(QWidget *parent)
MainWindow::~MainWindow()
{
delete pgl;
#ifdef Q_OS_WIN32
//! \todo - find a way to terminate cleanly
localServer_->kill();
#else
localServer_->terminate();
localServer_->waitForFinished();
delete localServer_;
#endif
delete pgl;
QByteArray layout = saveState(0);
appSettings->setValue(kApplicationWindowLayout, layout);
appSettings->setValue(kApplicationWindowGeometryKey, geometry());
localServer_->waitForFinished();
delete localServer_;
}
void MainWindow::on_actionPreferences_triggered()

View File

@ -7,22 +7,27 @@ QT += network script xml
INCLUDEPATH += "../rpc/" "../common/"
win32 {
CONFIG(debug, debug|release) {
LIBS += -L"../common/debug" -lostproto
LIBS += -L"../common/debug" -lostprotogui -lostproto
LIBS += -L"../rpc/debug" -lpbrpc
POST_TARGETDEPS += \
"../common/debug/libostprotogui.a" \
"../common/debug/libostproto.a" \
"../rpc/debug/libpbrpc.a"
} else {
LIBS += -L"../common/release" -lostproto
LIBS += -L"../common/release" -lostprotogui -lostproto
LIBS += -L"../rpc/release" -lpbrpc
POST_TARGETDEPS += \
"../common/release/libostprotogui.a" \
"../common/release/libostproto.a" \
"../rpc/release/libpbrpc.a"
}
} else {
LIBS += -L"../common" -lostproto
LIBS += -L"../common" -lostprotogui -lostproto
LIBS += -L"../rpc" -lpbrpc
POST_TARGETDEPS += "../common/libostproto.a" "../rpc/libpbrpc.a"
POST_TARGETDEPS += \
"../common/libostprotogui.a" \
"../common/libostproto.a" \
"../rpc/libpbrpc.a"
}
LIBS += -lprotobuf
LIBS += -L"../extra/qhexedit2/$(OBJECTS_DIR)/" -lqhexedit2

View File

@ -17,11 +17,14 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
/*!
* \todo Remove this class
*/
#include <qendian.h>
#include <QHostAddress>
#include "stream.h"
//#include "../common/protocollist.h"
#include "../common/protocollistiterator.h"
#include "../common/abstractprotocol.h"
@ -37,43 +40,12 @@ Stream::~Stream()
void Stream::loadProtocolWidgets()
{
#if 0
//protocols.loadConfigWidgets();
foreach(AbstractProtocol* proto, *currentFrameProtocols)
{
proto->loadConfigWidget();
}
#else
ProtocolListIterator *iter;
iter = createProtocolListIterator();
while (iter->hasNext())
{
AbstractProtocol* p = iter->next();
p->loadConfigWidget();
}
delete iter;
#endif
qWarning("%s: DOES NOTHING", __PRETTY_FUNCTION__);
return;
}
void Stream::storeProtocolWidgets()
{
#if 0
//protocols.storeConfigWidgets();
foreach(const AbstractProtocol* proto, frameProtocol())
{
proto->storeConfigWidget();
_iter->toFront();
}
#else
ProtocolListIterator *iter;
iter = createProtocolListIterator();
while (iter->hasNext())
{
AbstractProtocol* p = iter->next();
p->storeConfigWidget();
}
delete iter;
#endif
qWarning("%s: DOES NOTHING", __PRETTY_FUNCTION__);
return;
}

View File

@ -22,13 +22,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "streamconfigdialog.h"
#include "stream.h"
#include "abstractprotocol.h"
#include "abstractprotocolconfig.h"
#include "protocollistiterator.h"
#include "modeltest.h"
// FIXME(HI) - remove
#include "../common/protocolmanager.h"
#include "../common/protocolwidgetfactory.h"
extern ProtocolManager *OstProtocolManager;
extern ProtocolWidgetFactory *OstProtocolWidgetFactory;
QRect StreamConfigDialog::lastGeometry;
int StreamConfigDialog::lastTopLevelTabIndex = 0;
@ -83,6 +86,7 @@ StreamConfigDialog::StreamConfigDialog(Port &port, uint streamIndex,
connect(rbL4Other, SIGNAL(toggled(bool)), rbPayloadOther, SLOT(setChecked(bool)));
connect(rbL4Other, SIGNAL(toggled(bool)), gbPayloadProto, SLOT(setDisabled(bool)));
#if 1 // temp mask
// Setup valid subsequent protocols for L2 to L4 protocols
for (int i = ProtoL2; i <= ProtoL4; i++)
{
@ -129,6 +133,7 @@ StreamConfigDialog::StreamConfigDialog(Port &port, uint streamIndex,
}
}
}
#endif
mpAvailableProtocolsModel = new QStringListModel(
OstProtocolManager->protocolDatabase(), this);
@ -306,10 +311,60 @@ StreamConfigDialog::~StreamConfigDialog()
for (int i = ProtoMin; i < ProtoMax; i++)
delete bgProto[i];
foreach (AbstractProtocolConfigForm* w, _protocolWidgets) {
OstProtocolWidgetFactory->deleteConfigWidget(w);
}
delete _iter;
delete mpStream;
}
void StreamConfigDialog::loadProtocolWidgets()
{
ProtocolListIterator *iter;
// NOTE: Protocol Widgets are created on demand. Once created we
// store them in _protocolWidgets indexed by the protocol
// object's address (to ensure unique widgets for multiple
// objects of the same class). Subsequently we check
// _protocolWidgets before creating a new widget
iter = mpStream->createProtocolListIterator();
while (iter->hasNext())
{
AbstractProtocol* p = iter->next();
AbstractProtocolConfigForm *w = _protocolWidgets.value(p);
if (!w) {
w = OstProtocolWidgetFactory->createConfigWidget(
p->protocolNumber());
_protocolWidgets.insert(p, w);
}
w->loadWidget(p);
}
delete iter;
}
void StreamConfigDialog::storeProtocolWidgets()
{
ProtocolListIterator *iter;
// NOTE: After creating a widget, we need to call loadWidget()
// to load the protocol's default values
iter = mpStream->createProtocolListIterator();
while (iter->hasNext())
{
AbstractProtocol* p = iter->next();
AbstractProtocolConfigForm *w = _protocolWidgets.value(p);
if (!w) {
w = OstProtocolWidgetFactory->createConfigWidget(
p->protocolNumber());
w->loadWidget(p);
_protocolWidgets.insert(p, w);
}
w->storeWidget(p);
}
delete iter;
}
void StreamConfigDialog::on_cmbPktLenMode_currentIndexChanged(QString mode)
{
if (mode == "Fixed")
@ -565,12 +620,19 @@ void StreamConfigDialog::on_twTopLevel_currentChanged(int index)
w->setParent(0);
}
// Repopulate the widgets
// Repopulate the widgets - create new ones, if required
_iter->toFront();
while (_iter->hasNext())
{
AbstractProtocol* p = _iter->next();
tbProtocolData->addItem(p->configWidget(), p->name());
AbstractProtocolConfigForm *w = _protocolWidgets.value(p);
if (!w) {
w = OstProtocolWidgetFactory->createConfigWidget(
p->protocolNumber());
w->loadWidget(p);
_protocolWidgets.insert(p, w);
}
tbProtocolData->addItem(w, p->name());
}
if (lastProtocolDataIndex < tbProtocolData->count())
@ -892,7 +954,7 @@ void StreamConfigDialog::LoadCurrentStream()
updateSelectProtocolsSimpleWidget();
updateSelectProtocolsAdvancedWidget();
mpStream->loadProtocolWidgets();
loadProtocolWidgets();
}
// Stream Control
@ -967,7 +1029,7 @@ void StreamConfigDialog::StoreCurrentStream()
// Protocols
{
pStream->storeProtocolWidgets();
storeProtocolWidgets();
}
// Stream Control
@ -1005,8 +1067,8 @@ void StreamConfigDialog::on_tbProtocolData_currentChanged(int /*index*/)
// protocols e.g. TCP/UDP port numbers are dependent on Port/Protocol
// selection in TextProtocol
#if 0 // FIXME: temp mask to avoid crash till we fix it
mpStream->storeProtocolWidgets();
mpStream->loadProtocolWidgets();
storeProtocolWidgets();
loadProtocolWidgets();
#endif
}

View File

@ -37,6 +37,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
**
*/
class AbstractProtocolConfigForm;
class StreamConfigDialog : public QDialog, public Ui::StreamConfigDialog
{
@ -76,6 +77,7 @@ private:
Stream *mpStream;
ProtocolListIterator *_iter;
QHash<AbstractProtocol*, AbstractProtocolConfigForm*> _protocolWidgets;
bool isUpdateInProgress;
@ -92,6 +94,8 @@ private:
void setupUiExtra();
void LoadCurrentStream();
void StoreCurrentStream();
void loadProtocolWidgets();
void storeProtocolWidgets();
private slots:
void on_cmbPktLenMode_currentIndexChanged(QString mode);

View File

@ -17,11 +17,12 @@ 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 "abstractprotocol.h"
#include "streambase.h"
#include "protocollistiterator.h"
#include "streambase.h"
#include <qendian.h>
/*!
\class AbstractProtocol
@ -46,9 +47,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
- fieldFlags()
- fieldData()
- setFieldData()
- configWidget() [pure virtual]
- loadConfigWidget() [pure virtual]
- storeConfigWidget() [pure virtual]
Depending on certain conditions, subclasses may need to reimplement the
following additional methods -
@ -107,6 +105,8 @@ AbstractProtocol* AbstractProtocol::createInstance(StreamBase* /* stream */,
(file: protocol.proto)
Subclasses MUST implement this function
\todo convert this to a protected data member instead of a virtual function
*/
quint32 AbstractProtocol::protocolNumber() const
{
@ -838,36 +838,6 @@ out:
return (quint16) ~sum;
}
/*!
\fn virtual QWidget* AbstractProtocol::configWidget() = 0;
Returns the configuration widget for the protocol. The protocol retains
ownership of the configuration widget - the caller should not free it.
In the base class this is a pure virtual function. Subclasses MUST implement
this function. See the SampleProtocol for an example
*/
/*!
\fn virtual void AbstractProtocol::loadConfigWidget() = 0;
Loads data from the protocol's protobuf into the configuration widget of
the protocol
In the base class this is a pure virtual function. Subclasses MUST implement
this function. See the SampleProtocol for an example
*/
/*!
\fn virtual void AbstractProtocol::storeConfigWidget() = 0;
Stores data from the configuration widget of the protocol into the protocol's
protobuf
In the base class this is a pure virtual function. Subclasses MUST implement
this function. See the SampleProtocol for an example
*/
// Stein's binary GCD algo - from wikipedia
quint64 AbstractProtocol::gcd(quint64 u, quint64 v)
{

View File

@ -23,9 +23,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include <QString>
#include <QVariant>
#include <QByteArray>
#include <QWidget>
#include <QLinkedList>
#include <QFlags>
#include <qendian.h>
//#include "../rpc/pbhelper.h"
#include "protocol.pb.h"
@ -155,10 +155,6 @@ public:
CksumType cksumType = CksumIp,
CksumScope cksumScope = CksumScopeAllProtocols) const;
virtual QWidget* configWidget() = 0;
virtual void loadConfigWidget() = 0;
virtual void storeConfigWidget() = 0;
static quint64 lcm(quint64 u, quint64 v);
static quint64 gcd(quint64 u, quint64 v);
};

View File

@ -0,0 +1,83 @@
/*
Copyright (C) 2013-2014 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 _ABSTRACT_PROTOCOL_CONFIG_H
#define _ABSTRACT_PROTOCOL_CONFIG_H
#include <QWidget>
class AbstractProtocol;
class AbstractProtocolConfigForm : public QWidget
{
Q_OBJECT
public:
/*!
Constructs the widget
*/
AbstractProtocolConfigForm(QWidget *parent = 0)
: QWidget(parent)
{
// Do nothing!
}
/*!
Destroys the widget
*/
virtual ~AbstractProtocolConfigForm()
{
// Do nothing!
}
/*!
Allocates and returns a new instance of the widget.
Caller is responsible for freeing up after use. Subclasses MUST implement
this function
*/
static AbstractProtocolConfigForm* createInstance()
{
return NULL;
}
/*!
Loads data from the protocol using it's fieldData() method into this
widget
Subclasses MUST implement this function. See the SampleProtocol for
an example
*/
virtual void loadWidget(AbstractProtocol *proto)
{
// Do nothing!
}
/*!
Stores data from this widget into the protocol using the protocol's
setFieldData() method
Subclasses MUST implement this function. See the SampleProtocol for
an example
*/
virtual void storeWidget(AbstractProtocol *proto)
{
// Do nothing!
}
};
#endif

View File

@ -1,32 +1,12 @@
TEMPLATE = lib
CONFIG += qt staticlib
QT += network script xml
INCLUDEPATH += "../extra/qhexedit2/src"
QT -= gui
QT += network script
LIBS += \
-lprotobuf
FORMS += \
pcapfileimport.ui \
mac.ui \
payload.ui \
eth2.ui \
dot3.ui \
llc.ui \
snap.ui \
vlan.ui \
arp.ui \
ip4.ui \
ip6.ui \
icmp.ui \
gmp.ui \
tcp.ui \
udp.ui \
textproto.ui \
userscript.ui \
hexdump.ui \
sample.ui
PROTOS += \
PROTOS = \
protocol.proto \
fileformat.proto \
mac.proto \
payload.proto \
eth2.proto \
@ -55,24 +35,22 @@ PROTOS += \
userscript.proto \
hexdump.proto \
sample.proto
HEADERS += \
ostprotolib.h \
HEADERS = \
abstractprotocol.h \
comboprotocol.h \
abstractfileformat.h \
fileformat.h \
pcapfileformat.h \
pdmlfileformat.h \
pdmlprotocol.h \
pdmlprotocols.h \
pdmlreader.h \
protocolmanager.h \
protocollist.h \
protocollistiterator.h \
streambase.h \
HEADERS += \
mac.h \
payload.h \
eth2.h \
ip6.h
HEADERS1 += \
dot3.h \
llc.h \
snap.h \
@ -83,7 +61,6 @@ HEADERS += \
vlanstack.h \
arp.h \
ip4.h \
ip6.h \
ipv4addressdelegate.h \
ipv6addressdelegate.h \
ip6over4.h \
@ -100,24 +77,22 @@ HEADERS += \
userscript.h \
hexdump.h \
sample.h
SOURCES += \
ostprotolib.cpp \
SOURCES = \
abstractprotocol.cpp \
crc32c.cpp \
abstractfileformat.cpp \
fileformat.cpp \
pcapfileformat.cpp \
pdmlfileformat.cpp \
pdmlprotocol.cpp \
pdmlprotocols.cpp \
pdmlreader.cpp \
protocolmanager.cpp \
protocollist.cpp \
protocollistiterator.cpp \
streambase.cpp \
SOURCES += \
mac.cpp \
payload.cpp \
eth2.cpp \
ip6.cpp
SOURCES1 += \
dot3.cpp \
llc.cpp \
snap.cpp \
@ -125,7 +100,6 @@ SOURCES += \
svlan.cpp \
arp.cpp \
ip4.cpp \
ip6.cpp \
icmp.cpp \
gmp.cpp \
igmp.cpp \
@ -140,3 +114,4 @@ SOURCES += \
QMAKE_DISTCLEAN += object_script.*
include(../protobuf.pri)

73
common/ostprotogui.pro Normal file
View File

@ -0,0 +1,73 @@
TEMPLATE = lib
CONFIG += qt staticlib
QT += network xml
LIBS += \
-lprotobuf
FORMS = \
pcapfileimport.ui \
FORMS += \
mac.ui \
payload.ui \
eth2.ui \
ip6.ui \
FORMS1 += \
dot3.ui \
llc.ui \
snap.ui \
vlan.ui \
arp.ui \
ip4.ui \
icmp.ui \
gmp.ui \
tcp.ui \
udp.ui \
textproto.ui \
userscript.ui \
hexdump.ui \
sample.ui
PROTOS = \
fileformat.proto
# TODO: Move fileformat related stuff into a different library
HEADERS = \
ostprotolib.h \
abstractfileformat.h \
fileformat.h \
pcapfileformat.h \
pdmlfileformat.h \
pdmlprotocol.h \
pdmlprotocols.h \
pdmlreader.h
HEADERS += \
abstractprotocolconfig.h \
protocolwidgetfactory.h \
macconfig.h \
payloadconfig.h \
eth2config.h \
ip6config.h
SOURCES += \
ostprotolib.cpp \
abstractfileformat.cpp \
fileformat.cpp \
pcapfileformat.cpp \
pdmlfileformat.cpp \
pdmlprotocol.cpp \
pdmlprotocols.cpp \
pdmlreader.cpp \
SOURCES += \
protocolwidgetfactory.cpp \
macconfig.cpp \
payloadconfig.cpp \
eth2config.cpp \
ip6config.cpp
QMAKE_DISTCLEAN += object_script.*
include(../protobuf.pri)

View File

@ -24,6 +24,7 @@ QString OstProtoLib::gzipPath_;
QString OstProtoLib::diffPath_;
QString OstProtoLib::awkPath_;
// TODO: one set method for each external app
void OstProtoLib::setExternalApplicationPaths(QString tsharkPath,
QString gzipPath, QString diffPath, QString awkPath)
{
@ -52,4 +53,3 @@ QString OstProtoLib::awkPath()
{
return awkPath_;
}

View File

@ -21,9 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "abstractprotocol.h"
#include "protocol.pb.h"
#include "mac.h"
#include "payload.h"
#include "eth2.h"
#if 0
#include "dot3.h"
#include "llc.h"
#include "snap.h"
@ -33,7 +31,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "vlanstack.h"
#include "arp.h"
#include "ip4.h"
#include "ip6.h"
#include "ip6over4.h"
#include "ip4over6.h"
#include "ip4over4.h"
@ -47,6 +44,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "userscript.h"
#include "hexdump.h"
#include "sample.h"
#else
#include "mac.h"
#include "payload.h"
#include "eth2.h"
#include "ip6.h"
#endif
ProtocolManager *OstProtocolManager;
@ -55,11 +58,7 @@ ProtocolManager::ProtocolManager()
/*! \todo (LOW) calls to registerProtocol() should be done by the protocols
themselves (once this is done remove the #includes for all the protocols)
*/
registerProtocol(OstProto::Protocol::kMacFieldNumber,
(void*) MacProtocol::createInstance);
registerProtocol(OstProto::Protocol::kEth2FieldNumber,
(void*) Eth2Protocol::createInstance);
#if 0
registerProtocol(OstProto::Protocol::kDot3FieldNumber,
(void*) Dot3Protocol::createInstance);
registerProtocol(OstProto::Protocol::kLlcFieldNumber,
@ -82,8 +81,6 @@ ProtocolManager::ProtocolManager()
(void*) ArpProtocol::createInstance);
registerProtocol(OstProto::Protocol::kIp4FieldNumber,
(void*) Ip4Protocol::createInstance);
registerProtocol(OstProto::Protocol::kIp6FieldNumber,
(void*) Ip6Protocol::createInstance);
registerProtocol(OstProto::Protocol::kIp6over4FieldNumber,
(void*) Ip6over4Protocol::createInstance);
registerProtocol(OstProto::Protocol::kIp4over6FieldNumber,
@ -108,14 +105,22 @@ ProtocolManager::ProtocolManager()
registerProtocol(OstProto::Protocol::kHexDumpFieldNumber,
(void*) HexDumpProtocol::createInstance);
registerProtocol(OstProto::Protocol::kPayloadFieldNumber,
(void*) PayloadProtocol::createInstance);
registerProtocol(OstProto::Protocol::kUserScriptFieldNumber,
(void*) UserScriptProtocol::createInstance);
registerProtocol(OstProto::Protocol::kSampleFieldNumber,
(void*) SampleProtocol::createInstance);
#else
registerProtocol(OstProto::Protocol::kMacFieldNumber,
(void*) MacProtocol::createInstance);
registerProtocol(OstProto::Protocol::kPayloadFieldNumber,
(void*) PayloadProtocol::createInstance);
registerProtocol(OstProto::Protocol::kEth2FieldNumber,
(void*) Eth2Protocol::createInstance);
registerProtocol(OstProto::Protocol::kIp6FieldNumber,
(void*) Ip6Protocol::createInstance);
#endif
populateNeighbourProtocols();
}
@ -178,7 +183,9 @@ AbstractProtocol* ProtocolManager::createProtocol(int protoNumber,
pc = (AbstractProtocol* (*)(StreamBase*, AbstractProtocol*))
factory.value(protoNumber);
Q_ASSERT(pc != NULL);
Q_ASSERT_X(pc != NULL,
__FUNCTION__,
numberToNameMap.value(protoNumber).toAscii().constData());
p = (*pc)(stream, parent);

View File

@ -40,6 +40,7 @@ public:
ProtocolManager();
~ProtocolManager();
// TODO: make registerProtocol static
void registerProtocol(int protoNumber, void *protoInstanceCreator);
bool isRegisteredProtocol(int protoNumber);

View File

@ -0,0 +1,86 @@
/*
Copyright (C) 2014 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 "protocolwidgetfactory.h"
#include "macconfig.h"
#include "payloadconfig.h"
#include "eth2config.h"
#include "ip6config.h"
ProtocolWidgetFactory *OstProtocolWidgetFactory;
QMap<int, void*> ProtocolWidgetFactory::configWidgetFactory;
ProtocolWidgetFactory::ProtocolWidgetFactory()
{
/*!
* Ideally Protocol Widgets should register themselves
* with the Factory
*/
OstProtocolWidgetFactory->registerProtocolConfigWidget(
OstProto::Protocol::kMacFieldNumber,
(void*) MacConfigForm::createInstance);
OstProtocolWidgetFactory->registerProtocolConfigWidget(
OstProto::Protocol::kPayloadFieldNumber,
(void*) PayloadConfigForm::createInstance);
OstProtocolWidgetFactory->registerProtocolConfigWidget(
OstProto::Protocol::kEth2FieldNumber,
(void*) Eth2ConfigForm::createInstance);
OstProtocolWidgetFactory->registerProtocolConfigWidget(
OstProto::Protocol::kIp6FieldNumber,
(void*) Ip6ConfigForm::createInstance);
}
ProtocolWidgetFactory::~ProtocolWidgetFactory()
{
configWidgetFactory.clear();
}
void ProtocolWidgetFactory::registerProtocolConfigWidget(int protoNumber,
void *protoConfigWidgetInstanceCreator)
{
Q_ASSERT(!configWidgetFactory.contains(protoNumber));
configWidgetFactory.insert(protoNumber, protoConfigWidgetInstanceCreator);
}
AbstractProtocolConfigForm* ProtocolWidgetFactory::createConfigWidget(
int protoNumber)
{
AbstractProtocolConfigForm* (*pc)();
AbstractProtocolConfigForm* p;
pc = (AbstractProtocolConfigForm* (*)())
configWidgetFactory.value(protoNumber);
Q_ASSERT_X(pc != NULL,
__FUNCTION__,
QString(protoNumber).toAscii().constData());
p = (*pc)();
return p;
}
void ProtocolWidgetFactory::deleteConfigWidget(
AbstractProtocolConfigForm *configWidget)
{
delete configWidget;
}

View File

@ -0,0 +1,46 @@
/*
Copyright (C) 2014 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 _PROTOCOL_WIDGET_FACTORY_H
#define _PROTOCOL_WIDGET_FACTORY_H
#include <QMap>
class AbstractProtocolConfigForm;
// Singleton class
class ProtocolWidgetFactory
{
static QMap<int, void*> configWidgetFactory;
public:
ProtocolWidgetFactory();
~ProtocolWidgetFactory();
// TODO: make registerProtocolConfigWidget static??
// TODO: define a function pointer prototype instead of void* for
// protoConfigWidgetInstanceCreator
static void registerProtocolConfigWidget(int protoNumber,
void *protoConfigWidgetInstanceCreator);
AbstractProtocolConfigForm* createConfigWidget(int protoNumber);
void deleteConfigWidget(AbstractProtocolConfigForm *configWidget);
};
#endif

View File

@ -4,5 +4,6 @@ SUBDIRS = \
extra \
rpc/pbrpc.pro \
common/ostproto.pro \
common/ostprotogui.pro \
server/drone.pro \
client/ostinato.pro