2016-08-23 03:19:33 +02:00
|
|
|
/*
|
|
|
|
* RetroShare Android Service
|
2018-01-25 15:14:09 +01:00
|
|
|
* Copyright (C) 2016-2018 Gioacchino Mazzurco <gio@eigenlab.org>
|
2016-08-23 03:19:33 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <QCoreApplication>
|
2018-01-25 15:50:12 +01:00
|
|
|
#include <csignal>
|
2016-09-15 13:07:13 +02:00
|
|
|
|
|
|
|
#ifdef __ANDROID__
|
2016-12-22 00:33:34 +01:00
|
|
|
# include "util/androiddebug.h"
|
2016-09-15 13:07:13 +02:00
|
|
|
#endif
|
2016-08-23 03:19:33 +02:00
|
|
|
|
2018-09-01 16:16:15 +02:00
|
|
|
#ifdef LIBRESAPI_LOCAL_SERVER
|
|
|
|
# include <QDir>
|
|
|
|
# include <QTimer>
|
|
|
|
# include <QDebug>
|
2018-06-28 15:04:06 +02:00
|
|
|
|
2018-09-01 16:16:15 +02:00
|
|
|
# include "api/ApiServer.h"
|
|
|
|
# include "api/ApiServerLocal.h"
|
|
|
|
# include "api/RsControlModule.h"
|
|
|
|
#else // ifdef LIBRESAPI_LOCAL_SERVER
|
|
|
|
# include <QObject>
|
2018-06-28 15:04:06 +02:00
|
|
|
|
2018-09-01 16:16:15 +02:00
|
|
|
# include "retroshare/rsinit.h"
|
|
|
|
# include "retroshare/rsiface.h"
|
|
|
|
#endif // ifdef LIBRESAPI_LOCAL_SERVER
|
2018-06-27 08:52:03 +02:00
|
|
|
|
2018-09-01 16:16:15 +02:00
|
|
|
#ifdef RS_JSONAPI
|
|
|
|
# include "jsonapi/jsonapi.h"
|
2018-09-05 00:08:56 +02:00
|
|
|
# include "util/rsnet.h"
|
2018-09-06 02:05:29 +02:00
|
|
|
# include "util/rsurl.h"
|
2018-09-05 00:08:56 +02:00
|
|
|
|
|
|
|
# include <cstdint>
|
2018-09-01 16:16:15 +02:00
|
|
|
# include <QCommandLineParser>
|
|
|
|
# include <QString>
|
|
|
|
# include <iostream>
|
|
|
|
#endif // def RS_JSONAPI
|
2016-08-23 03:19:33 +02:00
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2016-12-22 00:33:34 +01:00
|
|
|
#ifdef __ANDROID__
|
|
|
|
AndroidStdIOCatcher dbg; (void) dbg;
|
|
|
|
#endif
|
|
|
|
|
2017-04-16 14:45:03 +02:00
|
|
|
QCoreApplication app(argc, argv);
|
2018-01-25 15:50:12 +01:00
|
|
|
|
2018-09-01 16:16:15 +02:00
|
|
|
signal(SIGINT, QCoreApplication::exit);
|
|
|
|
signal(SIGTERM, QCoreApplication::exit);
|
2018-01-25 15:50:12 +01:00
|
|
|
#ifdef SIGBREAK
|
2018-09-01 16:16:15 +02:00
|
|
|
signal(SIGBREAK, QCoreApplication::exit);
|
2018-06-28 15:04:06 +02:00
|
|
|
#endif // ifdef SIGBREAK
|
2018-01-25 15:50:12 +01:00
|
|
|
|
2018-08-28 14:19:41 +02:00
|
|
|
#ifdef LIBRESAPI_LOCAL_SERVER
|
2018-09-01 16:16:15 +02:00
|
|
|
using namespace resource_api;
|
|
|
|
|
2016-08-23 03:19:33 +02:00
|
|
|
ApiServer api;
|
|
|
|
RsControlModule ctrl_mod(argc, argv, api.getStateTokenServer(), &api, true);
|
2017-04-07 18:26:08 +02:00
|
|
|
api.addResourceHandler(
|
|
|
|
"control",
|
|
|
|
dynamic_cast<resource_api::ResourceRouter*>(&ctrl_mod),
|
|
|
|
&resource_api::RsControlModule::handleRequest);
|
2016-08-23 03:19:33 +02:00
|
|
|
|
2017-06-04 22:10:41 +02:00
|
|
|
QString sockPath = QDir::homePath() + "/.retroshare";
|
2016-08-23 03:19:33 +02:00
|
|
|
sockPath.append("/libresapi.sock");
|
|
|
|
qDebug() << "Listening on:" << sockPath;
|
2017-06-04 22:10:41 +02:00
|
|
|
|
2016-08-23 03:19:33 +02:00
|
|
|
ApiServerLocal apiServerLocal(&api, sockPath); (void) apiServerLocal;
|
|
|
|
|
2018-01-28 11:36:51 +01:00
|
|
|
// This ugly but RsControlModule has no other way to callback for stop
|
2018-01-25 15:14:09 +01:00
|
|
|
QTimer shouldExitTimer;
|
2018-01-28 11:36:51 +01:00
|
|
|
shouldExitTimer.setTimerType(Qt::VeryCoarseTimer);
|
|
|
|
shouldExitTimer.setInterval(1000);
|
2018-06-28 15:04:06 +02:00
|
|
|
QObject::connect( &shouldExitTimer, &QTimer::timeout, [&]()
|
2018-09-01 16:16:15 +02:00
|
|
|
{ if(ctrl_mod.processShouldExit()) QCoreApplication::exit(0); } );
|
2018-01-25 15:14:09 +01:00
|
|
|
shouldExitTimer.start();
|
2018-09-01 16:16:15 +02:00
|
|
|
#else // ifdef LIBRESAPI_LOCAL_SERVER
|
|
|
|
RsInit::InitRsConfig();
|
|
|
|
RsInit::InitRetroShare(argc, argv, true);
|
|
|
|
RsControl::earlyInitNotificationSystem();
|
2018-09-19 21:28:26 +02:00
|
|
|
rsControl->setShutdownCallback(QCoreApplication::exit);
|
2018-09-01 16:16:15 +02:00
|
|
|
QObject::connect(
|
|
|
|
&app, &QCoreApplication::aboutToQuit,
|
|
|
|
[](){
|
|
|
|
if(RsControl::instance()->isReady())
|
|
|
|
RsControl::instance()->rsGlobalShutDown(); } );
|
|
|
|
#endif // ifdef LIBRESAPI_LOCAL_SERVER
|
2017-04-07 18:26:08 +02:00
|
|
|
|
2017-04-16 14:45:03 +02:00
|
|
|
return app.exec();
|
2016-08-23 03:19:33 +02:00
|
|
|
}
|