Remove wireless disconnect callback.

Make an interruptable sleep so the USB connection can be aborted more quickly.
Updated translations.
This commit is contained in:
codestation
2014-01-03 16:08:16 -04:30
parent a2468ddf7a
commit 9784332bae
6 changed files with 49 additions and 37 deletions

View File

@@ -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()

View File

@@ -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;
}

View File

@@ -28,6 +28,7 @@
#include <QObject>
#include <QSemaphore>
#include <QString>
#include <QWaitCondition>
#include <vitamtp.h>
@@ -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:

View File

@@ -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();
}