Commit be9ef3ce authored by Adrien Béraud's avatar Adrien Béraud Committed by Sébastien Blin

dring/dbus: unregister signals on exit

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