diff options
Diffstat (limited to 'qdbd')
-rw-r--r-- | qdbd/createexecutor.cpp | 13 | ||||
-rw-r--r-- | qdbd/echoexecutor.cpp | 2 | ||||
-rw-r--r-- | qdbd/executor.h | 2 | ||||
-rw-r--r-- | qdbd/filepullexecutor.cpp | 108 | ||||
-rw-r--r-- | qdbd/filepullexecutor.h | 52 | ||||
-rw-r--r-- | qdbd/filepushexecutor.cpp | 102 | ||||
-rw-r--r-- | qdbd/filepushexecutor.h | 51 | ||||
-rw-r--r-- | qdbd/handshakeexecutor.cpp | 2 | ||||
-rw-r--r-- | qdbd/main.cpp | 2 | ||||
-rw-r--r-- | qdbd/processexecutor.cpp | 150 | ||||
-rw-r--r-- | qdbd/processexecutor.h | 59 | ||||
-rw-r--r-- | qdbd/qdbd.pro | 9 | ||||
-rw-r--r-- | qdbd/server.cpp | 10 | ||||
-rw-r--r-- | qdbd/server.h | 2 | ||||
-rw-r--r-- | qdbd/usb-gadget/usbgadget.cpp | 5 | ||||
-rw-r--r-- | qdbd/usb-gadget/usbgadgetreader.cpp | 4 | ||||
-rw-r--r-- | qdbd/usb-gadget/usbgadgetwriter.cpp | 4 |
17 files changed, 19 insertions, 558 deletions
diff --git a/qdbd/createexecutor.cpp b/qdbd/createexecutor.cpp index 06dc0c3..d11eb4c 100644 --- a/qdbd/createexecutor.cpp +++ b/qdbd/createexecutor.cpp @@ -20,13 +20,10 @@ ******************************************************************************/ #include "createexecutor.h" -#include "../utils/make_unique.h" #include "echoexecutor.h" -#include "filepullexecutor.h" -#include "filepushexecutor.h" #include "handshakeexecutor.h" -#include "processexecutor.h" -#include "protocol/services.h" +#include "libqdb/make_unique.h" +#include "libqdb/protocol/services.h" #include <QtCore/qdatastream.h> #include <QtCore/qfile.h> @@ -40,12 +37,6 @@ std::unique_ptr<Executor> createExecutor(Stream *stream, const QByteArray &tagBu switch (static_cast<ServiceTag>(tag)) { case EchoTag: return make_unique<EchoExecutor>(stream); - case ProcessTag: - return make_unique<ProcessExecutor>(stream); - case FilePushTag: - return make_unique<FilePushExecutor>(stream); - case FilePullTag: - return make_unique<FilePullExecutor>(stream); case HandshakeTag: return make_unique<HandshakeExecutor>(stream); default: diff --git a/qdbd/echoexecutor.cpp b/qdbd/echoexecutor.cpp index 8c6788f..325df7c 100644 --- a/qdbd/echoexecutor.cpp +++ b/qdbd/echoexecutor.cpp @@ -20,7 +20,7 @@ ******************************************************************************/ #include "echoexecutor.h" -#include "stream.h" +#include "libqdb/stream.h" #include <QtCore/qdebug.h> diff --git a/qdbd/executor.h b/qdbd/executor.h index 4dde463..cd4431b 100644 --- a/qdbd/executor.h +++ b/qdbd/executor.h @@ -22,7 +22,7 @@ #define EXECUTOR_H class Stream; -#include "streampacket.h" +#include "libqdb/streampacket.h" #include <QtCore/qobject.h> diff --git a/qdbd/filepullexecutor.cpp b/qdbd/filepullexecutor.cpp deleted file mode 100644 index ad581a8..0000000 --- a/qdbd/filepullexecutor.cpp +++ /dev/null @@ -1,108 +0,0 @@ -/****************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Debug Bridge. -** -** $QT_BEGIN_LICENSE:COMM$ -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** $QT_END_LICENSE$ -** -******************************************************************************/ -#include "filepullexecutor.h" - -#include "../utils/make_unique.h" -#include "filepullcommon.h" -#include "protocol/services.h" -#include "stream.h" - -#include <QtCore/qdatastream.h> -#include <QtCore/qdebug.h> -#include <QtCore/qfile.h> - -FilePullExecutor::FilePullExecutor(Stream *stream) - : m_stream{stream}, - m_source{nullptr}, - m_transferring{false} -{ - if (m_stream) - connect(m_stream, &Stream::packetAvailable, this, &Executor::receive); -} - -void FilePullExecutor::receive(StreamPacket packet) -{ - uint32_t typeValue; - packet >> typeValue; - auto type = toFilePullPacketType(typeValue); - switch (type) { - case FilePullOpen: { - QString sourcePath; - packet >> sourcePath; - if (openSource(sourcePath)) - transferBlock(); - break; - } - case FilePullWasRead: - qDebug() << "File pull read acknowledged."; - if (m_transferring) - transferBlock(); - else - closeSource(); - break; - case FilePullError: - qDebug() << "FilePullError from host"; - closeSource(); - break; - default: - qFatal("Unsupported FilePushPacketType %d in ProcessExecutor::receive", type); - } -} - -bool FilePullExecutor::openSource(const QString &path) -{ - qDebug() << "Opening source file" << path; - m_source = make_unique<QFile>(path); - bool opened = m_source->open(QIODevice::ReadOnly); - - StreamPacket packet; - - if (!opened) { - packet << FilePullError - << QString{"Could not open \"%1\" on device"}.arg(m_source->fileName()); - } else { - packet << FilePullOpened; - } - - return m_stream->write(packet) && opened; -} - -void FilePullExecutor::transferBlock() -{ - QByteArray block = m_source->read(fileTransferBlockSize); - m_transferring = !m_source->atEnd(); - - StreamPacket packet; - packet << FilePullRead << block; - - m_stream->write(packet); -} - -void FilePullExecutor::closeSource() -{ - qDebug() << "Closing source file" << m_source->fileName(); - m_source->close(); - - StreamPacket packet; - packet << FilePullEnd; - - m_stream->write(packet); -} diff --git a/qdbd/filepullexecutor.h b/qdbd/filepullexecutor.h deleted file mode 100644 index 7f33583..0000000 --- a/qdbd/filepullexecutor.h +++ /dev/null @@ -1,52 +0,0 @@ -/****************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Debug Bridge. -** -** $QT_BEGIN_LICENSE:COMM$ -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** $QT_END_LICENSE$ -** -******************************************************************************/ -#ifndef FILEPULLEXECUTOR_H -#define FILEPULLEXECUTOR_H - -#include "executor.h" -class Stream; - -QT_BEGIN_NAMESPACE -class QByteArray; -class QFile; -QT_END_NAMESPACE - -#include <memory> - -class FilePullExecutor : public Executor -{ -public: - explicit FilePullExecutor(Stream *stream); - -public slots: - void receive(StreamPacket packet) override; - -private: - bool openSource(const QString &path); - void transferBlock(); - void closeSource(); - - Stream* m_stream; - std::unique_ptr<QFile> m_source; - bool m_transferring; -}; - -#endif // FILEPULLEXECUTOR_H diff --git a/qdbd/filepushexecutor.cpp b/qdbd/filepushexecutor.cpp deleted file mode 100644 index a208a11..0000000 --- a/qdbd/filepushexecutor.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/****************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Debug Bridge. -** -** $QT_BEGIN_LICENSE:COMM$ -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** $QT_END_LICENSE$ -** -******************************************************************************/ -#include "filepushexecutor.h" - -#include "../utils/make_unique.h" -#include "filepushcommon.h" -#include "stream.h" - -#include <QtCore/qdatastream.h> -#include <QtCore/qdebug.h> -#include <QtCore/qfile.h> - -FilePushExecutor::FilePushExecutor(Stream *stream) - : m_stream{stream}, - m_sink{nullptr} -{ - if (m_stream) - connect(m_stream, &Stream::packetAvailable, this, &Executor::receive); -} - -void FilePushExecutor::receive(StreamPacket packet) -{ - uint32_t typeValue; - packet >> typeValue; - auto type = toFilePushPacketType(typeValue); - switch (type) { - case FilePushOpen: { - QString sinkPath; - packet >> sinkPath; - openSink(sinkPath); - break; - } - case FilePushWrite: { - QByteArray fileData; - packet >> fileData; - writeToSink(fileData); - break; - } - case FilePushEnd: - closeSink(); - break; - case FilePushError: - qDebug() << "FilePushError from host"; - if (m_sink) - m_sink->remove(); - break; - default: - qFatal("Unsupported FilePushPacketType %d in ProcessExecutor::receive", type); - } -} - -void FilePushExecutor::openSink(const QString &path) -{ - qDebug() << "Opening sink file" << path; - m_sink = make_unique<QFile>(path); - StreamPacket packet; - - if (!m_sink->open(QIODevice::WriteOnly)) - packet << FilePushError; - else - packet << FilePushOpened; - - m_stream->write(packet); -} - -void FilePushExecutor::writeToSink(const QByteArray &data) -{ - auto written = m_sink->write(data); - - StreamPacket packet; - - if (written != data.size()) - packet << FilePushError; - else - packet << FilePushWritten; - - m_stream->write(packet); -} - -void FilePushExecutor::closeSink() -{ - qDebug() << "Closing sink file" << m_sink->fileName(); - m_sink->close(); -} diff --git a/qdbd/filepushexecutor.h b/qdbd/filepushexecutor.h deleted file mode 100644 index 29f11b2..0000000 --- a/qdbd/filepushexecutor.h +++ /dev/null @@ -1,51 +0,0 @@ -/****************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Debug Bridge. -** -** $QT_BEGIN_LICENSE:COMM$ -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** $QT_END_LICENSE$ -** -******************************************************************************/ -#ifndef FILEPUSHEXECUTOR_H -#define FILEPUSHEXECUTOR_H - -#include "executor.h" -class Stream; - -QT_BEGIN_NAMESPACE -class QByteArray; -class QFile; -QT_END_NAMESPACE - -#include <memory> - -class FilePushExecutor : public Executor -{ -public: - explicit FilePushExecutor(Stream *stream); - -public slots: - void receive(StreamPacket packet) override; - -private: - void openSink(const QString &path); - void writeToSink(const QByteArray &data); - void closeSink(); - - Stream* m_stream; - std::unique_ptr<QFile> m_sink; -}; - -#endif // FILEPUSHEXECUTOR_H diff --git a/qdbd/handshakeexecutor.cpp b/qdbd/handshakeexecutor.cpp index b5dc9cb..f40ff97 100644 --- a/qdbd/handshakeexecutor.cpp +++ b/qdbd/handshakeexecutor.cpp @@ -20,7 +20,7 @@ ******************************************************************************/ #include "handshakeexecutor.h" -#include "stream.h" +#include "libqdb/stream.h" #include <QtCore/qdebug.h> #include <QtCore/qfile.h> diff --git a/qdbd/main.cpp b/qdbd/main.cpp index 208e8c9..17397ac 100644 --- a/qdbd/main.cpp +++ b/qdbd/main.cpp @@ -18,9 +18,9 @@ ** $QT_END_LICENSE$ ** ******************************************************************************/ +#include "libqdb/protocol/qdbtransport.h" #include "usb-gadget/usbgadget.h" #include "server.h" -#include "protocol/qdbtransport.h" #include <QtCore/qcommandlineparser.h> #include <QtCore/qcoreapplication.h> diff --git a/qdbd/processexecutor.cpp b/qdbd/processexecutor.cpp deleted file mode 100644 index 7ea2e6c..0000000 --- a/qdbd/processexecutor.cpp +++ /dev/null @@ -1,150 +0,0 @@ -/****************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Debug Bridge. -** -** $QT_BEGIN_LICENSE:COMM$ -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** $QT_END_LICENSE$ -** -******************************************************************************/ -#include "processexecutor.h" - -#include "../utils/make_unique.h" -#include "processcommon.h" -#include "stream.h" - -#include <QtCore/qdatastream.h> -#include <QtCore/qdebug.h> -#include <QtCore/qprocess.h> - -ProcessExecutor::ProcessExecutor(Stream *stream) - : m_stream{stream}, - m_process{nullptr} -{ - if (m_stream) { - connect(m_stream, &Stream::packetAvailable, this, &Executor::receive); - connect(m_stream, &Stream::closed, this, &Executor::onStreamClosed); - } -} - -void ProcessExecutor::receive(StreamPacket packet) -{ - uint32_t typeValue; - packet >> typeValue; - auto type = toProcessPacketType(typeValue); - switch (type) { - case ProcessStart: { - QString command; - QStringList arguments; - packet >> command >> arguments; - startProcess(command, arguments); - break; - } - case ProcessWrite: { - QByteArray data; - packet >> data; - writeToProcess(data); - break; - } - default: - Q_ASSERT_X(false, "ProcessExecutor::receive", "Unsupported ProcessPacketType"); - break; - } -} - -void ProcessExecutor::onStarted() -{ - qDebug() << "Process started"; - - StreamPacket packet; - packet << ProcessStarted; - - if (m_stream) - m_stream->write(packet); -} - -void ProcessExecutor::onReadyRead() -{ - qDebug() << "Process readyRead"; - auto size = m_process->bytesAvailable(); - QByteArray read = m_process->read(size); - - StreamPacket packet; - packet << ProcessRead; - packet << read; - - if (m_stream) - m_stream->write(packet); -} - -void ProcessExecutor::onFinished(int exitCode, QProcess::ExitStatus exitStatus) -{ - qDebug() << "Process finished:" << exitCode; - - QByteArray output = m_process->readAll(); - - StreamPacket packet; - packet << ProcessFinished; - packet << exitCode; - packet << (exitStatus == QProcess::NormalExit); - packet << output; - - if (m_stream) - m_stream->write(packet); -} - -void ProcessExecutor::onErrorOccurred(QProcess::ProcessError error) -{ - qDebug() << "Process error:" << error; - - StreamPacket packet; - packet << ProcessError; - uint32_t errorValue = static_cast<uint32_t>(error); - packet << errorValue; - - if (m_stream) - m_stream->write(packet); -} - -void ProcessExecutor::onStreamClosed() -{ - m_stream = nullptr; - if (m_process) { - m_process->kill(); - } -} - -void ProcessExecutor::startProcess(const QString &command, const QStringList &arguments) -{ - m_process = make_unique<QProcess>(); - // merge stdout and stderr - m_process->setProcessChannelMode(QProcess::MergedChannels); - - connect(m_process.get(), &QProcess::started, this, &ProcessExecutor::onStarted); - connect(m_process.get(), &QProcess::readyRead, this, &ProcessExecutor::onReadyRead); - connect(m_process.get(), static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished), - this, &ProcessExecutor::onFinished); - connect(m_process.get(), &QProcess::errorOccurred, this, &ProcessExecutor::onErrorOccurred); - - qDebug() << "Running" << command << arguments; - m_process->start(command, arguments); -} - -void ProcessExecutor::writeToProcess(const QByteArray &data) -{ - Q_ASSERT(m_process); - - qDebug() << "Writing to process:" << data; - m_process->write(data); -} diff --git a/qdbd/processexecutor.h b/qdbd/processexecutor.h deleted file mode 100644 index 2856391..0000000 --- a/qdbd/processexecutor.h +++ /dev/null @@ -1,59 +0,0 @@ -/****************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Debug Bridge. -** -** $QT_BEGIN_LICENSE:COMM$ -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** $QT_END_LICENSE$ -** -******************************************************************************/ -#ifndef PROCESSEXECUTOR_H -#define PROCESSEXECUTOR_H - -#include "executor.h" -class Stream; - -#include "QtCore/qprocess.h" -QT_BEGIN_NAMESPACE -class QByteArray; -class QDataStream; -QT_END_NAMESPACE - -#include <memory> - -class ProcessExecutor : public Executor -{ - Q_OBJECT -public: - explicit ProcessExecutor(Stream *stream); - -public slots: - void receive(StreamPacket packet) override; - -private slots: - void onStarted(); - void onReadyRead(); - void onFinished(int exitCode, QProcess::ExitStatus exitStatus); - void onErrorOccurred(QProcess::ProcessError error); - void onStreamClosed(); - -private: - void startProcess(const QString &command, const QStringList &arguments); - void writeToProcess(const QByteArray &data); - - Stream *m_stream; - std::unique_ptr<QProcess> m_process; -}; - -#endif // PROCESSEXECUTOR_H diff --git a/qdbd/qdbd.pro b/qdbd/qdbd.pro index 76ec5df..929d753 100644 --- a/qdbd/qdbd.pro +++ b/qdbd/qdbd.pro @@ -13,31 +13,24 @@ SOURCES += \ createexecutor.cpp \ echoexecutor.cpp \ executor.cpp \ - filepullexecutor.cpp \ - filepushexecutor.cpp \ handshakeexecutor.cpp \ main.cpp \ - processexecutor.cpp \ server.cpp \ usb-gadget/usbgadget.cpp \ usb-gadget/usbgadgetreader.cpp \ usb-gadget/usbgadgetwriter.cpp \ - HEADERS += \ createexecutor.h \ echoexecutor.h \ executor.h \ - filepullexecutor.h \ - filepushexecutor.h \ handshakeexecutor.h \ - processexecutor.h \ server.h \ usb-gadget/usbgadget.h \ usb-gadget/usbgadgetreader.h \ usb-gadget/usbgadgetwriter.h \ -INCLUDEPATH += $$PWD/../libqdb +INCLUDEPATH += $$PWD/../ LIBS = -L$$OUT_PWD/../libqdb -lqdb QMAKE_RPATHDIR += ../libqdb diff --git a/qdbd/server.cpp b/qdbd/server.cpp index 16b0476..2757c70 100644 --- a/qdbd/server.cpp +++ b/qdbd/server.cpp @@ -20,13 +20,13 @@ ******************************************************************************/ #include "server.h" -#include "../utils/make_unique.h" #include "createexecutor.h" #include "echoexecutor.h" -#include "protocol/protocol.h" -#include "protocol/qdbmessage.h" -#include "protocol/qdbtransport.h" -#include "stream.h" +#include "libqdb/make_unique.h" +#include "libqdb/protocol/protocol.h" +#include "libqdb/protocol/qdbmessage.h" +#include "libqdb/protocol/qdbtransport.h" +#include "libqdb/stream.h" #include <QtCore/qdebug.h> #include <QtCore/qloggingcategory.h> diff --git a/qdbd/server.h b/qdbd/server.h index 6f5d36a..8f8bf09 100644 --- a/qdbd/server.h +++ b/qdbd/server.h @@ -21,7 +21,7 @@ #ifndef SERVER_H #define SERVER_H -#include "abstractconnection.h" +#include "libqdb/abstractconnection.h" class Executor; class QdbMessage; class QdbTransport; diff --git a/qdbd/usb-gadget/usbgadget.cpp b/qdbd/usb-gadget/usbgadget.cpp index 6d65312..d660b22 100644 --- a/qdbd/usb-gadget/usbgadget.cpp +++ b/qdbd/usb-gadget/usbgadget.cpp @@ -20,9 +20,8 @@ ******************************************************************************/ #include "usbgadget.h" -#include "../utils/make_unique.h" -#include "protocol/protocol.h" -#include "protocol/qdbmessage.h" +#include "libqdb/make_unique.h" +#include "libqdb/qdbconstants.h" #include "usb-gadget/usbgadgetreader.h" #include "usb-gadget/usbgadgetwriter.h" diff --git a/qdbd/usb-gadget/usbgadgetreader.cpp b/qdbd/usb-gadget/usbgadgetreader.cpp index 2aa6bf0..dfb5600 100644 --- a/qdbd/usb-gadget/usbgadgetreader.cpp +++ b/qdbd/usb-gadget/usbgadgetreader.cpp @@ -20,8 +20,8 @@ ******************************************************************************/ #include "usbgadgetreader.h" -#include "protocol/protocol.h" -#include "protocol/qdbmessage.h" +#include "libqdb/protocol/protocol.h" +#include "libqdb/protocol/qdbmessage.h" #include <QtCore/qdebug.h> #include <QtCore/qfile.h> diff --git a/qdbd/usb-gadget/usbgadgetwriter.cpp b/qdbd/usb-gadget/usbgadgetwriter.cpp index 315514a..3e48349 100644 --- a/qdbd/usb-gadget/usbgadgetwriter.cpp +++ b/qdbd/usb-gadget/usbgadgetwriter.cpp @@ -20,8 +20,8 @@ ******************************************************************************/ #include "usbgadgetwriter.h" -#include "protocol/protocol.h" -#include "protocol/qdbmessage.h" +#include "libqdb/protocol/protocol.h" +#include "libqdb/protocol/qdbmessage.h" #include <QtCore/qdebug.h> #include <QtCore/qfile.h> |