hal/hald hald_dbus.c, 1.20, 1.21 hald_test.c, 1.1, 1.2 hald_test_libhal.c, 1.1, 1.2 osspec.h, 1.5, 1.6

David Zeuthen david at freedesktop.org
Wed Feb 2 12:44:27 PST 2005


Update of /cvs/hal/hal/hald
In directory gabe:/tmp/cvs-serv29310/hald

Modified Files:
	hald_dbus.c hald_test.c hald_test_libhal.c osspec.h 
Log Message:
2005-02-02  David Zeuthen  <david at fubar.dk>

	* hald/linux2/osspec.c: Adjust for changes in hotplug.h.
	(osspec_device_rescan): New function
	(osspec_device_reprobe): New function

	* hald/linux2/hotplug.h: Extend HotplugEvent struct to also be used
	for coldplugging/fake hotplugging (via Reprobe()) of ACPI devices.
	Add prototypes for hotplug_reprobe_tree() and hotplug_rescan_device().

	* hald/linux2/hotplug.c: Adjust to changes in hotplug.h
	(hotplug_event_begin_sysfs): New function; what used to be the
	function hotplug_event_begin().
	(hotplug_event_begin_acpi): New function
	(hotplug_event_begin): Now a simple dispatcher according to hotplug
	type; e.g. sysfs or acpi
	(hotplug_rescan_device): New function
	(hotplug_reprobe_generate_remove_events): New function
	(hotplug_reprobe_generate_add_events): New function
	(hotplug_reprobe_tree): New function

	* hald/linux2/coldplug.c: Adjust to changes in hotplug.h

	* hald/linux2/classdev.h: Add prototypes for classdev_generate_
	[add|remove]_hotplug_event() and classdev_rescan_device().

	* hald/linux2/classdev.c (hotplug_event_begin_add_classdev): Add
	some properties so we can reconstruct the hotplug event
	(classdev_rescan_device): New function
	(classdev_generate_add_hotplug_event): New function
	(classdev_generate_remove_hotplug_event): New function

	* hald/linux2/acpi.[ch]: Yikes, rewrite must of this to conform to
	the hotplug model so we can do Rescan() and Reprobe()

	* hald/osspec.h: Add prototypes for osspec_device_[rescan|reprobe]

	* hald/hald_test_libhal.c (send_tests_done): New function
	(check_libhal): Add some more tests and report back

	* hald/hald_test.c (check_properties): Fixup wrong failure reports
	(server_message_handler): Add new methods on the org.freedesktop.Hal.
	Tests interfaces to signal that a test is done
	(wait_for_external_test): New function; pretty ugly but it works
	for now. As noted: Patches are Welcome(tm)
	(main): Enable libhal tests

	* hald/hald_dbus.c (device_rescan): New function
	(device_reprobe): New function
	(hald_dbus_filter_function): Add checks for Rescan() and Reprobe()
	methods on the org.freedesktop.Hal.Device interface



Index: hald_dbus.c
===================================================================
RCS file: /cvs/hal/hal/hald/hald_dbus.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- hald_dbus.c	1 Feb 2005 05:17:55 -0000	1.20
+++ hald_dbus.c	2 Feb 2005 20:44:25 -0000	1.21
@@ -1854,6 +1854,95 @@
 	dbus_free (service_name);
 }
 
