Beispiel #1
0
gboolean
check_libhal (const char *server_addr)
{
	pid_t child_pid;

	child_pid = fork ();
	if (child_pid == -1) {
		printf ("Cannot fork\n");
		exit (1);
	} else if (child_pid == 0) {
		DBusError error;
		DBusConnection *conn;
		LibHalContext *ctx;
		dbus_bool_t passed;

		printf ("server address='%s'\n", server_addr);

		dbus_error_init (&error);
		if ((conn = dbus_connection_open (server_addr, &error)) == NULL) {
			printf ("Error connecting to server: %s\n", error.message);
			goto fail;
		}

		dbus_connection_setup_with_g_main (conn, NULL);

		if ((ctx = libhal_ctx_new ()) == NULL) {
			printf ("Error getting libhal context\n");
			goto fail;
		}

		
		libhal_ctx_set_dbus_connection (ctx, conn);

		libhal_ctx_init (ctx, &error);

		if (dbus_error_is_set (&error)) {
			printf ("FAILED98: %s\n", error.message);			
			goto fail;
		}
		printf ("SUCCESS98\n");

		libhal_device_print (ctx, "/org/freedesktop/Hal/devices/testobj1", &error);


		if (dbus_error_is_set (&error)) {
			printf ("FAILED99: %s\n", error.message);			
			goto fail;
		}
		printf ("SUCCESS99\n");

		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;
			}
			printf ("SUCCESS100\n");
			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 ("FAILED101: %s\n", error.message);			
				goto fail;
			}
			libhal_free_string (val);
			printf ("SUCCESS101\n");
		}

		{
			dbus_bool_t b;
			b = libhal_device_get_property_bool (
			    ctx, "/org/freedesktop/Hal/devices/testobj1", 
			    "test.bool", &error);
			    
			if (!b || dbus_error_is_set (&error)) {
				printf ("FAILED102: %s, %i\n", error.message, b);			
				goto fail;
			}
			printf ("SUCCESS102\n");
		}

		{
			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;
			}
			printf ("SUCCESS103\n");
		}

		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: %s\n", error.message);			
			goto fail;
		}
		printf ("SUCCESS104\n");
		
		{
			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: %s\n", error.message);			
				goto fail;
			}
			printf ("SUCCESS105\n");
			
			if (libhal_string_array_length (val) != 2) {
				libhal_free_string_array (val);
				printf ("FAILED106\n");			
				goto fail;
			}
			printf ("SUCCESS106\n");

			if (strcmp (val[0], "foostrlist2") != 0 ||
			    strcmp (val[1], "foostrlist3") != 0) {
				libhal_free_string_array (val);
				printf ("FAILED107\n");			
				goto fail;
			}
			printf ("SUCCESS107\n");

			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 ("SUCCESS108\n");
	
		/* tests for libhal_psi */
		{
			int type;
			char *key;
			LibHalPropertySet *pset;
			LibHalPropertySetIterator it;
			unsigned int psi_num_passed;
			unsigned int psi_num_elems;

			if ((pset = libhal_device_get_all_properties (ctx, "/org/freedesktop/Hal/devices/testobj1", 
								      &error)) == NULL)
				return FALSE;
			printf ("SUCCESS110\n");

			psi_num_passed = 0;
			psi_num_elems = libhal_property_set_get_num_elems (pset);

			for (libhal_psi_init (&it, pset); libhal_psi_has_more (&it); libhal_psi_next (&it)) {
				type = libhal_psi_get_type (&it);
				key = libhal_psi_get_key (&it);

				switch (type) {
				case LIBHAL_PROPERTY_TYPE_STRING:
					if (strcmp (key, "info.udi") == 0) {
						if (strcmp (libhal_psi_get_string (&it), 
							    "/org/freedesktop/Hal/devices/testobj1") == 0) {
							psi_num_passed++;
						} else {
							printf ("fail on %s\n", key);
						}
					} else if (strcmp (key, "test.string") == 0) {
						if (strcmp (libhal_psi_get_string (&it), 
							    "fooooobar22") == 0) {
							psi_num_passed++;
						} else {
							printf ("fail on %s\n", key);
						}
					} else if (strcmp (key, "test.string2") == 0) {
						if (strcmp (libhal_psi_get_string (&it), 
							    "fooøةמ") == 0) {
							psi_num_passed++;
						} else {
							printf ("fail on %s\n", key);
						}
					}
					break;

				case LIBHAL_PROPERTY_TYPE_INT32:
					if (strcmp (key, "test.int") == 0) {
						if (libhal_psi_get_int (&it) == 42)
							psi_num_passed++;
						else
							printf ("fail on %s\n", key);
					}
					break;

				case LIBHAL_PROPERTY_TYPE_UINT64:
					if (strcmp (key, "test.uint64") == 0) {
						if (libhal_psi_get_uint64 (&it) == ((((dbus_uint64_t)1)<<35) + 5))
							psi_num_passed++;
						else
							printf ("fail on %s\n", key);
					}
					break;

				case LIBHAL_PROPERTY_TYPE_BOOLEAN:
					if (strcmp (key, "test.bool") == 0) {
						if (libhal_psi_get_bool (&it) == TRUE)
							psi_num_passed++;
						else
							printf ("fail on %s\n", key);
					}
					break;

				case LIBHAL_PROPERTY_TYPE_DOUBLE:
					if (strcmp (key, "test.double") == 0) {
						double val = 0.53434343;
						double val2;

						val2 = libhal_psi_get_double (&it);
						if (memcmp (&val, &val2, sizeof (double)) == 0)
							psi_num_passed++;
						else
							printf ("fail on %s\n", key);
					}
					break;

				case LIBHAL_PROPERTY_TYPE_STRLIST:
					if (strcmp (key, "test.strlist") == 0) {
						char **val;
					
						val = libhal_psi_get_strlist (&it);
						if (libhal_string_array_length (val) == 2 &&
						    strcmp (val[0], "foostrlist2") == 0 &&
						    strcmp (val[1], "foostrlist3") == 0 &&
						    val[2] == NULL)
							psi_num_passed++;
						else
							printf ("fail on %s\n", key);
					}
					break;

				default:
					printf ("    *** unknown type for key %s\n", key);
					break;
				}
			}
			libhal_free_property_set (pset);

			if (psi_num_passed != psi_num_elems) {
				printf ("FAILED111\n");			
				goto fail;
			}
			printf ("SUCCESS111\n");			


		} /* end libhal_test_psi */

	
		printf ("Passed all libhal tests\n");
		passed = TRUE;
		
	fail:
		if (dbus_error_is_set (&error))
			dbus_error_free (&error);
			
		send_tests_done (conn, passed);
		exit (1);

	} else {
		printf ("child pid=%d\n", child_pid);
	}
	return TRUE;
}
Beispiel #2
0
int
prt_dev_props(LibHalContext *hal_ctx, char *dev_name)
{
	LibHalPropertySet *props;
	LibHalPropertySetIterator it;
	DBusError error;
	int type;
	char *devfs_path;

	dbus_error_init(&error);

	if (!(props =
		libhal_device_get_all_properties(hal_ctx, dev_name, &error))) {
		fprintf(stderr, "%s: %s\n", error.name, error.message);
		dbus_error_free(&error);
		return (1);
	}

	devfs_path = libhal_device_get_property_string(hal_ctx,
			dev_name, "solaris.devfs_path", &error);
	if (devfs_path) {
		printf("devfs path:%s\n", devfs_path);
		libhal_free_string(devfs_path);
	}

	for (libhal_psi_init(&it, props); libhal_psi_has_more(&it);
			libhal_psi_next(&it)) {
		type = libhal_psi_get_type(&it);
		switch (type) {
			case LIBHAL_PROPERTY_TYPE_STRING:
				printf("%s:'%s'\n",
					libhal_psi_get_key(&it),
					libhal_psi_get_string(&it));
				break;
			case LIBHAL_PROPERTY_TYPE_INT32:
				printf("%s:%d\n",
					libhal_psi_get_key(&it),
					libhal_psi_get_int(&it));
				break;
			case LIBHAL_PROPERTY_TYPE_UINT64:
				printf("%s:%lld\n",
					libhal_psi_get_key(&it),
				(long long) libhal_psi_get_uint64(&it));
				break;
			case LIBHAL_PROPERTY_TYPE_DOUBLE:
				printf("%s:%g\n",
					libhal_psi_get_key(&it),
					libhal_psi_get_double(&it));
				break;
			case LIBHAL_PROPERTY_TYPE_BOOLEAN:
				printf("%s:%s\n",
				libhal_psi_get_key(&it),
				libhal_psi_get_bool(&it) ? "true" : "false");
				break;
			case LIBHAL_PROPERTY_TYPE_STRLIST:
				{
					char **strlist;

					printf("%s:{ ",
					libhal_psi_get_key(&it));
					strlist = libhal_psi_get_strlist(&it);
					while (*strlist) {
						printf("'%s'%s",
					*strlist, strlist[1] ? ", " : "");
						strlist++;
					}
					printf(" }\n");
				}
				break;
			default:
				printf("Unknown type:%d=0x%02x\n",
					type, type);
				break;
			}
	}

	libhal_free_property_set(props);
	printf("\n");
	dbus_error_free(&error);
	return (0);
}
Beispiel #3
0
/*
 * Dump all devices.
 */
