From bacee5dd1817402897d38d8b9fbb819f49be3182 Mon Sep 17 00:00:00 2001 From: "Srivats P." Date: Sat, 19 Apr 2014 12:36:14 +0530 Subject: [PATCH] NOX: TextProtocol - Separated protocol and widget as per new framework --- common/ostproto.pro | 8 +-- common/ostprotogui.pro | 10 ++-- common/protocolmanager.cpp | 11 +++-- common/protocolwidgetfactory.cpp | 7 +++ common/textproto.cpp | 55 --------------------- common/textproto.h | 22 ++------- common/textproto.ui | 4 +- common/textprotoconfig.cpp | 84 ++++++++++++++++++++++++++++++++ common/textprotoconfig.h | 41 ++++++++++++++++ 9 files changed, 155 insertions(+), 87 deletions(-) create mode 100644 common/textprotoconfig.cpp create mode 100644 common/textprotoconfig.h diff --git a/common/ostproto.pro b/common/ostproto.pro index 2dbe0c1..c69e4e0 100644 --- a/common/ostproto.pro +++ b/common/ostproto.pro @@ -68,10 +68,10 @@ HEADERS += \ igmp.h \ mld.h \ tcp.h \ - udp.h + udp.h \ + textproto.h HEADERS1 += \ - textproto.h \ userscript.h \ hexdump.h \ sample.h @@ -101,10 +101,10 @@ SOURCES += \ igmp.cpp \ mld.cpp \ tcp.cpp \ - udp.cpp + udp.cpp \ + textproto.cpp SOURCES1 += \ - textproto.cpp \ userscript.cpp \ hexdump.cpp \ sample.cpp diff --git a/common/ostprotogui.pro b/common/ostprotogui.pro index e8a6909..98596bc 100644 --- a/common/ostprotogui.pro +++ b/common/ostprotogui.pro @@ -21,10 +21,10 @@ FORMS += \ gmp.ui \ icmp.ui \ tcp.ui \ - udp.ui + udp.ui \ + textproto.ui FORMS1 += \ - textproto.ui \ userscript.ui \ hexdump.ui \ sample.ui @@ -69,7 +69,8 @@ HEADERS += \ igmpconfig.h \ mldconfig.h \ tcpconfig.h \ - udpconfig.h + udpconfig.h \ + textprotoconfig.h SOURCES += \ ostprotolib.cpp \ @@ -98,7 +99,8 @@ SOURCES += \ igmpconfig.cpp \ mldconfig.cpp \ tcpconfig.cpp \ - udpconfig.cpp + udpconfig.cpp \ + textprotoconfig.cpp QMAKE_DISTCLEAN += object_script.* diff --git a/common/protocolmanager.cpp b/common/protocolmanager.cpp index db1a4ca..8649dc9 100644 --- a/common/protocolmanager.cpp +++ b/common/protocolmanager.cpp @@ -22,7 +22,6 @@ along with this program. If not, see #include "protocol.pb.h" #if 0 -#include "textproto.h" #include "userscript.h" #include "hexdump.h" #include "sample.h" @@ -52,6 +51,8 @@ along with this program. If not, see #include "mld.h" #include "tcp.h" #include "udp.h" +// L5 Protos +#include "textproto.h" #endif ProtocolManager *OstProtocolManager; @@ -62,9 +63,6 @@ ProtocolManager::ProtocolManager() themselves (once this is done remove the #includes for all the protocols) */ #if 0 - registerProtocol(OstProto::Protocol::kTextProtocolFieldNumber, - (void*) TextProtocol::createInstance); - registerProtocol(OstProto::Protocol::kHexDumpFieldNumber, (void*) HexDumpProtocol::createInstance); @@ -126,6 +124,11 @@ ProtocolManager::ProtocolManager() (void*) TcpProtocol::createInstance); registerProtocol(OstProto::Protocol::kUdpFieldNumber, (void*) UdpProtocol::createInstance); + + // Layer 5 Protocols + registerProtocol(OstProto::Protocol::kTextProtocolFieldNumber, + (void*) TextProtocol::createInstance); + #endif populateNeighbourProtocols(); } diff --git a/common/protocolwidgetfactory.cpp b/common/protocolwidgetfactory.cpp index 78347ad..8c59eb4 100644 --- a/common/protocolwidgetfactory.cpp +++ b/common/protocolwidgetfactory.cpp @@ -44,6 +44,8 @@ along with this program. If not, see #include "mldconfig.h" #include "tcpconfig.h" #include "udpconfig.h" +// L5 Protocol Widgets +#include "textprotoconfig.h" ProtocolWidgetFactory *OstProtocolWidgetFactory; QMap ProtocolWidgetFactory::configWidgetFactory; @@ -130,6 +132,11 @@ ProtocolWidgetFactory::ProtocolWidgetFactory() OstProtocolWidgetFactory->registerProtocolConfigWidget( OstProto::Protocol::kUdpFieldNumber, (void*) UdpConfigForm::createInstance); + + // Layer 5 Protocols + OstProtocolWidgetFactory->registerProtocolConfigWidget( + OstProto::Protocol::kTextProtocolFieldNumber, + (void*) TextProtocolConfigForm::createInstance); } ProtocolWidgetFactory::~ProtocolWidgetFactory() diff --git a/common/textproto.cpp b/common/textproto.cpp index 9834530..285668d 100644 --- a/common/textproto.cpp +++ b/common/textproto.cpp @@ -17,32 +17,15 @@ You should have received a copy of the GNU General Public License along with this program. If not, see */ -#include - #include "textproto.h" -TextProtocolConfigForm::TextProtocolConfigForm(QWidget *parent) - : QWidget(parent) -{ - setupUi(this); - - portNumCombo->setValidator(new QIntValidator(0, 0xFFFF, this)); - portNumCombo->addItem(0, "Reserved"); - portNumCombo->addItem(80, "HTTP"); - portNumCombo->addItem(554, "RTSP"); - portNumCombo->addItem(5060, "SIP"); -} - TextProtocol::TextProtocol(StreamBase *stream, AbstractProtocol *parent) : AbstractProtocol(stream, parent) { - /* The configWidget is created lazily */ - configForm = NULL; } TextProtocol::~TextProtocol() { - delete configForm; } AbstractProtocol* TextProtocol::createInstance(StreamBase *stream, @@ -255,41 +238,3 @@ int TextProtocol::protocolFrameSize(int streamIndex) const return fieldData(textProto_text, FieldFrameValue, streamIndex) .toByteArray().size() ; } - -QWidget* TextProtocol::configWidget() -{ - /* Lazy creation of the configWidget */ - if (configForm == NULL) - { - configForm = new TextProtocolConfigForm; - loadConfigWidget(); - } - - return configForm; -} - -void TextProtocol::loadConfigWidget() -{ - configWidget(); - - configForm->portNumCombo->setValue( - fieldData(textProto_portNum, FieldValue).toUInt()); - configForm->eolCombo->setCurrentIndex( - fieldData(textProto_eol, FieldValue).toUInt()); - configForm->encodingCombo->setCurrentIndex( - fieldData(textProto_encoding, FieldValue).toUInt()); - configForm->protoText->setText( - fieldData(textProto_text, FieldValue).toString()); -} - -void TextProtocol::storeConfigWidget() -{ - configWidget(); - - setFieldData(textProto_portNum, configForm->portNumCombo->currentValue()); - setFieldData(textProto_eol, configForm->eolCombo->currentIndex()); - setFieldData(textProto_encoding, configForm->encodingCombo->currentIndex()); - - setFieldData(textProto_text, configForm->protoText->toPlainText()); -} - diff --git a/common/textproto.h b/common/textproto.h index 1ec5fc0..8c00e47 100644 --- a/common/textproto.h +++ b/common/textproto.h @@ -20,10 +20,8 @@ along with this program. If not, see #ifndef _TEXT_PROTOCOL_H #define _TEXT_PROTOCOL_H -#include "textproto.pb.h" -#include "ui_textproto.h" - #include "abstractprotocol.h" +#include "textproto.pb.h" /* TextProtocol Protocol Frame Format - @@ -31,19 +29,9 @@ TextProtocol Protocol Frame Format - specified encoding */ -class TextProtocolConfigForm : public QWidget, public Ui::TextProtocol -{ - Q_OBJECT -public: - TextProtocolConfigForm(QWidget *parent = 0); -private slots: -}; - class TextProtocol : public AbstractProtocol { -private: - OstProto::TextProtocol data; - TextProtocolConfigForm *configForm; +public: enum textProtocolField { // Frame Fields @@ -57,7 +45,6 @@ private: textProto_fieldCount }; -public: TextProtocol(StreamBase *stream, AbstractProtocol *parent = 0); virtual ~TextProtocol(); @@ -83,9 +70,8 @@ public: virtual int protocolFrameSize(int streamIndex = 0) const; - virtual QWidget* configWidget(); - virtual void loadConfigWidget(); - virtual void storeConfigWidget(); +private: + OstProto::TextProtocol data; }; #endif diff --git a/common/textproto.ui b/common/textproto.ui index f6996aa..6e7ebdb 100644 --- a/common/textproto.ui +++ b/common/textproto.ui @@ -1,6 +1,6 @@ - TextProtocol - + TextProto + 0 diff --git a/common/textprotoconfig.cpp b/common/textprotoconfig.cpp new file mode 100644 index 0000000..0242ffa --- /dev/null +++ b/common/textprotoconfig.cpp @@ -0,0 +1,84 @@ +/* +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 "textprotoconfig.h" +#include "textproto.h" + +TextProtocolConfigForm::TextProtocolConfigForm(QWidget *parent) + : AbstractProtocolConfigForm(parent) +{ + setupUi(this); + + portNumCombo->setValidator(new QIntValidator(0, 0xFFFF, this)); + portNumCombo->addItem(0, "Reserved"); + portNumCombo->addItem(80, "HTTP"); + portNumCombo->addItem(554, "RTSP"); + portNumCombo->addItem(5060, "SIP"); +} + +TextProtocolConfigForm::~TextProtocolConfigForm() +{ +} + +TextProtocolConfigForm* TextProtocolConfigForm::createInstance() +{ + return new TextProtocolConfigForm; +} + +void TextProtocolConfigForm::loadWidget(AbstractProtocol *proto) +{ + portNumCombo->setValue( + proto->fieldData( + TextProtocol::textProto_portNum, + AbstractProtocol::FieldValue + ).toUInt()); + eolCombo->setCurrentIndex( + proto->fieldData( + TextProtocol::textProto_eol, + AbstractProtocol::FieldValue + ).toUInt()); + encodingCombo->setCurrentIndex( + proto->fieldData( + TextProtocol::textProto_encoding, + AbstractProtocol::FieldValue + ).toUInt()); + protoText->setText( + proto->fieldData( + TextProtocol::textProto_text, + AbstractProtocol::FieldValue + ).toString()); +} + +void TextProtocolConfigForm::storeWidget(AbstractProtocol *proto) +{ + proto->setFieldData( + TextProtocol::textProto_portNum, + portNumCombo->currentValue()); + proto->setFieldData( + TextProtocol::textProto_eol, + eolCombo->currentIndex()); + proto->setFieldData( + TextProtocol::textProto_encoding, + encodingCombo->currentIndex()); + + proto->setFieldData( + TextProtocol::textProto_text, + protoText->toPlainText()); +} + diff --git a/common/textprotoconfig.h b/common/textprotoconfig.h new file mode 100644 index 0000000..a1971ab --- /dev/null +++ b/common/textprotoconfig.h @@ -0,0 +1,41 @@ +/* +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 _TEXT_PROTOCOL_CONFIG_H +#define _TEXT_PROTOCOL_CONFIG_H + +#include "abstractprotocolconfig.h" +#include "ui_textproto.h" + +class TextProtocolConfigForm : + public AbstractProtocolConfigForm, + private Ui::TextProto +{ + Q_OBJECT +public: + TextProtocolConfigForm(QWidget *parent = 0); + virtual ~TextProtocolConfigForm(); + + static TextProtocolConfigForm* createInstance(); + + virtual void loadWidget(AbstractProtocol *proto); + virtual void storeWidget(AbstractProtocol *proto); +}; + +#endif