hal/tools Makefile.am, 1.14, 1.15 hal_find_by_capability.c, NONE, 1.1 hal_find_by_property.c, NONE, 1.1 hal_get_property.c, 1.10, 1.11

David Zeuthen david at freedesktop.org
Fri May 13 08:56:25 PDT 2005


Update of /cvs/hal/hal/tools
In directory gabe:/tmp/cvs-serv8700/tools

Modified Files:
	Makefile.am hal_get_property.c 
Added Files:
	hal_find_by_capability.c hal_find_by_property.c 
Log Message:
2005-05-13  David Zeuthen  <davidz at redhat.com>

	* tools/hal_find_by_capability.c: New file

	* tools/hal_find_by_property.c: New file

	* tools/hal_get_property.c (usage): Don't claim we support we the
	--quiet option because we don't

	* tools/Makefile.am: Add build rules for hal-find-by-capability and
	hal-find-by-property.



Index: Makefile.am
===================================================================
RCS file: /cvs/hal/hal/tools/Makefile.am,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- Makefile.am	12 May 2005 21:14:17 -0000	1.14
+++ Makefile.am	13 May 2005 15:56:23 -0000	1.15
@@ -9,7 +9,7 @@
 	-I$(top_srcdir) -I$(top_srcdir)/libhal \
 	@PACKAGE_CFLAGS@
 
-bin_PROGRAMS = lshal hal-get-property hal-set-property
+bin_PROGRAMS = lshal hal-get-property hal-set-property hal-find-by-capability hal-find-by-property
 
 if FSTAB_SYNC_ENABLED
 sbin_PROGRAMS = fstab-sync
@@ -24,6 +24,12 @@
 hal_set_property_SOURCES = hal_set_property.c
 hal_set_property_LDADD = @DBUS_LIBS@ $(top_builddir)/libhal/libhal.la
 
+hal_find_by_capability_SOURCES = hal_find_by_capability.c
+hal_find_by_capability_LDADD = @DBUS_LIBS@ $(top_builddir)/libhal/libhal.la
+
+hal_find_by_property_SOURCES = hal_find_by_property.c
+hal_find_by_property_LDADD = @DBUS_LIBS@ $(top_builddir)/libhal/libhal.la
+
 if FSTAB_SYNC_ENABLED
 fstab_sync_SOURCES = fstab-sync.c
 fstab_sync_LDADD = -lpopt $(top_builddir)/libhal/libhal.la $(top_builddir)/libhal-storage/libhal-storage.la

--- NEW FILE: hal_find_by_capability.c ---
/***************************************************************************
 * CVSID: $Id: hal_find_by_capability.c,v 1.1 2005/05/13 15:56:23 david Exp $
 *
 * hal_find_by_capability.c : Find hal devices
 *
 * Copyright (C) 2005 David Zeuthen, <david at fubar.dk>
 *
 * Licensed under the Academic Free License version 2.0
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 **************************************************************************/


#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <getopt.h>

#include <libhal/libhal.h>


/** Print out program usage.
 *
 *  @param  argc                Number of arguments given to program
 *  @param  argv                Arguments given to program
 */
static void
usage (int argc, char *argv[])
{
	fprintf (stderr,
 "\n"
 "usage : hal-find-by-capability --capability <capability>\n"
 "                              [--help] [--verbose] [--version]\n");
	fprintf (stderr,
 "\n"
 "        --capability     HAL Device Capability to search for\n"
 "        --verbose        Be verbose\n"
 "        --version        Show version and exit\n"
 "        --help           Show this information and exit\n"
 "\n"
 "This program prints the Unique Device Identifiers for HAL device\n"
 "objects of a given capability on stdout and exits with exit code 0\n"
 "If there is an error, the program exits with an exit code different\n"
 "from 0.\n"
 "\n");
}

/** Entry point
 *
 *  @param  argc                Number of arguments given to program
 *  @param  argv                Arguments given to program
 *  @return                     Return code
 */