int dump_devices(LibHalContext *hal_ctx, char *arg)
{
	int i;
	int num_devices;
	char **device_names;
	DBusError error;
	char *udi = NULL;

	if (arg) {
		if (*arg == '/') {
			udi = arg;
		} else {
#ifdef HAVE_ASPRINTF
			asprintf(&udi, "/org/freedesktop/Hal/devices/%s", arg);
#else
			udi = calloc(1, sizeof ("/org/freedesktop/Hal/devices/%s") + strlen(arg));
			sprintf(udi, "/org/freedesktop/Hal/devices/%s", arg);

#endif
		}
	}

	dbus_error_init(&error);

	if (!udi) {
		if (!(device_names = libhal_get_all_devices(hal_ctx, &num_devices, &error))) {
			fprintf(stderr, "Empty HAL device list.\n");
			LIBHAL_FREE_DBUS_ERROR (&error);
			return 31;
		}
	} else {
		device_names = calloc(2, sizeof *device_names);
		device_names[0] = strdup(udi);
		num_devices = 1;
	}

	for(i = 0; i < num_devices; i++) {
		LibHalPropertySet *props;
		LibHalPropertySetIterator it;
		int type;

		if (!(props = libhal_device_get_all_properties(hal_ctx, device_names[i], &error))) {
			fprintf(stderr, "%s: %s\n", error.name, error.message);
			dbus_error_init(&error);
			continue;
		}

		if (!udi)
			printf("%d: ", i);
		printf("udi = '%s'\n", device_names[i]);

		for(libhal_psi_init(&it, props); libhal_psi_has_more(&it); libhal_psi_next(&it)) {
			type = libhal_psi_get_type(&it);
			switch (type) {
			case LIBHAL_PROPERTY_TYPE_STRING:
				printf("  %s = '%s'  (string)\n",
					libhal_psi_get_key(&it),
					libhal_psi_get_string(&it)
				);
				break;
			case LIBHAL_PROPERTY_TYPE_INT32:
				printf("  %s = %d  (0x%x)  (int)\n",
					libhal_psi_get_key(&it),
					libhal_psi_get_int(&it),
					libhal_psi_get_int(&it)
				);
				break;
			case LIBHAL_PROPERTY_TYPE_UINT64:
				printf("  %s = %lld  (0x%llx)  (uint64)\n",
					libhal_psi_get_key(&it),
					(long long) libhal_psi_get_uint64(&it),
					(long long) libhal_psi_get_uint64(&it)
				);
				break;
			case LIBHAL_PROPERTY_TYPE_DOUBLE:
				printf("  %s = %g  (double)\n",
					libhal_psi_get_key(&it),
					libhal_psi_get_double(&it)
				);
				break;
			case LIBHAL_PROPERTY_TYPE_BOOLEAN:
				printf("  %s = %s  (bool)\n",
					libhal_psi_get_key(&it),
					libhal_psi_get_bool(&it) ? "true" : "false"
				);
				break;
			case LIBHAL_PROPERTY_TYPE_STRLIST:
				{
					char **strlist;

					printf ("  %s = { ", libhal_psi_get_key(&it));
					strlist = libhal_psi_get_strlist(&it);
					while (*strlist) {
						printf("'%s'%s", *strlist, strlist[1] ? ", " : "");
						strlist++;
					}
					printf(" } (string list)\n");
				}
				break;
			default:
				printf("Unknown type %d = 0x%02x\n", type, type);
				break;
			}
		}

		libhal_free_property_set(props);
		printf("\n");
	}

	libhal_free_string_array(device_names);
	dbus_error_free(&error);

	return 0;
}