-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from Mahlet-Inc/develop
merge in TCP stream import/export plugin
- Loading branch information
Showing
14 changed files
with
748 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#------------------------------------------------- | ||
# | ||
# Project created by QtCreator 2020-04-10T16:34:57.900Z | ||
# | ||
#------------------------------------------------- | ||
|
||
QT += widgets network | ||
|
||
QT -= gui | ||
|
||
TARGET = TcpData | ||
TEMPLATE = lib | ||
|
||
DEFINES += TCPDATA_LIBRARY | ||
|
||
CONFIG += c++11 plugin | ||
CONFIG -= debug_and_release_target | ||
|
||
# The following define makes your compiler emit warnings if you use | ||
# any feature of Qt which has been marked as deprecated (the exact warnings | ||
# depend on your compiler). Please consult the documentation of the | ||
# deprecated API in order to know how to port your code away from it. | ||
DEFINES += QT_DEPRECATED_WARNINGS | ||
|
||
# You can also make your code fail to compile if you use deprecated APIs. | ||
# In order to do so, uncomment the following line. | ||
# You can also select to disable deprecated APIs only up to a certain version of Qt. | ||
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 | ||
|
||
SOURCES += tcpdata.cpp \ | ||
tcpreceiver.cpp \ | ||
tcpsender.cpp | ||
|
||
HEADERS += tcpdata.h \ | ||
tcpreceiver.h \ | ||
tcpsender.h | ||
|
||
|
||
LIBS += -L$$OUT_PWD/../../../hobbits-core/ -lhobbits-core | ||
|
||
INCLUDEPATH += $$PWD/../../../hobbits-core | ||
DEPENDPATH += $$PWD/../../../hobbits-core | ||
|
||
unix:{ | ||
QMAKE_LFLAGS_RPATH= | ||
QMAKE_LFLAGS += "-Wl,-rpath,'$$ORIGIN/../../lib:$$ORIGIN'" | ||
} | ||
|
||
unix { | ||
target.path = target.path = $$(HOME)/.local/share/hobbits/plugins/analyzers | ||
INSTALLS += target | ||
} | ||
|
||
FORMS += \ | ||
tcpreceiver.ui \ | ||
tcpsender.ui |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#include "tcpdata.h" | ||
#include "tcpreceiver.h" | ||
#include "tcpsender.h" | ||
|
||
TcpData::TcpData() | ||
{ | ||
|
||
} | ||
|
||
TcpData::~TcpData() | ||
{ | ||
} | ||
|
||
ImportExportInterface* TcpData::createDefaultImporterExporter() | ||
{ | ||
return new TcpData(); | ||
} | ||
|
||
QString TcpData::getName() | ||
{ | ||
return "TCP Data"; | ||
} | ||
|
||
bool TcpData::canExport() | ||
{ | ||
return true; | ||
} | ||
|
||
bool TcpData::canImport() | ||
{ | ||
return true; | ||
} | ||
|
||
QString TcpData::getImportLabelForState(QJsonObject pluginState) | ||
{ | ||
if (pluginState.contains("port") && pluginState.value("port").isDouble()) { | ||
return QString("TCP Listen on port %1").arg(pluginState.value("port").toInt()); | ||
} | ||
return ""; | ||
} | ||
|
||
QString TcpData::getExportLabelForState(QJsonObject pluginState) | ||
{ | ||
if (pluginState.contains("port") && pluginState.value("port").isDouble() | ||
&& pluginState.contains("host") && pluginState.value("host").isString()) { | ||
return QString("TCP Export to %1 on port %2").arg(pluginState.value("host").toString()).arg(pluginState.value("port").toInt()); | ||
} | ||
return ""; | ||
} | ||
|
||
QSharedPointer<ImportExportResult> TcpData::importBits(QJsonObject pluginState, QWidget *parent) | ||
{ | ||
QSharedPointer<TcpReceiver> receiver = QSharedPointer<TcpReceiver>(new TcpReceiver(parent)); | ||
if (pluginState.contains("port") && pluginState.value("port").isDouble()) { | ||
receiver->setPort(pluginState.value("port").toInt()); | ||
receiver->startListening(); | ||
} | ||
|
||
if (receiver->exec()) { | ||
QSharedPointer<BitContainer> container = QSharedPointer<BitContainer>(new BitContainer()); | ||
container->setBits(receiver->getDownloadedData()); | ||
container->setName("TCP Import"); | ||
QJsonObject state; | ||
state.insert("port", receiver->getPort()); | ||
return ImportExportResult::create(container, state); | ||
} | ||
else { | ||
return ImportExportResult::error(receiver->getError()); | ||
} | ||
} | ||
|
||
QSharedPointer<ImportExportResult> TcpData::exportBits( | ||
QSharedPointer<const BitContainer> container, | ||
QJsonObject pluginState, | ||
QWidget *parent) | ||
{ | ||
QSharedPointer<TcpSender> sender = QSharedPointer<TcpSender>(new TcpSender(container->bits(), parent)); | ||
if (pluginState.contains("port") && pluginState.value("port").isDouble() | ||
&& pluginState.contains("host") && pluginState.value("host").isString()) { | ||
sender->setPort(pluginState.value("port").toInt()); | ||
sender->setHost(pluginState.value("host").toString()); | ||
sender->sendData(); | ||
} | ||
|
||
if (sender->exec()) { | ||
QJsonObject state; | ||
state.insert("port", sender->getPort()); | ||
state.insert("host", sender->getHost()); | ||
return ImportExportResult::create(state); | ||
} | ||
else { | ||
return ImportExportResult::error("Failed to export bits over TCP"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#ifndef TCPDATA_H | ||
#define TCPDATA_H | ||
|
||
#include "importexportinterface.h" | ||
|
||
class TcpData : public QObject, ImportExportInterface | ||
{ | ||
Q_OBJECT | ||
Q_PLUGIN_METADATA(IID "hobbits.ImportExportInterface.TcpData") | ||
Q_INTERFACES(ImportExportInterface) | ||
|
||
public: | ||
TcpData(); | ||
~TcpData(); | ||
|
||
ImportExportInterface* createDefaultImporterExporter() override; | ||
|
||
QString getName() override; | ||
|
||
bool canExport() override; | ||
bool canImport() override; | ||
|
||
QString getImportLabelForState(QJsonObject pluginState) override; | ||
QString getExportLabelForState(QJsonObject pluginState) override; | ||
|
||
QSharedPointer<ImportExportResult> importBits(QJsonObject pluginState, QWidget *parent) override; | ||
QSharedPointer<ImportExportResult> exportBits( | ||
QSharedPointer<const BitContainer> container, | ||
QJsonObject pluginState, | ||
QWidget *parent) override; | ||
|
||
private: | ||
}; | ||
|
||
#endif // TCPDATA_H |
Oops, something went wrong.