int
main (int argc, char *argv[])
{
	int i;
	int num_udis;
	char **udis;
	char *capability = NULL;
	dbus_bool_t is_verbose = FALSE;
	dbus_bool_t is_version = FALSE;
	DBusError error;
	LibHalContext *hal_ctx;

	if (argc <= 1) {
		usage (argc, argv);
		return 1;
	}

	while (1) {
		int c;
		int option_index = 0;
		const char *opt;
		static struct option long_options[] = {
			{"capability", 1, NULL, 0},
			{"verbose", 0, NULL, 0},
			{"version", 0, NULL, 0},
			{"help", 0, NULL, 0},
			{NULL, 0, NULL, 0}
		};

		c = getopt_long (argc, argv, "",
				 long_options, &option_index);
		if (c == -1)
			break;

		switch (c) {
		case 0:
			opt = long_options[option_index].name;

			if (strcmp (opt, "help") == 0) {
				usage (argc, argv);
				return 0;
			} else if (strcmp (opt, "verbose") == 0) {
				is_verbose = TRUE;
			} else if (strcmp (opt, "version") == 0) {
				is_version = TRUE;
			} else if (strcmp (opt, "capability") == 0) {
				capability = strdup (optarg);
			}
			break;

		default:
			usage (argc, argv);
			return 1;
			break;
		}
	}

	if (is_version) {
		printf ("hal-find-by-capability " PACKAGE_VERSION "\n");
		return 0;
	}

	if (capability == NULL) {
		usage (argc, argv);
		return 1;
	}

	dbus_error_init (&error);	
	if ((hal_ctx = libhal_ctx_new ()) == NULL) {
		fprintf (stderr, "error: libhal_ctx_new\n");
		return 1;
	}
	if (!libhal_ctx_set_dbus_connection (hal_ctx, dbus_bus_get (DBUS_BUS_SYSTEM, &error))) {
		fprintf (stderr, "error: libhal_ctx_set_dbus_connection: %s: %s\n", error.name, error.message);
		return 1;
	}
	if (!libhal_ctx_init (hal_ctx, &error)) {
		fprintf (stderr, "error: libhal_ctx_init: %s: %s\n", error.name, error.message);
		return 1;
	}


	udis = libhal_find_device_by_capability (hal_ctx, capability, &num_udis, &error);

	if (dbus_error_is_set (&error)) {
		fprintf (stderr, "error: %s: %s\n", error.name, error.message);
		return 1;
	}

	if (is_verbose)
		printf ("Found %d device objects of capability '%s'\n", num_udis, capability);

	if (num_udis == 0) {
		return 1;
	}

	for (i = 0; i < num_udis; i++) {
		printf ("%s\n", udis[i]);
	}

	libhal_free_string_array (udis);

	return 0;
}

/**
 * @}
 */

--- NEW FILE: hal_find_by_property.c ---
/***************************************************************************
 * CVSID: $Id: hal_find_by_property.c,v 1.1 2005/05/13 15:56:23 david Exp $
 *
 * hal_find_by_property.c : Find hal devices
 *
 * Copyright (C) 2005 David Zeuthen, <david at fubar.dk>
 *
 * Licensed under the Academic Free License version 2.0
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 **************************************************************************/


#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <getopt.h>

#include <libhal/libhal.h>


/** Print out program usage.
 *
 *  @param  argc                Number of arguments given to program
 *  @param  argv                Arguments given to program
 */
static void
usage (int argc, char *argv[])
{
	fprintf (stderr,
 "\n"
 "usage : hal-find-by-property --key <key> --string <value>\n"
 "                              [--help] [--verbose] [--version]\n");

/** @todo support other property types a'la hal-[get|set]-property */

	fprintf (stderr,
 "\n"
 "        --key            Key of the property to check\n"
 "        --string         String value of property\n"
 "        --verbose        Be verbose\n"
 "        --version        Show version and exit\n"
 "        --help           Show this information and exit\n"
 "\n"
 "This program prints the Unique Device Identifiers for HAL device\n"
 "objects where a given property assumes a given value. On success\n"
 "the program exists with exit code 0. If there is an error, the\n"
 "program exits with an exit code different from 0.\n"
 "\n");
}

