Remove Boost Dependency - Devices

All devices no longer need boost (use signals and slots instead), other
than SRM.
This commit is contained in:
Andy Bryson
2012-12-28 11:05:48 +00:00
committed by Mark Liversedge
parent 9039fca136
commit 356a80a448
11 changed files with 81 additions and 84 deletions

View File

@@ -17,6 +17,7 @@
*/
#include "Device.h"
#include "assert.h"
typedef QMap<QString,DevicesPtr> DevicesMap;
@@ -39,7 +40,6 @@ Device::~Device()
bool
Device::preview( QString &err )
{
(void) statusCallback;
(void) err;
return true;
@@ -60,6 +60,12 @@ Device::cleanup( QString &err )
return false;
}
void
Device::cancelled()
{
m_Cancelled = true;
}
QList<QString>
Devices::typeNames()

View File

@@ -21,7 +21,7 @@
#include "GoldenCheetah.h"
#include "CommPort.h"
#include <boost/function.hpp>
#include <QObject>
#include <QApplication>
struct DeviceDownloadFile
@@ -46,20 +46,16 @@ struct DeviceRideItem
};
typedef QSharedPointer<DeviceRideItem> DeviceRideItemPtr;
struct Device;
class Device;
typedef QSharedPointer<Device> DevicePtr;
struct Device
class Device : public QObject
{
Q_DECLARE_TR_FUNCTIONS(Device)
Q_OBJECT
public:
typedef boost::function<bool (void)> CancelCallback;
typedef boost::function<void (const QString &statusText)> StatusCallback;
typedef boost::function<void (const QString &progressText)> ProgressCallback;
Device( CommPortPtr dev, StatusCallback cb )
: dev( dev ), statusCallback( cb )
public:
Device( CommPortPtr dev )
: dev( dev ), m_Cancelled( false )
{};
virtual ~Device();
@@ -68,16 +64,21 @@ struct Device
virtual bool download( const QDir &tmpdir,
QList<DeviceDownloadFile> &files,
CancelCallback cancelCallback,
ProgressCallback progressCallback,
QString &err) = 0;
virtual bool cleanup( QString &err );
signals:
void updateStatus( QString statusText );
void updateProgress( QString progressText );
public slots:
virtual void cancelled();
protected:
QList<DeviceRideItemPtr> rideList;
CommPortPtr dev;
StatusCallback statusCallback;
bool m_Cancelled;
};
struct Devices;
@@ -86,7 +87,7 @@ typedef QSharedPointer<Devices> DevicesPtr;
struct Devices
{
virtual ~Devices() {}
virtual DevicePtr newDevice( CommPortPtr, Device::StatusCallback ) = 0;
virtual DevicePtr newDevice( CommPortPtr ) = 0;
// port *might* be supported by this device type implementation:
virtual bool supportsPort( CommPortPtr dev ) { (void)dev; return true; };

View File

@@ -25,7 +25,6 @@
#include <assert.h>
#include <errno.h>
#include <QtGui>
#include <boost/bind.hpp>
DownloadRideDialog::DownloadRideDialog(MainWindow *mainWindow,
const QDir &home) :
@@ -283,8 +282,11 @@ DownloadRideDialog::downloadClicked()
QList<DeviceDownloadFile> files;
DevicesPtr devtype = Devices::getType(deviceCombo->currentText());
DevicePtr device = devtype->newDevice( dev,
boost::bind(&DownloadRideDialog::updateStatus, this, _1) );
DevicePtr device = devtype->newDevice( dev );
connect( device.data(), SIGNAL(updateStatus(QString)), this, SLOT(updateStatus(QString)));
connect( this, SIGNAL(cancel()), device.data(), SLOT(cancelled()) );
connect( device.data(), SIGNAL(updateProgress(QString)), this, SLOT(updateProgress(QString)));
updateStatus(tr("getting summary ..."));
if( ! device->preview( err ) ){
@@ -303,10 +305,7 @@ DownloadRideDialog::downloadClicked()
}
updateStatus(tr("getting data ..."));
if (!device->download( home, files,
boost::bind(&DownloadRideDialog::isCancelled, this),
boost::bind(&DownloadRideDialog::updateProgress, this, _1),
err))
if (!device->download( home, files, err))
{
if (cancelled) {
QMessageBox::information(this, tr("Download canceled"),
@@ -415,8 +414,7 @@ DownloadRideDialog::eraseClicked()
}
assert(dev);
DevicesPtr devtype = Devices::getType(deviceCombo->currentText());
DevicePtr device = devtype->newDevice( dev,
boost::bind(&DownloadRideDialog::updateStatus, this, _1) );
DevicePtr device = devtype->newDevice( dev );
QString err;
if( device->cleanup( err) )
@@ -438,6 +436,7 @@ DownloadRideDialog::cancelClicked()
default:
cancelled = true;
emit cancel();
break;
}
}

View File

@@ -35,8 +35,9 @@ class DownloadRideDialog : public QDialog
DownloadRideDialog(MainWindow *mainWindow, const QDir &home);
bool isCancelled();
void updateStatus(const QString &statusText);
void updateProgress(const QString &progressText);
signals:
void cancel();
private slots:
void downloadClicked();
@@ -46,6 +47,8 @@ class DownloadRideDialog : public QDialog
void setReadyInstruct();
void scanCommPorts();
void deviceChanged(QString);
void updateStatus(const QString &statusText);
void updateProgress(const QString &progressText);
private:

View File

@@ -49,9 +49,9 @@ JouleDevices::downloadInstructions() const
}
DevicePtr
JouleDevices::newDevice( CommPortPtr dev, Device::StatusCallback cb )
JouleDevices::newDevice( CommPortPtr dev )
{
return DevicePtr( new JouleDevice( dev, cb ));
return DevicePtr( new JouleDevice( dev ));
}
static QString
@@ -113,8 +113,6 @@ readOneByOne(CommPortPtr dev, void *buf, size_t nbyte, QString &err)
bool
JouleDevice::download( const QDir &tmpdir,
QList<DeviceDownloadFile> &files,
CancelCallback cancelCallback,
ProgressCallback progressCallback,
QString &err)
{
if (JOULE_DEBUG) printf("download Joule 1.0 or GPS");
@@ -137,14 +135,14 @@ JouleDevice::download( const QDir &tmpdir,
}
bool isJouleGPS = getJouleGPS(versionResponse);
statusCallback(QString("Joule %1 indentified").arg(isJouleGPS?"GPS":"1.0"));
emit updateStatus(QString("Joule %1 indentified").arg(isJouleGPS?"GPS":"1.0"));
QList<DeviceStoredRideItem> trainings;
if (!getDownloadableRides(trainings, isJouleGPS, err))
return false;
for (int i=0; i<trainings.count(); i++) {
progressCallback(QString("Read ride detail for ride %1/%2").arg(i+1).arg(trainings.count()));
emit updateProgress(QString("Read ride detail for ride %1/%2").arg(i+1).arg(trainings.count()));
JoulePacket request(READ_RIDE_DETAIL);
int id1 = (trainings.at(i).id>255?trainings.at(i).id-255:trainings.at(i).id);
int id2 = (trainings.at(i).id>255?trainings.at(i).id%255:0);
@@ -156,7 +154,7 @@ JouleDevice::download( const QDir &tmpdir,
if (!request.write(dev, err))
return false;
if (cancelCallback())
if(m_Cancelled)
{
err = "download cancelled";
return false;
@@ -276,7 +274,7 @@ JouleDevice::download( const QDir &tmpdir,
bool
JouleDevice::getUnitVersion(JoulePacket &response, QString &err)
{
statusCallback("Get Unit Software Version...");
emit updateStatus("Get Unit Software Version...");
if (JOULE_DEBUG) printf("Get Unit Software Version\n");
JoulePacket request(READ_UNIT_VERSION);
@@ -295,7 +293,7 @@ JouleDevice::getUnitVersion(JoulePacket &response, QString &err)
data_version = qByteArray2Int(response.payload.right(2));
QString version = QString(minor_version<100?"%1.0%2 (%3)":"%1.%2 (%3)").arg(major_version).arg(minor_version).arg(data_version);
statusCallback("Version"+version);
emit updateStatus("Version"+version);
return true;
}
}
@@ -305,7 +303,7 @@ JouleDevice::getUnitVersion(JoulePacket &response, QString &err)
bool
JouleDevice::getSystemInfo(JoulePacket &response, QString &err)
{
statusCallback("Get System info...");
emit updateStatus("Get System info...");
if (JOULE_DEBUG) printf("Get System info\n");
JoulePacket request(READ_SYSTEM_INFO);
@@ -329,7 +327,7 @@ JouleDevice::getSystemInfo(JoulePacket &response, QString &err)
bool
JouleDevice::getUnitFreeSpace(QString &memory, QString &err)
{
statusCallback("Get Unit Free Space...");
emit updateStatus("Get Unit Free Space...");
if (JOULE_DEBUG) printf("Get Unit Free Space\n");
JoulePacket request1(GET_FREE_SPACE);
@@ -354,7 +352,7 @@ JouleDevice::getUnitFreeSpace(QString &memory, QString &err)
bool
JouleDevice::getDownloadableRides(QList<DeviceStoredRideItem> &rides, bool isJouleGPS, QString &err)
{
statusCallback("Read ride summary...");
emit updateStatus("Read ride summary...");
if (JOULE_DEBUG) printf("Read ride summary\n");
JoulePacket request(READ_RIDE_SUMMARY);
@@ -386,7 +384,7 @@ JouleDevice::getDownloadableRides(QList<DeviceStoredRideItem> &rides, bool isJou
rides.append(ride);
}
}
statusCallback(QString("%1 detailled rides").arg(rides.count()));
emit updateStatus(QString("%1 detailled rides").arg(rides.count()));
return true;
}
return false;
@@ -394,7 +392,7 @@ JouleDevice::getDownloadableRides(QList<DeviceStoredRideItem> &rides, bool isJou
bool
JouleDevice::cleanup( QString &err ) {
statusCallback("Erase all records on computer");
emit updateStatus("Erase all records on computer");
if (JOULE_DEBUG) printf("Erase all records on computer\n");
if (!dev->open(err)) {
@@ -412,7 +410,7 @@ JouleDevice::cleanup( QString &err ) {
return false;
for (int i=0; i<trainings.count(); i++) {
statusCallback(QString("Delete ride detail for ride %1/%2").arg(i+1).arg(trainings.count()));
emit updateStatus(QString("Delete ride detail for ride %1/%2").arg(i+1).arg(trainings.count()));
JoulePacket request(ERASE_RIDE_DETAIL);
int id1 = (trainings.at(i).id>255?trainings.at(i).id-255:trainings.at(i).id);
int id2 = (trainings.at(i).id>255?trainings.at(i).id%255:0);

View File

@@ -3,6 +3,7 @@
#include "CommPort.h"
#include "Device.h"
#include "stdint.h"
class DeviceFileInfo;
class JoulePacket;
@@ -12,7 +13,7 @@ struct JouleDevices : public Devices
Q_DECLARE_TR_FUNCTIONS(JouleDevices)
public:
virtual DevicePtr newDevice( CommPortPtr dev, Device::StatusCallback cb );
virtual DevicePtr newDevice( CommPortPtr dev );
virtual QString downloadInstructions() const;
virtual bool canCleanup( void ) {return true; };
};
@@ -22,13 +23,11 @@ struct JouleDevice : public Device
Q_DECLARE_TR_FUNCTIONS(JouleDevice)
public:
JouleDevice( CommPortPtr dev, StatusCallback cb ) :
Device( dev, cb ) {};
JouleDevice( CommPortPtr dev ) :
Device( dev ) {};
virtual bool download( const QDir &tmpdir,
QList<DeviceDownloadFile> &files,
CancelCallback cancelCallback,
ProgressCallback progressCallback,
QString &err);
virtual bool cleanup( QString &err );

View File

@@ -51,9 +51,9 @@ MacroDevices::downloadInstructions() const
}
DevicePtr
MacroDevices::newDevice( CommPortPtr dev, Device::StatusCallback cb )
MacroDevices::newDevice( CommPortPtr dev )
{
return DevicePtr( new MacroDevice( dev, cb ));
return DevicePtr( new MacroDevice( dev ));
}
static QString
@@ -93,8 +93,6 @@ hexHex2Int(char c, char c2)
bool
MacroDevice::download( const QDir &tmpdir,
QList<DeviceDownloadFile> &files,
CancelCallback cancelCallback,
ProgressCallback progressCallback,
QString &err)
{
if (MACRO_DEBUG) printf("download O-Synce Macro");
@@ -104,7 +102,7 @@ MacroDevice::download( const QDir &tmpdir,
return false;
}
statusCallback("Request number of training...");
emit updateStatus("Request number of training...");
if (MACRO_DEBUG) printf("Request number of training\n");
MacroPacket cmd(NUMBER_OF_TRAINING_REQUESTS);
@@ -112,7 +110,7 @@ MacroDevice::download( const QDir &tmpdir,
if (!cmd.write(dev, err)) return false;
if (cancelCallback())
if(m_Cancelled)
{
err = "download cancelled";
return false;
@@ -143,7 +141,7 @@ MacroDevice::download( const QDir &tmpdir,
return false;
}
if (cancelCallback())
if(m_Cancelled)
{
err = "download cancelled";
return false;
@@ -187,10 +185,10 @@ MacroDevice::download( const QDir &tmpdir,
for (int i = 0; i < count; i++)
{
if (MACRO_DEBUG) printf("Request training %d\n",i);
statusCallback( QString("Request datas of training %1 / %2...")
emit updateStatus( QString("Request datas of training %1 / %2...")
.arg(i+1).arg((int)count) );
if (cancelCallback())
if(m_Cancelled)
{
err = "download cancelled";
return false;
@@ -200,7 +198,7 @@ MacroDevice::download( const QDir &tmpdir,
cmd.addToPayload(i);
if (!cmd.write(dev, err)) return false;
if (cancelCallback())
if(m_Cancelled)
{
err = "download cancelled";
return false;
@@ -222,11 +220,11 @@ MacroDevice::download( const QDir &tmpdir,
//int training_flag = hex2Int(response2.payload.at(43));
tmp.write(response2.dataArray());
progressCallback( QString("training %1/%2... (%3 Bytes)")
emit updateProgress( QString("training %1/%2... (%3 Bytes)")
.arg(i+1)
.arg((int)count)
.arg(tmp.size()) );
if (cancelCallback())
if(m_Cancelled)
{
err = "download cancelled";
return false;

View File

@@ -11,7 +11,7 @@ struct MacroDevices : public Devices
Q_DECLARE_TR_FUNCTIONS(MacroDevices)
public:
virtual DevicePtr newDevice( CommPortPtr dev, Device::StatusCallback cb );
virtual DevicePtr newDevice( CommPortPtr dev );
virtual QString downloadInstructions() const;
virtual bool canCleanup( void ) {return true; };
};
@@ -21,13 +21,11 @@ struct MacroDevice : public Device
Q_DECLARE_TR_FUNCTIONS(MacroDevice)
public:
MacroDevice( CommPortPtr dev, StatusCallback cb ) :
Device( dev, cb ) {};
MacroDevice( CommPortPtr dev ) :
Device( dev ) {};
virtual bool download( const QDir &tmpdir,
QList<DeviceDownloadFile> &files,
CancelCallback cancelCallback,
ProgressCallback progressCallback,
QString &err);
virtual bool cleanup( QString &err );

View File

@@ -24,7 +24,6 @@
#include <errno.h>
#include <QtGui>
#include <math.h>
#include <boost/bind.hpp>
#include "Units.h"
#include "MetricAggregator.h"

View File

@@ -19,6 +19,7 @@
#include "PowerTapDevice.h"
#include "PowerTapUtil.h"
#include <math.h>
#include "assert.h"
#define PT_DEBUG false
@@ -26,9 +27,9 @@ static bool powerTapRegistered =
Devices::addType("PowerTap", DevicesPtr(new PowerTapDevices()) );
DevicePtr
PowerTapDevices::newDevice( CommPortPtr dev, Device::StatusCallback cb)
PowerTapDevices::newDevice( CommPortPtr dev )
{
return DevicePtr( new PowerTapDevice( dev, cb ));
return DevicePtr( new PowerTapDevice( dev ));
}
QString
@@ -122,8 +123,6 @@ readUntilNewline(CommPortPtr dev, char *buf, int len, QString &err)
bool
PowerTapDevice::download( const QDir &tmpdir,
QList<DeviceDownloadFile> &files,
CancelCallback cancelCallback,
ProgressCallback progressCallback,
QString &err)
{
if (!dev->open(err)) {
@@ -141,9 +140,9 @@ PowerTapDevice::download( const QDir &tmpdir,
if (!doWrite(dev, 0x56, false, err)) // 'V'
return false;
statusCallback( "Reading version..." );
if (cancelCallback()) {
err = "download cancelled";
emit updateStatus( "Reading version..." );
if(m_Cancelled) {
err = "download cancelled";
return false;
}
@@ -173,8 +172,8 @@ PowerTapDevice::download( const QDir &tmpdir,
bool hwecho = version.indexOf('V') < veridx;
if (PT_DEBUG) printf("hwecho=%s\n", hwecho ? "true" : "false");
statusCallback( "Reading header..." );
if (cancelCallback()) {
emit updateStatus( "Reading header..." );
if(m_Cancelled) {
err = "download cancelled";
return false;
}
@@ -199,8 +198,8 @@ PowerTapDevice::download( const QDir &tmpdir,
for (size_t i = 0; i < sizeof(header); ++i)
records.append(header[i]);
statusCallback( "Reading ride data..." );
if (cancelCallback()) {
emit updateStatus( "Reading ride data..." );
if(m_Cancelled) {
err = "download cancelled";
return false;
}
@@ -265,11 +264,11 @@ PowerTapDevice::download( const QDir &tmpdir,
}
if (recIntSecs != 0.0) {
int min = (int) round(records.size() / 6 * recIntSecs);
progressCallback( QString("progress: %1:%2")
emit updateProgress( QString("progress: %1:%2")
.arg(min / 60)
.arg(min % 60, 2, 10, QLatin1Char('0')));
}
if (cancelCallback()) {
if(m_Cancelled){
err = "download cancelled";
return false;
}
@@ -328,4 +327,3 @@ PowerTapDevice::download( const QDir &tmpdir,
files << file;
return true;
}

View File

@@ -27,7 +27,7 @@ struct PowerTapDevices : public Devices
Q_DECLARE_TR_FUNCTIONS(PowerTapDevices)
public:
virtual DevicePtr newDevice( CommPortPtr dev, Device::StatusCallback cb );
virtual DevicePtr newDevice( CommPortPtr dev );
virtual QString downloadInstructions() const;
};
@@ -36,13 +36,11 @@ struct PowerTapDevice : public Device
Q_DECLARE_TR_FUNCTIONS(PowerTapDevices)
public:
PowerTapDevice( CommPortPtr dev, StatusCallback cb ) :
Device( dev, cb ) {};
PowerTapDevice( CommPortPtr dev ) :
Device( dev ) {};
virtual bool download( const QDir &tmpdir,
QList<DeviceDownloadFile> &files,
CancelCallback cancelCallback,
ProgressCallback progressCallback,
QString &err);
};