hal/tools fstab-sync.c, 1.28, 1.29 hal_get_property.c, 1.7,
1.8 hal_set_property.c, 1.7, 1.8 lshal.c, 1.9, 1.10
David Zeuthen
david at freedesktop.org
Mon Jan 31 12:06:46 PST 2005
Update of /cvs/hal/hal/tools
In directory gabe:/tmp/cvs-serv1622/tools
Modified Files:
fstab-sync.c hal_get_property.c hal_set_property.c lshal.c
Log Message:
2005-01-31 David Zeuthen <davidz at redhat.com>
* configure.in: Prebump to 0.5.0 - but we're not doing a release yet!
Add libtool versioning since libhal and libhal-storage are going
to break API and ABI backwards compatibility.
* hald/hald_test.c: Add the beginnings of a test suite
* hald/hald_test_libhal.c: -do-
* hald/Makefile.am: Add build rules for test suite
* tools/linux/hal_hotplug_map.c: Update to use new libhal API.
* tools/lshal.c: Update to use new libhal API.
* tools/hal_set_property.c: Update to use new libhal API.
* tools/hal_get_property.c: Update to use new libhal API.
* tools/fstab-sync.c: Update to use new libhal API.
* libhal-storage/libhal-storage.c: Update to use new libhal API.
This library will also go through a renaming/cleanup before 0.5.0.
* libhal-storage/Makefile.am: Use library versioning
* libhal/libhal.[ch]: Prefix all function names and other identifiers
with libhal instead of hal. Add code for string lists. Change the
way libhal is initialized to be a multistep process. Use HAL_PROPERTY_
TYPE_* instead of DBUS_TYPE_*. Make all functions using IPC take
a DBusError argument for better error handling. Notable changes
(libhal_device_get_all_properties): Teach this function about
string lists
(libhal_psi_get_strlist): New function
(hal_initialize): Removed
(hal_shutdown): Removed
(libhal_device_get_property_strlist): New function
(libhal_device_property_strlist_append): New function
(libhal_device_property_strlist_prepend): New function
(libhal_device_property_strlist_remove_index): New function
(libhal_device_property_strlist_remove): New function
(libhal_ctx_new): New function
(libhal_ctx_set_cache): New function
(libhal_ctx_set_dbus_connection): New function
(libhal_ctx_init): New function
(libhal_ctx_shutdown): New function
(libhal_ctx_free): New function
(libhal_ctx_set_device_added): New function
(libhal_ctx_set_device_removed): New function
(libhal_ctx_set_device_new_capability): New function
(libhal_ctx_set_device_lost_capability): New function
(libhal_ctx_set_device_property_modified): New function
(libhal_ctx_set_device_condition): New function
* libhal/Makefile.am: Use library versioning
* hald/linux2/probing/probe-input.c: Port to new libhal API
* hald/property.h: Rename property types to HAL_PROPERTY_TYPE_*.
Add prototypes for new string list properties.
* hald/property.c: Rename property types to HAL_PROPERTY_TYPE_*.
(hal_property_free): Teach this function about string lists.
(hal_property_new_strlist): New function
(hal_property_get_strlist): New function
(hal_property_strlist_append): New function
(hal_property_strlist_prepend): New function
(hal_property_strlist_remove_elem): New function
(hal_property_strlist_add): New function
(hal_property_strlist_remove): New function
* hald/hald_dbus.c: Rename property types to HAL_PROPERTY_TYPE_*.
Add new ugly code to handle string lists with the current D-BUS.
(device_string_list_append_prepend): New function
(hald_dbus_filter_function): Rename from filter_function. Add
handlers for new D-BUS methods. Export this function
* hald/hald.[ch]: Rip out persistent property code.
* hald/device_info.c: Rename property types to HAL_PROPERTY_TYPE_*.
* hald/device.c: Rename to property to HAL_PROPERTY_TYPE_*. Rip out
persistent property code.
(hal_device_property_get_as_string): Add code for strlist type
(hal_device_property_get_strlist): New function
(hal_device_property_strlist_append): New function
(hal_device_property_strlist_prepend): New function
(hal_device_property_strlist_remove_elem): New function
(hal_device_property_strlist_add): New function
(hal_device_property_strlist_remove): New function
* hald/device.h: Add new strlist prototypes
* pstore.[ch]: Remove for now as persistent properties needs to be
reworked
Index: fstab-sync.c
===================================================================
RCS file: /cvs/hal/hal/tools/fstab-sync.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- fstab-sync.c 14 Dec 2004 02:57:48 -0000 1.28
+++ fstab-sync.c 31 Jan 2005 20:06:41 -0000 1.29
@@ -60,8 +60,8 @@
#define DBUS_API_SUBJECT_TO_CHANGE
-#include "libhal/libhal.h"
-#include "libhal-storage/libhal-storage.h"
+#include "../libhal/libhal.h"
+#include "../libhal-storage/libhal-storage.h"
typedef int boolean;
@@ -888,9 +888,11 @@
}
if (strcmp (block_device, buf) == 0) {
- /* update block.device with new value */
- fstab_update_debug (_("%d: Found %s pointing to %s in" _PATH_FSTAB), pid, field->value, buf);
- hal_device_set_property_string (hal_context, udi, "block.device", field->value);
+ DBusError error;
+ /* update block.device with new value */
+ fstab_update_debug (_("%d: Found %s pointing to %s in" _PATH_FSTAB), pid, field->value, buf);
+ dbus_error_init (&error);
+ libhal_device_set_property_string (hal_context, udi, "block.device", field->value, &error);
return TRUE;
}
@@ -1159,12 +1161,14 @@
/*fstab_update_debug (_("%d: drive=%x, volume=%x\n"), pid, drive, volume);*/
if (drive == NULL) {
char *udi_storage_device;
+ DBusError error;
/* try block.storage_device */
- udi_storage_device = hal_device_get_property_string (hal_context, udi, "block.storage_device");
+ dbus_error_init (&error);
+ udi_storage_device = libhal_device_get_property_string (hal_context, udi, "block.storage_device", &error);
if (udi_storage_device == NULL)
goto out;
drive = hal_drive_from_udi (hal_context, udi_storage_device);
- hal_free_string (udi_storage_device);
+ libhal_free_string (udi_storage_device);
if (drive == NULL)
goto out;
}
@@ -1323,6 +1327,7 @@
char *last_slash;
char *mount_point;
char *device_file;
+ DBusError error;
dir = strdup (_PATH_FSTAB);
last_slash = strrchr (dir, '/');
@@ -1370,14 +1375,15 @@
if (!create_mount_point_for_volume (mount_point))
goto error;
- device_file = hal_device_get_property_string (hal_context, udi, "block.device");
+ dbus_error_init (&error);
+ device_file = libhal_device_get_property_string (hal_context, udi, "block.device", &error);
fstab_update_debug (_("%d: added mount point '%s' for device '%s'\n"),
pid, mount_point, device_file);
syslog (LOG_INFO, _("added mount point %s for %s"),
mount_point, device_file);
- hal_free_string (device_file);
+ libhal_free_string (device_file);
close (fd);
@@ -1405,18 +1411,21 @@
boolean is_volume;
char *dir = NULL;
char *last_slash;
+ DBusError error;
- is_volume = hal_device_query_capability (hal_context, udi, "volume");
+ dbus_error_init (&error);
+
+ is_volume = libhal_device_query_capability (hal_context, udi, "volume", &error);
/* don't remove the fstab entry if we were spawned of a device with
* storage.no_partitions_hint set to TRUE. Per the spec this is
* exactly when block.no_partitions is TRUE on the volume. E.g.
* floppies and optical discs
*/
- if (is_volume && hal_device_get_property_bool (hal_context, udi, "block.no_partitions"))
+ if (is_volume && libhal_device_get_property_bool (hal_context, udi, "block.no_partitions", &error))
return FALSE;
- block_device = hal_device_get_property_string (hal_context, udi, "block.device");
+ block_device = libhal_device_get_property_string (hal_context, udi, "block.device", &error);
dir = strdup (_PATH_FSTAB);
last_slash = strrchr (dir, '/');
@@ -1653,6 +1662,8 @@
char *udi_to_add = NULL, *udi_to_remove = NULL, *hal_device_udi;
const char **left_over_args = NULL;
int lockfd = -1;
+ DBusError error;
+ DBusConnection *conn;
pid = getpid ();
@@ -1763,7 +1774,25 @@
}
}
- hal_context = hal_initialize (NULL, FALSE);
+ dbus_error_init (&error);
+ conn = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
+ if (conn == NULL) {
+ fprintf (stderr, "error: dbus_bus_get: %s: %s\n", error.name, error.message);
+ goto out;
+ }
+ if ((hal_context = libhal_ctx_new ()) == NULL) {
+ fprintf (stderr, "error: libhal_ctx_new\n");
+ goto out;
+ }
+ if (!libhal_ctx_set_dbus_connection (hal_context, conn)) {
+ fprintf (stderr, "error: libhal_ctx_set_dbus_connection: %s: %s\n", error.name, error.message);
+ goto out;
+ }
+ if (!libhal_ctx_init (hal_context, &error)) {
+ fprintf (stderr, "error: libhal_ctx_init: %s: %s\n", error.name, error.message);
+ goto out;
+ }
+
fsy_mount_root = hal_drive_policy_default_get_mount_root (hal_context);
if (fsy_mount_root == NULL)
goto out;
@@ -1787,7 +1816,8 @@
if (udi_to_remove)
retval |= !remove_udi (udi_to_remove);
- hal_shutdown (hal_context);
+ libhal_ctx_shutdown (hal_context, &error);
+ libhal_ctx_free (hal_context);
}
else if (should_clean)
retval = clean ();
Index: hal_get_property.c
===================================================================
RCS file: /cvs/hal/hal/tools/hal_get_property.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- hal_get_property.c 1 Sep 2004 17:38:59 -0000 1.7
+++ hal_get_property.c 31 Jan 2005 20:06:41 -0000 1.8
@@ -89,6 +89,7 @@
dbus_bool_t is_verbose = FALSE;
dbus_bool_t is_version = FALSE;
char *str;
+ DBusError error;
if (argc <= 1) {
usage (argc, argv);
@@ -151,51 +152,59 @@
return 1;
}
- if ((hal_ctx = hal_initialize (NULL, FALSE)) == NULL) {
- fprintf (stderr, "error: hal_initialize failed\n");
+ dbus_error_init (&error);
+ if ((hal_ctx = libhal_ctx_new ()) == NULL) {
+ fprintf (stderr, "error: libhal_ctx_new\n");
+ return 1;
+ }
+ if (!libhal_ctx_set_dbus_connection (hal_ctx, dbus_bus_get (DBUS_BUS_SYSTEM, &error))) {
+ fprintf (stderr, "error: libhal_ctx_set_dbus_connection: %s: %s\n", error.name, error.message);
+ return 1;
+ }
+ if (!libhal_ctx_init (hal_ctx, &error)) {
+ fprintf (stderr, "error: libhal_ctx_init: %s: %s\n", error.name, error.message);
return 1;
}
- type = hal_device_get_property_type (hal_ctx, udi, key);
+ type = libhal_device_get_property_type (hal_ctx, udi, key, &error);
if (type == DBUS_TYPE_NIL) {
+ fprintf (stderr, "error: libhal_device_get_property_type: %s: %s\n", error.name, error.message);
return 1;
}
- // emit the value to stdout
+ /* emit the value to stdout */
switch (type) {
case DBUS_TYPE_STRING:
- str = hal_device_get_property_string (hal_ctx, udi, key);
+ str = libhal_device_get_property_string (hal_ctx, udi, key, &error);
if (is_verbose)
printf ("Type is string\n");
printf ("%s\n", str);
- hal_free_string (str);
+ libhal_free_string (str);
break;
case DBUS_TYPE_INT32:
if (is_verbose)
printf ("Type is integer (shown in %s)\n",
(is_hex ? "hexadecimal" : "decimal"));
printf ((is_hex ? "%x\n" : "%d\n"),
- hal_device_get_property_int (hal_ctx, udi, key));
+ libhal_device_get_property_int (hal_ctx, udi, key, &error));
break;
case DBUS_TYPE_UINT64:
if (is_verbose)
printf ("Type is uint64 (shown in %s)\n",
(is_hex ? "hexadecimal" : "decimal"));
printf ((is_hex ? "%llx\n" : "%lld\n"),
- hal_device_get_property_uint64 (hal_ctx, udi, key));
+ libhal_device_get_property_uint64 (hal_ctx, udi, key, &error));
break;
case DBUS_TYPE_DOUBLE:
if (is_verbose)
printf ("Type is double\n");
printf ("%f\n",
- hal_device_get_property_double (hal_ctx, udi, key));
+ libhal_device_get_property_double (hal_ctx, udi, key, &error));
break;
case DBUS_TYPE_BOOLEAN:
if (is_verbose)
printf ("Type is boolean\n");
printf ("%s\n",
- hal_device_get_property_bool (hal_ctx, udi,
- key) ? "true" :
- "false");
+ libhal_device_get_property_bool (hal_ctx, udi, key, &error) ? "true" : "false");
break;
default:
@@ -204,6 +213,12 @@
break;
}
+ if (dbus_error_is_set (&error)) {
+ fprintf (stderr, "error: %s: %s\n", error.name, error.message);
+ return 1;
+ }
+
+
return 0;
}
Index: hal_set_property.c
===================================================================
RCS file: /cvs/hal/hal/tools/hal_set_property.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- hal_set_property.c 1 Sep 2004 17:38:59 -0000 1.7
+++ hal_set_property.c 31 Jan 2005 20:06:41 -0000 1.8
@@ -34,7 +34,7 @@
#include <unistd.h>
#include <getopt.h>
-#include <libhal/libhal.h>
+#include "libhal/libhal.h"
static LibHalContext *hal_ctx;
@@ -90,7 +90,7 @@
int
main (int argc, char *argv[])
{
- int rc = 0;
+ dbus_bool_t rc = 0;
char *udi = NULL;
char *key = NULL;
char *str_value = NULL;
@@ -101,6 +101,7 @@
dbus_bool_t remove = FALSE;
dbus_bool_t is_version = FALSE;
int type = DBUS_TYPE_NIL;
+ DBusError error;
if (argc <= 1) {
usage (argc, argv);
@@ -124,7 +125,7 @@
{"help", 0, NULL, 0},
{NULL, 0, NULL, 0}
};
-
+
c = getopt_long (argc, argv, "",
long_options, &option_index);
if (c == -1)
@@ -183,51 +184,58 @@
}
/* must have at least one, but not neither or both */
- if ((remove && type != DBUS_TYPE_NIL) ||
- ((!remove) && type == DBUS_TYPE_NIL)) {
+ if ((remove && type != DBUS_TYPE_NIL) || ((!remove) && type == DBUS_TYPE_NIL)) {
usage (argc, argv);
return 1;
}
-
+
fprintf (stderr, "\n");
-
- if ((hal_ctx = hal_initialize (NULL, FALSE)) == NULL) {
- fprintf (stderr, "error: hal_initialize failed\n");
+
+ dbus_error_init (&error);
+ if ((hal_ctx = libhal_ctx_new ()) == NULL) {
+ fprintf (stderr, "error: libhal_ctx_new\n");
+ return 1;
+ }
+ if (!libhal_ctx_set_dbus_connection (hal_ctx, dbus_bus_get (DBUS_BUS_SYSTEM, &error))) {
+ fprintf (stderr, "error: libhal_ctx_set_dbus_connection: %s: %s\n", error.name, error.message);
+ return 1;
+ }
+ if (!libhal_ctx_init (hal_ctx, &error)) {
+ fprintf (stderr, "error: libhal_ctx_init: %s: %s\n", error.name, error.message);
return 1;
}
if (remove) {
- rc = hal_device_remove_property (hal_ctx, udi, key);
- if (rc != 0)
+ rc = libhal_device_remove_property (hal_ctx, udi, key, &error);
+ if (rc != 0) {
+ fprintf (stderr, "error: libhal_device_remove_property: %s: %s\n", error.name, error.message);
return 1;
+ }
} else {
switch (type) {
case DBUS_TYPE_STRING:
- rc = hal_device_set_property_string (hal_ctx, udi, key,
- str_value);
+ rc = libhal_device_set_property_string (hal_ctx, udi, key, str_value, &error);
break;
case DBUS_TYPE_INT32:
- rc = hal_device_set_property_int (hal_ctx, udi, key,
- int_value);
+ rc = libhal_device_set_property_int (hal_ctx, udi, key, int_value, &error);
break;
case DBUS_TYPE_UINT64:
- rc = hal_device_set_property_uint64 (hal_ctx, udi, key,
- uint64_value);
+ rc = libhal_device_set_property_uint64 (hal_ctx, udi, key, uint64_value, &error);
break;
case DBUS_TYPE_DOUBLE:
- rc = hal_device_set_property_double (hal_ctx, udi, key,
- double_value);
+ rc = libhal_device_set_property_double (hal_ctx, udi, key, double_value, &error);
break;
case DBUS_TYPE_BOOLEAN:
- rc = hal_device_set_property_bool (hal_ctx, udi, key,
- bool_value);
+ rc = libhal_device_set_property_bool (hal_ctx, udi, key, bool_value, &error);
break;
}
- if (rc != 0)
+ if (!rc) {
+ fprintf (stderr, "error: libhal_device_set_property: %s: %s\n", error.name, error.message);
return 1;
+ }
}
-
- return 0;
+
+ return rc ? 0 : 1;
}
/**
Index: lshal.c
===================================================================
RCS file: /cvs/hal/hal/tools/lshal.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- lshal.c 14 Oct 2004 19:16:30 -0000 1.9
+++ lshal.c 31 Jan 2005 20:06:42 -0000 1.10
@@ -64,9 +64,11 @@
int i;
int num_devices;
char **device_names;
+ DBusError error;
- device_names = hal_get_all_devices (hal_ctx, &num_devices);
+ dbus_error_init (&error);
+ device_names = libhal_get_all_devices (hal_ctx, &num_devices, &error);
if (device_names == NULL)
DIE (("Couldn't obtain list of devices\n"));
@@ -80,8 +82,7 @@
LibHalPropertySetIterator it;
int type;
- props = hal_device_get_all_properties (hal_ctx,
- device_names[i]);
+ props = libhal_device_get_all_properties (hal_ctx, device_names[i], &error);
/* NOTE NOTE NOTE: This may be NULL if the device was removed
* in the daemon; this is because
@@ -94,49 +95,69 @@
printf ("udi = '%s'\n", device_names[i]);
- for (hal_psi_init (&it, props); hal_psi_has_more (&it);
- hal_psi_next (&it)) {
- type = hal_psi_get_type (&it);
+ for (libhal_psi_init (&it, props); libhal_psi_has_more (&it); libhal_psi_next (&it)) {
+ type = libhal_psi_get_type (&it);
switch (type) {
- case DBUS_TYPE_STRING:
+ case LIBHAL_PROPERTY_TYPE_STRING:
printf (" %s = '%s' (string)\n",
- hal_psi_get_key (&it),
- hal_psi_get_string (&it));
+ libhal_psi_get_key (&it),
+ libhal_psi_get_string (&it));
break;
- case DBUS_TYPE_INT32:
+ case LIBHAL_PROPERTY_TYPE_INT32:
printf (" %s = %d (0x%x) (int)\n",
- hal_psi_get_key (&it),
- hal_psi_get_int (&it),
- hal_psi_get_int (&it));
+ libhal_psi_get_key (&it),
+ libhal_psi_get_int (&it),
+ libhal_psi_get_int (&it));
break;
- case DBUS_TYPE_UINT64:
+ case LIBHAL_PROPERTY_TYPE_UINT64:
printf (" %s = %lld (0x%llx) (uint64)\n",
- hal_psi_get_key (&it),
- hal_psi_get_uint64 (&it),
- hal_psi_get_uint64 (&it));
+ libhal_psi_get_key (&it),
+ libhal_psi_get_uint64 (&it),
+ libhal_psi_get_uint64 (&it));
break;
- case DBUS_TYPE_DOUBLE:
+ case LIBHAL_PROPERTY_TYPE_DOUBLE:
printf (" %s = %g (double)\n",
- hal_psi_get_key (&it),
- hal_psi_get_double (&it));
+ libhal_psi_get_key (&it),
+ libhal_psi_get_double (&it));
break;
- case DBUS_TYPE_BOOLEAN:
+ case LIBHAL_PROPERTY_TYPE_BOOLEAN:
printf (" %s = %s (bool)\n",
- hal_psi_get_key (&it),
- hal_psi_get_bool (&it) ? "true" :
+ libhal_psi_get_key (&it),
+ libhal_psi_get_bool (&it) ? "true" :
"false");
break;
+
+ case LIBHAL_PROPERTY_TYPE_STRLIST:
+ {
+ unsigned int i;
+ char **strlist;
+
+ printf (" %s = {", libhal_psi_get_key (&it));
+
+ strlist = libhal_psi_get_strlist (&it);
+ for (i = 0; strlist[i] != 0; i++) {
+ printf ("'%s'", strlist[i]);
+ if (strlist[i+1] != NULL)
+ printf (", ");
+ }
+ printf ("} (string list)\n");
+ break;
+ }
+
+ default:
+ printf ("Unknown type %d=0x%02x\n", type, type);
+ break;
}
}
- hal_free_property_set (props);
+ libhal_free_property_set (props);
printf ("\n");
}
- hal_free_string_array (device_names);
+ libhal_free_string_array (device_names);
printf ("\n"
"Dumped %d device(s) from the Global Device List:\n"
@@ -156,7 +177,7 @@
const char *udi)
{
fprintf (stderr, "*** lshal: device_added, udi='%s'\n", udi);
- dump_devices ();
+ /*dump_devices ();*/
}
/** Invoked when a device is removed from the Global Device List. Simply
@@ -169,7 +190,7 @@
const char *udi)
{
fprintf (stderr, "*** lshal: device_removed, udi='%s'\n", udi);
- dump_devices ();
+ /*dump_devices ();*/
}
/** Invoked when device in the Global Device List acquires a new capability.
@@ -204,7 +225,6 @@
/*dump_devices(); */
}
-
/** Acquires and prints the value of of a property to stderr.
*
* @param udi Universal Device Id
@@ -215,43 +235,59 @@
{
int type;
char *str;
+ DBusError error;
- type = hal_device_get_property_type (hal_ctx, udi, key);
+ dbus_error_init (&error);
+
+ type = libhal_device_get_property_type (hal_ctx, udi, key, &error);
switch (type) {
- case DBUS_TYPE_STRING:
- str = hal_device_get_property_string (hal_ctx, udi, key);
+ case LIBHAL_PROPERTY_TYPE_STRING:
+ str = libhal_device_get_property_string (hal_ctx, udi, key, &error);
fprintf (stderr, "*** new value: '%s' (string)\n", str);
- hal_free_string (str);
+ libhal_free_string (str);
break;
- case DBUS_TYPE_INT32:
+ case LIBHAL_PROPERTY_TYPE_INT32:
{
- dbus_int32_t value =
- hal_device_get_property_int (hal_ctx, udi, key);
+ dbus_int32_t value = libhal_device_get_property_int (hal_ctx, udi, key, &error);
fprintf (stderr,
"*** new value: %d (0x%x) (int)\n",
value, value);
}
break;
- case DBUS_TYPE_UINT64:
+ case LIBHAL_PROPERTY_TYPE_UINT64:
{
- dbus_uint64_t value =
- hal_device_get_property_uint64 (hal_ctx, udi, key);
+ dbus_uint64_t value = libhal_device_get_property_uint64 (hal_ctx, udi, key, &error);
fprintf (stderr,
"*** new value: %lld (0x%llx) (uint64)\n",
value, value);
}
break;
- case DBUS_TYPE_DOUBLE:
+ case LIBHAL_PROPERTY_TYPE_DOUBLE:
fprintf (stderr, "*** new value: %g (double)\n",
- hal_device_get_property_double (hal_ctx, udi, key));
+ libhal_device_get_property_double (hal_ctx, udi, key, &error));
break;
- case DBUS_TYPE_BOOLEAN:
+ case LIBHAL_PROPERTY_TYPE_BOOLEAN:
fprintf (stderr, "*** new value: %s (bool)\n",
- hal_device_get_property_bool (hal_ctx, udi,
- key) ? "true" :
- "false");
+ libhal_device_get_property_bool (hal_ctx, udi, key, &error) ? "true" : "false");
break;
+ case LIBHAL_PROPERTY_TYPE_STRLIST:
+ {
+ unsigned int i;
+ char **strlist;
+
+ fprintf (stderr, "*** new value: {");
+
+ strlist = libhal_device_get_property_strlist (hal_ctx, udi, key, &error);
+ for (i = 0; strlist[i] != 0; i++) {
+ fprintf (stderr, "'%s'", strlist[i]);
+ if (strlist[i+1] != NULL)
+ fprintf (stderr, ", ");
+ }
+ fprintf (stderr, "} (string list)\n");
+ libhal_free_string_array (strlist);
+ break;
+ }
default:
fprintf (stderr, "Unknown type %d='%c'\n", type, type);
@@ -305,17 +341,6 @@
}
-/** Invoked by libhal for integration with our mainloop. We take the
- * easy route and use link with glib for painless integrate.
- *
- * @param dbus_connection D-BUS connection to integrate
- */
-static void
-mainloop_integration (LibHalContext *ctx, DBusConnection * dbus_connection)
-{
- dbus_connection_setup_with_g_main (dbus_connection, NULL);
-}
-
/** Print out program usage.
*
@@ -345,16 +370,10 @@
int
main (int argc, char *argv[])
{
+ DBusError error;
dbus_bool_t do_monitor = FALSE;
GMainLoop *loop;
- LibHalFunctions hal_functions = { mainloop_integration,
- device_added,
- device_removed,
- device_new_capability,
- device_lost_capability,
- property_modified,
- device_condition
- };
+ DBusConnection *conn;
fprintf (stderr, "lshal version " PACKAGE_VERSION "\n");
@@ -394,25 +413,47 @@
}
}
+ dbus_error_init (&error);
+ conn = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
+ if (conn == NULL) {
+ fprintf (stderr, "error: dbus_bus_get: %s: %s\n", error.name, error.message);
+ return 1;
+ }
+ dbus_connection_setup_with_g_main (conn, NULL);
- if ((hal_ctx = hal_initialize (&hal_functions, FALSE)) == NULL) {
- fprintf (stderr, "error: hal_initialize failed\n");
- exit (1);
+ if ((hal_ctx = libhal_ctx_new ()) == NULL) {
+ fprintf (stderr, "error: libhal_ctx_new\n");
+ return 1;
+ }
+ if (!libhal_ctx_set_dbus_connection (hal_ctx, conn)) {
+ fprintf (stderr, "error: libhal_ctx_set_dbus_connection: %s: %s\n", error.name, error.message);
+ return 1;
}
+ if (!libhal_ctx_init (hal_ctx, &error)) {
+ fprintf (stderr, "error: libhal_ctx_init: %s: %s\n", error.name, error.message);
+ return 1;
+ }
+
+ libhal_ctx_set_device_added (hal_ctx, device_added);
+ libhal_ctx_set_device_removed (hal_ctx, device_removed);
+ libhal_ctx_set_device_new_capability (hal_ctx, device_new_capability);
+ libhal_ctx_set_device_lost_capability (hal_ctx, device_lost_capability);
+ libhal_ctx_set_device_property_modified (hal_ctx, property_modified);
+ libhal_ctx_set_device_condition (hal_ctx, device_condition);
dump_devices ();
/* run the main loop only if we should monitor */
if (do_monitor) {
- hal_device_property_watch_all (hal_ctx);
+ libhal_device_property_watch_all (hal_ctx, &error);
g_main_loop_run (loop);
}
- hal_shutdown (hal_ctx);
+ libhal_ctx_shutdown (hal_ctx, &error);
+ libhal_ctx_free (hal_ctx);
return 0;
}
-
/**
* @}
*/
More information about the hal-commit
mailing list