Implemented android module startup with default settings.
Simplified main_android.
This commit is contained in:
@@ -3,6 +3,7 @@ include(../common/defines.pri)
|
|||||||
|
|
||||||
TARGET = qcma_android
|
TARGET = qcma_android
|
||||||
TEMPLATE=app
|
TEMPLATE=app
|
||||||
|
QT += network sql
|
||||||
LIBS += -L../common -lqcma_common
|
LIBS += -L../common -lqcma_common
|
||||||
|
|
||||||
# this library needs to link statically their deps but Qt doesn't pass --static to PKGCONFIG
|
# this library needs to link statically their deps but Qt doesn't pass --static to PKGCONFIG
|
||||||
@@ -10,11 +11,11 @@ QMAKE_CXXFLAGS += $$system(pkg-config --static --cflags libvitamtp libavformat l
|
|||||||
LIBS += $$system(pkg-config --static --libs libvitamtp libavformat libavcodec libavutil libswscale)
|
LIBS += $$system(pkg-config --static --libs libvitamtp libavformat libavcodec libavutil libswscale)
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
main_android.cpp
|
main_android.cpp \
|
||||||
# headlessmanager.cpp
|
sevicemanager.cpp
|
||||||
|
|
||||||
#HEADERS += \
|
HEADERS += \
|
||||||
# headlessmanager.h
|
servicemanager.h
|
||||||
|
|
||||||
DISTFILES += \
|
DISTFILES += \
|
||||||
android-src/gradle/wrapper/gradle-wrapper.jar \
|
android-src/gradle/wrapper/gradle-wrapper.jar \
|
||||||
|
|||||||
@@ -29,62 +29,25 @@
|
|||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <vitamtp.h>
|
#include <vitamtp.h>
|
||||||
|
|
||||||
#include "headlessmanager.h"
|
#include "servicemanager.h"
|
||||||
|
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
|
||||||
static void noDebugOutput(QtMsgType type, const QMessageLogContext &, const QString & msg)
|
|
||||||
{
|
|
||||||
QByteArray localMsg = msg.toLocal8Bit();
|
|
||||||
const char *message = localMsg.constData();
|
|
||||||
#else
|
|
||||||
static void noDebugOutput(QtMsgType type, const char *message)
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
switch (type) {
|
|
||||||
case QtDebugMsg:
|
|
||||||
break;
|
|
||||||
case QtWarningMsg:
|
|
||||||
fprintf(stderr, "Warning: %s\n", message);
|
|
||||||
break;
|
|
||||||
case QtCriticalMsg:
|
|
||||||
fprintf(stderr, "Critical: %s\n", message);
|
|
||||||
break;
|
|
||||||
case QtFatalMsg:
|
|
||||||
fprintf(stderr, "Fatal: %s\n", message);
|
|
||||||
abort();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QCoreApplication app(argc, argv);
|
QCoreApplication app(argc, argv);
|
||||||
|
app.setApplicationName("Qcma");
|
||||||
|
|
||||||
// FIXME: libmtp sends SIGPIPE if a socket write fails crashing the whole app
|
// FIXME: libmtp sends SIGPIPE if a socket write fails crashing the whole app
|
||||||
// the proper fix is to libmtp to handle the cancel properly or ignoring
|
// the proper fix is to libmtp to handle the cancel properly or ignoring
|
||||||
// SIGPIPE on the socket
|
// SIGPIPE on the socket
|
||||||
signal(SIGPIPE, SIG_IGN);
|
signal(SIGPIPE, SIG_IGN);
|
||||||
|
|
||||||
if(app.arguments().contains("--with-debug")) {
|
// stdout goes to /dev/null on android
|
||||||
VitaMTP_Set_Logging(VitaMTP_DEBUG);
|
VitaMTP_Set_Logging(VitaMTP_NONE);
|
||||||
} else if(app.arguments().contains("--verbose")) {
|
|
||||||
VitaMTP_Set_Logging(VitaMTP_VERBOSE);
|
|
||||||
} else {
|
|
||||||
VitaMTP_Set_Logging(VitaMTP_NONE);
|
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
|
||||||
qInstallMessageHandler(noDebugOutput);
|
|
||||||
#else
|
|
||||||
qInstallMsgHandler(noDebugOutput);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
|
qDebug("Starting Qcma %s", QCMA_VER);
|
||||||
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
QTextStream(stdout) << "Starting Qcma " << QCMA_VER << endl;
|
|
||||||
|
|
||||||
QTranslator translator;
|
QTranslator translator;
|
||||||
QString locale = QLocale().system().name();
|
QString locale = "en"; //QLocale().system().name();
|
||||||
qDebug() << "Current locale:" << locale;
|
qDebug() << "Current locale:" << locale;
|
||||||
|
|
||||||
if(app.arguments().contains("--set-locale")) {
|
if(app.arguments().contains("--set-locale")) {
|
||||||
@@ -111,12 +74,8 @@ int main(int argc, char *argv[])
|
|||||||
app.setOrganizationName("codestation");
|
app.setOrganizationName("codestation");
|
||||||
app.setApplicationName("qcma");
|
app.setApplicationName("qcma");
|
||||||
|
|
||||||
//HeadlessManager manager;
|
ServiceManager manager;
|
||||||
|
manager.start();
|
||||||
// receive the message from another process
|
|
||||||
//QObject::connect(&app, SIGNAL(messageAvailable(QString)), &manager, SLOT(receiveMessage(QString)));
|
|
||||||
|
|
||||||
//manager.start();
|
|
||||||
|
|
||||||
return app.exec();
|
return app.exec();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,30 +17,27 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef HEADLESSMANAGER_H
|
#ifndef SERVICEMANAGER_H
|
||||||
#define HEADLESSMANAGER_H
|
#define SERVICEMANAGER_H
|
||||||
|
|
||||||
#include "database.h"
|
#include "database.h"
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <QSocketNotifier>
|
|
||||||
|
|
||||||
class HeadlessManager : public QObject
|
class ServiceManager : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit HeadlessManager(QObject *parent = 0);
|
explicit ServiceManager(QObject *parent = 0);
|
||||||
~HeadlessManager();
|
~ServiceManager();
|
||||||
|
|
||||||
void start();
|
void start();
|
||||||
|
|
||||||
// unix signal handlers
|
|
||||||
static void hupSignalHandler(int);
|
|
||||||
static void termSignalHandler(int);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void loadDefaultSettings();
|
||||||
|
|
||||||
int thread_count;
|
int thread_count;
|
||||||
QMutex mutex;
|
QMutex mutex;
|
||||||
|
|
||||||
@@ -49,13 +46,6 @@ private:
|
|||||||
QThread *usb_thread;
|
QThread *usb_thread;
|
||||||
QThread *wireless_thread;
|
QThread *wireless_thread;
|
||||||
|
|
||||||
// signal handling
|
|
||||||
static int sighup_fd[2];
|
|
||||||
static int sigterm_fd[2];
|
|
||||||
|
|
||||||
QSocketNotifier *sn_hup;
|
|
||||||
QSocketNotifier *sn_term;
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void stopped();
|
void stopped();
|
||||||
void databaseUpdated(int count);
|
void databaseUpdated(int count);
|
||||||
@@ -64,13 +54,9 @@ public slots:
|
|||||||
void refreshDatabase();
|
void refreshDatabase();
|
||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
// Qt signal handlers
|
|
||||||
void handleSigHup();
|
|
||||||
void handleSigTerm();
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void threadStopped();
|
void threadStopped();
|
||||||
void receiveMessage(QString message);
|
void receiveMessage(QString message);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // HEADLESSMANAGER_H
|
#endif // SERVICEMANAGER_H
|
||||||
@@ -21,40 +21,27 @@
|
|||||||
#include "cmautils.h"
|
#include "cmautils.h"
|
||||||
#include "sqlitedb.h"
|
#include "sqlitedb.h"
|
||||||
#include "qlistdb.h"
|
#include "qlistdb.h"
|
||||||
#include "headlessmanager.h"
|
#include "servicemanager.h"
|
||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
|
#include <QDir>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
#include <QStandardPaths>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <vitamtp.h>
|
#include <vitamtp.h>
|
||||||
|
|
||||||
int HeadlessManager::sighup_fd[2];
|
ServiceManager::ServiceManager(QObject *obj_parent) :
|
||||||
int HeadlessManager::sigterm_fd[2];
|
|
||||||
|
|
||||||
HeadlessManager::HeadlessManager(QObject *obj_parent) :
|
|
||||||
QObject(obj_parent)
|
QObject(obj_parent)
|
||||||
{
|
{
|
||||||
if (::socketpair(AF_UNIX, SOCK_STREAM, 0, sighup_fd))
|
|
||||||
qFatal("Couldn't create HUP socketpair");
|
|
||||||
|
|
||||||
if (::socketpair(AF_UNIX, SOCK_STREAM, 0, sigterm_fd))
|
|
||||||
qFatal("Couldn't create TERM socketpair");
|
|
||||||
|
|
||||||
sn_hup = new QSocketNotifier(sighup_fd[1], QSocketNotifier::Read, this);
|
|
||||||
connect(sn_hup, SIGNAL(activated(int)), this, SLOT(handleSigHup()));
|
|
||||||
sn_term = new QSocketNotifier(sigterm_fd[1], QSocketNotifier::Read, this);
|
|
||||||
connect(sn_term, SIGNAL(activated(int)), this, SLOT(handleSigTerm()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HeadlessManager::~HeadlessManager()
|
ServiceManager::~ServiceManager()
|
||||||
{
|
{
|
||||||
VitaMTP_Cleanup();
|
VitaMTP_Cleanup();
|
||||||
delete m_db;
|
delete m_db;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HeadlessManager::refreshDatabase()
|
void ServiceManager::refreshDatabase()
|
||||||
{
|
{
|
||||||
if(m_db->load()) {
|
if(m_db->load()) {
|
||||||
return;
|
return;
|
||||||
@@ -67,13 +54,15 @@ void HeadlessManager::refreshDatabase()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HeadlessManager::start()
|
void ServiceManager::start()
|
||||||
{
|
{
|
||||||
if(VitaMTP_Init() < 0) {
|
if(VitaMTP_Init() < 0) {
|
||||||
qCritical("Cannot initialize VitaMTP library");
|
qCritical("Cannot initialize VitaMTP library");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
loadDefaultSettings();
|
||||||
|
|
||||||
if(QSettings().value("useMemoryStorage", true).toBool()) {
|
if(QSettings().value("useMemoryStorage", true).toBool()) {
|
||||||
m_db = new QListDB();
|
m_db = new QListDB();
|
||||||
} else {
|
} else {
|
||||||
@@ -93,9 +82,6 @@ void HeadlessManager::start()
|
|||||||
|
|
||||||
if(!settings.value("disableUSB", false).toBool()) {
|
if(!settings.value("disableUSB", false).toBool()) {
|
||||||
|
|
||||||
if(!belongsToGroup("vitamtp"))
|
|
||||||
qCritical() << tr("This user doesn't belong to the vitamtp group, there could be a problem while reading the USB bus.");
|
|
||||||
|
|
||||||
usb_thread = new QThread();
|
usb_thread = new QThread();
|
||||||
client = new CmaClient(m_db);
|
client = new CmaClient(m_db);
|
||||||
usb_thread->setObjectName("usb_thread");
|
usb_thread->setObjectName("usb_thread");
|
||||||
@@ -135,19 +121,19 @@ void HeadlessManager::start()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HeadlessManager::receiveMessage(QString message)
|
void ServiceManager::receiveMessage(QString message)
|
||||||
{
|
{
|
||||||
QTextStream(stdout) << message << endl;
|
QTextStream(stdout) << message << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HeadlessManager::stop()
|
void ServiceManager::stop()
|
||||||
{
|
{
|
||||||
if(CmaClient::stop() < 0) {
|
if(CmaClient::stop() < 0) {
|
||||||
QCoreApplication::quit();
|
QCoreApplication::quit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HeadlessManager::threadStopped()
|
void ServiceManager::threadStopped()
|
||||||
{
|
{
|
||||||
mutex.lock();
|
mutex.lock();
|
||||||
if(--thread_count == 0) {
|
if(--thread_count == 0) {
|
||||||
@@ -156,36 +142,54 @@ void HeadlessManager::threadStopped()
|
|||||||
mutex.unlock();
|
mutex.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HeadlessManager::hupSignalHandler(int)
|
void ServiceManager::loadDefaultSettings()
|
||||||
{
|
{
|
||||||
char a = 1;
|
QString defaultdir;
|
||||||
::write(sighup_fd[0], &a, sizeof(a));
|
QSettings settings;
|
||||||
}
|
|
||||||
|
defaultdir = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
|
||||||
void HeadlessManager::termSignalHandler(int)
|
qDebug("photoPath: %s", qPrintable(defaultdir));
|
||||||
{
|
settings.setValue("photoPath", defaultdir);
|
||||||
char a = 1;
|
|
||||||
::write(sigterm_fd[0], &a, sizeof(a));
|
defaultdir = QStandardPaths::writableLocation(QStandardPaths::MusicLocation);
|
||||||
}
|
qDebug("musicPath: %s", qPrintable(defaultdir));
|
||||||
|
settings.setValue("musicPath", defaultdir);
|
||||||
void HeadlessManager::handleSigTerm()
|
|
||||||
{
|
defaultdir = QStandardPaths::writableLocation(QStandardPaths::MoviesLocation);
|
||||||
sn_term->setEnabled(false);
|
qDebug("photoPath: %s", qPrintable(defaultdir));
|
||||||
char tmp;
|
settings.setValue("videoPath", defaultdir);
|
||||||
::read(sigterm_fd[1], &tmp, sizeof(tmp));
|
|
||||||
|
defaultdir = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
|
||||||
stop();
|
defaultdir.append(QDir::separator()).append("PS Vita");
|
||||||
|
qDebug("appsPath: %s", qPrintable(defaultdir));
|
||||||
sn_term->setEnabled(true);
|
settings.setValue("appsPath", defaultdir);
|
||||||
}
|
|
||||||
|
defaultdir = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
|
||||||
void HeadlessManager::handleSigHup()
|
defaultdir.append(QDir::separator()).append("PSV Updates");
|
||||||
{
|
qDebug("urlPath: %s", qPrintable(defaultdir));
|
||||||
sn_hup->setEnabled(false);
|
settings.setValue("urlPath", defaultdir);
|
||||||
char tmp;
|
|
||||||
::read(sighup_fd[1], &tmp, sizeof(tmp));
|
defaultdir = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
|
||||||
|
defaultdir.append(QDir::separator()).append("PSV Packages");
|
||||||
refreshDatabase();
|
qDebug("pkgPath: %s", qPrintable(defaultdir));
|
||||||
|
settings.setValue("pkgPath", defaultdir);
|
||||||
sn_hup->setEnabled(true);
|
|
||||||
|
settings.setValue("offlineMode", true);
|
||||||
|
settings.setValue("skipMetadata", false);
|
||||||
|
|
||||||
|
// disable USB for now
|
||||||
|
settings.setValue("disableUSB", true);
|
||||||
|
|
||||||
|
settings.setValue("disableWireless", false);
|
||||||
|
settings.setValue("useMemoryStorage", true);
|
||||||
|
|
||||||
|
settings.setValue("photoSkip", false);
|
||||||
|
settings.setValue("videoSkip", false);
|
||||||
|
settings.setValue("musicSkip", false);
|
||||||
|
|
||||||
|
settings.setValue("protocolMode", "automatic");
|
||||||
|
|
||||||
|
settings.setValue("protocolIndex", 0);
|
||||||
|
|
||||||
|
settings.setValue("protocolVersion", VITAMTP_PROTOCOL_MAX_VERSION);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user