/* * Copyright © 2017 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Pete Woods */ #include #include #include #pragma once #pragma GCC visibility push(default) namespace lomiri { namespace app_launch { struct DBusSignalUnsubscriber { std::shared_ptr bus_; void operator()(guint handle) { if (handle != 0 && G_IS_OBJECT(bus_.get())) { g_dbus_connection_signal_unsubscribe(bus_.get(), handle); } } }; typedef lomiri::util::ResourcePtr ManagedDBusSignalConnection; inline ManagedDBusSignalConnection managedDBusSignalConnection(guint id, std::shared_ptr bus) { return ManagedDBusSignalConnection(id, DBusSignalUnsubscriber{bus}); } template struct SignalUnsubscriber { std::shared_ptr obj_; void operator()(gulong handle) { if (handle != 0 && G_IS_OBJECT(obj_.get())) { g_signal_handler_disconnect(obj_.get(), handle); } } }; template using ManagedSignalConnection = lomiri::util::ResourcePtr>; template inline ManagedSignalConnection managedSignalConnection(gulong id, std::shared_ptr obj) { return ManagedSignalConnection(id, SignalUnsubscriber{obj}); } } // namespace app_launch } // namespace lomiri #pragma GCC visibility pop