hal: Branch 'master'

Danny Kukawka dkukawka at kemper.freedesktop.org
Tue Aug 28 10:42:49 PDT 2007


 doc/spec/hal-spec-fdi-files.xml |   40 +++++++++++++++++++
 fdi/fdi.dtd                     |    4 +
 hald/create_cache.c             |    8 +++
 hald/device_info.c              |   83 ++++++++++++++++++++++++++++++++++++++++
 hald/rule.h                     |    6 ++
 5 files changed, 140 insertions(+), 1 deletion(-)

New commits:
diff-tree 926e7c2979c12a0d0f9316b31d66beac5a8f4b19 (from 7deca6dbcdd21325077943ca65ba88db5be6040b)
Author: Danny Kukawka <danny.kukawka at web.de>
Date:   Tue Aug 28 19:42:21 2007 +0200

    add new fdi directives *_outof
    
    This introduce new fdi-file <match> directives for strings. The new are:
     - int_outof
     - string_outof
     - prefix_outof
     - contains_outof
    
    They all work like the normal directives (string, prefix, contains), but only
    on string properties and match against a ';'-separated list (any other ideas
    for a char as separator?) as in this examples:
    
      <match key="usb.product_id" int_outof="0x4115;0x4116">
      - matches if "usb.product_id" is '0x4115' or '0x4115'
    
      <match key="system.hardware.product" string_outof="foo;bar">
      - matches if "system.hardware.product" is exact 'foo' or 'bar'
    
      <match key="system.hardware.product" prefix_outof="foo;bar">
      - matches if "system.hardware.product" starts with 'foo' or 'bar'
    
      <match key="system.hardware.product" contains_outof="foo;bar">
      - matches if "system.hardware.product" contains the (sub-)string
        'foo' or 'bar'
    
    This new match directives allow us to reduce the size (and number of
    duplicated rules) of many fdi files in hal and hal-info. As example I reduced:
    
      - 30-keymap-acer.fdi from 28532 to 8123 bytes (~ -72 %)
      - 10-usb-music-players.fdi from 78817 to 49860 Bytes (~ -37 %)

diff --git a/doc/spec/hal-spec-fdi-files.xml b/doc/spec/hal-spec-fdi-files.xml
index 60cfb70..916754b 100644
--- a/doc/spec/hal-spec-fdi-files.xml
+++ b/doc/spec/hal-spec-fdi-files.xml
@@ -68,11 +68,30 @@
         </listitem>
         <listitem>
           <para>
+            <literal>string_outof</literal> - work like <literal>string</literal> but
+	    the match is done against a list of strings separated by ';'. 
+	    For example: 
+	    <literal>&#60;match key="system.hardware.product" string_outof="Satellite A30;Portable PC"&#62;</literal>	
+	    In this example the line matches if <literal>system.hardware.product</literal>
+	    is exactly 'Satellite A30' or 'Portable PC'.
+          </para>
+        </listitem>
+        <listitem>
+          <para>
             <literal>int</literal> - match an integer property
           </para>
         </listitem>
         <listitem>
           <para>
+            <literal>int_outof</literal> - work like <literal>int</literal> but
+	    the match is done against a list of integer separated by ';'. 
+	    For example: 
+	    <literal>&#60;match key="usb.product_id" int_outof="0x1007;0x1008;0x1009"&#62;</literal>	
+	    In this example the line matches if <literal>usb.product_id</literal> is 0x1007, 0x1008 or 0x1009.
+          </para>
+        </listitem>
+        <listitem>
+          <para>
             <literal>uint64</literal> - match property with the 64-bit unsigned type
           </para>
         </listitem>
@@ -149,6 +168,17 @@
         </listitem>
         <listitem>
           <para>
+            <literal>contains_outof</literal> - like <literal>contains</literal> but can be
+	    used only with strings and the match is done against a list of (sub-)strings 
+	    separated by ';'. 
+	    For example: 
+	    <literal>&#60;match key="system.hardware.product" contains_outof="D600;D610;C540"&#62;</literal>	
+	    In this example the line matches if <literal>system.hardware.product</literal>
+	    contains D600, D610 or C540.
+          </para>
+        </listitem>
+        <listitem>
+          <para>
             <literal>prefix</literal> - can only be used with string properties.
             Matches if property begins with the key.
           </para>
@@ -161,6 +191,16 @@
         </listitem>
         <listitem>
           <para>
+            <literal>prefix_outof</literal> - like <literal>prefix</literal> but the
+	    match is done against a list of prefixes separated by ';'. 
+	    For example: 
+	    <literal>&#60;match key="system.hardware.product" prefix_outof="1860;2366;2371"&#62;</literal>	
+	    In this example the line matches if <literal>system.hardware.product</literal>
+	    starts with 1860, 2366 or 2371.
+          </para>
+        </listitem>
+        <listitem>
+          <para>
             <literal>suffix</literal> - can only be used with string properties.
             Matches if property ends with the key.
           </para>
diff --git a/fdi/fdi.dtd b/fdi/fdi.dtd
index ba4fc47..3658ea9 100644
--- a/fdi/fdi.dtd
+++ b/fdi/fdi.dtd
@@ -12,7 +12,9 @@
 <!ATTLIST match 
     key              CDATA #REQUIRED
     string           CDATA #IMPLIED
+    string_outof     CDATA #IMPLIED
     int              CDATA #IMPLIED
+    int_outof        CDATA #IMPLIED
     uint64           CDATA #IMPLIED
     bool             (false|true) #IMPLIED
     exists           (false|true) #IMPLIED
@@ -22,8 +24,10 @@
     contains         CDATA #IMPLIED
     contains_ncase   CDATA #IMPLIED
     contains_not     CDATA #IMPLIED
