Fix memory leaks.

Use "/" separator for internal cmaobject nodes.
Use new vitamtp init function.
Remove console config for Win32.
This commit is contained in:
codestation
2013-09-22 19:02:42 -04:30
parent d2e584220e
commit 71a7bed50d
9 changed files with 44 additions and 22 deletions

View File

@@ -80,8 +80,8 @@ bool DeviceCapability::exchangeInfo(vita_device_t *device)
void DeviceCapability::free_pc_capability_info(capability_info_t *info) void DeviceCapability::free_pc_capability_info(capability_info_t *info)
{ {
delete &info->functions.formats.next_item[-1]; delete[] &info->functions.formats.next_item[-1];
delete &info->functions.next_item[-1]; delete[] &info->functions.next_item[-1];
delete info; delete info;
} }

View File

@@ -20,12 +20,18 @@
#include "clientmanager.h" #include "clientmanager.h"
#include "progressform.h" #include "progressform.h"
#include "cmaclient.h" #include "cmaclient.h"
#include "utils.h"
ClientManager::ClientManager(QObject *parent) : ClientManager::ClientManager(QObject *parent) :
QObject(parent) QObject(parent)
{ {
} }
ClientManager::~ClientManager()
{
VitaMTP_Cleanup();
}
void ClientManager::databaseUpdated(int count) void ClientManager::databaseUpdated(int count)
{ {
progress.hide(); progress.hide();
@@ -44,6 +50,12 @@ void ClientManager::showPinDialog(QString name, int pin)
void ClientManager::start() void ClientManager::start()
{ {
if(VitaMTP_Init() < 0)
{
emit messageSent(tr("Cannot initialize VitaMTP library"));
return;
}
// initializing database for the first use // initializing database for the first use
refreshDatabase(); refreshDatabase();
CmaEvent::db = &db; CmaEvent::db = &db;
@@ -102,7 +114,9 @@ void ClientManager::refreshDatabase()
void ClientManager::stop() void ClientManager::stop()
{ {
CmaClient::stop(); if(CmaClient::stop() < 0) {
emit stopped();
}
} }
void ClientManager::threadStopped() void ClientManager::threadStopped()

View File

@@ -32,6 +32,7 @@ class ClientManager : public QObject
Q_OBJECT Q_OBJECT
public: public:
explicit ClientManager(QObject *parent = 0); explicit ClientManager(QObject *parent = 0);
~ClientManager();
void start(); void start();
void stop(); void stop();

View File

@@ -37,7 +37,7 @@ QMutex CmaClient::runner;
QMutex CmaClient::cancel; QMutex CmaClient::cancel;
QSemaphore CmaClient::sema; QSemaphore CmaClient::sema;
bool CmaClient::is_active = true; bool CmaClient::is_active = false;
bool CmaClient::in_progress = false; bool CmaClient::in_progress = false;
int CmaClient::is_cancelled = false; int CmaClient::is_cancelled = false;
@@ -53,12 +53,13 @@ void CmaClient::connectUsb()
{ {
vita_device_t *vita; vita_device_t *vita;
qDebug() << "Starting usb_thread:" << QThread::currentThreadId(); qDebug("Starting usb_thread: %u", (unsigned int)QThread::currentThreadId());
setActive(true);
do { do {
if((vita = VitaMTP_Get_First_USB_Vita()) !=NULL) { if((vita = VitaMTP_Get_First_USB_Vita()) !=NULL) {
processNewConnection(vita); processNewConnection(vita);
VitaMTP_Close_USB_Vita();
} else { } else {
//TODO: replace this with an event-driven setup //TODO: replace this with an event-driven setup
Sleeper::msleep(2000); Sleeper::msleep(2000);
@@ -83,7 +84,9 @@ void CmaClient::connectWireless()
QTime now = QTime::currentTime(); QTime now = QTime::currentTime();
qsrand(now.msec()); qsrand(now.msec());
qDebug() << "Starting wireless_thread:" << QThread::currentThreadId(); qDebug("Starting wireless_thread: %u", (unsigned int)QThread::currentThreadId());
setActive(true);
do { 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::cancelCallback, CC::deviceRegistered, CC::generatePin, CC::registrationComplete)) != NULL) {
@@ -109,17 +112,18 @@ void CmaClient::processNewConnection(vita_device_t *device)
broadcast.setUnavailable(); broadcast.setUnavailable();
qDebug("Vita connected: id %s", VitaMTP_Get_Identification(device)); qDebug("Vita connected: id %s", VitaMTP_Get_Identification(device));
DeviceCapability *vita_info = new DeviceCapability(); DeviceCapability vita_info;
if(!vita_info->exchangeInfo(device)) { if(!vita_info.exchangeInfo(device)) {
qCritical("Error while exchanging info with the vita"); qCritical("Error while exchanging info with the vita");
} else { } else {
// Conection successful, inform the user // Conection successful, inform the user
emit deviceConnected(QString(tr("Connected to ")) + vita_info->getOnlineId()); emit deviceConnected(QString(tr("Connected to ")) + vita_info.getOnlineId());
enterEventLoop(device); enterEventLoop(device);
} }
VitaMTP_SendHostStatus(device, VITA_HOST_STATUS_EndConnection); VitaMTP_SendHostStatus(device, VITA_HOST_STATUS_EndConnection);
qDebug("Releasing device...");
VitaMTP_Release_Device(device); VitaMTP_Release_Device(device);
emit deviceDisconnected(); emit deviceDisconnected();
@@ -202,12 +206,16 @@ void CmaClient::enterEventLoop(vita_device_t *device)
qDebug("Finishing event loop"); qDebug("Finishing event loop");
} }
void CmaClient::stop() int CmaClient::stop()
{ {
if(!isActive()) {
return -1;
}
CmaClient::setActive(false); CmaClient::setActive(false);
cancel.lock(); cancel.lock();
is_cancelled = true; is_cancelled = true;
cancel.unlock(); cancel.unlock();
return 0;
} }
bool CmaClient::isActive() bool CmaClient::isActive()

View File

@@ -76,7 +76,7 @@ signals:
void finished(); void finished();
public slots: public slots:
static void stop(); static int stop();
private slots: private slots:
void connectUsb(); void connectUsb();

View File

@@ -40,7 +40,7 @@ CmaEvent::CmaEvent(vita_device_t *s_device) :
void CmaEvent::process() void CmaEvent::process()
{ {
qDebug() << "Starting event_thread:" << QThread::currentThreadId(); qDebug("Starting event_thread: %u", (unsigned int)QThread::currentThreadId());
while(true) { while(true) {
sema.acquire(); sema.acquire();
if(!isActive()) { if(!isActive()) {

View File

@@ -185,7 +185,7 @@ void CMAObject::initObject(const QFileInfo &file, int file_type)
if(parent->metadata.path == NULL) { if(parent->metadata.path == NULL) {
metadata.path = strdup(metadata.name); metadata.path = strdup(metadata.name);
} else { } else {
QString newpath = QString(parent->metadata.path) + QDir::separator() + metadata.name; QString newpath = QString(parent->metadata.path) + "/" + metadata.name;
metadata.path = strdup(newpath.toUtf8().data()); metadata.path = strdup(newpath.toUtf8().data());
} }
@@ -216,22 +216,22 @@ void CMAObject::rename(const QString &newname)
metadata.name = strdup(newname.toUtf8().data()); metadata.name = strdup(newname.toUtf8().data());
if(metadata.path) { if(metadata.path) {
QStringList metadata_path(QString(metadata.path).split(QDir::separator())); QStringList metadata_path(QString(metadata.path).split("/"));
metadata_path.replace(metadata_path.count() - 1, newname); metadata_path.replace(metadata_path.count() - 1, newname);
free(metadata.path); free(metadata.path);
metadata.path = strdup(metadata_path.join(QDir::separator()).toUtf8().data()); metadata.path = strdup(metadata_path.join("/").toUtf8().data());
} }
path = QFileInfo(path).absoluteDir().path() + QDir::separator() + newname; path = QFileInfo(path).absoluteDir().path() + "/" + newname;
} }
void CMAObject::refreshPath() void CMAObject::refreshPath()
{ {
if(parent) { if(parent) {
free(metadata.path); free(metadata.path);
QString newpath(QString(parent->metadata.path) + QDir::separator() + metadata.name); QString newpath(QString(parent->metadata.path) + "/" + metadata.name);
metadata.path = strdup(newpath.toUtf8().data()); metadata.path = strdup(newpath.toUtf8().data());
path = parent->path + QDir::separator() + metadata.name; path = parent->path + "/" + metadata.name;
} }
} }

View File

@@ -71,12 +71,12 @@ int main(int argc, char *argv[])
QTranslator translator; QTranslator translator;
QString locale = QLocale().system().name(); QString locale = QLocale().system().name();
qDebug() << "Current locale:" << locale; qDebug("Current locale: %s", locale.toUtf8().data());
if(translator.load("qcma." + locale, ":/main/resources/translations")) { if(translator.load("qcma." + locale, ":/main/resources/translations")) {
app.installTranslator(&translator); app.installTranslator(&translator);
} }
qDebug() << "From main thread: "<< QThread::currentThreadId(); qDebug("Starting main thread: %u", (unsigned int)QThread::currentThreadId());
// set the organization/application for QSettings to work properly // set the organization/application for QSettings to work properly
app.setOrganizationName("qcma"); app.setOrganizationName("qcma");

View File

@@ -99,5 +99,4 @@ unix {
} }
win32:RC_FILE = qcma.rc win32:RC_FILE = qcma.rc
win32:CONFIG += console
win32:QMAKE_CXXFLAGS += -mno-ms-bitfields win32:QMAKE_CXXFLAGS += -mno-ms-bitfields