hal/hald Makefile.am, 1.26, 1.27 device.c, 1.6, 1.7 device.h, 1.5,
1.6 hald.c, 1.8, 1.9 hald.conf, 1.2, 1.3 hald.h, 1.4,
1.5 hald_conf.c, 1.3, 1.4 hald_conf.h, 1.2, 1.3 hald_dbus.c,
1.5, 1.6 property.c, 1.3, 1.4 property.h, 1.3, 1.4
David Zeuthen
david at pdx.freedesktop.org
Sun Jun 20 06:27:56 PDT 2004
Update of /cvs/hal/hal/hald
In directory pdx:/tmp/cvs-serv21894/hald
Modified Files:
Makefile.am device.c device.h hald.c hald.conf hald.h
hald_conf.c hald_conf.h hald_dbus.c property.c property.h
Log Message:
2004-06-20 David Zeuthen <david at fubar.dk>
* hald/Makefile.am (install-data-local): Create
$(LOCALSTATEDIR)/lib/hal
* hald/linux/common.c (rename_and_merge): Check
persistent_device_list configuration value
* hald/device.c (hal_device_property_set_attribute)
(hal_device_property_set_string, hal_device_property_set_bool)
(hal_device_property_set_double, hal_device_property_remove):
Check persistent_device_list configuration value
* hald/hald.c (main): Check persistent_device_list configuration
value
* hald/hald.conf: Add persistent_device_list tag, set to false
as default
* hald/hald_conf.h: Add persistent_device_list member
* hald/hald_conf.c (hald_conf): Add persistent_device_list member
(end): Check for persistent_device_list tag
* hald/property.h: Rename property_attribute to PropertyAttribute
2004-06-20 David Zeuthen <david at fubar.dk>
Patch from Kay Sievers <kay.sievers at vrfy.org>
* hald/pstore.[ch]: New files
* hald/linux/common.c (rename_and_merge): Load a device from disk
* hald/property.h: Add property_attribute enum and
hal_property_get_attribute(), hal_property_set_attribute()
* hald/property.c: Add readonly, persistence, callout bools to
HalProperty
(hal_property_set_attribute): New function
(hal_property_get_attribute): New function
* hald/hald_dbus.c (device_set_property): Set property to persistent
* hald/hald.h: Add hald_get_pstore_sys
* hald/hald.c (hald_get_pstore_sys): New function
(main): Load persistent store
* hald/device.h: Add hal_device_property_set_attribute()
* hald/device.c (hal_device_property_set_string):
(hal_device_property_set_int, hal_device_property_set_bool)
(hal_device_property_set_double): Save property to disk if the
PERSISTENCE attribute is set
(hal_device_property_remove): Delete property from disk if the
PERSISTENCE attribyte is set
(hal_device_property_set_attribute): New function
* hald/Makefile.am (INCLUDES): Add PACKAGE_LOCALSTATEDIR
(hald_SOURCES): add pstore.[ch]
Index: Makefile.am
===================================================================
RCS file: /cvs/hal/hal/hald/Makefile.am,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- Makefile.am 1 Jun 2004 21:10:02 -0000 1.26
+++ Makefile.am 20 Jun 2004 13:27:45 -0000 1.27
@@ -5,6 +5,7 @@
-DPACKAGE_DATA_DIR=\""$(datadir)"\" \
-DPACKAGE_BIN_DIR=\""$(bindir)"\" \
-DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\" \
+ -DPACKAGE_LOCALSTATEDIR=\""$(localstatedir)"\" \
-I$(top_srcdir) \
@PACKAGE_CFLAGS@
@@ -25,6 +26,7 @@
logger.h logger.c \
osspec.h \
property.h property.c \
+ pstore.h pstore.c \
hald_conf.h hald_conf.c
hald_SOURCES += \
@@ -111,4 +113,5 @@
$(mkinstalldirs) $(DESTDIR)$(SYSCONFDIR)/hal/device.d
$(mkinstalldirs) $(DESTDIR)$(SYSCONFDIR)/hal/capability.d
$(mkinstalldirs) $(DESTDIR)$(SYSCONFDIR)/hal/property.d
+ $(mkinstalldirs) $(DESTDIR)$(LOCALSTATEDIR)/lib/hal
Index: device.c
===================================================================
RCS file: /cvs/hal/hal/hald/device.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- device.c 26 Apr 2004 20:08:58 -0000 1.6
+++ device.c 20 Jun 2004 13:27:45 -0000 1.7
@@ -31,9 +31,12 @@
#include <stdio.h>
#include <string.h>
+#include "hald.h"
#include "device.h"
+#include "pstore.h"
#include "hald_marshal.h"
#include "logger.h"
+#include "hald_conf.h"
static GObjectClass *parent_class;
@@ -603,15 +606,21 @@
g_signal_emit (device, signals[PROPERTY_CHANGED], 0,
key, FALSE, FALSE);
- return TRUE;
- }
+ if (hal_property_get_attribute (prop, PERSISTENCE) &&
+ hald_get_conf ()->persistent_device_list) {
+ hal_pstore_save_property (hald_get_pstore_sys (),
+ device, prop);
+ }
- prop = hal_property_new_string (key, value);
+ } else {
- device->properties = g_slist_prepend (device->properties, prop);
+ prop = hal_property_new_string (key, value);
- g_signal_emit (device, signals[PROPERTY_CHANGED], 0,
- key, FALSE, TRUE);
+ device->properties = g_slist_prepend (device->properties, prop);
+
+ g_signal_emit (device, signals[PROPERTY_CHANGED], 0,
+ key, FALSE, TRUE);
+ }
return TRUE;
}
@@ -638,15 +647,20 @@
g_signal_emit (device, signals[PROPERTY_CHANGED], 0,
key, FALSE, FALSE);
- return TRUE;
- }
+ if (hal_property_get_attribute (prop, PERSISTENCE) &&
+ hald_get_conf ()->persistent_device_list) {
+ hal_pstore_save_property (hald_get_pstore_sys (),
+ device, prop);
+ }
- prop = hal_property_new_int (key, value);
+ } else {
+ prop = hal_property_new_int (key, value);
- device->properties = g_slist_prepend (device->properties, prop);
+ device->properties = g_slist_prepend (device->properties, prop);
- g_signal_emit (device, signals[PROPERTY_CHANGED], 0,
- key, FALSE, TRUE);
+ g_signal_emit (device, signals[PROPERTY_CHANGED], 0,
+ key, FALSE, TRUE);
+ }
return TRUE;
}
@@ -673,15 +687,20 @@
g_signal_emit (device, signals[PROPERTY_CHANGED], 0,
key, FALSE, FALSE);
- return TRUE;
- }
+ if (hal_property_get_attribute (prop, PERSISTENCE) &&
+ hald_get_conf ()->persistent_device_list) {
+ hal_pstore_save_property (hald_get_pstore_sys (),
+ device, prop);
+ }
- prop = hal_property_new_bool (key, value);
+ } else {
+ prop = hal_property_new_bool (key, value);
- device->properties = g_slist_prepend (device->properties, prop);
+ device->properties = g_slist_prepend (device->properties, prop);
- g_signal_emit (device, signals[PROPERTY_CHANGED], 0,
- key, FALSE, TRUE);
+ g_signal_emit (device, signals[PROPERTY_CHANGED], 0,
+ key, FALSE, TRUE);
+ }
return TRUE;
}
@@ -708,15 +727,20 @@
g_signal_emit (device, signals[PROPERTY_CHANGED], 0,
key, FALSE, FALSE);
- return TRUE;
- }
+ if (hal_property_get_attribute (prop, PERSISTENCE) &&
+ hald_get_conf ()->persistent_device_list) {
+ hal_pstore_save_property (hald_get_pstore_sys (),
+ device, prop);
+ }
- prop = hal_property_new_double (key, value);
+ } else {
+ prop = hal_property_new_double (key, value);
- device->properties = g_slist_prepend (device->properties, prop);
+ device->properties = g_slist_prepend (device->properties, prop);
- g_signal_emit (device, signals[PROPERTY_CHANGED], 0,
- key, FALSE, TRUE);
+ g_signal_emit (device, signals[PROPERTY_CHANGED], 0,
+ key, FALSE, TRUE);
+ }
return TRUE;
}
@@ -731,6 +755,12 @@
if (prop == NULL)
return FALSE;
+ if (hal_property_get_attribute (prop, PERSISTENCE) &&
+ hald_get_conf ()->persistent_device_list) {
+ hal_pstore_delete_property (hald_get_pstore_sys (),
+ device, prop);
+ }
+
device->properties = g_slist_remove (device->properties, prop);
hal_property_free (prop);
@@ -741,6 +771,36 @@
return TRUE;
}
+gboolean
+hal_device_property_set_attribute (HalDevice *device,
+ const char *key,
+ enum PropertyAttribute attr,
+ gboolean val)
+{
+ HalProperty *prop;
+
+ prop = hal_device_property_find (device, key);
+
+ if (prop == NULL)
+ return FALSE;
+
+ hal_property_set_attribute (prop, PERSISTENCE, val);
+
+ if (attr == PERSISTENCE &&
+ hald_get_conf ()->persistent_device_list) {
+ /* Save property to disk, or delete it */
+ if (val) {
+ hal_pstore_save_property (hald_get_pstore_sys (),
+ device, prop);
+ } else {
+ hal_pstore_delete_property (hald_get_pstore_sys (),
+ device, prop);
+ }
+ }
+
+ return TRUE;
+}
+
void
hal_device_print (HalDevice *device)
{
Index: device.h
===================================================================
RCS file: /cvs/hal/hal/hald/device.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- device.h 26 Apr 2004 20:08:58 -0000 1.5
+++ device.h 20 Jun 2004 13:27:45 -0000 1.6
@@ -150,4 +150,9 @@
void hal_device_callouts_finished (HalDevice *device);
+gboolean hal_device_property_set_attribute (HalDevice *device,
+ const char *key,
+ enum PropertyAttribute attr,
+ gboolean persistence);
+
#endif /* DEVICE_H */
Index: hald.c
===================================================================
RCS file: /cvs/hal/hal/hald/hald.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- hald.c 1 Jun 2004 21:10:02 -0000 1.8
+++ hald.c 20 Jun 2004 13:27:45 -0000 1.9
@@ -46,6 +46,7 @@
#include "logger.h"
#include "hald.h"
#include "device_store.h"
+#include "pstore.h"
#include "device_info.h"
#include "osspec.h"
#include "hald_dbus.h"
@@ -61,6 +62,8 @@
static HalDeviceStore *temporary_device_list = NULL;
+static HalPStore *pstore_sys = NULL;
+
static void
gdl_store_changed (HalDeviceStore *store, HalDevice *device,
gboolean is_added, gpointer user_data)
@@ -131,6 +134,16 @@
return temporary_device_list;
}
+HalPStore *
+hald_get_pstore_sys (void)
+{
+ if (pstore_sys == NULL)
+ pstore_sys = hal_pstore_open (PACKAGE_LOCALSTATEDIR
+ "/lib/hal");
+
+ return pstore_sys;
+}
+
/**
* @defgroup MainDaemon Basic functions
* @ingroup HalDaemon
@@ -273,6 +286,10 @@
loop = g_main_loop_new (NULL, FALSE);
+ /* initialize persitent property store, read uuid from path */
+ if (hald_get_conf ()->persistent_device_list)
+ hal_pstore_init (PACKAGE_LOCALSTATEDIR "/lib/hal/uuid");
+
/* initialize operating system specific parts */
osspec_init (dbus_connection);
/* and detect devices */
Index: hald.conf
===================================================================
RCS file: /cvs/hal/hal/hald/hald.conf,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- hald.conf 1 Jun 2004 21:30:01 -0000 1.2
+++ hald.conf 20 Jun 2004 13:27:45 -0000 1.3
@@ -7,6 +7,11 @@
<haldconfig>
+ <!-- If true, then the device list is saved to disk such that
+ properties are kept between invocations of hald.
+ -->
+ <persistent_device_list>false</persistent_device_list>
+
<!-- Default value for storage.media_check_enabled for devices of
capability storage - this can be overridden by .fdi files.
Index: hald.h
===================================================================
RCS file: /cvs/hal/hal/hald/hald.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- hald.h 3 Apr 2004 07:46:33 -0000 1.4
+++ hald.h 20 Jun 2004 13:27:45 -0000 1.5
@@ -31,6 +31,7 @@
#include <dbus/dbus.h>
#include "device_store.h"
+#include "pstore.h"
/**
* @addtogroup HalDaemon
@@ -40,6 +41,7 @@
HalDeviceStore *hald_get_gdl (void);
HalDeviceStore *hald_get_tdl (void);
+HalPStore *hald_get_pstore_sys (void);
void property_atomic_update_begin ();
void property_atomic_update_end ();
Index: hald_conf.c
===================================================================
RCS file: /cvs/hal/hal/hald/hald_conf.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- hald_conf.c 7 Jun 2004 17:59:35 -0000 1.3
+++ hald_conf.c 20 Jun 2004 13:27:45 -0000 1.4
@@ -39,10 +39,12 @@
#define HALD_CONF_FILE PACKAGE_SYSCONF_DIR "/hal/hald.conf"
+/* default values */
static HaldConf hald_conf = {
- TRUE, /* storage.media_check_enabled */
- TRUE, /* storage.automount_enabled */
- TRUE /* storage.cdrom.eject_check_enabled */
+ TRUE, /* storage.media_check_enabled */
+ TRUE, /* storage.automount_enabled */
+ TRUE, /* storage.cdrom.eject_check_enabled */
+ FALSE /* persistent_device_list */
};
HaldConf *
@@ -114,8 +116,12 @@
} else if ((strcmp (key, "storage_cdrom_eject_check_enabled") == 0) &&
(strcmp (value, "false") == 0)) {
hald_conf.storage_cdrom_eject_check_enabled = FALSE;
+ } else if ((strcmp (key, "persistent_device_list") == 0) &&
+ (strcmp (value, "true") == 0)) {
+ hald_conf.persistent_device_list = TRUE;
}
+
pc->elem[0] = '\0';
pc->cdata_buf[0] = '\0';
pc->cdata_buf_len = 0;
Index: hald_conf.h
===================================================================
RCS file: /cvs/hal/hal/hald/hald_conf.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- hald_conf.h 1 Jun 2004 21:10:02 -0000 1.2
+++ hald_conf.h 20 Jun 2004 13:27:45 -0000 1.3
@@ -83,6 +83,11 @@
* Default value is TRUE, this may be overridden in hald.conf.
*/
dbus_bool_t storage_cdrom_eject_check_enabled;
+
+ /** If true, then the device list is saved to disk such that
+ * properties are kept between invocations of hald.
+ */
+ dbus_bool_t persistent_device_list;
};
HaldConf *hald_get_conf (void);
Index: hald_dbus.c
===================================================================
RCS file: /cvs/hal/hal/hald/hald_dbus.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- hald_dbus.c 4 May 2004 16:05:35 -0000 1.5
+++ hald_dbus.c 20 Jun 2004 13:27:45 -0000 1.6
@@ -872,6 +872,7 @@
type = dbus_message_iter_get_arg_type (&iter);
rc = FALSE;
+
switch (type) {
case DBUS_TYPE_STRING:
rc = hal_device_property_set_string (device, key,
@@ -899,6 +900,11 @@
break;
}
+ /* FIXME: temporary pstore test only */
+ hal_device_property_set_attribute (device, key, PERSISTENCE, TRUE);
+ HAL_WARNING (("FIXME: persistence set for all D-BUS props; "
+ "udi=%s, key=%s", udi, key));
+
if (!rc) {
raise_property_type_error (connection, message, udi, key);
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
Index: property.c
===================================================================
RCS file: /cvs/hal/hal/hald/property.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- property.c 20 Apr 2004 20:54:15 -0000 1.3
+++ property.c 20 Jun 2004 13:27:45 -0000 1.4
@@ -42,13 +42,16 @@
dbus_bool_t bool_value;
double double_value;
};
+ gboolean readonly;
+ gboolean persistence;
+ gboolean callout;
};
void
hal_property_free (HalProperty *prop)
{
g_free (prop->key);
-
+
if (prop->type == DBUS_TYPE_STRING)
g_free (prop->str_value);
@@ -226,3 +229,41 @@
prop->type = DBUS_TYPE_DOUBLE;
prop->double_value = value;
}
+
+void
+hal_property_set_attribute (HalProperty *prop,
+ enum PropertyAttribute attr,
+ gboolean val)
+{
+ g_return_if_fail (prop != NULL);
+
+ switch (attr) {
+ case READONLY:
+ prop->readonly = val;
+ break;
+ case PERSISTENCE:
+ prop->persistence = val;
+ break;
+ case CALLOUT:
+ prop->callout = val;
+ break;
+ }
+}
+
+gboolean
+hal_property_get_attribute (HalProperty *prop,
+ enum PropertyAttribute attr)
+{
+ g_return_val_if_fail (prop != NULL, -1);
+
+ switch (attr) {
+ case READONLY:
+ return prop->readonly;
+ case PERSISTENCE:
+ return prop->persistence;
+ case CALLOUT:
+ return prop->callout;
+ default:
+ return -1;
+ }
+}
Index: property.h
===================================================================
RCS file: /cvs/hal/hal/hald/property.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- property.h 20 Apr 2004 20:54:15 -0000 1.3
+++ property.h 20 Jun 2004 13:27:45 -0000 1.4
@@ -31,6 +31,12 @@
typedef struct _HalProperty HalProperty;
+enum PropertyAttribute {
+ READONLY,
+ PERSISTENCE,
+ CALLOUT
+};
+
void hal_property_free (HalProperty *prop);
HalProperty *hal_property_new_string (const char *key,
@@ -59,5 +65,10 @@
dbus_bool_t value);
void hal_property_set_double (HalProperty *prop,
double value);
+void hal_property_set_attribute (HalProperty *prop,
+ enum PropertyAttribute attr,
+ gboolean val);
+gboolean hal_property_get_attribute (HalProperty *prop,
+ enum PropertyAttribute attr);
#endif /* PROPERTY_H */
More information about the hal-commit
mailing list