hal: Branch 'hal-0_5_9-branch'

David Zeuthen david at kemper.freedesktop.org
Wed May 2 18:51:50 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 73306179e3786876b1e0097b761c620b2dadc7ea (from 1e6f3de1151af9b20ac20d1c07d7f34726cbafd5)
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 1fdb8d6..3d84320 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>&#60;[merge|append|prepend] key="some_property"
+      include <literal>&#60;[merge|append|prepend|addset] key="some_property"
         type="[string|int|bool|..]"&#62;
       </literal>
       directives to
@@ -35,12 +35,14 @@
     </para>
     <para>
       The <literal>&#60;match&#62;</literal>,
-      <literal>&#60;merge&#62;</literal>, <literal>&#60;append&#62;</literal>
-      and <literal>&#60;prepend&#62;</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>&#60;merge&#62;</literal>, <literal>&#60;append&#62;</literal>, 
+      <literal>&#60;prepend&#62;</literal>
+      and <literal>&#60;addset&#62;</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
@@ -176,8 +178,9 @@
     <title>Merging</title>
     <para>
 
-      The <literal>&#60;merge&#62;</literal>, <literal>&#60;append&#62;</literal>
-      and <literal>&#60;prepend&#62;</literal> directives all require
+      The <literal>&#60;merge&#62;</literal>, <literal>&#60;append&#62;</literal>, 
+      <literal>&#60;prepend&#62;</literal>
+      and <literal>&#60;addset&#62;</literal> directives all require
       the <literal>type</literal> attribute which specifies what to
       merge. The following values are supported
       <itemizedlist>
@@ -192,8 +195,12 @@
           <para>
             <literal>strlist</literal> - For <literal>&#60;merge&#62;</literal> the value is
             copied to the property and the current property will be overwritten. For
-            <literal>&#60;append&#62;</literal> and <literal>&#60;prepend&#62;</literal> the
-            value is append or prepend to the list as new item. Usage of 
+            <literal>&#60;append&#62;</literal>
+            and <literal>&#60;prepend&#62;</literal> the value is
+            append or prepend to the list as new
+            item. For <literal>&#60;addset&#62;</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>&#60;copy_property&#62;</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 eed9a14..bb2b256 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 3b9cf7b..2c416f0 100644
--- a/hald/device_info.c
+++ b/hald/device_info.c
@@ -858,6 +858,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) {
@@ -954,6 +967,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 c73f4c6..5cbac62 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