1
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
4
* Copyright (C) Philippe Rouquier 2005-2009 <bonfire-app@wanadoo.fr>
6
* Libbrasero-media is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* The Libbrasero-media authors hereby grant permission for non-GPL compatible
12
* GStreamer plugins to be used and distributed together with GStreamer
13
* and Libbrasero-media. This permission is above and beyond the permissions granted
14
* by the GPL license by which Libbrasero-media is covered. If you modify this code
15
* you may extend this exception to your version of the code, but you are not
16
* obligated to do so. If you do not wish to do so, delete this exception
17
* statement from your version.
19
* Libbrasero-media is distributed in the hope that it will be useful,
20
* but WITHOUT ANY WARRANTY; without even the implied warranty of
21
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
* GNU Library General Public License for more details.
24
* You should have received a copy of the GNU General Public License
25
* along with this program; if not, write to:
26
* The Free Software Foundation, Inc.,
27
* 51 Franklin Street, Fifth Floor
28
* Boston, MA 02110-1301, USA.
36
#include <glib-object.h>
38
#include <dbus/dbus.h>
39
#include <dbus/dbus-glib.h>
40
#include <dbus/dbus-glib-lowlevel.h>
44
#include "brasero-media.h"
45
#include "brasero-media-private.h"
47
#include "burn-hal-watch.h"
48
#include "libbrasero-marshal.h"
50
typedef struct _BraseroHALWatchPrivate BraseroHALWatchPrivate;
51
struct _BraseroHALWatchPrivate
56
#define BRASERO_HAL_WATCH_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), BRASERO_TYPE_HAL_WATCH, BraseroHALWatchPrivate))
67
static guint hal_watch_signals[LAST_SIGNAL] = { 0 };
69
G_DEFINE_TYPE (BraseroHALWatch, brasero_hal_watch, G_TYPE_OBJECT);
72
brasero_hal_watch_get_ctx (BraseroHALWatch *self)
74
BraseroHALWatchPrivate *priv;
76
priv = BRASERO_HAL_WATCH_PRIVATE (self);
78
BRASERO_MEDIA_LOG ("HAL context is NULL");
84
brasero_hal_watch_property_changed_cb (LibHalContext *ctx,
87
dbus_bool_t is_removed,
90
BraseroHALWatch *self;
92
self = libhal_ctx_get_user_data (ctx);
94
hal_watch_signals [PROPERTY_CHANGED],
101
brasero_hal_watch_device_added_cb (LibHalContext *ctx,
104
BraseroHALWatch *self;
106
self = libhal_ctx_get_user_data (ctx);
108
hal_watch_signals [DEVICE_ADDED],
114
brasero_hal_watch_device_removed_cb (LibHalContext *ctx,
117
BraseroHALWatch *self;
119
self = libhal_ctx_get_user_data (ctx);
121
hal_watch_signals [DEVICE_REMOVED],
127
brasero_hal_watch_init (BraseroHALWatch *object)
130
BraseroHALWatchPrivate *priv;
131
DBusConnection *dbus_connection = NULL;
133
priv = BRASERO_HAL_WATCH_PRIVATE (object);
135
/* initialize the connection with hal */
136
priv->ctx = libhal_ctx_new ();
137
if (priv->ctx == NULL) {
138
g_warning ("Cannot initialize hal library\n");
142
dbus_error_init (&error);
143
dbus_connection = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
144
if (dbus_error_is_set (&error)) {
145
g_warning ("Cannot connect to DBus %s\n", error.message);
146
dbus_error_free (&error);
150
dbus_connection_setup_with_g_main (dbus_connection, NULL);
151
libhal_ctx_set_dbus_connection (priv->ctx, dbus_connection);
153
libhal_ctx_set_user_data (priv->ctx, object);
154
libhal_ctx_set_cache (priv->ctx, FALSE);
156
/* monitor devices addition and removal */
157
libhal_ctx_set_device_added (priv->ctx, brasero_hal_watch_device_added_cb);
158
libhal_ctx_set_device_removed (priv->ctx, brasero_hal_watch_device_removed_cb);
159
libhal_ctx_set_device_property_modified (priv->ctx, brasero_hal_watch_property_changed_cb);
161
if (libhal_ctx_init (priv->ctx, &error))
164
g_warning ("Failed to initialize hal : %s\n", error.message);
165
dbus_error_free (&error);
169
libhal_ctx_shutdown (priv->ctx, NULL);
170
libhal_ctx_free (priv->ctx);
174
dbus_connection_unref (dbus_connection);
178
brasero_hal_watch_finalize (GObject *object)
180
BraseroHALWatchPrivate *priv;
182
priv = BRASERO_HAL_WATCH_PRIVATE (object);
185
DBusConnection *connection;
187
connection = libhal_ctx_get_dbus_connection (priv->ctx);
188
dbus_connection_unref (connection);
190
libhal_ctx_shutdown (priv->ctx, NULL);
191
libhal_ctx_free (priv->ctx);
195
G_OBJECT_CLASS (brasero_hal_watch_parent_class)->finalize (object);
199
brasero_hal_watch_class_init (BraseroHALWatchClass *klass)
201
GObjectClass* object_class = G_OBJECT_CLASS (klass);
203
g_type_class_add_private (klass, sizeof (BraseroHALWatchPrivate));
205
object_class->finalize = brasero_hal_watch_finalize;
207
hal_watch_signals[PROPERTY_CHANGED] =
208
g_signal_new ("property_changed",
209
G_OBJECT_CLASS_TYPE (klass),
210
G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
213
brasero_marshal_VOID__STRING_STRING,
217
hal_watch_signals[DEVICE_ADDED] =
218
g_signal_new ("device_added",
219
G_OBJECT_CLASS_TYPE (klass),
220
G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
223
g_cclosure_marshal_VOID__STRING,
226
hal_watch_signals[DEVICE_REMOVED] =
227
g_signal_new ("device_removed",
228
G_OBJECT_CLASS_TYPE (klass),
229
G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
232
g_cclosure_marshal_VOID__STRING,
237
static BraseroHALWatch *singleton = NULL;
240
brasero_hal_watch_get_default (void)
245
singleton = g_object_new (BRASERO_TYPE_HAL_WATCH, NULL);
250
brasero_hal_watch_destroy (void)
253
g_object_unref (singleton);