hal: Branch 'master'
David Zeuthen
david at kemper.freedesktop.org
Mon Oct 9 15:49:49 PDT 2006
hald/device.c | 26 ++++++++++++++------------
hald/device.h | 16 +++++++++++-----
hald/hald_dbus.c | 49 ++++++++++++++++++++++---------------------------
hald/hald_runner.c | 9 +++++----
hald/property.c | 1 +
hald/property.h | 8 --------
6 files changed, 53 insertions(+), 56 deletions(-)
New commits:
diff-tree 1f777cb8d4a4300c7762eeb6150789ba0dec9e44 (from 6ae9274c007edfbec8ac101f42a0e8f2a4424bc2)
Author: David Zeuthen <davidz at redhat.com>
Date: Mon Oct 9 18:49:43 2006 -0400
make HalProperty private to HalDevice implementation (makes it easier to nuke)
diff --git a/hald/device.c b/hald/device.c
index cfd0f8f..b10dc84 100644
--- a/hald/device.c
+++ b/hald/device.c
@@ -33,6 +33,7 @@
#include "hald.h"
#include "device.h"
+#include "property.h"
#include "hald_marshal.h"
#include "logger.h"
#include "hald_runner.h"
@@ -443,15 +444,6 @@ hal_device_has_capability (HalDevice *de
return matched;
}
-gboolean
-hal_device_has_property (HalDevice *device, const char *key)
-{
- g_return_val_if_fail (device != NULL, FALSE);
- g_return_val_if_fail (key != NULL, FALSE);
-
- return hal_device_property_find (device, key) != NULL;
-}
-
int
hal_device_num_properties (HalDevice *device)
{
@@ -460,7 +452,7 @@ hal_device_num_properties (HalDevice *de
return g_slist_length (device->private->properties);
}
-HalProperty *
+static HalProperty *
hal_device_property_find (HalDevice *device, const char *key)
{
GSList *iter;
@@ -471,13 +463,23 @@ hal_device_property_find (HalDevice *dev
for (iter = device->private->properties; iter != NULL; iter = iter->next) {
HalProperty *p = iter->data;
- if (strcmp (hal_property_get_key (p), key) == 0)
+ if (strcmp (hal_property_get_key (p), key) == 0) {
return p;
+ }
}
return NULL;
}
+gboolean
+hal_device_has_property (HalDevice *device, const char *key)
+{
+ g_return_val_if_fail (device != NULL, FALSE);
+ g_return_val_if_fail (key != NULL, FALSE);
+
+ return hal_device_property_find (device, key) != NULL;
+}
+
char *
hal_device_property_to_string (HalDevice *device, const char *key)
{
@@ -504,7 +506,7 @@ hal_device_property_foreach (HalDevice *
HalProperty *p = iter->data;
gboolean cont;
- cont = callback (device, p, user_data);
+ cont = callback (device, hal_property_get_key (p), user_data);
if (cont == FALSE)
return;
diff --git a/hald/device.h b/hald/device.h
index 247e143..b30109c 100644
--- a/hald/device.h
+++ b/hald/device.h
@@ -30,8 +30,6 @@
#include <glib-object.h>
#include <dbus/dbus.h>
-#include "property.h"
-
struct _HalDevicePrivate;
typedef struct _HalDevicePrivate HalDevicePrivate;
@@ -67,9 +65,18 @@ struct _HalDeviceClass {
#define HAL_IS_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), \
HAL_TYPE_DEVICE))
+#define HAL_PROPERTY_TYPE_INVALID DBUS_TYPE_INVALID
+#define HAL_PROPERTY_TYPE_INT32 DBUS_TYPE_INT32
+#define HAL_PROPERTY_TYPE_UINT64 DBUS_TYPE_UINT64
+#define HAL_PROPERTY_TYPE_DOUBLE DBUS_TYPE_DOUBLE
+#define HAL_PROPERTY_TYPE_BOOLEAN DBUS_TYPE_BOOLEAN
+#define HAL_PROPERTY_TYPE_STRING DBUS_TYPE_STRING
+#define HAL_PROPERTY_TYPE_STRLIST ((int) (DBUS_TYPE_STRING<<8)+('l'))
+
+
/* Return value of FALSE means that the foreach should be short-circuited */
typedef gboolean (*HalDevicePropertyForeachFn) (HalDevice *device,
- HalProperty *property,
+ const char *key,
gpointer user_data);
GType hal_device_get_type (void);
@@ -99,8 +106,7 @@ gboolean hal_device_has_capability
gboolean hal_device_has_property (HalDevice *device,
const char *key);
-HalProperty *hal_device_property_find (HalDevice *device,
- const char *key);
+
int hal_device_num_properties (HalDevice *device);
char * hal_device_property_to_string (HalDevice *device,
const char *key);
diff --git a/hald/hald_dbus.c b/hald/hald_dbus.c
index 834ee06..f864e63 100644
--- a/hald/hald_dbus.c
+++ b/hald/hald_dbus.c
@@ -675,12 +675,12 @@ out:
*/
static gboolean
-foreach_property_append (HalDevice *device, HalProperty *p,
+foreach_property_append (HalDevice *device,
+ const char *key,
gpointer user_data)
{
DBusMessageIter *iter;
DBusMessageIter iter_dict_entry;
- const char *key;
int type;
iter = (DBusMessageIter *)user_data;
@@ -690,8 +690,7 @@ foreach_property_append (HalDevice *devi
NULL,
&iter_dict_entry);
- key = hal_property_get_key (p);
- type = hal_property_get_type (p);
+ type = hal_device_property_get_type (device, key);
dbus_message_iter_append_basic (&iter_dict_entry, DBUS_TYPE_STRING, &key);
@@ -701,7 +700,7 @@ foreach_property_append (HalDevice *devi
DBusMessageIter iter_var;
const char *v;
- v = hal_property_get_string (p);
+ v = hal_device_property_get_string (device, key);
dbus_message_iter_open_container (&iter_dict_entry,
DBUS_TYPE_VARIANT,
@@ -721,7 +720,7 @@ foreach_property_append (HalDevice *devi
DBusMessageIter iter_var;
dbus_int32_t v;
- v = hal_property_get_int (p);
+ v = hal_device_property_get_int (device, key);
dbus_message_iter_open_container (&iter_dict_entry,
DBUS_TYPE_VARIANT,
@@ -741,7 +740,7 @@ foreach_property_append (HalDevice *devi
DBusMessageIter iter_var;
dbus_uint64_t v;
- v = hal_property_get_uint64 (p);
+ v = hal_device_property_get_uint64 (device, key);
dbus_message_iter_open_container (&iter_dict_entry,
DBUS_TYPE_VARIANT,
@@ -761,7 +760,7 @@ foreach_property_append (HalDevice *devi
DBusMessageIter iter_var;
double v;
- v = hal_property_get_double (p);
+ v = hal_device_property_get_double (device, key);
dbus_message_iter_open_container (&iter_dict_entry,
DBUS_TYPE_VARIANT,
@@ -781,7 +780,7 @@ foreach_property_append (HalDevice *devi
DBusMessageIter iter_var;
dbus_bool_t v;
- v = hal_property_get_bool (p);
+ v = hal_device_property_get_bool (device, key);
dbus_message_iter_open_container (&iter_dict_entry,
DBUS_TYPE_VARIANT,
@@ -812,7 +811,7 @@ foreach_property_append (HalDevice *devi
DBUS_TYPE_STRING_AS_STRING,
&iter_array);
- for (iter = hal_property_get_strlist (p); iter != NULL; iter = iter->next) {
+ for (iter = hal_device_property_get_strlist (device, key); iter != NULL; iter = iter->next) {
const char *v;
v = (const char *) iter->data;
@@ -1125,11 +1124,10 @@ device_get_property (DBusConnection * co
const char *udi;
char *key;
int type;
- HalProperty *p;
udi = dbus_message_get_path (message);
- HAL_TRACE (("entering, udi=%s", udi));
+ HAL_TRACE (("entering, udi=%s", udi));
d = hal_device_store_find (hald_get_gdl (), udi);
if (d == NULL)
@@ -1148,8 +1146,7 @@ device_get_property (DBusConnection * co
return DBUS_HANDLER_RESULT_HANDLED;
}
- p = hal_device_property_find (d, key);
- if (p == NULL) {
+ if (!hal_device_has_property (d, key)) {
raise_no_such_property (connection, message, udi, key);
return DBUS_HANDLER_RESULT_HANDLED;
}
@@ -1160,40 +1157,40 @@ device_get_property (DBusConnection * co
dbus_message_iter_init_append (reply, &iter);
- type = hal_property_get_type (p);
+ type = hal_device_property_get_type (d, key);
switch (type) {
case HAL_PROPERTY_TYPE_STRING:
{
const char *s;
- s = hal_property_get_string (p);
+ s = hal_device_property_get_string (d, key);
dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &s);
break;
}
case HAL_PROPERTY_TYPE_INT32:
{
dbus_int32_t i;
- i = hal_property_get_int (p);
+ i = hal_device_property_get_int (d, key);
dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &i);
break;
}
case HAL_PROPERTY_TYPE_UINT64:
{
dbus_uint64_t ul;
- ul = hal_property_get_uint64 (p);
+ ul = hal_device_property_get_uint64 (d, key);
dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT64, &ul);
break;
}
case HAL_PROPERTY_TYPE_DOUBLE:
{
- double d;
- d = hal_property_get_double (p);
- dbus_message_iter_append_basic (&iter, DBUS_TYPE_DOUBLE, &d);
+ double vd;
+ vd = hal_device_property_get_double (d, key);
+ dbus_message_iter_append_basic (&iter, DBUS_TYPE_DOUBLE, &vd);
break;
}
case HAL_PROPERTY_TYPE_BOOLEAN:
{
dbus_bool_t b;
- b = hal_property_get_bool (p);
+ b = hal_device_property_get_bool (d, key);
dbus_message_iter_append_basic (&iter, DBUS_TYPE_BOOLEAN, &b);
break;
}
@@ -1207,7 +1204,7 @@ device_get_property (DBusConnection * co
DBUS_TYPE_STRING_AS_STRING,
&iter_array);
- for (l = hal_property_get_strlist (p); l != NULL; l = g_slist_next (l)) {
+ for (l = hal_device_property_get_strlist (d, key); l != NULL; l = g_slist_next (l)) {
dbus_message_iter_append_basic (&iter_array, DBUS_TYPE_STRING, &(l->data));
}
@@ -1252,7 +1249,6 @@ device_get_property_type (DBusConnection
HalDevice *d;
const char *udi;
char *key;
- HalProperty *p;
dbus_int32_t i;
udi = dbus_message_get_path (message);
@@ -1276,8 +1272,7 @@ device_get_property_type (DBusConnection
return DBUS_HANDLER_RESULT_HANDLED;
}
- p = hal_device_property_find (d, key);
- if (p == NULL) {
+ if (!hal_device_has_property (d, key)) {
raise_no_such_property (connection, message, udi, key);
return DBUS_HANDLER_RESULT_HANDLED;
}
@@ -1286,7 +1281,7 @@ device_get_property_type (DBusConnection
if (reply == NULL)
DIE (("No memory"));
- i = hal_property_get_type (p);
+ i = hal_device_property_get_type (d, key);
dbus_message_iter_init_append (reply, &iter);
dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &i);
diff --git a/hald/hald_runner.c b/hald/hald_runner.c
index b605424..3f916b8 100644
--- a/hald/hald_runner.c
+++ b/hald/hald_runner.c
@@ -289,15 +289,16 @@ error:
}
static gboolean
-add_property_to_msg (HalDevice *device, HalProperty *property,
- gpointer user_data)
+add_property_to_msg (HalDevice *device,
+ const char *key,
+ gpointer user_data)
{
char *prop_upper, *value;
char *c;
gchar *env;
DBusMessageIter *iter = (DBusMessageIter *)user_data;
- prop_upper = g_ascii_strup (hal_property_get_key (property), -1);
+ prop_upper = g_ascii_strup (key, -1);
/* periods aren't valid in the environment, so replace them with
* underscores. */
@@ -306,7 +307,7 @@ add_property_to_msg (HalDevice *device,
*c = '_';
}
- value = hal_property_to_string (property);
+ value = hal_device_property_to_string (device, key);
env = g_strdup_printf ("HAL_PROP_%s=%s", prop_upper, value);
dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &env);
diff --git a/hald/property.c b/hald/property.c
index 9a1adaa..5f89e78 100644
--- a/hald/property.c
+++ b/hald/property.c
@@ -31,6 +31,7 @@
#include <string.h>
#include <glib.h>
+#include "device.h"
#include "logger.h"
#include "property.h"
diff --git a/hald/property.h b/hald/property.h
index 32f21df..07d9597 100644
--- a/hald/property.h
+++ b/hald/property.h
@@ -31,14 +31,6 @@
typedef struct _HalProperty HalProperty;
-#define HAL_PROPERTY_TYPE_INVALID DBUS_TYPE_INVALID
-#define HAL_PROPERTY_TYPE_INT32 DBUS_TYPE_INT32
-#define HAL_PROPERTY_TYPE_UINT64 DBUS_TYPE_UINT64
-#define HAL_PROPERTY_TYPE_DOUBLE DBUS_TYPE_DOUBLE
-#define HAL_PROPERTY_TYPE_BOOLEAN DBUS_TYPE_BOOLEAN
-#define HAL_PROPERTY_TYPE_STRING DBUS_TYPE_STRING
-#define HAL_PROPERTY_TYPE_STRLIST ((int) (DBUS_TYPE_STRING<<8)+('l'))
-
void hal_property_free (HalProperty *prop);
HalProperty *hal_property_new_string (const char *key,
More information about the hal-commit
mailing list