+static DBusHandlerResult
+device_rescan (DBusConnection * connection, DBusMessage * message)
+{
+	const char *udi;
+	HalDevice *device;
+	DBusMessage *reply;
+	DBusMessageIter iter;
+	gboolean res;	
+
+	HAL_TRACE (("entering"));
+
+	udi = dbus_message_get_path (message);
+
+	if (!sender_has_privileges (connection, message)) {
+		raise_permission_denied (connection, message, "Rescan: not privileged");
+		return DBUS_HANDLER_RESULT_HANDLED;
+	}
+
+	HAL_DEBUG (("udi=%s", udi));
+
+	device = hal_device_store_find (hald_get_gdl (), udi);
+	if (device == NULL)
+		device = hal_device_store_find (hald_get_tdl (), udi);
+
+	if (device == NULL) {
+		raise_no_such_device (connection, message, udi);
+		return DBUS_HANDLER_RESULT_HANDLED;
+	}
+
+	res = osspec_device_rescan (device);
+
+	reply = dbus_message_new_method_return (message);
+	if (reply == NULL)
+		DIE (("No memory"));
+	dbus_message_iter_init (reply, &iter);
+	dbus_message_iter_append_boolean (&iter, res);
+
+	if (!dbus_connection_send (connection, reply, NULL))
+		DIE (("No memory"));
+
+	dbus_message_unref (reply);
+	return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+static DBusHandlerResult
+device_reprobe (DBusConnection * connection, DBusMessage * message)
+{
+	const char *udi;
+	HalDevice *device;
+	DBusMessageIter iter;
+	DBusMessage *reply;
+	gboolean res;
+	
+	HAL_TRACE (("entering"));
+
+	udi = dbus_message_get_path (message);
+
+	if (!sender_has_privileges (connection, message)) {
+		raise_permission_denied (connection, message, "Reprobe: not privileged");
+		return DBUS_HANDLER_RESULT_HANDLED;
+	}
+
+	HAL_DEBUG (("udi=%s", udi));
+
+	device = hal_device_store_find (hald_get_gdl (), udi);
+	if (device == NULL)
+		device = hal_device_store_find (hald_get_tdl (), udi);
+
+	if (device == NULL) {
+		raise_no_such_device (connection, message, udi);
+		return DBUS_HANDLER_RESULT_HANDLED;
+	}
+
+	res = osspec_device_reprobe (device);
+
+	reply = dbus_message_new_method_return (message);
+	if (reply == NULL)
+		DIE (("No memory"));
+	dbus_message_iter_init (reply, &iter);
+	dbus_message_iter_append_boolean (&iter, res);
+
+	if (!dbus_connection_send (connection, reply, NULL))
+		DIE (("No memory"));
+
+	dbus_message_unref (reply);
+	return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+
 /** Message handler for method invocations. All invocations on any object
  *  or interface is routed through this function.
  *
@@ -1995,6 +2084,14 @@
 						"org.freedesktop.Hal.Device",
 						"StringListPrepend")) {
 		return device_string_list_append_prepend (connection, message, TRUE);
+	} else if (dbus_message_is_method_call (message,
+						"org.freedesktop.Hal.Device",
+						"Rescan")) {
+		return device_rescan (connection, message);
+	} else if (dbus_message_is_method_call (message,
+						"org.freedesktop.Hal.Device",
+						"Reprobe")) {
+		return device_reprobe (connection, message);
 	} else
 		osspec_filter_function (connection, message, user_data);
 

Index: hald_test.c
===================================================================
RCS file: /cvs/hal/hal/hald/hald_test.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- hald_test.c	31 Jan 2005 20:06:39 -0000	1.1
+++ hald_test.c	2 Feb 2005 20:44:25 -0000	1.2
@@ -364,13 +364,13 @@
 	    !hal_device_has_property (d, "test.string") ||
 	    !hal_device_has_property (d, "test.string2") ||
 	    !hal_device_has_property (d, "test.strlist")) {
-		printf ("FAILED0\n");
+		printf ("FAILED80\n");
 		goto out;
 	}
 	if (hal_device_has_property (d, "moe") ||
 	    hal_device_has_property (d, "joe") ||
 	    hal_device_has_property (d, "woo")) {
-		printf ("FAILED1\n");
+		printf ("FAILED81\n");
 		goto out;
 	}
 	printf ("PASSED\n");
@@ -401,20 +401,52 @@
 	    dbus_message_get_destination (message));
 }
 
+static int num_tests_done;
+static gboolean num_tests_done_last_result;
+
 static DBusHandlerResult 
 server_message_handler (DBusConnection *connection, 
 			DBusMessage *message, 
 			void *user_data)
 {
+/*
 	printf ("destination=%s obj_path=%s interface=%s method=%s\n", 
 		dbus_message_get_destination (message), 
 		dbus_message_get_path (message), 
 		dbus_message_get_interface (message),
 		dbus_message_get_member (message));
+*/
+	/* handle our TestsDone Method */
+	if (dbus_message_is_method_call (message, "org.freedesktop.Hal.Tests", "TestsDone")) {
+		DBusError error;
+		dbus_bool_t passed;
+		DBusMessage *reply;
 
-	/* cheat, and handle AddMatch since libhal will try that */
-	if (dbus_message_is_method_call (message, "org.freedesktop.DBus", "AddMatch")) {
+		dbus_error_init (&error);
+		if (!dbus_message_get_args (message, &error,
+					    DBUS_TYPE_BOOLEAN, &passed,
+					    DBUS_TYPE_INVALID)) {
+
+			reply = dbus_message_new_error (message, "org.freedesktop.Hal.SyntaxError", "Syntax Error");
+			dbus_connection_send (connection, reply, NULL);
+			dbus_message_unref (reply);
+			passed = FALSE;			
+		} else {
+
+			reply = dbus_message_new_method_return (message);
+			dbus_connection_send (connection, reply, NULL);
+			dbus_message_unref (reply);
+		}
+
+		num_tests_done++;
+		num_tests_done_last_result = passed;
+
+		return DBUS_HANDLER_RESULT_HANDLED;
+       
+	} else if (dbus_message_is_method_call (message, "org.freedesktop.DBus", "AddMatch")) {
 		DBusMessage *reply;
+
+                /* cheat, and handle AddMatch since libhal will try that */
 		
 		reply = dbus_message_new_error (message, "org.freedesktop.Hal.Error",
 						"Not handled in HAL testing mode");
@@ -464,6 +496,23 @@
 }
 
 
+static gboolean
+wait_for_external_test (void)
+{
+	int num_tests_done_pre;
+
+	/* sure, this is pretty ugly. Patches welcome */
+
+	num_tests_done_pre = num_tests_done;
+	while (num_tests_done_pre == num_tests_done) {
+		g_main_context_iteration (NULL, TRUE);
+		if (!g_main_context_pending (NULL))
+			usleep (100*1000);
+	}
+
+	return num_tests_done_last_result;
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -494,20 +543,21 @@
 
 	dbus_server_set_new_connection_function (server, server_handle_connection, NULL, NULL);
 
+	/* this creates the /org/freedesktop/Hal/devices/testobj1 object  */
 	if (!check_properties ())
 		num_tests_failed++;
-/*
+
+	/* tests of libhal against /org/freedesktop/Hal/devices/testobj1 for getting  */
 	if (!check_libhal (dbus_server_get_address (server)))
 		num_tests_failed++;
-*/
+	if (!wait_for_external_test ())
+		num_tests_failed++;
+
+
 	printf ("=============================\n");
 
 	printf ("Total number of tests failed: %d\n", num_tests_failed);
 
-/*
-	g_main_loop_run (loop);
-*/
-
 out:
 	return num_tests_failed;
 }

Index: hald_test_libhal.c
===================================================================
RCS file: /cvs/hal/hal/hald/hald_test_libhal.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- hald_test_libhal.c	31 Jan 2005 20:06:39 -0000	1.1
+++ hald_test_libhal.c	2 Feb 2005 20:44:25 -0000	1.2
@@ -48,8 +48,49 @@
 
 #include "libhal/libhal.h"
 
+static void
+send_tests_done (DBusConnection *conn, dbus_bool_t passed)
+{
+	int i;
+	DBusMessage *message;
+	DBusMessage *reply;
+	DBusMessageIter iter;
+	DBusError error;
+
+	message = dbus_message_new_method_call ("org.freedesktop.Hal",
+						"/org/freedesktop/Hal/Tests",
+						"org.freedesktop.Hal.Tests",
+						"TestsDone");
+	if (message == NULL) {
+		fprintf (stderr, "%s %d : Couldn't allocate D-BUS message\n", __FILE__, __LINE__);
+		goto out;
+	}
+
+	dbus_message_iter_init (message, &iter);
+	dbus_message_iter_append_boolean (&iter, passed);
+
+	dbus_error_init (&error);
+	reply = dbus_connection_send_with_reply_and_block (conn, message, -1, &error);
+	if (dbus_error_is_set (&error)) {
+		dbus_message_unref (message);
+		fprintf (stderr, "%s %d : Error sending message: %s: %s\n", 
+			 __FILE__, __LINE__, error.name, error.message);
+		return;
+	}
+
+	if (reply == NULL) {
+		dbus_message_unref (message);
+		fprintf (stderr, "%s %d : No reply!\n", __FILE__, __LINE__);
+		return;
+	}
+
+	dbus_message_unref (message);
+	dbus_message_unref (reply);
+out:
+	;
+}
+
 
-/* TODO: All this needs work */
 
 gboolean
 check_libhal (const char *server_addr)
@@ -64,6 +105,7 @@
 		DBusError error;
 		DBusConnection *conn;
 		LibHalContext *ctx;
+		dbus_bool_t passed;
 
 		printf ("server address='%s'\n", server_addr);
 
@@ -82,9 +124,100 @@
 
 		libhal_ctx_set_dbus_connection (ctx, conn);
 		libhal_ctx_init (ctx, &error);
-		printf ("got %s\n", libhal_device_get_property_string (ctx, "/org/freedesktop/Hal/devices/testobj1", "test.string", &error));
 		libhal_device_print (ctx, "/org/freedesktop/Hal/devices/testobj1", &error);
 
+		passed = FALSE;
+
+		{
+			char *val;
+			val = libhal_device_get_property_string (ctx, "/org/freedesktop/Hal/devices/testobj1", "test.string", &error);
+			if (val == NULL || strcmp (val, "fooooobar22") != 0 || dbus_error_is_set (&error)) {
+				libhal_free_string (val);
+				printf ("FAILED100\n");			
+				goto fail;
+			}
+			libhal_free_string (val);
+		}
+
+		{
+			char *val;
+			val = libhal_device_get_property_string (ctx, "/org/freedesktop/Hal/devices/testobj1", "test.string2", &error);
+			if (val == NULL || strcmp (val, "fooøةמ") != 0 || dbus_error_is_set (&error)) {
+				libhal_free_string (val);
+				printf ("FAILED100\n");			
+				goto fail;
+			}
+			libhal_free_string (val);
+		}
+
+
+		if (libhal_device_get_property_bool (
+			    ctx, "/org/freedesktop/Hal/devices/testobj1", "test.bool", &error) != TRUE ||
+		    dbus_error_is_set (&error)) {
+			printf ("FAILED102\n");			
+			goto fail;
+		}
+
+		{
+			double val;
+			double expected_val = 0.53434343;
+
+			val = libhal_device_get_property_double (ctx, "/org/freedesktop/Hal/devices/testobj1", 
+								 "test.double", &error);
+			if ( memcmp (&val, &expected_val, sizeof (double)) != 0 || dbus_error_is_set (&error)) {
+				printf ("FAILED103\n");
+				goto fail;
+			}
+		}
+
+		if (libhal_device_get_property_uint64 (
+			    ctx, "/org/freedesktop/Hal/devices/testobj1", "test.uint64", &error) != 
+		    ((((dbus_uint64_t)1)<<35) + 5) ||
+		    dbus_error_is_set (&error)) {
+			printf ("FAILED104\n");			
+			goto fail;
+		}
+
+		{
+			char **val;
+			val = libhal_device_get_property_strlist (ctx, "/org/freedesktop/Hal/devices/testobj1", "test.strlist", &error);
+			if (val == NULL ||  dbus_error_is_set (&error)) {
+				libhal_free_string_array (val);
+				printf ("FAILED105\n");			
+				goto fail;
+			}
+
+			if (libhal_string_array_length (val) != 2) {
+				libhal_free_string_array (val);
+				printf ("FAILED106\n");			
+				goto fail;
+			}
+
+			if (strcmp (val[0], "foostrlist2") != 0 ||
+			    strcmp (val[1], "foostrlist3") != 0) {
+				libhal_free_string_array (val);
+				printf ("FAILED107\n");			
+				goto fail;
+			}
+
+			libhal_free_string_array (val);
+		}
+
+		if (libhal_device_get_property_int (
+			    ctx, "/org/freedesktop/Hal/devices/testobj1", "test.int", &error) != 42 ||
+		    dbus_error_is_set (&error)) {
+			printf ("FAILED108\n");			
+			goto fail;
+		}
+
+		printf ("Passed all libhal tests\n");
+		passed = TRUE;
+
+	fail:
+
+		send_tests_done (conn, passed);
+		exit (1);
+
 	} else {
 		printf ("child pid=%d\n", child_pid);
 	}

Index: osspec.h
===================================================================
RCS file: /cvs/hal/hal/hald/osspec.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- osspec.h	22 Aug 2004 19:27:22 -0000	1.5
+++ osspec.h	2 Feb 2005 20:44:25 -0000	1.6
@@ -30,6 +30,7 @@
 #include <stdint.h>
 #include <dbus/dbus.h>
 
+#include "device.h"
 
 /** Initialize the kernel specific parts of the daemon */
 void osspec_init (void);
@@ -46,6 +47,10 @@
 /* Called by kernel specific parts when probing is done */
 void osspec_shutdown_done (void);
 
+gboolean osspec_device_rescan (HalDevice *d);
+
+gboolean osspec_device_reprobe (HalDevice *d);
+
 /** Called when the org.freedesktop.Hal service receives a messaged that the generic daemon 
  *  doesn't handle. Can be used for intercepting messages from kernel or core OS components.
  *




More information about the hal-commit mailing list