gudevclient.c revision bb061708d5aa83579f213bdfb67253f7027217c3
/* -*- Mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
*
* Copyright (C) 2008-2010 David Zeuthen <davidz@redhat.com>
*
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; 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 <stdlib.h>
#include <string.h>
#include "gudevclient.h"
#include "gudevdevice.h"
#include "gudevmarshal.h"
#include "gudevprivate.h"
/**
* SECTION:gudevclient
* @short_description: Query devices and listen to uevents
*
* #GUdevClient is used to query information about devices on a Linux
* system from the Linux kernel and the udev device
* manager.
*
* Device information is retrieved from the kernel (through the
* <literal>sysfs</literal> filesystem) and the udev daemon (through a
* <literal>tmpfs</literal> filesystem) and presented through
* #GUdevDevice objects. This means that no blocking IO ever happens
* (in both cases, we are essentially just reading data from kernel
* memory) and as such there are no asynchronous versions of the
* provided methods.
*
* To get #GUdevDevice objects, use
* g_udev_client_query_by_subsystem(),
* g_udev_client_query_by_device_number(),
* g_udev_client_query_by_device_file(),
* g_udev_client_query_by_sysfs_path(),
* g_udev_client_query_by_subsystem_and_name()
* or the #GUdevEnumerator type.
*
* To listen to uevents, connect to the #GUdevClient::uevent signal.
*/
struct _GUdevClientPrivate
{
struct udev_monitor *monitor;
gchar **subsystems;
};
enum
{
};
enum
{
};
/* ---------------------------------------------------------------------------------------------------- */
static gboolean
{
struct udev_device *udevice;
goto out;
goto out;
0,
device);
out:
return TRUE;
}
static void
{
{
}
{
}
{
}
}
static void
{
switch (prop_id)
{
case PROP_SUBSYSTEMS:
break;
default:
break;
}
}
static void
{
switch (prop_id)
{
case PROP_SUBSYSTEMS:
break;
default:
break;
}
}
static void
{
guint n;
/* connect to event source */
//g_debug ("ss = %p", client->priv->subsystems);
{
/* install subsystem filters to only wake up for certain events */
{
gchar *s;
//g_debug ("s = '%s'", subsystem);
if (s != NULL)
{
devtype = s + 1;
*s = '\0';
}
}
/* listen to events, and buffer them */
{
}
else
{
}
}
}
static void
{
/**
* GUdevClient:subsystems:
*
* The subsystems to listen for uevents on.
*
* To listen for only a specific DEVTYPE for a given SUBSYSTEM, use
* where SUBSYSTEM is usb and DEVTYPE is usb_interface, use
* "usb/usb_interface".
*
* If this property is %NULL, then no events will be reported. If
* it's the empty array, events from all subsystems will be
* reported.
*/
g_param_spec_boxed ("subsystems",
"The subsystems to listen for changes on",
"The subsystems to listen for changes on",
/**
* GUdevClient::uevent:
* @client: The #GUdevClient receiving the event.
* @action: The action for the uevent e.g. "add", "remove", "change", "move", etc.
* @device: Details about the #GUdevDevice the event is for.
*
* Emitted when @client receives an uevent.
*
* This signal is emitted in the
* <link linkend="g-main-context-push-thread-default">thread-default main loop</link>
* of the thread that @client was created in.
*/
NULL,
NULL,
2,
}
static void
{
}
/**
* g_udev_client_new:
* @subsystems: (array zero-terminated=1) (element-type utf8) (transfer none) (allow-none): A %NULL terminated string array of subsystems to listen for uevents on, %NULL to not listen on uevents at all, or an empty array to listen to uevents on all subsystems. See the documentation for the #GUdevClient:subsystems property for details on this parameter.
*
* Constructs a #GUdevClient object that can be used to query
* information about devices. Connect to the #GUdevClient::uevent
* signal to listen for uevents. Note that signals are emitted in the
* <link linkend="g-main-context-push-thread-default">thread-default main loop</link>
* of the thread that you call this constructor from.
*
* Returns: A new #GUdevClient object. Free with g_object_unref().
*/
{
}
/**
* g_udev_client_query_by_subsystem:
* @client: A #GUdevClient.
* @subsystem: (allow-none): The subsystem to get devices for or %NULL to get all devices.
*
* Gets all devices belonging to @subsystem.
*
* Returns: (element-type GUdevDevice) (transfer full): A list of #GUdevDevice objects. The caller should free the result by using g_object_unref() on each element in the list and then g_list_free() on the list.
*/
GList *
{
struct udev_enumerate *enumerate;
struct udev_list_entry *l, *devices;
/* prepare a device scan */
/* filter for subsystem */
/* retrieve the list */
/* add devices to the list */
{
struct udev_device *udevice;
udev_list_entry_get_name (l));
continue;
}
return ret;
}
/**
* g_udev_client_query_by_device_number:
* @client: A #GUdevClient.
* @type: A value from the #GUdevDeviceType enumeration.
* @number: A device number.
*
* Looks up a device for a type and device number.
*
* Returns: (transfer full): A #GUdevDevice object or %NULL if the device was not found. Free with g_object_unref().
*/
{
struct udev_device *udevice;
goto out;
out:
return device;
}
/**
* g_udev_client_query_by_device_file:
* @client: A #GUdevClient.
* @device_file: A device file.
*
* Looks up a device for a device file.
*
* Returns: (transfer full): A #GUdevDevice object or %NULL if the device was not found. Free with g_object_unref().
*/
const gchar *device_file)
{
goto out;
goto out;
out:
return device;
}
/**
* g_udev_client_query_by_sysfs_path:
* @client: A #GUdevClient.
* @sysfs_path: A sysfs path.
*
* Looks up a device for a sysfs path.
*
* Returns: (transfer full): A #GUdevDevice object or %NULL if the device was not found. Free with g_object_unref().
*/
const gchar *sysfs_path)
{
struct udev_device *udevice;
goto out;
out:
return device;
}
/**
* g_udev_client_query_by_subsystem_and_name:
* @client: A #GUdevClient.
* @subsystem: A subsystem name.
* @name: The name of the device.
*
* Looks up a device for a subsystem and name.
*
* Returns: (transfer full): A #GUdevDevice object or %NULL if the device was not found. Free with g_object_unref().
*/
{
struct udev_device *udevice;
goto out;
out:
return device;
}
struct udev *
{
}