My Project
GioMemory.h
1 /*
2  * Copyright (C) 2013-2017 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License version 3 as
6  * published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Pete Woods <pete.woods@canonical.com>
17  */
18 
19 #ifndef LOMIRI_UTIL_GIOMEMORY_H
20 #define LOMIRI_UTIL_GIOMEMORY_H
21 
22 #include <gio/gio.h>
23 
24 #include <lomiri/util/GObjectMemory.h>
25 
26 namespace lomiri
27 {
28 
29 namespace util
30 {
31 
32 namespace internal
33 {
34 struct GDBusSignalUnsubscriber
35 {
36 public:
37  void operator()(guint handle) noexcept
38  {
39  if (handle != 0 && G_IS_OBJECT(bus_.get()))
40  {
41  g_dbus_connection_signal_unsubscribe(bus_.get(), handle);
42  }
43  }
44 
45  GObjectSPtr<GDBusConnection> bus_;
46 };
47 
48 }
49 
50 typedef ResourcePtr<guint, internal::GDBusSignalUnsubscriber> GDBusSignalConnection;
51 
63 inline GDBusSignalConnection gdbus_signal_connection(guint id, GObjectSPtr<GDBusConnection> bus) noexcept
64 {
65  return GDBusSignalConnection(id, internal::GDBusSignalUnsubscriber{bus});
66 }
67 
68 } // namespace until
69 
70 } // namespace lomiri
71 
72 #endif
lomiri
Top-level namespace for all things Lomiri-related.
Definition: Version.h:38