/** Entry point
 *
 *  @param  argc                Number of arguments given to program
 *  @param  argv                Arguments given to program
 *  @return                     Return code
 */
int
main (int argc, char *argv[])
{
	int i;
	int num_udis;
	char **udis;
	char *key = NULL;
	char *value = NULL;
	dbus_bool_t is_verbose = FALSE;
	dbus_bool_t is_version = FALSE;
	DBusError error;
	LibHalContext *hal_ctx;

	if (argc <= 1) {
		usage (argc, argv);
		return 1;
	}

	while (1) {
		int c;
		int option_index = 0;
		const char *opt;
		static struct option long_options[] = {
			{"key", 1, NULL, 0},
			{"string", 1, NULL, 0},
			{"verbose", 0, NULL, 0},
			{"version", 0, NULL, 0},
			{"help", 0, NULL, 0},
			{NULL, 0, NULL, 0}
		};

		c = getopt_long (argc, argv, "",
				 long_options, &option_index);
		if (c == -1)
			break;

		switch (c) {
		case 0:
			opt = long_options[option_index].name;

			if (strcmp (opt, "help") == 0) {
				usage (argc, argv);
				return 0;
			} else if (strcmp (opt, "verbose") == 0) {
				is_verbose = TRUE;
			} else if (strcmp (opt, "version") == 0) {
				is_version = TRUE;
			} else if (strcmp (opt, "key") == 0) {
				key = strdup (optarg);
			} else if (strcmp (opt, "string") == 0) {
				value = strdup (optarg);
			}
			break;

		default:
			usage (argc, argv);
			return 1;
			break;
		}
	}

	if (is_version) {
		printf ("hal-find-by-property " PACKAGE_VERSION "\n");
		return 0;
	}

	if (key == NULL || value == NULL) {
		usage (argc, argv);
		return 1;
	}

	dbus_error_init (&error);	
	if ((hal_ctx = libhal_ctx_new ()) == NULL) {
		fprintf (stderr, "error: libhal_ctx_new\n");
		return 1;
	}
	if (!libhal_ctx_set_dbus_connection (hal_ctx, dbus_bus_get (DBUS_BUS_SYSTEM, &error))) {
		fprintf (stderr, "error: libhal_ctx_set_dbus_connection: %s: %s\n", error.name, error.message);
		return 1;
	}
	if (!libhal_ctx_init (hal_ctx, &error)) {
		fprintf (stderr, "error: libhal_ctx_init: %s: %s\n", error.name, error.message);
		return 1;
	}


	udis = libhal_manager_find_device_string_match (hal_ctx, key, value, &num_udis, &error);

	if (dbus_error_is_set (&error)) {
		fprintf (stderr, "error: %s: %s\n", error.name, error.message);
		return 1;
	}

	if (is_verbose)
		printf ("Found %d device objects with string property %s = '%s'\n", num_udis, key, value);

	if (num_udis == 0) {
		return 1;
	}

	for (i = 0; i < num_udis; i++) {
		printf ("%s\n", udis[i]);
	}

	libhal_free_string_array (udis);

	return 0;
}

/**
 * @}
 */

Index: hal_get_property.c
===================================================================
RCS file: /cvs/hal/hal/tools/hal_get_property.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- hal_get_property.c	13 Mar 2005 03:39:53 -0000	1.10
+++ hal_get_property.c	13 May 2005 15:56:23 -0000	1.11
@@ -57,7 +57,7 @@
 	fprintf (stderr,
  "\n"
  "usage : hal-get-property --udi <udi> --key <key> \n"
- "                        [--hex] [--quiet] [--help] [--verbose] [--version]\n");
+ "                        [--hex] [--help] [--verbose] [--version]\n");
 	fprintf (stderr,
  "\n"
  "        --udi            Unique Device Id\n"




More information about the hal-commit mailing list