/***************************************************************************
* CVSID: $Id$
*
* lshal.c : Show devices managed by HAL
*
* Copyright (C) 2003 David Zeuthen, <david@fubar.dk>
* Copyright (C) 2005 Pierre Ossman, <drzeus@drzeus.cx>
*
* Licensed under the Academic Free License version 2.1
*
* 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
**************************************************************************/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <getopt.h>
#include <glib.h>
#include <dbus/dbus-glib-lowlevel.h>
#include <dbus/dbus-glib.h>
#include <libhal.h>
#ifdef __SUNPRO_C
#endif
/**
* @defgroup HalLsHal List HAL devices
* @ingroup HalMisc
*
* @brief A commandline tool, lshal, for displaying and, optionally,
* monitor the devices managed by the HAL daemon. Uses libhal.
*
* @{
*/
/** Macro for terminating the program on an unrecoverable error */
#define DIE(expr) do {printf("*** [DIE] %s:%s():%d : ", __FILE__, __FUNCTION__, __LINE__); printf expr; printf("\n"); exit(1); } while(0)
struct Device {
char *name;
char *parent;
};
/** Generate a short name for a device
*
* @param udi Universal Device Id
*/
static const char *
{
}
/** Print all properties of a device
*
* @param udi Universal Device Id
*/
static void
{
int type;
dbus_error_init (&error);
/* NOTE : This may be NULL if the device was removed
* in the daemon; this is because
* hal_device_get_all_properties() is a in
* essence an IPC call and other stuff may
* be happening..
*/
return;
}
switch (type) {
printf (" %s = '%s' (string)\n",
libhal_psi_get_key (&it),
libhal_psi_get_string (&it));
break;
printf (" %s = %d (0x%x) (int)\n",
libhal_psi_get_key (&it),
libhal_psi_get_int (&it),
libhal_psi_get_int (&it));
break;
printf (" %s = %llu (0x%llx) (uint64)\n",
libhal_psi_get_key (&it),
(long long unsigned int) libhal_psi_get_uint64 (&it),
(long long unsigned int) libhal_psi_get_uint64 (&it));
break;
printf (" %s = %g (double)\n",
libhal_psi_get_key (&it),
libhal_psi_get_double (&it));
break;
printf (" %s = %s (bool)\n",
libhal_psi_get_key (&it),
"false");
break;
{
unsigned int i;
char **strlist;
for (i = 0; strlist[i] != 0; i++) {
printf (", ");
}
printf ("} (string list)\n");
break;
}
default:
break;
}
}
}
/** Dumps information about a single device
*
* @param udi Universal Device Id
*/
static void
{
dbus_error_init (&error);
return;
}
if (long_list) {
print_props (udi);
printf ("\n");
}
else
}
/** Dump all children of device
*
* @param udi Universal Device Id of parent
* @param num_devices Total number of devices in device list
* @param devices List of devices
* @param depth Current recursion depth
*/
static void
{
int i;
for (i = 0; i < num_devices; i++) {
if (!udi) {
continue;
}
else {
continue;
continue;
}
if (long_list)
else {
int j;
if (tree_view) {
for (j = 0;j < depth;j++)
printf(" ");
}
}
if (long_list) {
printf ("\n");
}
}
}
/** Dump all devices to stdout
*
*/
static void
dump_devices (void)
{
int i;
int num_devices;
char **device_names;
dbus_error_init (&error);
if (device_names == NULL) {
DIE (("Couldn't obtain list of devices\n"));
}
if (!devices) {
return;
}
for (i = 0;i < num_devices;i++) {
if (dbus_error_is_set (&error)) {
/* Free the error (which include a dbus_error_init())
This should prevent errors if a call above fails */
dbus_error_free (&error);
}
}
if (long_list) {
printf ("\n"
"Dumping %d device(s) from the Global Device List:\n"
"-------------------------------------------------\n",
}
for (i = 0;i < num_devices;i++) {
}
if (long_list) {
printf ("\n"
"Dumped %d device(s) from the Global Device List.\n"
"------------------------------------------------\n",
printf ("\n");
}
}
/** Invoked when a device is added to the Global Device List. Simply prints
* a message on stdout.
*
* @param udi Universal Device Id
*/
static void
const char *udi)
{
return;
if (long_list) {
print_props (udi);
} else
}
/** Invoked when a device is removed from the Global Device List. Simply
* prints a message on stdout.
*
* @param udi Universal Device Id
*/
static void
const char *udi)
{
return;
if (long_list)
else
}
/** Invoked when device in the Global Device List acquires a new capability.
* Prints the name of the capability to stdout.
*
* @param udi Universal Device Id
* @param capability Name of capability
*/
static void
const char *udi,
const char *capability)
{
return;
if (long_list) {
} else
}
/** Invoked when device in the Global Device List loses a capability.
* Prints the name of the capability to stdout.
*
* @param udi Universal Device Id
* @param capability Name of capability
*/
static void
const char *udi,
const char *capability)
{
return;
if (long_list) {
} else
}
/** Acquires and prints the value of of a property to stdout.
*
* @param udi Universal Device Id
* @param key Key of property
*/
static void
{
int type;
char *str;
dbus_error_init (&error);
switch (type) {
break;
{
}
break;
{
}
break;
break;
break;
{
unsigned int i;
char **strlist;
if (long_list)
printf ("*** new value: {");
else
printf ("{");
for (i = 0; strlist[i] != 0; i++) {
printf (", ");
}
if (long_list)
printf ("} (string list)\n");
else
printf ("}");
break;
}
default:
break;
}
if (dbus_error_is_set (&error))
dbus_error_free (&error);
}
/** Invoked when a property of a device in the Global Device List is
* changed, and we have we have subscribed to changes for that device.
*
* @param udi Univerisal Device Id
* @param key Key of property
*/
static void
const char *udi,
const char *key,
{
return;
if (long_list) {
printf ("*** lshal: property_modified, udi=%s, key=%s\n",
printf (" is_removed=%s, is_added=%s\n",
if (!is_removed)
printf ("\n");
} else {
if (is_removed)
printf ("removed");
else {
printf ("= ");
if (is_added)
printf (" (new)");
}
printf ("\n");
}
}
/** Invoked when a property of a device in the Global Device List is
* changed, and we have we have subscribed to changes for that device.
*
* @param udi Univerisal Device Id
* @param condition_name Name of condition
* @param message D-BUS message with parameters
*/
static void
const char *udi,
const char *condition_name,
const char *condition_details)
{
return;
if (long_list) {
printf ("\n");
} else {
}
}
/** Print out program usage.
*
* @param argc Number of arguments given to program
* @param argv Arguments given to program
*/
static void
{
"\n"
"Options:\n"
" -m, --monitor Monitor device list\n"
" -s, --short short output (print only nonstatic part of udi)\n"
" -l, --long Long output\n"
" -t, --tree Tree view\n"
" -u, --show <udi> Show only the specified device\n"
"\n"
" -h, --help Show this information and exit\n"
" -V, --version Print version number\n"
"\n"
"Without any given options lshal will start with option --long."
"\n"
"Shows all devices and their properties. If the --monitor option is given\n"
"then the device list and all devices are monitored for changes.\n"
"\n");
}
/** Entry point
*
* @param argc Number of arguments given to program
* @param argv Arguments given to program
* @return Return code
*/
int
{
if (argc == 1) {
/* This is the default case lshal without any options */
}
else {
};
while (1) {
int c;
if (c == -1) {
/* this should happen e.g. if 'lshal -' and this is incorrect/incomplete option */
return 1;
}
break;
}
switch (c) {
case 'm':
do_monitor = TRUE;
break;
case 'l':
break;
case 's':
short_list = TRUE;
break;
case 't':
break;
case 'u':
else {
}
break;
case 'h':
case 'U':
return 0;
case 'V':
return 0;
default:
return 1;
}
}
}
if (do_monitor)
else
dbus_error_init (&error);
return 1;
}
if (do_monitor)
return 1;
}
return 1;
}
if (dbus_error_is_set(&error)) {
}
"Normally this means the HAL daemon (hald) is not running or not ready.\n");
return 1;
}
if (show_device)
else if (!do_monitor)
dump_devices ();
/* run the main loop only if we should monitor */
dump_devices ();
return 1;
}
printf ("\nStart monitoring devicelist:\n"
"-------------------------------------------------\n");
}
if (show_device)
return 0;
}
/**
* @}
*/