hook gvariant vectors up to kdbus
[platform/upstream/glib.git] / gio / gnotificationbackend.c
1 /*
2  * Copyright © 2013 Lars Uebernickel
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 as published
6  * by the Free Software Foundation; either version 2 of the licence or (at
7  * your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General
15  * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
16  *
17  * Authors: Lars Uebernickel <lars@uebernic.de>
18  */
19
20 #include "gnotificationbackend.h"
21
22 #include "gnotification.h"
23 #include "gapplication.h"
24 #include "gactiongroup.h"
25 #include "giomodule-priv.h"
26
27 G_DEFINE_TYPE (GNotificationBackend, g_notification_backend, G_TYPE_OBJECT);
28
29 static void
30 g_notification_backend_class_init (GNotificationBackendClass *class)
31 {
32 }
33
34 static void
35 g_notification_backend_init (GNotificationBackend *backend)
36 {
37 }
38
39 GNotificationBackend *
40 g_notification_backend_new_default (GApplication *application)
41 {
42   GType backend_type;
43   GNotificationBackend *backend;
44
45   g_return_val_if_fail (G_IS_APPLICATION (application), NULL);
46
47   backend_type = _g_io_module_get_default_type (G_NOTIFICATION_BACKEND_EXTENSION_POINT_NAME,
48                                                 "GNOTIFICATION_BACKEND",
49                                                 G_STRUCT_OFFSET (GNotificationBackendClass, is_supported));
50
51   backend = g_object_new (backend_type, NULL);
52
53   /* Avoid ref cycle by not taking a ref to the application at all. The
54    * backend only lives as long as the application does.
55    */
56   backend->application = application;
57
58   backend->dbus_connection = g_object_ref (g_application_get_dbus_connection (application));
59
60   return backend;
61 }
62
63 void
64 g_notification_backend_send_notification (GNotificationBackend *backend,
65                                           const gchar          *id,
66                                           GNotification        *notification)
67 {
68   g_return_if_fail (G_IS_NOTIFICATION_BACKEND (backend));
69   g_return_if_fail (G_IS_NOTIFICATION (notification));
70
71   G_NOTIFICATION_BACKEND_GET_CLASS (backend)->send_notification (backend, id, notification);
72 }
73
74 void
75 g_notification_backend_withdraw_notification (GNotificationBackend *backend,
76                                               const gchar          *id)
77 {
78   g_return_if_fail (G_IS_NOTIFICATION_BACKEND (backend));
79   g_return_if_fail (id != NULL);
80
81   G_NOTIFICATION_BACKEND_GET_CLASS (backend)->withdraw_notification (backend, id);
82 }