Unix now survives physical disconnects. Duct Tape necessary.

This commit is contained in:
EspoTek 2017-05-16 15:08:29 +10:00
parent c0e554e37f
commit 28a4df9834
8 changed files with 37 additions and 18 deletions

View File

@ -1073,7 +1073,7 @@ void MainWindow::reinitUsb(void){
reinitUsbStage2();
#else
ui->controller_iso->driver->shutdownProcedure();
QTimer::singleShot(2000, this, SLOT(reinitUsbStage2()));
QTimer::singleShot(3000, this, SLOT(reinitUsbStage2()));
#endif
qDebug() << "ReinitUsb Stage 1 complete";
}

Binary file not shown.

View File

@ -109,8 +109,8 @@ int worker::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
return _id;
}
struct qt_meta_stringdata_unixUsbDriver_t {
QByteArrayData data[5];
char stringdata0[59];
QByteArrayData data[6];
char stringdata0[73];
};
#define QT_MOC_LITERAL(idx, ofs, len) \
Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \
@ -123,11 +123,12 @@ QT_MOC_LITERAL(0, 0, 13), // "unixUsbDriver"
QT_MOC_LITERAL(1, 14, 12), // "isoTimerTick"
QT_MOC_LITERAL(2, 27, 0), // ""
QT_MOC_LITERAL(3, 28, 12), // "recoveryTick"
QT_MOC_LITERAL(4, 41, 17) // "shutdownProcedure"
QT_MOC_LITERAL(4, 41, 17), // "shutdownProcedure"
QT_MOC_LITERAL(5, 59, 13) // "backupCleanup"
},
"unixUsbDriver\0isoTimerTick\0\0recoveryTick\0"
"shutdownProcedure"
"shutdownProcedure\0backupCleanup"
};
#undef QT_MOC_LITERAL
@ -137,7 +138,7 @@ static const uint qt_meta_data_unixUsbDriver[] = {
7, // revision
0, // classname
0, 0, // classinfo
3, 14, // methods
4, 14, // methods
0, 0, // properties
0, 0, // enums/sets
0, 0, // constructors
@ -145,13 +146,15 @@ static const uint qt_meta_data_unixUsbDriver[] = {
0, // signalCount
// slots: name, argc, parameters, tag, flags
1, 0, 29, 2, 0x0a /* Public */,
3, 0, 30, 2, 0x0a /* Public */,
4, 0, 31, 2, 0x0a /* Public */,
1, 0, 34, 2, 0x0a /* Public */,
3, 0, 35, 2, 0x0a /* Public */,
4, 0, 36, 2, 0x0a /* Public */,
5, 0, 37, 2, 0x0a /* Public */,
// slots: parameters
QMetaType::Void,
QMetaType::Void,
QMetaType::Void,
QMetaType::Void,
0 // eod
@ -166,6 +169,7 @@ void unixUsbDriver::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _i
case 0: _t->isoTimerTick(); break;
case 1: _t->recoveryTick(); break;
case 2: _t->shutdownProcedure(); break;
case 3: _t->backupCleanup(); break;
default: ;
}
}
@ -197,13 +201,13 @@ int unixUsbDriver::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
if (_id < 0)
return _id;
if (_c == QMetaObject::InvokeMetaMethod) {
if (_id < 3)
if (_id < 4)
qt_static_metacall(this, _c, _id, _a);
_id -= 3;
_id -= 4;
} else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
if (_id < 3)
if (_id < 4)
*reinterpret_cast<int*>(_a[0]) = -1;
_id -= 3;
_id -= 4;
}
return _id;
}

View File

@ -12,7 +12,6 @@ unixUsbDriver::~unixUsbDriver(void){
qDebug() << "\n\nunixUsbDriver destructor ran!";
//unixDriverDeleteMutex.lock();
workerThread->terminate();
//workerThread->deleteLater();
delete(isoHandler);
delete(workerThread);
qDebug() << "THREAD Gone!";
@ -195,6 +194,7 @@ void unixUsbDriver::isoTimerTick(void){
error = libusb_cancel_transfer(isoCtx[k][earliest]);
numCancelled++;
qDebug() << "Cancelled" << earliest << k;
qDebug() << "Total Cancelled =" << numCancelled;
if(numCancelled == (NUM_FUTURE_CTX * NUM_ISO_ENDPOINTS)){
isoHandler->stopTime = true;
}
@ -239,4 +239,10 @@ bool unixUsbDriver::allEndpointsComplete(int n){
void unixUsbDriver::shutdownProcedure(){
shutdownMode = true;
QTimer::singleShot(1000, this, SLOT(backupCleanup()));
}
//On physical disconnect, isoTimerTick will not assert stopTime. Hence this duct-tape function.
void unixUsbDriver::backupCleanup(){
isoHandler->stopTime = true;
}

View File

@ -27,15 +27,23 @@ public:
~worker(){};
libusb_context *ctx;
bool stopTime = false;
unsigned char cleanupRemaining = 2;
public slots:
void handle(){
qDebug() << "SUB THREAD ID" << QThread::currentThreadId();
while(1){
if(!stopTime){
//qDebug() << cleanupRemaining;
if(libusb_event_handling_ok(ctx)){
libusb_handle_events_timeout(ctx, &tv);
//qDebug() << "HANDLED";
}
if(stopTime){
if(cleanupRemaining){
cleanupRemaining--;
}else while(1){
QThread::msleep(100);
qDebug() << "Cleanup complete";
}
}
}
}
@ -73,6 +81,7 @@ public slots:
void isoTimerTick(void);
void recoveryTick(void);
void shutdownProcedure(void);
void backupCleanup(void);
};
//Callback on iso transfer complete.

Binary file not shown.