Skip to content
Snippets Groups Projects
Commit be9ef3ce authored by Adrien Béraud's avatar Adrien Béraud Committed by Sébastien Blin
Browse files

dring/dbus: unregister signals on exit


Change-Id: Ia50ab7aba5e600b5a53736bcf73130973dd71efb
Reviewed-by: default avatarSébastien Blin <sebastien.blin@savoirfairelinux.com>
parent e6c421dd
No related branches found
No related tags found
No related merge requests found
...@@ -23,13 +23,9 @@ ...@@ -23,13 +23,9 @@
#include "config.h" #include "config.h"
#endif // HAVE_CONFIG_H #endif // HAVE_CONFIG_H
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <stdexcept>
#include "dbusclient.h" #include "dbusclient.h"
#include "dbus_cpp.h" #include "dbus_cpp.h"
#include "dring.h"
#include "dbusinstance.h" #include "dbusinstance.h"
...@@ -49,6 +45,11 @@ ...@@ -49,6 +45,11 @@
#include "videomanager_interface.h" #include "videomanager_interface.h"
#endif #endif
#include <iostream>
#include <stdexcept>
#include <cstdlib>
#include <cstring>
class EventCallback : class EventCallback :
public DBus::Callback_Base<void, DBus::DefaultTimeout&> public DBus::Callback_Base<void, DBus::DefaultTimeout&>
{ {
...@@ -102,7 +103,7 @@ DBusClient::~DBusClient() ...@@ -102,7 +103,7 @@ DBusClient::~DBusClient()
{ {
// instances destruction order is important // instances destruction order is important
// so we enforce it here // so we enforce it here
DRing::unregisterSignalHandlers();
#ifdef ENABLE_VIDEO #ifdef ENABLE_VIDEO
videoManager_.reset(); videoManager_.reset();
#endif #endif
...@@ -220,13 +221,13 @@ DBusClient::initLibrary(int flags) ...@@ -220,13 +221,13 @@ DBusClient::initLibrary(int flags)
if (!DRing::init(static_cast<DRing::InitFlag>(flags))) if (!DRing::init(static_cast<DRing::InitFlag>(flags)))
return -1; return -1;
registerSignalHandlers(callEvHandlers); DRing::registerSignalHandlers(callEvHandlers);
registerSignalHandlers(configEvHandlers); DRing::registerSignalHandlers(configEvHandlers);
registerSignalHandlers(presEvHandlers); DRing::registerSignalHandlers(presEvHandlers);
registerSignalHandlers(audioEvHandlers); DRing::registerSignalHandlers(audioEvHandlers);
registerSignalHandlers(dataXferEvHandlers); DRing::registerSignalHandlers(dataXferEvHandlers);
#ifdef ENABLE_VIDEO #ifdef ENABLE_VIDEO
registerSignalHandlers(videoEvHandlers); DRing::registerSignalHandlers(videoEvHandlers);
#endif #endif
if (!DRing::start()) if (!DRing::start())
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
#endif // HAVE_CONFIG_H #endif // HAVE_CONFIG_H
#include "dring/def.h" #include "dring/def.h"
#include "dring.h"
#include <memory> #include <memory>
class DBusConfigurationManager; class DBusConfigurationManager;
......
...@@ -21,13 +21,6 @@ ...@@ -21,13 +21,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#include <iostream>
#include <thread>
#include <cstring>
#include <signal.h>
#include <getopt.h>
#include <cstdlib>
#include "dring/dring.h" #include "dring/dring.h"
#include "logger.h" #include "logger.h"
...@@ -40,13 +33,22 @@ ...@@ -40,13 +33,22 @@
#include "fileutils.h" #include "fileutils.h"
#include <signal.h>
#include <getopt.h>
#include <iostream>
#include <thread>
#include <memory>
#include <cstring>
#include <cstdlib>
static int ringFlags = 0; static int ringFlags = 0;
static int port = 8080; static int port = 8080;
#if REST_API #if REST_API
static std::unique_ptr<RestClient> restClient; static std::weak_ptr<RestClient> weakClient;
#else #else
static std::unique_ptr<DBusClient> dbusClient; static std::weak_ptr<DBusClient> weakClient;
#endif #endif
static void static void
...@@ -88,14 +90,14 @@ parse_args(int argc, char *argv[], bool& persistent) ...@@ -88,14 +90,14 @@ parse_args(int argc, char *argv[], bool& persistent)
const struct option long_options[] = { const struct option long_options[] = {
/* These options set a flag. */ /* These options set a flag. */
{"debug", no_argument, NULL, 'd'}, {"debug", no_argument, nullptr, 'd'},
{"console", no_argument, NULL, 'c'}, {"console", no_argument, nullptr, 'c'},
{"persistent", no_argument, NULL, 'p'}, {"persistent", no_argument, nullptr, 'p'},
{"help", no_argument, NULL, 'h'}, {"help", no_argument, nullptr, 'h'},
{"version", no_argument, NULL, 'v'}, {"version", no_argument, nullptr, 'v'},
{"auto-answer", no_argument, &autoAnswer, true}, {"auto-answer", no_argument, &autoAnswer, true},
{"port", optional_argument, NULL, 'x'}, {"port", optional_argument, nullptr, 'x'},
{0, 0, 0, 0} /* Sentinel */ {nullptr, 0, nullptr, 0} /* Sentinel */
}; };
while (true) { while (true) {
...@@ -173,13 +175,8 @@ signal_handler(int code) ...@@ -173,13 +175,8 @@ signal_handler(int code)
signal(SIGTERM, SIG_DFL); signal(SIGTERM, SIG_DFL);
// Interrupt the process // Interrupt the process
#if REST_API if (auto client = weakClient.lock())
if (restClient) client->exit();
restClient->exit();
#else
if (dbusClient)
dbusClient->exit();
#endif
} }
int int
...@@ -211,31 +208,18 @@ main(int argc, char *argv []) ...@@ -211,31 +208,18 @@ main(int argc, char *argv [])
signal(SIGTERM, signal_handler); signal(SIGTERM, signal_handler);
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);
#if REST_API
try { try {
restClient.reset(new RestClient {port, ringFlags, persistent}); #if REST_API
} catch (const std::exception& ex) { if (auto client = std::make_shared<RestClient>(port, ringFlags, persistent))
std::cerr << "One does not simply initialize the rest client: " << ex.what() << std::endl;
return 1;
}
if (restClient)
return restClient->event_loop();
else
return 1;
#else #else
// initialize client/library if (auto client = std::make_shared<DBusClient>(ringFlags, persistent))
try { #endif
dbusClient.reset(new DBusClient {ringFlags, persistent}); {
weakClient = client;
return client->event_loop();
}
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
std::cerr << "One does not simply initialize the DBus client: " << ex.what() << std::endl; std::cerr << "One does not simply initialize the client: " << ex.what() << std::endl;
return 1;
} }
if (dbusClient)
return dbusClient->event_loop();
else
return 1; return 1;
#endif
} }
...@@ -139,4 +139,14 @@ registerSignalHandlers(const std::map<std::string, ...@@ -139,4 +139,14 @@ registerSignalHandlers(const std::map<std::string,
} }
} }
void
unregisterSignalHandlers()
{
auto& handlers_ = jami::getSignalHandlers();
for (auto& item : handlers_) {
item.second = {};
}
}
} }
...@@ -145,6 +145,7 @@ exportable_callback(std::function<typename Ts::cb_type>&& func) { ...@@ -145,6 +145,7 @@ exportable_callback(std::function<typename Ts::cb_type>&& func) {
} }
DRING_PUBLIC void registerSignalHandlers(const std::map<std::string, std::shared_ptr<CallbackWrapperBase>>&); DRING_PUBLIC void registerSignalHandlers(const std::map<std::string, std::shared_ptr<CallbackWrapperBase>>&);
DRING_PUBLIC void unregisterSignalHandlers();
} // namespace DRing } // namespace DRing
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment