From 4acbf775a59c7365cab8ecec95edcbb847927c93 Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Sat, 1 Sep 2018 16:16:15 +0200 Subject: [PATCH] retroshare-android-service can be built without libresapi --- .../src/retroshare-android-service.pro | 4 +- retroshare-android-service/src/service.cpp | 89 +++++++++++++------ 2 files changed, 63 insertions(+), 30 deletions(-) diff --git a/retroshare-android-service/src/retroshare-android-service.pro b/retroshare-android-service/src/retroshare-android-service.pro index f83392456..9815f51ca 100644 --- a/retroshare-android-service/src/retroshare-android-service.pro +++ b/retroshare-android-service/src/retroshare-android-service.pro @@ -11,7 +11,9 @@ android-*:CONFIG += dll android-*:TEMPLATE = lib !android-*:TEMPLATE = app -!include("../../libresapi/src/use_libresapi.pri"):error("Including") +libresapilocalserver { + !include("../../libresapi/src/use_libresapi.pri"):error("Including") +} !include("../../libretroshare/src/use_libretroshare.pri"):error("Including") diff --git a/retroshare-android-service/src/service.cpp b/retroshare-android-service/src/service.cpp index 83381975c..5f53f9a3b 100644 --- a/retroshare-android-service/src/service.cpp +++ b/retroshare-android-service/src/service.cpp @@ -17,36 +17,34 @@ */ #include -#include -#include -#include #include #ifdef __ANDROID__ # include "util/androiddebug.h" #endif -#include "api/ApiServer.h" -#include "api/ApiServerLocal.h" -#include "api/RsControlModule.h" +#ifdef LIBRESAPI_LOCAL_SERVER +# include +# include +# include + +# include "api/ApiServer.h" +# include "api/ApiServerLocal.h" +# include "api/RsControlModule.h" +#else // ifdef LIBRESAPI_LOCAL_SERVER +# include + +# include "retroshare/rsinit.h" +# include "retroshare/rsiface.h" +#endif // ifdef LIBRESAPI_LOCAL_SERVER #ifdef RS_JSONAPI +# include # include "jsonapi/jsonapi.h" -# include "retroshare/rsiface.h" - -JsonApiServer jas(9092, [](int ec) -{ - RsControl::instance()->rsGlobalShutDown(); - QCoreApplication::exit(ec); -}); - -void exitGracefully(int ec) { jas.shutdown(ec); } - -#else // ifdef RS_JSONAPI -void exitGracefully(int ec) { QCoreApplication::exit(ec); } -#endif // ifdef RS_JSONAPI - -using namespace resource_api; +# include +# include +# include +#endif // def RS_JSONAPI int main(int argc, char *argv[]) { @@ -56,13 +54,15 @@ int main(int argc, char *argv[]) QCoreApplication app(argc, argv); - signal(SIGINT, exitGracefully); - signal(SIGTERM, exitGracefully); + signal(SIGINT, QCoreApplication::exit); + signal(SIGTERM, QCoreApplication::exit); #ifdef SIGBREAK - signal(SIGBREAK, exitGracefully); + signal(SIGBREAK, QCoreApplication::exit); #endif // ifdef SIGBREAK #ifdef LIBRESAPI_LOCAL_SERVER + using namespace resource_api; + ApiServer api; RsControlModule ctrl_mod(argc, argv, api.getStateTokenServer(), &api, true); api.addResourceHandler( @@ -81,15 +81,46 @@ int main(int argc, char *argv[]) shouldExitTimer.setTimerType(Qt::VeryCoarseTimer); shouldExitTimer.setInterval(1000); QObject::connect( &shouldExitTimer, &QTimer::timeout, [&]() - { if(ctrl_mod.processShouldExit()) exitGracefully(0); } ); + { if(ctrl_mod.processShouldExit()) QCoreApplication::exit(0); } ); shouldExitTimer.start(); -#else -# error retroshare-android-service need CONFIG+=libresapilocalserver to build -#endif +#else // ifdef LIBRESAPI_LOCAL_SERVER + RsInit::InitRsConfig(); + RsInit::InitRetroShare(argc, argv, true); + RsControl::earlyInitNotificationSystem(); + QObject::connect( + &app, &QCoreApplication::aboutToQuit, + [](){ + if(RsControl::instance()->isReady()) + RsControl::instance()->rsGlobalShutDown(); } ); +#endif // ifdef LIBRESAPI_LOCAL_SERVER #ifdef RS_JSONAPI + uint16_t jsonApiPort = 9092; + + { + QCommandLineOption jsonApiPortOpt( + "jsonApiPort", "JSON API listening port.", "port", "9092"); + QCommandLineParser cmdParser; + cmdParser.addHelpOption(); + cmdParser.addOption(jsonApiPortOpt); + cmdParser.parse(app.arguments()); + QString jsonApiPortStr = cmdParser.value(jsonApiPortOpt); + bool portOk; + jsonApiPort = jsonApiPortStr.toUShort(&portOk); + if(!portOk) + { + std::cerr << "ERROR: jsonApiPort option value must be a valid TCP " + << "port!" << std::endl; + cmdParser.showHelp(); + QCoreApplication::exit(EINVAL); + } + } + + JsonApiServer jas(jsonApiPort, [](int ec) { QCoreApplication::exit(ec); }); jas.start(); -#endif + std::cerr << "JSON API listening on port " << jsonApiPort << std::endl; + +#endif // ifdef RS_JSONAPI return app.exec(); }