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:
parent
925697dfcc
commit
cabd6ad096
@ -20,6 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
|||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "../common/ostprotolib.h"
|
#include "../common/ostprotolib.h"
|
||||||
#include "../common/protocolmanager.h"
|
#include "../common/protocolmanager.h"
|
||||||
|
#include "../common/protocolwidgetfactory.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
|
||||||
#include <QApplication>
|
#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* version;
|
||||||
extern const char* revision;
|
extern const char* revision;
|
||||||
extern ProtocolManager *OstProtocolManager;
|
extern ProtocolManager *OstProtocolManager;
|
||||||
|
extern ProtocolWidgetFactory *OstProtocolWidgetFactory;
|
||||||
|
|
||||||
QSettings *appSettings;
|
QSettings *appSettings;
|
||||||
QMainWindow *mainWindow;
|
QMainWindow *mainWindow;
|
||||||
@ -58,6 +60,7 @@ int main(int argc, char* argv[])
|
|||||||
app.setProperty("revision", revision);
|
app.setProperty("revision", revision);
|
||||||
|
|
||||||
OstProtocolManager = new ProtocolManager();
|
OstProtocolManager = new ProtocolManager();
|
||||||
|
OstProtocolWidgetFactory = new ProtocolWidgetFactory();
|
||||||
|
|
||||||
/* (Portable Mode) If we have a .ini file in the same directory as the
|
/* (Portable Mode) If we have a .ini file in the same directory as the
|
||||||
executable, we use that instead of the platform specific location
|
executable, we use that instead of the platform specific location
|
||||||
|
@ -100,14 +100,21 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
{
|
{
|
||||||
delete pgl;
|
#ifdef Q_OS_WIN32
|
||||||
|
//! \todo - find a way to terminate cleanly
|
||||||
|
localServer_->kill();
|
||||||
|
#else
|
||||||
localServer_->terminate();
|
localServer_->terminate();
|
||||||
localServer_->waitForFinished();
|
#endif
|
||||||
delete localServer_;
|
|
||||||
|
delete pgl;
|
||||||
|
|
||||||
QByteArray layout = saveState(0);
|
QByteArray layout = saveState(0);
|
||||||
appSettings->setValue(kApplicationWindowLayout, layout);
|
appSettings->setValue(kApplicationWindowLayout, layout);
|
||||||
appSettings->setValue(kApplicationWindowGeometryKey, geometry());
|
appSettings->setValue(kApplicationWindowGeometryKey, geometry());
|
||||||
|
|
||||||
|
localServer_->waitForFinished();
|
||||||
|
delete localServer_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionPreferences_triggered()
|
void MainWindow::on_actionPreferences_triggered()
|
||||||
|
@ -7,22 +7,27 @@ QT += network script xml
|
|||||||
INCLUDEPATH += "../rpc/" "../common/"
|
INCLUDEPATH += "../rpc/" "../common/"
|
||||||
win32 {
|
win32 {
|
||||||
CONFIG(debug, debug|release) {
|
CONFIG(debug, debug|release) {
|
||||||
LIBS += -L"../common/debug" -lostproto
|
LIBS += -L"../common/debug" -lostprotogui -lostproto
|
||||||
LIBS += -L"../rpc/debug" -lpbrpc
|
LIBS += -L"../rpc/debug" -lpbrpc
|
||||||
POST_TARGETDEPS += \
|
POST_TARGETDEPS += \
|
||||||
|
"../common/debug/libostprotogui.a" \
|
||||||
"../common/debug/libostproto.a" \
|
"../common/debug/libostproto.a" \
|
||||||
"../rpc/debug/libpbrpc.a"
|
"../rpc/debug/libpbrpc.a"
|
||||||
} else {
|
} else {
|
||||||
LIBS += -L"../common/release" -lostproto
|
LIBS += -L"../common/release" -lostprotogui -lostproto
|
||||||
LIBS += -L"../rpc/release" -lpbrpc
|
LIBS += -L"../rpc/release" -lpbrpc
|
||||||
POST_TARGETDEPS += \
|
POST_TARGETDEPS += \
|
||||||
|
"../common/release/libostprotogui.a" \
|
||||||
"../common/release/libostproto.a" \
|
"../common/release/libostproto.a" \
|
||||||
"../rpc/release/libpbrpc.a"
|
"../rpc/release/libpbrpc.a"
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LIBS += -L"../common" -lostproto
|
LIBS += -L"../common" -lostprotogui -lostproto
|
||||||
LIBS += -L"../rpc" -lpbrpc
|
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 += -lprotobuf
|
||||||
LIBS += -L"../extra/qhexedit2/$(OBJECTS_DIR)/" -lqhexedit2
|
LIBS += -L"../extra/qhexedit2/$(OBJECTS_DIR)/" -lqhexedit2
|
||||||
|
@ -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/>
|
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \todo Remove this class
|
||||||
|
*/
|
||||||
|
|
||||||
#include <qendian.h>
|
#include <qendian.h>
|
||||||
#include <QHostAddress>
|
#include <QHostAddress>
|
||||||
|
|
||||||
#include "stream.h"
|
#include "stream.h"
|
||||||
//#include "../common/protocollist.h"
|
|
||||||
#include "../common/protocollistiterator.h"
|
#include "../common/protocollistiterator.h"
|
||||||
#include "../common/abstractprotocol.h"
|
#include "../common/abstractprotocol.h"
|
||||||
|
|
||||||
@ -37,43 +40,12 @@ Stream::~Stream()
|
|||||||
|
|
||||||
void Stream::loadProtocolWidgets()
|
void Stream::loadProtocolWidgets()
|
||||||
{
|
{
|
||||||
#if 0
|
qWarning("%s: DOES NOTHING", __PRETTY_FUNCTION__);
|
||||||
//protocols.loadConfigWidgets();
|
return;
|
||||||
foreach(AbstractProtocol* proto, *currentFrameProtocols)
|
|
||||||
{
|
|
||||||
proto->loadConfigWidget();
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
ProtocolListIterator *iter;
|
|
||||||
|
|
||||||
iter = createProtocolListIterator();
|
|
||||||
while (iter->hasNext())
|
|
||||||
{
|
|
||||||
AbstractProtocol* p = iter->next();
|
|
||||||
p->loadConfigWidget();
|
|
||||||
}
|
|
||||||
delete iter;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Stream::storeProtocolWidgets()
|
void Stream::storeProtocolWidgets()
|
||||||
{
|
{
|
||||||
#if 0
|
qWarning("%s: DOES NOTHING", __PRETTY_FUNCTION__);
|
||||||
//protocols.storeConfigWidgets();
|
return;
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
@ -22,13 +22,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
|||||||
#include "streamconfigdialog.h"
|
#include "streamconfigdialog.h"
|
||||||
#include "stream.h"
|
#include "stream.h"
|
||||||
#include "abstractprotocol.h"
|
#include "abstractprotocol.h"
|
||||||
|
#include "abstractprotocolconfig.h"
|
||||||
#include "protocollistiterator.h"
|
#include "protocollistiterator.h"
|
||||||
|
|
||||||
#include "modeltest.h"
|
#include "modeltest.h"
|
||||||
|
|
||||||
// FIXME(HI) - remove
|
|
||||||
#include "../common/protocolmanager.h"
|
#include "../common/protocolmanager.h"
|
||||||
|
#include "../common/protocolwidgetfactory.h"
|
||||||
|
|
||||||
extern ProtocolManager *OstProtocolManager;
|
extern ProtocolManager *OstProtocolManager;
|
||||||
|
extern ProtocolWidgetFactory *OstProtocolWidgetFactory;
|
||||||
|
|
||||||
QRect StreamConfigDialog::lastGeometry;
|
QRect StreamConfigDialog::lastGeometry;
|
||||||
int StreamConfigDialog::lastTopLevelTabIndex = 0;
|
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)), rbPayloadOther, SLOT(setChecked(bool)));
|
||||||
connect(rbL4Other, SIGNAL(toggled(bool)), gbPayloadProto, SLOT(setDisabled(bool)));
|
connect(rbL4Other, SIGNAL(toggled(bool)), gbPayloadProto, SLOT(setDisabled(bool)));
|
||||||
|
|
||||||
|
#if 1 // temp mask
|
||||||
// Setup valid subsequent protocols for L2 to L4 protocols
|
// Setup valid subsequent protocols for L2 to L4 protocols
|
||||||
for (int i = ProtoL2; i <= ProtoL4; i++)
|
for (int i = ProtoL2; i <= ProtoL4; i++)
|
||||||
{
|
{
|
||||||
@ -129,6 +133,7 @@ StreamConfigDialog::StreamConfigDialog(Port &port, uint streamIndex,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
mpAvailableProtocolsModel = new QStringListModel(
|
mpAvailableProtocolsModel = new QStringListModel(
|
||||||
OstProtocolManager->protocolDatabase(), this);
|
OstProtocolManager->protocolDatabase(), this);
|
||||||
@ -306,10 +311,60 @@ StreamConfigDialog::~StreamConfigDialog()
|
|||||||
for (int i = ProtoMin; i < ProtoMax; i++)
|
for (int i = ProtoMin; i < ProtoMax; i++)
|
||||||
delete bgProto[i];
|
delete bgProto[i];
|
||||||
|
|
||||||
|
foreach (AbstractProtocolConfigForm* w, _protocolWidgets) {
|
||||||
|
OstProtocolWidgetFactory->deleteConfigWidget(w);
|
||||||
|
}
|
||||||
|
|
||||||
delete _iter;
|
delete _iter;
|
||||||
delete mpStream;
|
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)
|
void StreamConfigDialog::on_cmbPktLenMode_currentIndexChanged(QString mode)
|
||||||
{
|
{
|
||||||
if (mode == "Fixed")
|
if (mode == "Fixed")
|
||||||
@ -565,12 +620,19 @@ void StreamConfigDialog::on_twTopLevel_currentChanged(int index)
|
|||||||
w->setParent(0);
|
w->setParent(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Repopulate the widgets
|
// Repopulate the widgets - create new ones, if required
|
||||||
_iter->toFront();
|
_iter->toFront();
|
||||||
while (_iter->hasNext())
|
while (_iter->hasNext())
|
||||||
{
|
{
|
||||||
AbstractProtocol* p = _iter->next();
|
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())
|
if (lastProtocolDataIndex < tbProtocolData->count())
|
||||||
@ -892,7 +954,7 @@ void StreamConfigDialog::LoadCurrentStream()
|
|||||||
updateSelectProtocolsSimpleWidget();
|
updateSelectProtocolsSimpleWidget();
|
||||||
updateSelectProtocolsAdvancedWidget();
|
updateSelectProtocolsAdvancedWidget();
|
||||||
|
|
||||||
mpStream->loadProtocolWidgets();
|
loadProtocolWidgets();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stream Control
|
// Stream Control
|
||||||
@ -967,7 +1029,7 @@ void StreamConfigDialog::StoreCurrentStream()
|
|||||||
|
|
||||||
// Protocols
|
// Protocols
|
||||||
{
|
{
|
||||||
pStream->storeProtocolWidgets();
|
storeProtocolWidgets();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stream Control
|
// 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
|
// protocols e.g. TCP/UDP port numbers are dependent on Port/Protocol
|
||||||
// selection in TextProtocol
|
// selection in TextProtocol
|
||||||
#if 0 // FIXME: temp mask to avoid crash till we fix it
|
#if 0 // FIXME: temp mask to avoid crash till we fix it
|
||||||
mpStream->storeProtocolWidgets();
|
storeProtocolWidgets();
|
||||||
mpStream->loadProtocolWidgets();
|
loadProtocolWidgets();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
class StreamConfigDialog : public QDialog, public Ui::StreamConfigDialog
|
||||||
{
|
{
|
||||||
@ -76,6 +77,7 @@ private:
|
|||||||
|
|
||||||
Stream *mpStream;
|
Stream *mpStream;
|
||||||
ProtocolListIterator *_iter;
|
ProtocolListIterator *_iter;
|
||||||
|
QHash<AbstractProtocol*, AbstractProtocolConfigForm*> _protocolWidgets;
|
||||||
|
|
||||||
bool isUpdateInProgress;
|
bool isUpdateInProgress;
|
||||||
|
|
||||||
@ -92,6 +94,8 @@ private:
|
|||||||
void setupUiExtra();
|
void setupUiExtra();
|
||||||
void LoadCurrentStream();
|
void LoadCurrentStream();
|
||||||
void StoreCurrentStream();
|
void StoreCurrentStream();
|
||||||
|
void loadProtocolWidgets();
|
||||||
|
void storeProtocolWidgets();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_cmbPktLenMode_currentIndexChanged(QString mode);
|
void on_cmbPktLenMode_currentIndexChanged(QString mode);
|
||||||
|
@ -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/>
|
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <qendian.h>
|
|
||||||
|
|
||||||
#include "abstractprotocol.h"
|
#include "abstractprotocol.h"
|
||||||
#include "streambase.h"
|
|
||||||
#include "protocollistiterator.h"
|
#include "protocollistiterator.h"
|
||||||
|
#include "streambase.h"
|
||||||
|
|
||||||
|
#include <qendian.h>
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\class AbstractProtocol
|
\class AbstractProtocol
|
||||||
@ -46,9 +47,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
|||||||
- fieldFlags()
|
- fieldFlags()
|
||||||
- fieldData()
|
- fieldData()
|
||||||
- setFieldData()
|
- setFieldData()
|
||||||
- configWidget() [pure virtual]
|
|
||||||
- loadConfigWidget() [pure virtual]
|
|
||||||
- storeConfigWidget() [pure virtual]
|
|
||||||
|
|
||||||
Depending on certain conditions, subclasses may need to reimplement the
|
Depending on certain conditions, subclasses may need to reimplement the
|
||||||
following additional methods -
|
following additional methods -
|
||||||
@ -107,6 +105,8 @@ AbstractProtocol* AbstractProtocol::createInstance(StreamBase* /* stream */,
|
|||||||
(file: protocol.proto)
|
(file: protocol.proto)
|
||||||
|
|
||||||
Subclasses MUST implement this function
|
Subclasses MUST implement this function
|
||||||
|
|
||||||
|
\todo convert this to a protected data member instead of a virtual function
|
||||||
*/
|
*/
|
||||||
quint32 AbstractProtocol::protocolNumber() const
|
quint32 AbstractProtocol::protocolNumber() const
|
||||||
{
|
{
|
||||||
@ -838,36 +838,6 @@ out:
|
|||||||
return (quint16) ~sum;
|
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
|
// Stein's binary GCD algo - from wikipedia
|
||||||
quint64 AbstractProtocol::gcd(quint64 u, quint64 v)
|
quint64 AbstractProtocol::gcd(quint64 u, quint64 v)
|
||||||
{
|
{
|
||||||
|
@ -23,9 +23,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
#include <QWidget>
|
|
||||||
#include <QLinkedList>
|
#include <QLinkedList>
|
||||||
#include <QFlags>
|
#include <QFlags>
|
||||||
|
#include <qendian.h>
|
||||||
|
|
||||||
//#include "../rpc/pbhelper.h"
|
//#include "../rpc/pbhelper.h"
|
||||||
#include "protocol.pb.h"
|
#include "protocol.pb.h"
|
||||||
@ -155,10 +155,6 @@ public:
|
|||||||
CksumType cksumType = CksumIp,
|
CksumType cksumType = CksumIp,
|
||||||
CksumScope cksumScope = CksumScopeAllProtocols) const;
|
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 lcm(quint64 u, quint64 v);
|
||||||
static quint64 gcd(quint64 u, quint64 v);
|
static quint64 gcd(quint64 u, quint64 v);
|
||||||
};
|
};
|
||||||
|
83
common/abstractprotocolconfig.h
Normal file
83
common/abstractprotocolconfig.h
Normal 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
|
@ -1,32 +1,12 @@
|
|||||||
TEMPLATE = lib
|
TEMPLATE = lib
|
||||||
CONFIG += qt staticlib
|
CONFIG += qt staticlib
|
||||||
QT += network script xml
|
QT -= gui
|
||||||
INCLUDEPATH += "../extra/qhexedit2/src"
|
QT += network script
|
||||||
LIBS += \
|
LIBS += \
|
||||||
-lprotobuf
|
-lprotobuf
|
||||||
FORMS += \
|
|
||||||
pcapfileimport.ui \
|
PROTOS = \
|
||||||
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 += \
|
|
||||||
protocol.proto \
|
protocol.proto \
|
||||||
fileformat.proto \
|
|
||||||
mac.proto \
|
mac.proto \
|
||||||
payload.proto \
|
payload.proto \
|
||||||
eth2.proto \
|
eth2.proto \
|
||||||
@ -55,24 +35,22 @@ PROTOS += \
|
|||||||
userscript.proto \
|
userscript.proto \
|
||||||
hexdump.proto \
|
hexdump.proto \
|
||||||
sample.proto
|
sample.proto
|
||||||
HEADERS += \
|
|
||||||
ostprotolib.h \
|
HEADERS = \
|
||||||
abstractprotocol.h \
|
abstractprotocol.h \
|
||||||
comboprotocol.h \
|
comboprotocol.h \
|
||||||
abstractfileformat.h \
|
|
||||||
fileformat.h \
|
|
||||||
pcapfileformat.h \
|
|
||||||
pdmlfileformat.h \
|
|
||||||
pdmlprotocol.h \
|
|
||||||
pdmlprotocols.h \
|
|
||||||
pdmlreader.h \
|
|
||||||
protocolmanager.h \
|
protocolmanager.h \
|
||||||
protocollist.h \
|
protocollist.h \
|
||||||
protocollistiterator.h \
|
protocollistiterator.h \
|
||||||
streambase.h \
|
streambase.h \
|
||||||
|
|
||||||
|
HEADERS += \
|
||||||
mac.h \
|
mac.h \
|
||||||
payload.h \
|
payload.h \
|
||||||
eth2.h \
|
eth2.h \
|
||||||
|
ip6.h
|
||||||
|
|
||||||
|
HEADERS1 += \
|
||||||
dot3.h \
|
dot3.h \
|
||||||
llc.h \
|
llc.h \
|
||||||
snap.h \
|
snap.h \
|
||||||
@ -83,7 +61,6 @@ HEADERS += \
|
|||||||
vlanstack.h \
|
vlanstack.h \
|
||||||
arp.h \
|
arp.h \
|
||||||
ip4.h \
|
ip4.h \
|
||||||
ip6.h \
|
|
||||||
ipv4addressdelegate.h \
|
ipv4addressdelegate.h \
|
||||||
ipv6addressdelegate.h \
|
ipv6addressdelegate.h \
|
||||||
ip6over4.h \
|
ip6over4.h \
|
||||||
@ -100,24 +77,22 @@ HEADERS += \
|
|||||||
userscript.h \
|
userscript.h \
|
||||||
hexdump.h \
|
hexdump.h \
|
||||||
sample.h
|
sample.h
|
||||||
SOURCES += \
|
|
||||||
ostprotolib.cpp \
|
SOURCES = \
|
||||||
abstractprotocol.cpp \
|
abstractprotocol.cpp \
|
||||||
crc32c.cpp \
|
crc32c.cpp \
|
||||||
abstractfileformat.cpp \
|
|
||||||
fileformat.cpp \
|
|
||||||
pcapfileformat.cpp \
|
|
||||||
pdmlfileformat.cpp \
|
|
||||||
pdmlprotocol.cpp \
|
|
||||||
pdmlprotocols.cpp \
|
|
||||||
pdmlreader.cpp \
|
|
||||||
protocolmanager.cpp \
|
protocolmanager.cpp \
|
||||||
protocollist.cpp \
|
protocollist.cpp \
|
||||||
protocollistiterator.cpp \
|
protocollistiterator.cpp \
|
||||||
streambase.cpp \
|
streambase.cpp \
|
||||||
|
|
||||||
|
SOURCES += \
|
||||||
mac.cpp \
|
mac.cpp \
|
||||||
payload.cpp \
|
payload.cpp \
|
||||||
eth2.cpp \
|
eth2.cpp \
|
||||||
|
ip6.cpp
|
||||||
|
|
||||||
|
SOURCES1 += \
|
||||||
dot3.cpp \
|
dot3.cpp \
|
||||||
llc.cpp \
|
llc.cpp \
|
||||||
snap.cpp \
|
snap.cpp \
|
||||||
@ -125,7 +100,6 @@ SOURCES += \
|
|||||||
svlan.cpp \
|
svlan.cpp \
|
||||||
arp.cpp \
|
arp.cpp \
|
||||||
ip4.cpp \
|
ip4.cpp \
|
||||||
ip6.cpp \
|
|
||||||
icmp.cpp \
|
icmp.cpp \
|
||||||
gmp.cpp \
|
gmp.cpp \
|
||||||
igmp.cpp \
|
igmp.cpp \
|
||||||
@ -140,3 +114,4 @@ SOURCES += \
|
|||||||
QMAKE_DISTCLEAN += object_script.*
|
QMAKE_DISTCLEAN += object_script.*
|
||||||
|
|
||||||
include(../protobuf.pri)
|
include(../protobuf.pri)
|
||||||
|
|
||||||
|
73
common/ostprotogui.pro
Normal file
73
common/ostprotogui.pro
Normal 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)
|
@ -24,6 +24,7 @@ QString OstProtoLib::gzipPath_;
|
|||||||
QString OstProtoLib::diffPath_;
|
QString OstProtoLib::diffPath_;
|
||||||
QString OstProtoLib::awkPath_;
|
QString OstProtoLib::awkPath_;
|
||||||
|
|
||||||
|
// TODO: one set method for each external app
|
||||||
void OstProtoLib::setExternalApplicationPaths(QString tsharkPath,
|
void OstProtoLib::setExternalApplicationPaths(QString tsharkPath,
|
||||||
QString gzipPath, QString diffPath, QString awkPath)
|
QString gzipPath, QString diffPath, QString awkPath)
|
||||||
{
|
{
|
||||||
@ -52,4 +53,3 @@ QString OstProtoLib::awkPath()
|
|||||||
{
|
{
|
||||||
return awkPath_;
|
return awkPath_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,9 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
|||||||
#include "abstractprotocol.h"
|
#include "abstractprotocol.h"
|
||||||
|
|
||||||
#include "protocol.pb.h"
|
#include "protocol.pb.h"
|
||||||
#include "mac.h"
|
#if 0
|
||||||
#include "payload.h"
|
|
||||||
#include "eth2.h"
|
|
||||||
#include "dot3.h"
|
#include "dot3.h"
|
||||||
#include "llc.h"
|
#include "llc.h"
|
||||||
#include "snap.h"
|
#include "snap.h"
|
||||||
@ -33,7 +31,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
|||||||
#include "vlanstack.h"
|
#include "vlanstack.h"
|
||||||
#include "arp.h"
|
#include "arp.h"
|
||||||
#include "ip4.h"
|
#include "ip4.h"
|
||||||
#include "ip6.h"
|
|
||||||
#include "ip6over4.h"
|
#include "ip6over4.h"
|
||||||
#include "ip4over6.h"
|
#include "ip4over6.h"
|
||||||
#include "ip4over4.h"
|
#include "ip4over4.h"
|
||||||
@ -47,6 +44,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
|||||||
#include "userscript.h"
|
#include "userscript.h"
|
||||||
#include "hexdump.h"
|
#include "hexdump.h"
|
||||||
#include "sample.h"
|
#include "sample.h"
|
||||||
|
#else
|
||||||
|
#include "mac.h"
|
||||||
|
#include "payload.h"
|
||||||
|
#include "eth2.h"
|
||||||
|
#include "ip6.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
ProtocolManager *OstProtocolManager;
|
ProtocolManager *OstProtocolManager;
|
||||||
|
|
||||||
@ -55,11 +58,7 @@ ProtocolManager::ProtocolManager()
|
|||||||
/*! \todo (LOW) calls to registerProtocol() should be done by the protocols
|
/*! \todo (LOW) calls to registerProtocol() should be done by the protocols
|
||||||
themselves (once this is done remove the #includes for all the protocols)
|
themselves (once this is done remove the #includes for all the protocols)
|
||||||
*/
|
*/
|
||||||
registerProtocol(OstProto::Protocol::kMacFieldNumber,
|
#if 0
|
||||||
(void*) MacProtocol::createInstance);
|
|
||||||
|
|
||||||
registerProtocol(OstProto::Protocol::kEth2FieldNumber,
|
|
||||||
(void*) Eth2Protocol::createInstance);
|
|
||||||
registerProtocol(OstProto::Protocol::kDot3FieldNumber,
|
registerProtocol(OstProto::Protocol::kDot3FieldNumber,
|
||||||
(void*) Dot3Protocol::createInstance);
|
(void*) Dot3Protocol::createInstance);
|
||||||
registerProtocol(OstProto::Protocol::kLlcFieldNumber,
|
registerProtocol(OstProto::Protocol::kLlcFieldNumber,
|
||||||
@ -82,8 +81,6 @@ ProtocolManager::ProtocolManager()
|
|||||||
(void*) ArpProtocol::createInstance);
|
(void*) ArpProtocol::createInstance);
|
||||||
registerProtocol(OstProto::Protocol::kIp4FieldNumber,
|
registerProtocol(OstProto::Protocol::kIp4FieldNumber,
|
||||||
(void*) Ip4Protocol::createInstance);
|
(void*) Ip4Protocol::createInstance);
|
||||||
registerProtocol(OstProto::Protocol::kIp6FieldNumber,
|
|
||||||
(void*) Ip6Protocol::createInstance);
|
|
||||||
registerProtocol(OstProto::Protocol::kIp6over4FieldNumber,
|
registerProtocol(OstProto::Protocol::kIp6over4FieldNumber,
|
||||||
(void*) Ip6over4Protocol::createInstance);
|
(void*) Ip6over4Protocol::createInstance);
|
||||||
registerProtocol(OstProto::Protocol::kIp4over6FieldNumber,
|
registerProtocol(OstProto::Protocol::kIp4over6FieldNumber,
|
||||||
@ -108,14 +105,22 @@ ProtocolManager::ProtocolManager()
|
|||||||
|
|
||||||
registerProtocol(OstProto::Protocol::kHexDumpFieldNumber,
|
registerProtocol(OstProto::Protocol::kHexDumpFieldNumber,
|
||||||
(void*) HexDumpProtocol::createInstance);
|
(void*) HexDumpProtocol::createInstance);
|
||||||
registerProtocol(OstProto::Protocol::kPayloadFieldNumber,
|
|
||||||
(void*) PayloadProtocol::createInstance);
|
|
||||||
|
|
||||||
registerProtocol(OstProto::Protocol::kUserScriptFieldNumber,
|
registerProtocol(OstProto::Protocol::kUserScriptFieldNumber,
|
||||||
(void*) UserScriptProtocol::createInstance);
|
(void*) UserScriptProtocol::createInstance);
|
||||||
registerProtocol(OstProto::Protocol::kSampleFieldNumber,
|
registerProtocol(OstProto::Protocol::kSampleFieldNumber,
|
||||||
(void*) SampleProtocol::createInstance);
|
(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();
|
populateNeighbourProtocols();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,7 +183,9 @@ AbstractProtocol* ProtocolManager::createProtocol(int protoNumber,
|
|||||||
pc = (AbstractProtocol* (*)(StreamBase*, AbstractProtocol*))
|
pc = (AbstractProtocol* (*)(StreamBase*, AbstractProtocol*))
|
||||||
factory.value(protoNumber);
|
factory.value(protoNumber);
|
||||||
|
|
||||||
Q_ASSERT(pc != NULL);
|
Q_ASSERT_X(pc != NULL,
|
||||||
|
__FUNCTION__,
|
||||||
|
numberToNameMap.value(protoNumber).toAscii().constData());
|
||||||
|
|
||||||
p = (*pc)(stream, parent);
|
p = (*pc)(stream, parent);
|
||||||
|
|
||||||
|
@ -40,6 +40,7 @@ public:
|
|||||||
ProtocolManager();
|
ProtocolManager();
|
||||||
~ProtocolManager();
|
~ProtocolManager();
|
||||||
|
|
||||||
|
// TODO: make registerProtocol static
|
||||||
void registerProtocol(int protoNumber, void *protoInstanceCreator);
|
void registerProtocol(int protoNumber, void *protoInstanceCreator);
|
||||||
|
|
||||||
bool isRegisteredProtocol(int protoNumber);
|
bool isRegisteredProtocol(int protoNumber);
|
||||||
|
86
common/protocolwidgetfactory.cpp
Normal file
86
common/protocolwidgetfactory.cpp
Normal 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;
|
||||||
|
}
|
46
common/protocolwidgetfactory.h
Normal file
46
common/protocolwidgetfactory.h
Normal 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
|
Loading…
Reference in New Issue
Block a user