Skip to content

Commit

Permalink
fix: code quality improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
CooperW824 committed Aug 21, 2021
1 parent 001e772 commit a44f957
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 33 deletions.
4 changes: 2 additions & 2 deletions src/hobbits-plugins/importerexporters/UsbDevice/usbdevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ QSharedPointer<ImportResult> UsbDevice::importBits(const Parameters &parameters,
attach = false;
}
//throw an error if an error occured
return ImportResult::error("Transfer Error, Code: " + QString::number(transferReturn) + " " + libusb_error_name(transferReturn));
return returnError(transferReturn);
}
else
{
Expand Down Expand Up @@ -333,7 +333,7 @@ QSharedPointer<ImportResult> UsbDevice::importBits(const Parameters &parameters,
libusb_reset_device(params.handle);
attach = false;
}
return ImportResult::error("Transfer Error, Code: " + QString::number(transferReturn) + " " + libusb_error_name(transferReturn));
return returnError(transferReturn);
}
else
{
Expand Down
60 changes: 31 additions & 29 deletions src/hobbits-plugins/importerexporters/UsbDevice/usbdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,6 @@
#include "parameterdelegate.h"
#include <libusb-1.0/libusb.h>

typedef struct UsbParams
{
//the pointer to the libusb device selected
libusb_device *dev;
//the pointer to the device list generated
libusb_device **devs;
//the pointer to the configuration descriptor generated
libusb_config_descriptor *config;
// the pointer to the libusb context for the active libusb session
libusb_context *ctx;
//the handle of the device used for transfers and device interactions
libusb_device_handle *handle;
//the number of the device selected
int deviceNum;
//the number of the interface selected
int interfaceNum;
//the number of the alternate setting selected
int altSetNum;
//number of the endpoint selected
int endpointNum;
//the address of the endpoint selected
unsigned char endpoint;
//any possible error codes passed
int errorCode;
}StructName;

class UsbDevice : public QObject, ImporterExporterInterface
{
Q_OBJECT
Expand Down Expand Up @@ -59,14 +33,42 @@ class UsbDevice : public QObject, ImporterExporterInterface
const Parameters &parameters,
QSharedPointer<PluginActionProgress> progress) override;

void setupLibusb(UsbParams &params);

QSharedPointer<ImportResult> returnError(int errorCode);
void exitLibusb(bool closeDevice, UsbParams &params);


private:
QSharedPointer<ParameterDelegate> m_importDelegate;
QSharedPointer<ParameterDelegate> m_exportDelegate;


typedef struct UsbParams
{
//the pointer to the libusb device selected
libusb_device *dev;
//the pointer to the device list generated
libusb_device **devs;
//the pointer to the configuration descriptor generated
libusb_config_descriptor *config;
// the pointer to the libusb context for the active libusb session
libusb_context *ctx;
//the handle of the device used for transfers and device interactions
libusb_device_handle *handle;
//the number of the device selected
int deviceNum;
//the number of the interface selected
int interfaceNum;
//the number of the alternate setting selected
int altSetNum;
//number of the endpoint selected
int endpointNum;
//the address of the endpoint selected
unsigned char endpoint;
//any possible error codes passed
int errorCode;
}UsbParams;

void exitLibusb(bool closeDevice, UsbParams &params);
void setupLibusb(UsbParams &params);
};


Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ public slots:
void initLibusb();
QStringList getUsbDevices();
void updateSelector(QComboBox *selector, QStringList items);
void clearSelectors(QComboBox *boxes[]);
QString addLeadingZeros(std::string str);
QStringList getVendorAndProduct(QString idVendor, QString idProduct);
Ui::UsbDeviceImportEditor *ui;
QSharedPointer<ParameterHelper> m_paramHelper;
Expand Down

0 comments on commit a44f957

Please sign in to comment.