Remove Boost - SrmDevice

converted SrmDevice to use signals instead of callback.
Also add missing erase connections.

Signed-off-by: Andy Bryson <agbryson@gmail.com>
This commit is contained in:
Rainer Clasen
2012-12-28 20:35:44 +01:00
committed by Mark Liversedge
parent 356a80a448
commit 5d1e67b5f5
3 changed files with 32 additions and 22 deletions

View File

@@ -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") );

View File

@@ -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<Device::StatusCallback*>(data);
SrmDevice *dev = reinterpret_cast<SrmDevice*>(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<void*>( &statusCallback ), &serr ) ){
reinterpret_cast<void*>( 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<DeviceDownloadFile> &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")

View File

@@ -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<DeviceDownloadFile> &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;