From 5d1e67b5f531b10f1237c9b45fa33d272eb16f8f Mon Sep 17 00:00:00 2001 From: Rainer Clasen Date: Fri, 28 Dec 2012 20:35:44 +0100 Subject: [PATCH] Remove Boost - SrmDevice converted SrmDevice to use signals instead of callback. Also add missing erase connections. Signed-off-by: Andy Bryson --- src/DownloadRideDialog.cpp | 4 ++++ src/SrmDevice.cpp | 39 +++++++++++++++++++++----------------- src/SrmDevice.h | 11 ++++++----- 3 files changed, 32 insertions(+), 22 deletions(-) diff --git a/src/DownloadRideDialog.cpp b/src/DownloadRideDialog.cpp index 407cf0837..bdb759450 100644 --- a/src/DownloadRideDialog.cpp +++ b/src/DownloadRideDialog.cpp @@ -416,6 +416,10 @@ DownloadRideDialog::eraseClicked() DevicesPtr devtype = Devices::getType(deviceCombo->currentText()); 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))); + QString err; if( device->cleanup( err) ) updateStatus( tr("cleaned data") ); diff --git a/src/SrmDevice.cpp b/src/SrmDevice.cpp index e732be0f2..4e19f7552 100644 --- a/src/SrmDevice.cpp +++ b/src/SrmDevice.cpp @@ -28,9 +28,9 @@ static bool srm7Registered = Devices::addType("SRM PCVI/7", DevicesPtr(new SrmDevices( 7 ))); DevicePtr -SrmDevices::newDevice( CommPortPtr dev, Device::StatusCallback cb ) +SrmDevices::newDevice( CommPortPtr dev ) { - return DevicePtr( new SrmDevice( dev, cb, protoVersion)); + return DevicePtr( new SrmDevice( dev, protoVersion)); } bool @@ -97,11 +97,18 @@ SrmDevice::~SrmDevice() close(); } +// translate C callback function to method emitting signal static void logfunc( const char *msg, void *data ) { - Device::StatusCallback *cb = reinterpret_cast(data); + SrmDevice *dev = reinterpret_cast(data); - (*cb)( msg ); + dev->_emit_updateStatus( msg ); +} + +void +SrmDevice::_emit_updateStatus( QString statusText ) +{ + emit updateStatus( statusText ); } bool @@ -156,13 +163,13 @@ SrmDevice::open( QString &err ) switch( protoVersion ){ case 5: - statusCallback( tr("opening PCV at %1").arg(dev->name()) ); + emit updateStatus( tr("opening PCV at %1").arg(dev->name()) ); pc = srmio_pc5_new( &serr ); break; case 6: case 7: - statusCallback( tr("opening PC6/7 at %1").arg(dev->name()) ); + emit updateStatus( tr("opening PC6/7 at %1").arg(dev->name()) ); pc = srmio_pc7_new( &serr ); break; @@ -185,7 +192,7 @@ SrmDevice::open( QString &err ) } if( ! srmio_pc_set_logfunc( pc, logfunc, - reinterpret_cast( &statusCallback ), &serr ) ){ + reinterpret_cast( this ), &serr ) ){ err = tr("Couldn't set logging function: %1") .arg(serr.message); @@ -269,7 +276,7 @@ SrmDevice::preview( QString &err ) .arg(serr.message); goto fail; } - statusCallback(tr("found %1 ride blocks").arg(block_cnt)); + emit updateStatus(tr("found %1 ride blocks").arg(block_cnt)); while( srmio_pc_xfer_block_next( pc, &block )){ @@ -311,8 +318,6 @@ fail: bool SrmDevice::download( const QDir &tmpdir, QList &files, - CancelCallback cancelCallback, - ProgressCallback progressCallback, QString &err) { srmio_error_t serr; @@ -344,7 +349,7 @@ SrmDevice::download( const QDir &tmpdir, goto fail; } - if( cancelCallback() ){ + if( m_Cancelled ){ err = tr("download cancelled"); goto fail; } @@ -386,7 +391,7 @@ SrmDevice::download( const QDir &tmpdir, } if( ! wanted ){ - statusCallback(tr("skipping unselected ride block %1") + emit updateStatus(tr("skipping unselected ride block %1") .arg(block_num +1)); ++block_num; continue; @@ -412,7 +417,7 @@ SrmDevice::download( const QDir &tmpdir, } while( srmio_pc_xfer_chunk_next( pc, &chunk, &is_int, &is_first ) ){ - if( cancelCallback() ){ + if( m_Cancelled ){ err = tr("download cancelled"); goto fail1; } @@ -432,7 +437,7 @@ SrmDevice::download( const QDir &tmpdir, + 1000 * block.total / block_done; } - progressCallback( tr("progress: %1/%2") + emit updateProgress( tr("progress: %1/%2") .arg(block_done) .arg(prog_total)); } @@ -497,9 +502,9 @@ SrmDevice::download( const QDir &tmpdir, goto fail; } - statusCallback( tr("got %1 records").arg(data->cused) ); + emit updateStatus( tr("got %1 records").arg(data->cused) ); - if( cancelCallback() ){ + if( m_Cancelled ){ err = tr("download cancelled"); goto fail; } @@ -608,7 +613,7 @@ SrmDevice::cleanup( QString &err ) goto cleanup; } - statusCallback( tr("cleaning device ...")); + emit updateStatus( tr("cleaning device ...")); if( ! srmio_pc_cmd_clear( pc, &serr ) ){ err = tr("failed to clear Powercontrol memory: %1") diff --git a/src/SrmDevice.h b/src/SrmDevice.h index 67e23cede..979ec2f31 100644 --- a/src/SrmDevice.h +++ b/src/SrmDevice.h @@ -30,7 +30,7 @@ struct SrmDevices : public Devices public: SrmDevices( int protoVersion ) : protoVersion( protoVersion ) {} - virtual DevicePtr newDevice( CommPortPtr dev, Device::StatusCallback cb ); + virtual DevicePtr newDevice( CommPortPtr dev ); virtual bool canCleanup( void ) {return true; }; virtual bool supportsPort( CommPortPtr dev ); virtual bool exclusivePort( CommPortPtr dev ); @@ -44,8 +44,8 @@ struct SrmDevice : public Device Q_DECLARE_TR_FUNCTIONS(SrmDevice) public: - SrmDevice( CommPortPtr dev, StatusCallback cb, int protoVersion ) : - Device( dev, cb ), + SrmDevice( CommPortPtr dev, int protoVersion ) : + Device( dev ), protoVersion( protoVersion ), is_open( false ), io( NULL ), pc( NULL ) { }; @@ -55,12 +55,13 @@ struct SrmDevice : public Device virtual bool download( const QDir &tmpdir, QList &files, - CancelCallback cancelCallback, - ProgressCallback progressCallback, QString &err); virtual bool cleanup( QString &err ); + // hack for translating C callback to signal: + void _emit_updateStatus( QString statusText ); + private: int protoVersion; bool is_open;