+    contains_outof   CDATA #IMPLIED
     prefix           CDATA #IMPLIED
     prefix_ncase     CDATA #IMPLIED
+    prefix_outof     CDATA #IMPLIED
     suffix           CDATA #IMPLIED
     suffix_ncase     CDATA #IMPLIED
     compare_lt       CDATA #IMPLIED
diff --git a/hald/create_cache.c b/hald/create_cache.c
index a76f60d..0250456 100644
--- a/hald/create_cache.c
+++ b/hald/create_cache.c
@@ -139,6 +139,14 @@ get_match_type(const char *str)
 		return MATCH_COMPARE_NE;
 	if (strcmp (str, "contains_not") == 0)
 		return MATCH_CONTAINS_NOT;
+	if (strcmp (str, "contains_outof") == 0)
+		return MATCH_CONTAINS_OUTOF;
+	if (strcmp (str, "int_outof") == 0)
+		return MATCH_CONTAINS_OUTOF;
+	if (strcmp (str, "prefix_outof") == 0)
+		return MATCH_PREFIX_OUTOF;
+	if (strcmp (str, "string_outof") == 0)
+		return MATCH_STRING_OUTOF;
 	return MATCH_UNKNOWN;
 }
 
diff --git a/hald/device_info.c b/hald/device_info.c
index 2404079..2b18346 100644
--- a/hald/device_info.c
+++ b/hald/device_info.c
@@ -65,8 +65,12 @@ get_match_type_str (enum match_type type
 	switch (type) {
 	case MATCH_STRING:
 		return "string";
+	case MATCH_STRING_OUTOF:
+		return "string_outof";
 	case MATCH_INT:
 		return "int";
+	case MATCH_INT_OUTOF:
+		return "int_outof";
 	case MATCH_UINT64:
 		return "uint64";
 	case MATCH_BOOL:
@@ -89,10 +93,14 @@ get_match_type_str (enum match_type type
 		return "contains_ncase";
 	case MATCH_CONTAINS_NOT:
 		return "contains_not";
+	case MATCH_CONTAINS_OUTOF:
+		return "contains_outof";
 	case MATCH_PREFIX:
 		return "prefix";
 	case MATCH_PREFIX_NCASE:
 		return "prefix_ncase";
+	case MATCH_PREFIX_OUTOF:
+		return "prefix_outof";
 	case MATCH_SUFFIX:
 		return "suffix";
 	case MATCH_SUFFIX_NCASE:
@@ -490,6 +498,81 @@ handle_match (struct rule *rule, HalDevi
 			return !contains; /* rule->type_match == MATCH_CONTAINS_NOT  */
 		}
 	}
+	
+	case MATCH_CONTAINS_OUTOF:
+	case MATCH_PREFIX_OUTOF:
+	case MATCH_STRING_OUTOF:
+	{
+		dbus_bool_t contains = FALSE;
+
+		if (hal_device_has_property (d, prop_to_check) && value != NULL) {
+
+			if (hal_device_property_get_type (d, prop_to_check) == HAL_PROPERTY_TYPE_STRING) {
+				const char *haystack;
+				gchar **values;
+        			int i;
+
+                		values = g_strsplit (value, ";", 0);
+				
+				haystack = hal_device_property_get_string (d, prop_to_check);
+				if (haystack != NULL && values != NULL) {
+					for (i = 0; values [i] ; ++i) {
+						if (rule->type_match == MATCH_CONTAINS_OUTOF) {
+							if (strstr(haystack, values[i]) != NULL) {
+								contains = TRUE;
+								break;
+							}
+						}
+						else if (rule->type_match == MATCH_PREFIX_OUTOF) {
+							if (g_str_has_prefix (haystack, values[i])) {
+								contains = TRUE;
+								break;
+							}	
+						}
+						else if (rule->type_match == MATCH_STRING_OUTOF) {
+							if (strcmp (haystack, values[i]) == 0) {
+								contains = TRUE;
+								break;
+							}
+						}
+					}
+				}
+				g_strfreev (values);	
+			} 
+		}
+	
+		return contains;
+	}
+
+	case MATCH_INT_OUTOF:
+	{
+		dbus_bool_t contained = FALSE;
+
+		if (hal_device_has_property (d, prop_to_check) && value != NULL) {
+
+			if (hal_device_property_get_type (d, prop_to_check) == HAL_PROPERTY_TYPE_INT32) {
+				gchar **values;
+        			int i;
+				int to_check;
+
+                		values = g_strsplit (value, ";", 0);
+				to_check = hal_device_property_get_int (d, prop_to_check);				
+
+				if (values != NULL) {
+					for (i = 0; values [i] ; ++i) {
+                				if (to_check == strtol (values[i], NULL, 0)) {
+							contained = TRUE;
+							break;
+						}	
+					}
+				}
+				g_strfreev (values);	
+			} 
+		}
+	
+		return contained;
+	}
+
 
 	case MATCH_SIBLING_CONTAINS:
 	{
diff --git a/hald/rule.h b/hald/rule.h
index 5885ebb..832759d 100644
--- a/hald/rule.h
+++ b/hald/rule.h
@@ -81,7 +81,11 @@ typedef enum {
 	MATCH_SIBLING_CONTAINS,
 	MATCH_COMPARE_NE,
 	MATCH_CONTAINS_NOT,
-	MATCH_DOUBLE
+	MATCH_DOUBLE,
+	MATCH_CONTAINS_OUTOF,
+	MATCH_INT_OUTOF,
+	MATCH_PREFIX_OUTOF,
+	MATCH_STRING_OUTOF,
 } match_type;
 
 /* a "rule" structure that is a generic node of the fdi file */


More information about the hal-commit mailing list