Catch SIGINT signal.

Show pin, connection, disconnection and database messages if verbose
logging is disabled.
This commit is contained in:
codestation
2015-03-15 01:53:46 -04:30
parent 22395a71ac
commit 659d72bced
6 changed files with 33 additions and 5 deletions

View File

@@ -26,7 +26,7 @@ You can control \fBqcma_cli\fR using signals, i.e. using the \fBkill\fR command
Refreshes the database.
.TP
.B SIGTERM
.B SIGTERM or SIGINT
Shuts down the process but waits until the current event is finished.
.SH "SEE ALSO"

View File

@@ -25,6 +25,7 @@
#include <QCoreApplication>
#include <QSettings>
#include <QTextStream>
#include <sys/socket.h>
#include <unistd.h>
#include <vitamtp.h>
@@ -59,6 +60,8 @@ void HeadlessManager::refreshDatabase()
return;
}
QTextStream(stdout) << "Database scan has started" << endl;
if(!m_db->rescan()) {
qDebug("No PS Vita system has been registered");
}
@@ -128,6 +131,11 @@ void HeadlessManager::start()
}
}
void HeadlessManager::receiveMessage(QString message)
{
QTextStream(stdout) << message << endl;
}
void HeadlessManager::stop()
{
if(CmaClient::stop() < 0) {

View File

@@ -70,6 +70,7 @@ public slots:
private slots:
void threadStopped();
void receiveMessage(QString message);
};
#endif // HEADLESSMANAGER_H

View File

@@ -70,12 +70,18 @@ static bool setup_handlers()
return false;
}
if (sigaction(SIGINT, &term, NULL) != 0) {
qCritical("SIGINT signal handle failed");
return false;
}
return true;
}
int main(int argc, char *argv[])
{
if(SingleCoreApplication::sendMessage(QObject::tr("An instance of Qcma is already running"))) {
if(SingleCoreApplication::sendMessage("Another instance of Qcma tried to start")) {
QTextStream(stdout) << "An instance of Qcma is already running" << endl;
return 0;
}
@@ -137,6 +143,10 @@ int main(int argc, char *argv[])
app.setApplicationName("qcma");
HeadlessManager manager;
// receive the message from another process
QObject::connect(&app, SIGNAL(messageAvailable(QString)), &manager, SLOT(receiveMessage(QString)));
manager.start();
return app.exec();

View File

@@ -27,6 +27,7 @@
#include <QDebug>
#include <QDir>
#include <QImage>
#include <QTextStream>
#include <QTime>
#include <QSettings>
#include <QUrl>
@@ -132,7 +133,7 @@ void CmaClient::processNewConnection(vita_device_t *device)
QMutexLocker locker(&mutex);
in_progress = true;
qDebug("Vita connected: id %s", VitaMTP_Get_Identification(device));
QTextStream(stdout) << "Vita connected, id: " << VitaMTP_Get_Identification(device) << endl;
DeviceCapability vita_info;
if(!vita_info.exchangeInfo(device)) {
@@ -187,7 +188,12 @@ int CmaClient::generatePin(wireless_vita_info_t *info, int *p_err)
tempOnlineId = QString(info->name);
qDebug("Registration request from %s (MAC: %s)", info->name, info->mac_addr);
int pin = rand() % 10000 * 10000 | rand() % 10000;
qDebug("Your registration PIN for %s is: %08d", info->name, pin);
QTextStream out(stdout);
out << "Your registration PIN for " << info->name << " is: ";
out.setFieldWidth(8);
out.setPadChar('0');
out << pin << endl;
*p_err = 0;
emit this_object->receivedPin(info->name, pin);
return pin;
@@ -240,6 +246,8 @@ void CmaClient::enterEventLoop(vita_device_t *device)
int CmaClient::stop()
{
QTextStream(stdout) << "Stopping Qcma" << endl;
if(!isActive()) {
return -1;
}

View File

@@ -23,6 +23,7 @@
#include <QDebug>
#include <QImage>
#include <QSettings>
#include <QTextStream>
#include <QThread>
const file_type audio_list[] = {
@@ -58,7 +59,7 @@ void Database::process()
cancel_operation = false;
int count = create();
cancel_operation = false;
qDebug("Total entries added to the database: %i", count);
QTextStream(stdout) << "Total entries added to the database: " << count << endl;
if(count < 0) {
clear();
}