Merge branch '976-disable-assert-checks' into 'master'
[glib.git] / gio / gnotificationbackend.c
blobb2c0729e85414481fbba185f3fea09996c64fa2f
1 /*
2 * Copyright © 2013 Lars Uebernickel
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
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.
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/>.
17 * Authors: Lars Uebernickel <lars@uebernic.de>
20 #include "gnotificationbackend.h"
22 #include "gnotification.h"
23 #include "gapplication.h"
24 #include "gactiongroup.h"
25 #include "giomodule-priv.h"
27 G_DEFINE_TYPE (GNotificationBackend, g_notification_backend, G_TYPE_OBJECT)
29 static void
30 g_notification_backend_class_init (GNotificationBackendClass *class)
34 static void
35 g_notification_backend_init (GNotificationBackend *backend)
39 GNotificationBackend *
40 g_notification_backend_new_default (GApplication *application)
42 GType backend_type;
43 GNotificationBackend *backend;
45 g_return_val_if_fail (G_IS_APPLICATION (application), NULL);
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));
51 backend = g_object_new (backend_type, NULL);
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.
56 backend->application = application;
58 backend->dbus_connection = g_application_get_dbus_connection (application);
59 if (backend->dbus_connection)
60 g_object_ref (backend->dbus_connection);
62 return backend;
65 void
66 g_notification_backend_send_notification (GNotificationBackend *backend,
67 const gchar *id,
68 GNotification *notification)
70 g_return_if_fail (G_IS_NOTIFICATION_BACKEND (backend));
71 g_return_if_fail (G_IS_NOTIFICATION (notification));
73 G_NOTIFICATION_BACKEND_GET_CLASS (backend)->send_notification (backend, id, notification);
76 void
77 g_notification_backend_withdraw_notification (GNotificationBackend *backend,
78 const gchar *id)
80 g_return_if_fail (G_IS_NOTIFICATION_BACKEND (backend));
81 g_return_if_fail (id != NULL);
83 G_NOTIFICATION_BACKEND_GET_CLASS (backend)->withdraw_notification (backend, id);