hal: Branch 'master'
David Zeuthen
david at kemper.freedesktop.org
Wed May 2 18:51:30 PDT 2007
doc/spec/hal-spec-fdi-files.xml | 29 ++++++++++++++++++-----------
fdi/fdi.dtd | 8 +++++++-
hald/create_cache.c | 3 +++
hald/device_info.c | 14 ++++++++++++++
hald/rule.h | 1 +
5 files changed, 43 insertions(+), 12 deletions(-)
New commits:
diff-tree 6a3d21ee7d309c8107098e175f8d15f8ea191684 (from b023f793ea9791acdda64fbab5b3536deb793454)
Author: David Zeuthen <davidz at redhat.com>
Date: Wed May 2 21:51:32 2007 -0400
introduce new <addset> operator
This appends a value to a strlist if, and only if, it doesn't exist already.
diff --git a/doc/spec/hal-spec-fdi-files.xml b/doc/spec/hal-spec-fdi-files.xml
index 9739a21..60cfb70 100644
--- a/doc/spec/hal-spec-fdi-files.xml
+++ b/doc/spec/hal-spec-fdi-files.xml
@@ -24,7 +24,7 @@
directives
that is tested against the properties of the device object. If
all the match directives passes then the device information can
- include <literal><[merge|append|prepend] key="some_property"
+ include <literal><[merge|append|prepend|addset] key="some_property"
type="[string|int|bool|..]">
</literal>
directives to
@@ -35,12 +35,14 @@
</para>
<para>
The <literal><match></literal>,
- <literal><merge></literal>, <literal><append></literal>
- and <literal><prepend></literal> directives always requires
- the <literal>key</literal> attribute which must be either a
- property name on the device object in question or a path to a
- property on another device object. The latter case is expressed
- either through direct specification of the UDI, such as
+ <literal><merge></literal>, <literal><append></literal>,
+ <literal><prepend></literal>
+ and <literal><addset></literal> directives always
+ requires the <literal>key</literal> attribute which must be
+ either a property name on the device object in question or a
+ path to a property on another device object. The latter case is
+ expressed either through direct specification of the UDI, such
+ as
<literal>/org/freedesktop/Hal/devices/computer:foo.bar</literal>
or indirect references such as
<literal>@info.parent:baz</literal> where the latter means that
@@ -209,8 +211,9 @@
<title>Merging</title>
<para>
- The <literal><merge></literal>, <literal><append></literal>
- and <literal><prepend></literal> directives all require
+ The <literal><merge></literal>, <literal><append></literal>,
+ <literal><prepend></literal>
+ and <literal><addset></literal> directives all require
the <literal>type</literal> attribute which specifies what to
merge. The following values are supported
<itemizedlist>
@@ -225,8 +228,12 @@
<para>
<literal>strlist</literal> - For <literal><merge></literal> the value is
copied to the property and the current property will be overwritten. For
- <literal><append></literal> and <literal><prepend></literal> the
- value is append or prepend to the list as new item. Usage of
+ <literal><append></literal>
+ and <literal><prepend></literal> the value is
+ append or prepend to the list as new
+ item. For <literal><addset></literal> the strlist
+ is treated as a set and the value is appended if, and only
+ if, the value doesn't exist already. Usage of
<literal><copy_property></literal> overwrite the complete list with the
value of the given property to copy from.
</para>
diff --git a/fdi/fdi.dtd b/fdi/fdi.dtd
index 6084bb1..7adb36c 100644
--- a/fdi/fdi.dtd
+++ b/fdi/fdi.dtd
@@ -8,7 +8,7 @@
<!ELEMENT device (match|merge)* >
-<!ELEMENT match (match|merge|prepend|append|remove|spawn)* >
+<!ELEMENT match (match|merge|prepend|append|addset|remove|spawn)* >
<!ATTLIST match
key CDATA #REQUIRED
string CDATA #IMPLIED
@@ -51,6 +51,12 @@
type (string|strlist|int|bool|double|copy_property) #REQUIRED
>
+<!ELEMENT addset (#PCDATA) >
+<!ATTLIST addset
+ key CDATA #REQUIRED
+ type (string|strlist|int|bool|double|copy_property) #REQUIRED
+>
+
<!ELEMENT remove (#PCDATA) >
<!ATTLIST remove
key CDATA #REQUIRED
diff --git a/hald/create_cache.c b/hald/create_cache.c
index 35b4a46..ab7b724 100644
--- a/hald/create_cache.c
+++ b/hald/create_cache.c
@@ -82,6 +82,8 @@ get_rule_type (const char *str)
return RULE_APPEND;
if (strcmp (str, "prepend") == 0)
return RULE_PREPEND;
+ if (strcmp (str, "addset") == 0)
+ return RULE_ADDSET;
if (strcmp (str, "remove") == 0)
return RULE_REMOVE;
if (strcmp (str, "clear") == 0)
@@ -401,6 +403,7 @@ cdata (void *data, const char *s, int le
if (fdi_ctx->rule.rtype != RULE_MERGE &&
fdi_ctx->rule.rtype != RULE_PREPEND &&
+ fdi_ctx->rule.rtype != RULE_ADDSET &&
fdi_ctx->rule.rtype != RULE_APPEND &&
fdi_ctx->rule.rtype != RULE_REMOVE &&
fdi_ctx->rule.rtype != RULE_SPAWN)
diff --git a/hald/device_info.c b/hald/device_info.c
index d1a73c1..46aa88e 100644
--- a/hald/device_info.c
+++ b/hald/device_info.c
@@ -871,6 +871,19 @@ handle_merge (struct rule *rule, HalDevi
hal_device_property_set_string (d, key, buf2);
}
+ } else if (rule->rtype == RULE_ADDSET) {
+
+ if (hal_device_property_get_type (d, key) != HAL_PROPERTY_TYPE_STRLIST &&
+ hal_device_property_get_type (d, key) != HAL_PROPERTY_TYPE_INVALID) {
+ HAL_ERROR (("invalid key type"));
+ return FALSE;
+ }
+
+ if (!hal_device_has_property (d, key) ||
+ !hal_device_property_strlist_contains (d, key, value)) {
+ hal_device_property_strlist_append (d, key, value);
+ }
+
} else if (rule->rtype == RULE_REMOVE) {
if (rule->type_merge == MERGE_STRLIST) {
@@ -967,6 +980,7 @@ rules_match_and_merge_device (void *fdi_
case RULE_APPEND:
case RULE_PREPEND:
+ case RULE_ADDSET:
case RULE_REMOVE:
case RULE_CLEAR:
case RULE_SPAWN:
diff --git a/hald/rule.h b/hald/rule.h
index 971c5f6..5885ebb 100644
--- a/hald/rule.h
+++ b/hald/rule.h
@@ -41,6 +41,7 @@ typedef enum {
RULE_CLEAR,
RULE_SPAWN,
RULE_EOF,
+ RULE_ADDSET
} rule_type;
/* type of merge command */
More information about the hal-commit
mailing list