Catch SIGINT signal.
Show pin, connection, disconnection and database messages if verbose logging is disabled.
This commit is contained in:
@@ -26,7 +26,7 @@ You can control \fBqcma_cli\fR using signals, i.e. using the \fBkill\fR command
|
|||||||
Refreshes the database.
|
Refreshes the database.
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.B SIGTERM
|
.B SIGTERM or SIGINT
|
||||||
Shuts down the process but waits until the current event is finished.
|
Shuts down the process but waits until the current event is finished.
|
||||||
|
|
||||||
.SH "SEE ALSO"
|
.SH "SEE ALSO"
|
||||||
|
@@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
#include <QTextStream>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <vitamtp.h>
|
#include <vitamtp.h>
|
||||||
@@ -59,6 +60,8 @@ void HeadlessManager::refreshDatabase()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QTextStream(stdout) << "Database scan has started" << endl;
|
||||||
|
|
||||||
if(!m_db->rescan()) {
|
if(!m_db->rescan()) {
|
||||||
qDebug("No PS Vita system has been registered");
|
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()
|
void HeadlessManager::stop()
|
||||||
{
|
{
|
||||||
if(CmaClient::stop() < 0) {
|
if(CmaClient::stop() < 0) {
|
||||||
|
@@ -70,6 +70,7 @@ public slots:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void threadStopped();
|
void threadStopped();
|
||||||
|
void receiveMessage(QString message);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // HEADLESSMANAGER_H
|
#endif // HEADLESSMANAGER_H
|
||||||
|
@@ -70,12 +70,18 @@ static bool setup_handlers()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (sigaction(SIGINT, &term, NULL) != 0) {
|
||||||
|
qCritical("SIGINT signal handle failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,6 +143,10 @@ int main(int argc, char *argv[])
|
|||||||
app.setApplicationName("qcma");
|
app.setApplicationName("qcma");
|
||||||
|
|
||||||
HeadlessManager manager;
|
HeadlessManager manager;
|
||||||
|
|
||||||
|
// receive the message from another process
|
||||||
|
QObject::connect(&app, SIGNAL(messageAvailable(QString)), &manager, SLOT(receiveMessage(QString)));
|
||||||
|
|
||||||
manager.start();
|
manager.start();
|
||||||
|
|
||||||
return app.exec();
|
return app.exec();
|
||||||
|
@@ -27,6 +27,7 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
|
#include <QTextStream>
|
||||||
#include <QTime>
|
#include <QTime>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
@@ -132,7 +133,7 @@ void CmaClient::processNewConnection(vita_device_t *device)
|
|||||||
QMutexLocker locker(&mutex);
|
QMutexLocker locker(&mutex);
|
||||||
in_progress = true;
|
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;
|
DeviceCapability vita_info;
|
||||||
|
|
||||||
if(!vita_info.exchangeInfo(device)) {
|
if(!vita_info.exchangeInfo(device)) {
|
||||||
@@ -187,7 +188,12 @@ int CmaClient::generatePin(wireless_vita_info_t *info, int *p_err)
|
|||||||
tempOnlineId = QString(info->name);
|
tempOnlineId = QString(info->name);
|
||||||
qDebug("Registration request from %s (MAC: %s)", info->name, info->mac_addr);
|
qDebug("Registration request from %s (MAC: %s)", info->name, info->mac_addr);
|
||||||
int pin = rand() % 10000 * 10000 | rand() % 10000;
|
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;
|
*p_err = 0;
|
||||||
emit this_object->receivedPin(info->name, pin);
|
emit this_object->receivedPin(info->name, pin);
|
||||||
return pin;
|
return pin;
|
||||||
@@ -240,6 +246,8 @@ void CmaClient::enterEventLoop(vita_device_t *device)
|
|||||||
|
|
||||||
int CmaClient::stop()
|
int CmaClient::stop()
|
||||||
{
|
{
|
||||||
|
QTextStream(stdout) << "Stopping Qcma" << endl;
|
||||||
|
|
||||||
if(!isActive()) {
|
if(!isActive()) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@@ -23,6 +23,7 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
#include <QTextStream>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
|
|
||||||
const file_type audio_list[] = {
|
const file_type audio_list[] = {
|
||||||
@@ -58,7 +59,7 @@ void Database::process()
|
|||||||
cancel_operation = false;
|
cancel_operation = false;
|
||||||
int count = create();
|
int count = create();
|
||||||
cancel_operation = false;
|
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) {
|
if(count < 0) {
|
||||||
clear();
|
clear();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user