2016-08-22 21:19:33 -04:00
|
|
|
/*
|
|
|
|
* RetroShare Android Service
|
2018-01-25 09:14:09 -05:00
|
|
|
* Copyright (C) 2016-2018 Gioacchino Mazzurco <gio@eigenlab.org>
|
2016-08-22 21:19:33 -04: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>
|
|
|
|
#include <QDebug>
|
2017-04-18 17:14:44 -04:00
|
|
|
#include <QDir>
|
2018-01-25 09:14:09 -05:00
|
|
|
#include <QTimer>
|
2018-01-25 09:50:12 -05:00
|
|
|
#include <csignal>
|
2016-09-15 07:07:13 -04:00
|
|
|
|
|
|
|
#ifdef __ANDROID__
|
2016-12-21 18:33:34 -05:00
|
|
|
# include "util/androiddebug.h"
|
2016-09-15 07:07:13 -04:00
|
|
|
#endif
|
2016-08-22 21:19:33 -04:00
|
|
|
|
|
|
|
#include "api/ApiServer.h"
|
|
|
|
#include "api/ApiServerLocal.h"
|
|
|
|
#include "api/RsControlModule.h"
|
|
|
|
|
|
|
|
using namespace resource_api;
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2016-12-21 18:33:34 -05:00
|
|
|
#ifdef __ANDROID__
|
|
|
|
AndroidStdIOCatcher dbg; (void) dbg;
|
|
|
|
#endif
|
|
|
|
|
2017-04-16 08:45:03 -04:00
|
|
|
QCoreApplication app(argc, argv);
|
2018-01-25 09:50:12 -05:00
|
|
|
|
|
|
|
signal(SIGINT, &QCoreApplication::exit);
|
|
|
|
signal(SIGTERM, &QCoreApplication::exit);
|
|
|
|
#ifdef SIGBREAK
|
|
|
|
signal(SIGBREAK, &QCoreApplication::exit);
|
|
|
|
#endif // def SIGBREAK
|
|
|
|
|
2016-08-22 21:19:33 -04:00
|
|
|
ApiServer api;
|
|
|
|
RsControlModule ctrl_mod(argc, argv, api.getStateTokenServer(), &api, true);
|
2017-04-07 12:26:08 -04:00
|
|
|
api.addResourceHandler(
|
|
|
|
"control",
|
|
|
|
dynamic_cast<resource_api::ResourceRouter*>(&ctrl_mod),
|
|
|
|
&resource_api::RsControlModule::handleRequest);
|
2016-08-22 21:19:33 -04:00
|
|
|
|
2017-03-25 13:12:39 -04:00
|
|
|
|
2017-06-04 16:10:41 -04:00
|
|
|
QString sockPath = QDir::homePath() + "/.retroshare";
|
2016-08-22 21:19:33 -04:00
|
|
|
sockPath.append("/libresapi.sock");
|
|
|
|
qDebug() << "Listening on:" << sockPath;
|
2017-06-04 16:10:41 -04:00
|
|
|
|
2016-08-22 21:19:33 -04:00
|
|
|
ApiServerLocal apiServerLocal(&api, sockPath); (void) apiServerLocal;
|
|
|
|
|
2018-01-28 05:36:51 -05:00
|
|
|
// This ugly but RsControlModule has no other way to callback for stop
|
2018-01-25 09:14:09 -05:00
|
|
|
QTimer shouldExitTimer;
|
2018-01-28 05:36:51 -05:00
|
|
|
shouldExitTimer.setTimerType(Qt::VeryCoarseTimer);
|
|
|
|
shouldExitTimer.setInterval(1000);
|
2018-01-25 09:14:09 -05:00
|
|
|
QObject::connect( &shouldExitTimer, &QTimer::timeout, [&](){
|
2018-01-28 05:36:51 -05:00
|
|
|
if(ctrl_mod.processShouldExit()) app.quit(); } );
|
2018-01-25 09:14:09 -05:00
|
|
|
shouldExitTimer.start();
|
2017-04-07 12:26:08 -04:00
|
|
|
|
2017-04-16 08:45:03 -04:00
|
|
|
return app.exec();
|
2016-08-22 21:19:33 -04:00
|
|
|
}
|