From 9784332bae03e14f54d26ae70310d2575be7cbf1 Mon Sep 17 00:00:00 2001 From: codestation Date: Fri, 3 Jan 2014 16:08:16 -0430 Subject: [PATCH] Remove wireless disconnect callback. Make an interruptable sleep so the USB connection can be aborted more quickly. Updated translations. --- resources/translations/qcma.es.ts | 22 +++++++++++++--------- resources/translations/qcma.ja.ts | 22 +++++++++++++--------- src/clientmanager.cpp | 4 +++- src/cmaclient.cpp | 31 ++++++++++++++++--------------- src/cmaclient.h | 5 +++-- src/mainwidget.cpp | 2 +- 6 files changed, 49 insertions(+), 37 deletions(-) diff --git a/resources/translations/qcma.es.ts b/resources/translations/qcma.es.ts index 4f5542c..ec9edba 100644 --- a/resources/translations/qcma.es.ts +++ b/resources/translations/qcma.es.ts @@ -1,6 +1,6 @@ - + BackupItem @@ -73,7 +73,7 @@ - + Filter Filtro @@ -93,7 +93,7 @@ Uso de disco en respaldos: %1 - + - (Launcher only) - (Solo lanzador LiveArea) @@ -120,12 +120,12 @@ No se pudo inicializar VitaMTP - + Cannot refresh the database while is in use No se puede actualizar la base de datos mientras se encuentre en uso - + No PS Vita system has been registered Nigún sistema PS Vita ha sido registrado @@ -137,8 +137,8 @@ Conectado a - - + + Connected to %1 (PS Vita) Conectado a %1 (PS Vita) @@ -330,9 +330,13 @@ Cerrando... - Stopping QCMA... - Deteniendo QCMA... + Deteniendo QCMA... + + + + Stopping QCMA (disconnect your PS Vita) + Deteniendo QCMA (desconecte su PS Vita) diff --git a/resources/translations/qcma.ja.ts b/resources/translations/qcma.ja.ts index d4899eb..4d234a2 100644 --- a/resources/translations/qcma.ja.ts +++ b/resources/translations/qcma.ja.ts @@ -1,6 +1,6 @@ - + BackupItem @@ -73,7 +73,7 @@ - + Filter @@ -93,7 +93,7 @@ バックアップディスク使用容量: %1 - + - (Launcher only) - (LiveArea専用) @@ -120,12 +120,12 @@ - + Cannot refresh the database while is in use 使用中にはデータベースを更新できません - + No PS Vita system has been registered @@ -137,8 +137,8 @@ 次のデバイスに接続しました - - + + Connected to %1 (PS Vita) @@ -331,9 +331,13 @@ 終了しています... - Stopping QCMA... - QCMAを停止しています... + QCMAを停止しています... + + + + Stopping QCMA (disconnect your PS Vita) + diff --git a/src/clientmanager.cpp b/src/clientmanager.cpp index ea9bb17..b5a4085 100644 --- a/src/clientmanager.cpp +++ b/src/clientmanager.cpp @@ -65,7 +65,7 @@ void ClientManager::start() connect(&db, SIGNAL(updated(int)), this, SLOT(databaseUpdated(int))); connect(&progress, SIGNAL(canceled()), &db, SLOT(cancelOperation()), Qt::DirectConnection); - thread_count = 2; + thread_count = 0; qDebug("Starting cma threads"); CmaClient *client; @@ -84,6 +84,7 @@ void ClientManager::start() client->moveToThread(usb_thread); usb_thread->start(); + thread_count++; wireless_thread = new QThread(); client = new CmaClient(); @@ -102,6 +103,7 @@ void ClientManager::start() client->moveToThread(wireless_thread); wireless_thread->start(); + thread_count++; } void ClientManager::refreshDatabase() diff --git a/src/cmaclient.cpp b/src/cmaclient.cpp index b2d41a1..3fe5802 100644 --- a/src/cmaclient.cpp +++ b/src/cmaclient.cpp @@ -34,14 +34,14 @@ QMutex CmaClient::mutex; QMutex CmaClient::runner; -QMutex CmaClient::cancel; +QWaitCondition CmaClient::usbcondition; +QMutex CmaClient::usbwait; QSemaphore CmaClient::sema; QString CmaClient::tempOnlineId = QString(); bool CmaClient::is_active = false; bool CmaClient::in_progress = false; -int CmaClient::is_cancelled = false; CmaClient *CmaClient::this_object = NULL; @@ -58,13 +58,14 @@ void CmaClient::connectUsb() qDebug("Starting usb_thread: 0x%016" PRIxPTR, (uintptr_t)QThread::currentThreadId()); setActive(true); + usbwait.lock(); do { if((vita = VitaMTP_Get_First_USB_Vita()) !=NULL) { processNewConnection(vita); } else { //TODO: replace this with an event-driven setup - Sleeper::msleep(2000); + usbcondition.wait(&usbwait, 2000); mutex.lock(); if(in_progress) { sema.acquire(); @@ -91,15 +92,22 @@ void CmaClient::connectWireless() setActive(true); do { - if((vita = VitaMTP_Get_First_Wireless_Vita(&host, 0, CC::cancelCallback, CC::deviceRegistered, CC::generatePin, CC::registrationComplete)) != NULL) { + if((vita = VitaMTP_Get_First_Wireless_Vita(&host, 0, CC::deviceRegistered, CC::generatePin, CC::registrationComplete)) != NULL) { processNewConnection(vita); } else { - Sleeper::msleep(2000); mutex.lock(); if(in_progress) { sema.acquire(); } - mutex.unlock();; + mutex.unlock(); + + // if is active then something happened while setting the socket, wait a little and try again + if(isActive()) { + qDebug("Error getting wireless connection"); + Sleeper::sleep(2000); + } else { + qDebug("Wireless connection cancelled by the user"); + } } } while(isActive()); @@ -171,12 +179,6 @@ int CmaClient::generatePin(wireless_vita_info_t *info, int *p_err) return pin; } -int CmaClient::cancelCallback() -{ - QMutexLocker locker(&cancel); - return is_cancelled; -} - void CmaClient::enterEventLoop(vita_device_t *device) { vita_event_t event; @@ -227,9 +229,8 @@ int CmaClient::stop() return -1; } CmaClient::setActive(false); - cancel.lock(); - is_cancelled = true; - cancel.unlock(); + VitaMTP_Cancel_Get_Wireless_Vita(); + usbcondition.wakeAll(); return 0; } diff --git a/src/cmaclient.h b/src/cmaclient.h index b8550ad..df90c9e 100644 --- a/src/cmaclient.h +++ b/src/cmaclient.h @@ -28,6 +28,7 @@ #include #include #include +#include #include @@ -59,11 +60,11 @@ private: //TODO: move all the control variables to the client manager class static bool is_active; static bool in_progress; - static int is_cancelled; static CmaClient *this_object; static QMutex mutex; static QMutex runner; - static QMutex cancel; + static QMutex usbwait; + static QWaitCondition usbcondition; static QSemaphore sema; signals: diff --git a/src/mainwidget.cpp b/src/mainwidget.cpp index a334d3f..c1f296e 100644 --- a/src/mainwidget.cpp +++ b/src/mainwidget.cpp @@ -77,7 +77,7 @@ void MainWidget::dialogResult(int result) void MainWidget::stopServer() { setTrayTooltip(tr("Shutting down...")); - receiveMessage(tr("Stopping QCMA...")); + receiveMessage(tr("Stopping QCMA (disconnect your PS Vita)")); manager.stop(); }