src/gudev: remove Gobject libudev support.

Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
This commit is contained in:
Anthony G. Basile 2015-07-20 08:41:41 -04:00
parent 1b6370e74b
commit 252150e181
22 changed files with 0 additions and 3015 deletions

7
.gitignore vendored
View File

@ -35,13 +35,6 @@ src/mtd_probe/mtd_probe
src/scsi_id/scsi_id
src/v4l_id/v4l_id
src/gudev/gudevenumtypes.c
src/gudev/gudevenumtypes.h
src/gudev/gudevmarshal.c
src/gudev/gudevmarshal.h
src/gudev/GUdev-1.0.gir
src/gudev/GUdev-1.0.typelib
src/udev/keyboard-keys-from-name.gperf
src/udev/keyboard-keys-from-name.h
src/udev/keyboard-keys-to-name.h

View File

@ -182,9 +182,6 @@ AC_SUBST([udevrulesdir],[${udevlibexecdir}/rules.d])
AC_SUBST([pkgconfiglibdir], [${libdir}/pkgconfig])
AC_SUBST([sharepkgconfigdir],[${datadir}/pkgconfig])
# gudev paths
AC_SUBST([libgudev_includedir],[${includedir}/gudev-1.0/gudev])
# introspection paths
AC_SUBST([girdir], [${datadir}/gir-1.0])
AC_SUBST([typelibsdir], [${libdir}/girepository-1.0])
@ -236,13 +233,6 @@ AC_CHECK_DECL([unshare],
[#include <syscall.h>])],
[#include <sched.h>])
# ------------------------------------------------------------------------------
AC_ARG_ENABLE([gudev],
AS_HELP_STRING([--disable-gudev], [disable Gobject libudev support @<:@default=enabled@:>@]),
[], [enable_gudev=yes])
AS_IF([test "x$enable_gudev" = "xyes"], [ PKG_CHECK_MODULES([GLIB], [glib-2.0 >= 2.22.0 gobject-2.0 >= 2.22.0]) ])
AM_CONDITIONAL([ENABLE_GUDEV], [test "x$enable_gudev" = "xyes"])
# ------------------------------------------------------------------------------
AC_PATH_TOOL(GPERF, gperf)
if test -z "$GPERF" ; then
@ -287,8 +277,6 @@ AC_CONFIG_FILES([Makefile
src/mtd_probe/Makefile
src/scsi_id/Makefile
src/v4l_id/Makefile
src/gudev/Makefile
src/gudev/gudev-1.0.pc
src/shared/Makefile
src/libudev/Makefile
src/libudev/libudev.pc
@ -326,8 +314,6 @@ AC_MSG_RESULT([
pkgconfiglibdir: ${libdir}/pkgconfig
sharepkgconfigdir ${datadir}/pkgconfig
libgudev_includedir ${includedir}/gudev-1.0/gudev
girdir ${datadir}/gir-1.0
typelibsdir ${libdir}/girepository-1.0
])

View File

@ -13,8 +13,3 @@ SUBDIRS += \
mtd_probe \
scsi_id \
v4l_id
if ENABLE_GUDEV
SUBDIRS += \
gudev
endif

View File

@ -1,169 +0,0 @@
ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
LIBGUDEV_CURRENT=2
LIBGUDEV_REVISION=0
LIBGUDEV_AGE=2
libgudev_include_HEADERS = \
gudev.h \
gudevenums.h \
gudevenumtypes.h \
gudevtypes.h \
gudevclient.h \
gudevdevice.h \
gudevenumerator.h
EXTRA_DIST = \
gudev-1.0.pc.in \
gudevmarshal.list \
gudevprivate.h \
gudevenumtypes.h.template \
gudevenumtypes.c.template \
gjs-example.js \
seed-example-enum.js \
seed-example.js
lib_LTLIBRARIES = \
libgudev-1.0.la
pkgconfiglib_DATA = \
gudev-1.0.pc
CLEANFILES = \
gudev-1.0.pc
libgudev_1_0_la_SOURCES = \
libgudev-1.0.sym \
gudevenumtypes.c\
gudevclient.c \
gudevdevice.c \
gudevenumerator.c
nodist_libgudev_1_0_la_SOURCES = \
gudevmarshal.c
BUILT_SOURCES = \
gudevenumtypes.h\
gudevmarshal.h \
$(nodist_libgudev_1_0_la_SOURCES)
libgudev_1_0_la_CPPFLAGS = \
$(AM_CPPFLAGS) \
-I$(top_srcdir)/src\
-I$(top_builddir)/src\
-I$(top_srcdir)/src/libudev \
-I$(top_builddir)/src/gudev \
-I$(top_srcdir)/src/gudev \
-D_POSIX_PTHREAD_SEMANTICS -D_REENTRANT \
-D_GUDEV_COMPILATION \
-DG_LOG_DOMAIN=\"GUdev\"
libgudev_1_0_la_CFLAGS = \
$(AM_CFLAGS) \
-fvisibility=default \
$(GLIB_CFLAGS)
libgudev_1_0_la_LIBADD = \
$(top_builddir)/src/libudev/libudev.la \
$(GLIB_LIBS)
libgudev_1_0_la_LDFLAGS = \
$(AM_LDFLAGS) \
-version-info $(LIBGUDEV_CURRENT):$(LIBGUDEV_REVISION):$(LIBGUDEV_AGE) \
-export-dynamic \
-no-undefined \
-Wl,--version-script=$(top_srcdir)/src/gudev/libgudev-1.0.sym
gudevmarshal.h: gudevmarshal.list
$(AM_V_at)$(MKDIR_P) $(dir $@)
$(AM_V_GEN)glib-genmarshal $< --prefix=g_udev_marshal --header > $@
gudevmarshal.c: gudevmarshal.list
$(AM_V_at)$(MKDIR_P) $(dir $@)
$(AM_V_GEN)echo '#include "gudevmarshal.h"' > $@ && \
glib-genmarshal $< --prefix=g_udev_marshal --body >> $@
gudevenumtypes.%: gudevenumtypes.%.template gudevenums.h
$(AM_V_at)$(MKDIR_P) $(dir $@)
$(AM_V_GEN)glib-mkenums --template $^ > $@
CLEANFILES += \
gudevmarshal.h \
gudevmarshal.c \
gudevenumtypes.h \
gudevenumtypes.c
if HAVE_INTROSPECTION
-include $(INTROSPECTION_MAKEFILE)
GUdev-1.0.gir: \
libgudev-1.0.la
GUdev_1_0_gir_INCLUDES = \
GObject-2.0
GUdev_1_0_gir_CFLAGS = \
$(INCLUDES) \
-D_GUDEV_COMPILATION \
-D_GUDEV_WORK_AROUND_DEV_T_BUG \
-I$(top_srcdir)/src \
-I$(top_builddir)/src \
-I$(top_srcdir)/src/gudev \
-I$(top_builddir)/src/gudev
GUdev_1_0_gir_LIBS = \
$(top_builddir)/src/gudev/libgudev-1.0.la \
$(top_builddir)/src/udev/libudev-core.la
GUdev_1_0_gir_SCANNERFLAGS = \
--pkg-export=gudev-1.0 \
--warn-all
GUdev_1_0_gir_FILES = \
gudev.h \
gudevtypes.h \
gudevenums.h \
gudevenumtypes.h \
gudevclient.h \
gudevdevice.h \
gudevenumerator.h \
gudevclient.c \
gudevdevice.c \
gudevenumerator.c
INTROSPECTION_GIRS = \
GUdev-1.0.gir
INTROSPECTION_SCANNER_ARGS = \
--c-include=gudev.h
gir_DATA = \
GUdev-1.0.gir
typelibs_DATA = \
GUdev-1.0.typelib
CLEANFILES += \
$(gir_DATA) $(typelibs_DATA)
endif # HAVE_INTROSPECTION
# move lib from $(libdir) to $(rootlibdir) and update devel link, if needed
libgudev-install-move-hook:
if test "$(libdir)" != "$(rootlibdir)"; then \
$(MKDIR_P) $(DESTDIR)$(rootlibdir) && \
so_img_name=$$(readlink $(DESTDIR)$(libdir)/libgudev-1.0.so) && \
so_img_rel_target_prefix=$$(echo $(libdir) | sed 's,\(^/\|\)[^/][^/]*,..,g') && \
ln -sf $$so_img_rel_target_prefix$(rootlibdir)/$$so_img_name $(DESTDIR)$(libdir)/libgudev-1.0.so && \
mv $(DESTDIR)$(libdir)/libgudev-1.0.so.* $(DESTDIR)$(rootlibdir); \
fi
libgudev-uninstall-move-hook:
rm -f $(DESTDIR)$(rootlibdir)/libgudev-1.0.so*
INSTALL_EXEC_HOOKS = \
libgudev-install-move-hook
UNINSTALL_EXEC_HOOKS = \
libgudev-uninstall-move-hook

View File

@ -1,75 +0,0 @@
#!/usr/bin/env gjs-console
// This currently depends on the following patches to gjs
//
// http://bugzilla.gnome.org/show_bug.cgi?id=584558
// http://bugzilla.gnome.org/show_bug.cgi?id=584560
// http://bugzilla.gnome.org/show_bug.cgi?id=584568
const GUdev = imports.gi.GUdev;
const Mainloop = imports.mainloop;
function print_device (device) {
print (" subsystem: " + device.get_subsystem ());
print (" devtype: " + device.get_devtype ());
print (" name: " + device.get_name ());
print (" number: " + device.get_number ());
print (" sysfs_path: " + device.get_sysfs_path ());
print (" driver: " + device.get_driver ());
print (" action: " + device.get_action ());
print (" seqnum: " + device.get_seqnum ());
print (" device type: " + device.get_device_type ());
print (" device number: " + device.get_device_number ());
print (" device file: " + device.get_device_file ());
print (" device file symlinks: " + device.get_device_file_symlinks ());
print (" foo: " + device.get_sysfs_attr_as_strv ("stat"));
var keys = device.get_property_keys ();
for (var n = 0; n < keys.length; n++) {
print (" " + keys[n] + "=" + device.get_property (keys[n]));
}
}
function on_uevent (client, action, device) {
print ("action " + action + " on device " + device.get_sysfs_path());
print_device (device);
print ("");
}
var client = new GUdev.Client ({subsystems: ["block", "usb/usb_interface"]});
client.connect ("uevent", on_uevent);
var block_devices = client.query_by_subsystem ("block");
for (var n = 0; n < block_devices.length; n++) {
print ("block device: " + block_devices[n].get_device_file ());
}
var d;
d = client.query_by_device_number (GUdev.DeviceType.BLOCK, 0x0810);
if (d == null) {
print ("query_by_device_number 0x810 -> null");
} else {
print ("query_by_device_number 0x810 -> " + d.get_device_file ());
var dd = d.get_parent_with_subsystem ("usb", null);
print_device (dd);
print ("--------------------------------------------------------------------------");
while (d != null) {
print_device (d);
print ("");
d = d.get_parent ();
}
}
d = client.query_by_sysfs_path ("/sys/block/sda/sda1");
print ("query_by_sysfs_path (\"/sys/block/sda1\") -> " + d.get_device_file ());
d = client.query_by_subsystem_and_name ("block", "sda2");
print ("query_by_subsystem_and_name (\"block\", \"sda2\") -> " + d.get_device_file ());
d = client.query_by_device_file ("/dev/sda");
print ("query_by_device_file (\"/dev/sda\") -> " + d.get_device_file ());
d = client.query_by_device_file ("/dev/block/8:0");
print ("query_by_device_file (\"/dev/block/8:0\") -> " + d.get_device_file ());
Mainloop.run('udev-example');

View File

@ -1,11 +0,0 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
Name: gudev-1.0
Description: GObject bindings for libudev
Version: @UDEV_VERSION@
Requires: glib-2.0, gobject-2.0
Libs: -L${libdir} -lgudev-1.0
Cflags: -I${includedir}/gudev-1.0

View File

@ -1,32 +0,0 @@
/* -*- Mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
*
* Copyright (C) 2008 David Zeuthen <davidz@redhat.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef __G_UDEV_H__
#define __G_UDEV_H__
#define _GUDEV_INSIDE_GUDEV_H
#include <gudev/gudevenums.h>
#include <gudev/gudevenumtypes.h>
#include <gudev/gudevtypes.h>
#include <gudev/gudevclient.h>
#include <gudev/gudevdevice.h>
#include <gudev/gudevenumerator.h>
#undef _GUDEV_INSIDE_GUDEV_H
#endif /* __G_UDEV_H__ */

View File

@ -1,532 +0,0 @@
/* -*- Mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
*
* Copyright (C) 2008-2010 David Zeuthen <davidz@redhat.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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
{
GSource *watch_source;
struct udev *udev;
struct udev_monitor *monitor;
gchar **subsystems;
};
enum
{
PROP_0,
PROP_SUBSYSTEMS,
};
enum
{
UEVENT_SIGNAL,
LAST_SIGNAL,
};
static guint signals[LAST_SIGNAL] = { 0 };
G_DEFINE_TYPE (GUdevClient, g_udev_client, G_TYPE_OBJECT)
/* ---------------------------------------------------------------------------------------------------- */
static gboolean
monitor_event (GIOChannel *source,
GIOCondition condition,
gpointer data)
{
GUdevClient *client = (GUdevClient *) data;
GUdevDevice *device;
struct udev_device *udevice;
if (client->priv->monitor == NULL)
goto out;
udevice = udev_monitor_receive_device (client->priv->monitor);
if (udevice == NULL)
goto out;
device = _g_udev_device_new (udevice);
udev_device_unref (udevice);
g_signal_emit (client,
signals[UEVENT_SIGNAL],
0,
g_udev_device_get_action (device),
device);
g_object_unref (device);
out:
return TRUE;
}
static void
g_udev_client_finalize (GObject *object)
{
GUdevClient *client = G_UDEV_CLIENT (object);
if (client->priv->watch_source != NULL)
{
g_source_destroy (client->priv->watch_source);
client->priv->watch_source = NULL;
}
if (client->priv->monitor != NULL)
{
udev_monitor_unref (client->priv->monitor);
client->priv->monitor = NULL;
}
if (client->priv->udev != NULL)
{
udev_unref (client->priv->udev);
client->priv->udev = NULL;
}
g_strfreev (client->priv->subsystems);
if (G_OBJECT_CLASS (g_udev_client_parent_class)->finalize != NULL)
G_OBJECT_CLASS (g_udev_client_parent_class)->finalize (object);
}
static void
g_udev_client_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GUdevClient *client = G_UDEV_CLIENT (object);
switch (prop_id)
{
case PROP_SUBSYSTEMS:
if (client->priv->subsystems != NULL)
g_strfreev (client->priv->subsystems);
client->priv->subsystems = g_strdupv (g_value_get_boxed (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
g_udev_client_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GUdevClient *client = G_UDEV_CLIENT (object);
switch (prop_id)
{
case PROP_SUBSYSTEMS:
g_value_set_boxed (value, client->priv->subsystems);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
g_udev_client_constructed (GObject *object)
{
GUdevClient *client = G_UDEV_CLIENT (object);
GIOChannel *channel;
guint n;
client->priv->udev = udev_new ();
/* connect to event source */
client->priv->monitor = udev_monitor_new_from_netlink (client->priv->udev, "udev");
//g_debug ("ss = %p", client->priv->subsystems);
if (client->priv->subsystems != NULL)
{
/* install subsystem filters to only wake up for certain events */
for (n = 0; client->priv->subsystems[n] != NULL; n++)
{
gchar *subsystem;
gchar *devtype;
gchar *s;
subsystem = g_strdup (client->priv->subsystems[n]);
devtype = NULL;
//g_debug ("s = '%s'", subsystem);
s = strstr (subsystem, "/");
if (s != NULL)
{
devtype = s + 1;
*s = '\0';
}
if (client->priv->monitor != NULL)
udev_monitor_filter_add_match_subsystem_devtype (client->priv->monitor, subsystem, devtype);
g_free (subsystem);
}
/* listen to events, and buffer them */
if (client->priv->monitor != NULL)
{
udev_monitor_enable_receiving (client->priv->monitor);
channel = g_io_channel_unix_new (udev_monitor_get_fd (client->priv->monitor));
client->priv->watch_source = g_io_create_watch (channel, G_IO_IN);
g_io_channel_unref (channel);
g_source_set_callback (client->priv->watch_source, (GSourceFunc) monitor_event, client, NULL);
g_source_attach (client->priv->watch_source, g_main_context_get_thread_default ());
g_source_unref (client->priv->watch_source);
}
else
{
client->priv->watch_source = NULL;
}
}
if (G_OBJECT_CLASS (g_udev_client_parent_class)->constructed != NULL)
G_OBJECT_CLASS (g_udev_client_parent_class)->constructed (object);
}
static void
g_udev_client_class_init (GUdevClientClass *klass)
{
GObjectClass *gobject_class = (GObjectClass *) klass;
gobject_class->constructed = g_udev_client_constructed;
gobject_class->set_property = g_udev_client_set_property;
gobject_class->get_property = g_udev_client_get_property;
gobject_class->finalize = g_udev_client_finalize;
/**
* GUdevClient:subsystems:
*
* The subsystems to listen for uevents on.
*
* To listen for only a specific DEVTYPE for a given SUBSYSTEM, use
* "subsystem/devtype". For example, to only listen for uevents
* 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_object_class_install_property (gobject_class,
PROP_SUBSYSTEMS,
g_param_spec_boxed ("subsystems",
"The subsystems to listen for changes on",
"The subsystems to listen for changes on",
G_TYPE_STRV,
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_READWRITE));
/**
* 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.
*/
signals[UEVENT_SIGNAL] = g_signal_new ("uevent",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GUdevClientClass, uevent),
NULL,
NULL,
g_udev_marshal_VOID__STRING_OBJECT,
G_TYPE_NONE,
2,
G_TYPE_STRING,
G_UDEV_TYPE_DEVICE);
g_type_class_add_private (klass, sizeof (GUdevClientPrivate));
}
static void
g_udev_client_init (GUdevClient *client)
{
client->priv = G_TYPE_INSTANCE_GET_PRIVATE (client,
G_UDEV_TYPE_CLIENT,
GUdevClientPrivate);
}
/**
* 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().
*/
GUdevClient *
g_udev_client_new (const gchar * const *subsystems)
{
return G_UDEV_CLIENT (g_object_new (G_UDEV_TYPE_CLIENT, "subsystems", subsystems, NULL));
}
/**
* 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: (nullable) (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 *
g_udev_client_query_by_subsystem (GUdevClient *client,
const gchar *subsystem)
{
struct udev_enumerate *enumerate;
struct udev_list_entry *l, *devices;
GList *ret;
g_return_val_if_fail (G_UDEV_IS_CLIENT (client), NULL);
ret = NULL;
/* prepare a device scan */
enumerate = udev_enumerate_new (client->priv->udev);
/* filter for subsystem */
if (subsystem != NULL)
udev_enumerate_add_match_subsystem (enumerate, subsystem);
/* retrieve the list */
udev_enumerate_scan_devices (enumerate);
/* add devices to the list */
devices = udev_enumerate_get_list_entry (enumerate);
for (l = devices; l != NULL; l = udev_list_entry_get_next (l))
{
struct udev_device *udevice;
GUdevDevice *device;
udevice = udev_device_new_from_syspath (udev_enumerate_get_udev (enumerate),
udev_list_entry_get_name (l));
if (udevice == NULL)
continue;
device = _g_udev_device_new (udevice);
udev_device_unref (udevice);
ret = g_list_prepend (ret, device);
}
udev_enumerate_unref (enumerate);
ret = g_list_reverse (ret);
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: (nullable) (transfer full): A #GUdevDevice object or %NULL
* if the device was not found. Free with g_object_unref().
*/
GUdevDevice *
g_udev_client_query_by_device_number (GUdevClient *client,
GUdevDeviceType type,
GUdevDeviceNumber number)
{
struct udev_device *udevice;
GUdevDevice *device;
g_return_val_if_fail (G_UDEV_IS_CLIENT (client), NULL);
device = NULL;
udevice = udev_device_new_from_devnum (client->priv->udev, type, number);
if (udevice == NULL)
goto out;
device = _g_udev_device_new (udevice);
udev_device_unref (udevice);
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: (nullable) (transfer full): A #GUdevDevice object or %NULL
* if the device was not found. Free with g_object_unref().
*/
GUdevDevice *
g_udev_client_query_by_device_file (GUdevClient *client,
const gchar *device_file)
{
struct stat stat_buf;
GUdevDevice *device;
g_return_val_if_fail (G_UDEV_IS_CLIENT (client), NULL);
g_return_val_if_fail (device_file != NULL, NULL);
device = NULL;
if (stat (device_file, &stat_buf) != 0)
goto out;
if (stat_buf.st_rdev == 0)
goto out;
if (S_ISBLK (stat_buf.st_mode))
device = g_udev_client_query_by_device_number (client, G_UDEV_DEVICE_TYPE_BLOCK, stat_buf.st_rdev);
else if (S_ISCHR (stat_buf.st_mode))
device = g_udev_client_query_by_device_number (client, G_UDEV_DEVICE_TYPE_CHAR, stat_buf.st_rdev);
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: (nullable) (transfer full): A #GUdevDevice object or %NULL
* if the device was not found. Free with g_object_unref().
*/
GUdevDevice *
g_udev_client_query_by_sysfs_path (GUdevClient *client,
const gchar *sysfs_path)
{
struct udev_device *udevice;
GUdevDevice *device;
g_return_val_if_fail (G_UDEV_IS_CLIENT (client), NULL);
g_return_val_if_fail (sysfs_path != NULL, NULL);
device = NULL;
udevice = udev_device_new_from_syspath (client->priv->udev, sysfs_path);
if (udevice == NULL)
goto out;
device = _g_udev_device_new (udevice);
udev_device_unref (udevice);
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: (nullable) (transfer full): A #GUdevDevice object or %NULL
* if the device was not found. Free with g_object_unref().
*/
GUdevDevice *
g_udev_client_query_by_subsystem_and_name (GUdevClient *client,
const gchar *subsystem,
const gchar *name)
{
struct udev_device *udevice;
GUdevDevice *device;
g_return_val_if_fail (G_UDEV_IS_CLIENT (client), NULL);
g_return_val_if_fail (subsystem != NULL, NULL);
g_return_val_if_fail (name != NULL, NULL);
device = NULL;
udevice = udev_device_new_from_subsystem_sysname (client->priv->udev, subsystem, name);
if (udevice == NULL)
goto out;
device = _g_udev_device_new (udevice);
udev_device_unref (udevice);
out:
return device;
}
struct udev *
_g_udev_client_get_udev (GUdevClient *client)
{
g_return_val_if_fail (G_UDEV_IS_CLIENT (client), NULL);
return client->priv->udev;
}

View File

@ -1,99 +0,0 @@
/* -*- Mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
*
* Copyright (C) 2008 David Zeuthen <davidz@redhat.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#if !defined (_GUDEV_COMPILATION) && !defined(_GUDEV_INSIDE_GUDEV_H)
#error "Only <gudev/gudev.h> can be included directly, this file may disappear or change contents."
#endif
#ifndef __G_UDEV_CLIENT_H__
#define __G_UDEV_CLIENT_H__
#include <gudev/gudevtypes.h>
G_BEGIN_DECLS
#define G_UDEV_TYPE_CLIENT (g_udev_client_get_type ())
#define G_UDEV_CLIENT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), G_UDEV_TYPE_CLIENT, GUdevClient))
#define G_UDEV_CLIENT_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), G_UDEV_TYPE_CLIENT, GUdevClientClass))
#define G_UDEV_IS_CLIENT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_UDEV_TYPE_CLIENT))
#define G_UDEV_IS_CLIENT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), G_UDEV_TYPE_CLIENT))
#define G_UDEV_CLIENT_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), G_UDEV_TYPE_CLIENT, GUdevClientClass))
typedef struct _GUdevClientClass GUdevClientClass;
typedef struct _GUdevClientPrivate GUdevClientPrivate;
/**
* GUdevClient:
*
* The #GUdevClient struct is opaque and should not be accessed directly.
*/
struct _GUdevClient
{
GObject parent;
/*< private >*/
GUdevClientPrivate *priv;
};
/**
* GUdevClientClass:
* @parent_class: Parent class.
* @uevent: Signal class handler for the #GUdevClient::uevent signal.
*
* Class structure for #GUdevClient.
*/
struct _GUdevClientClass
{
GObjectClass parent_class;
/* signals */
void (*uevent) (GUdevClient *client,
const gchar *action,
GUdevDevice *device);
/*< private >*/
/* Padding for future expansion */
void (*reserved1) (void);
void (*reserved2) (void);
void (*reserved3) (void);
void (*reserved4) (void);
void (*reserved5) (void);
void (*reserved6) (void);
void (*reserved7) (void);
void (*reserved8) (void);
};
GType g_udev_client_get_type (void) G_GNUC_CONST;
GUdevClient *g_udev_client_new (const gchar* const *subsystems);
GList *g_udev_client_query_by_subsystem (GUdevClient *client,
const gchar *subsystem);
GUdevDevice *g_udev_client_query_by_device_number (GUdevClient *client,
GUdevDeviceType type,
GUdevDeviceNumber number);
GUdevDevice *g_udev_client_query_by_device_file (GUdevClient *client,
const gchar *device_file);
GUdevDevice *g_udev_client_query_by_sysfs_path (GUdevClient *client,
const gchar *sysfs_path);
GUdevDevice *g_udev_client_query_by_subsystem_and_name (GUdevClient *client,
const gchar *subsystem,
const gchar *name);
G_END_DECLS
#endif /* __G_UDEV_CLIENT_H__ */

File diff suppressed because it is too large Load Diff

View File

@ -1,130 +0,0 @@
/* -*- Mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
*
* Copyright (C) 2008 David Zeuthen <davidz@redhat.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#if !defined (_GUDEV_COMPILATION) && !defined(_GUDEV_INSIDE_GUDEV_H)
#error "Only <gudev/gudev.h> can be included directly, this file may disappear or change contents."
#endif
#ifndef __G_UDEV_DEVICE_H__
#define __G_UDEV_DEVICE_H__
#include <gudev/gudevtypes.h>
G_BEGIN_DECLS
#define G_UDEV_TYPE_DEVICE (g_udev_device_get_type ())
#define G_UDEV_DEVICE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), G_UDEV_TYPE_DEVICE, GUdevDevice))
#define G_UDEV_DEVICE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), G_UDEV_TYPE_DEVICE, GUdevDeviceClass))
#define G_UDEV_IS_DEVICE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_UDEV_TYPE_DEVICE))
#define G_UDEV_IS_DEVICE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), G_UDEV_TYPE_DEVICE))
#define G_UDEV_DEVICE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), G_UDEV_TYPE_DEVICE, GUdevDeviceClass))
typedef struct _GUdevDeviceClass GUdevDeviceClass;
typedef struct _GUdevDevicePrivate GUdevDevicePrivate;
/**
* GUdevDevice:
*
* The #GUdevDevice struct is opaque and should not be accessed directly.
*/
struct _GUdevDevice
{
GObject parent;
/*< private >*/
GUdevDevicePrivate *priv;
};
/**
* GUdevDeviceClass:
* @parent_class: Parent class.
*
* Class structure for #GUdevDevice.
*/
struct _GUdevDeviceClass
{
GObjectClass parent_class;
/*< private >*/
/* Padding for future expansion */
void (*reserved1) (void);
void (*reserved2) (void);
void (*reserved3) (void);
void (*reserved4) (void);
void (*reserved5) (void);
void (*reserved6) (void);
void (*reserved7) (void);
void (*reserved8) (void);
};
GType g_udev_device_get_type (void) G_GNUC_CONST;
gboolean g_udev_device_get_is_initialized (GUdevDevice *device);
guint64 g_udev_device_get_usec_since_initialized (GUdevDevice *device);
const gchar *g_udev_device_get_subsystem (GUdevDevice *device);
const gchar *g_udev_device_get_devtype (GUdevDevice *device);
const gchar *g_udev_device_get_name (GUdevDevice *device);
const gchar *g_udev_device_get_number (GUdevDevice *device);
const gchar *g_udev_device_get_sysfs_path (GUdevDevice *device);
const gchar *g_udev_device_get_driver (GUdevDevice *device);
const gchar *g_udev_device_get_action (GUdevDevice *device);
guint64 g_udev_device_get_seqnum (GUdevDevice *device);
GUdevDeviceType g_udev_device_get_device_type (GUdevDevice *device);
GUdevDeviceNumber g_udev_device_get_device_number (GUdevDevice *device);
const gchar *g_udev_device_get_device_file (GUdevDevice *device);
const gchar* const *g_udev_device_get_device_file_symlinks (GUdevDevice *device);
GUdevDevice *g_udev_device_get_parent (GUdevDevice *device);
GUdevDevice *g_udev_device_get_parent_with_subsystem (GUdevDevice *device,
const gchar *subsystem,
const gchar *devtype);
const gchar* const *g_udev_device_get_property_keys (GUdevDevice *device);
gboolean g_udev_device_has_property (GUdevDevice *device,
const gchar *key);
const gchar *g_udev_device_get_property (GUdevDevice *device,
const gchar *key);
gint g_udev_device_get_property_as_int (GUdevDevice *device,
const gchar *key);
guint64 g_udev_device_get_property_as_uint64 (GUdevDevice *device,
const gchar *key);
gdouble g_udev_device_get_property_as_double (GUdevDevice *device,
const gchar *key);
gboolean g_udev_device_get_property_as_boolean (GUdevDevice *device,
const gchar *key);
const gchar* const *g_udev_device_get_property_as_strv (GUdevDevice *device,
const gchar *key);
const gchar* const *g_udev_device_get_sysfs_attr_keys (GUdevDevice *device);
gboolean g_udev_device_has_sysfs_attr (GUdevDevice *device,
const gchar *key);
const gchar *g_udev_device_get_sysfs_attr (GUdevDevice *device,
const gchar *name);
gint g_udev_device_get_sysfs_attr_as_int (GUdevDevice *device,
const gchar *name);
guint64 g_udev_device_get_sysfs_attr_as_uint64 (GUdevDevice *device,
const gchar *name);
gdouble g_udev_device_get_sysfs_attr_as_double (GUdevDevice *device,
const gchar *name);
gboolean g_udev_device_get_sysfs_attr_as_boolean (GUdevDevice *device,
const gchar *name);
const gchar* const *g_udev_device_get_sysfs_attr_as_strv (GUdevDevice *device,
const gchar *name);
const gchar* const *g_udev_device_get_tags (GUdevDevice *device);
G_END_DECLS
#endif /* __G_UDEV_DEVICE_H__ */

View File

@ -1,429 +0,0 @@
/* -*- Mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
*
* Copyright (C) 2008-2010 David Zeuthen <davidz@redhat.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdlib.h>
#include <string.h>
#include "gudevclient.h"
#include "gudevenumerator.h"
#include "gudevdevice.h"
#include "gudevmarshal.h"
#include "gudevprivate.h"
/**
* SECTION:gudevenumerator
* @short_description: Lookup and sort devices
*
* #GUdevEnumerator is used to lookup and sort devices.
*
* Since: 165
*/
struct _GUdevEnumeratorPrivate
{
GUdevClient *client;
struct udev_enumerate *e;
};
enum
{
PROP_0,
PROP_CLIENT,
};
G_DEFINE_TYPE (GUdevEnumerator, g_udev_enumerator, G_TYPE_OBJECT)
/* ---------------------------------------------------------------------------------------------------- */
static void
g_udev_enumerator_finalize (GObject *object)
{
GUdevEnumerator *enumerator = G_UDEV_ENUMERATOR (object);
if (enumerator->priv->client != NULL)
{
g_object_unref (enumerator->priv->client);
enumerator->priv->client = NULL;
}
if (enumerator->priv->e != NULL)
{
udev_enumerate_unref (enumerator->priv->e);
enumerator->priv->e = NULL;
}
if (G_OBJECT_CLASS (g_udev_enumerator_parent_class)->finalize != NULL)
G_OBJECT_CLASS (g_udev_enumerator_parent_class)->finalize (object);
}
static void
g_udev_enumerator_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GUdevEnumerator *enumerator = G_UDEV_ENUMERATOR (object);
switch (prop_id)
{
case PROP_CLIENT:
if (enumerator->priv->client != NULL)
g_object_unref (enumerator->priv->client);
enumerator->priv->client = g_value_dup_object (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
g_udev_enumerator_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GUdevEnumerator *enumerator = G_UDEV_ENUMERATOR (object);
switch (prop_id)
{
case PROP_CLIENT:
g_value_set_object (value, enumerator->priv->client);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
g_udev_enumerator_constructed (GObject *object)
{
GUdevEnumerator *enumerator = G_UDEV_ENUMERATOR (object);
g_assert (G_UDEV_IS_CLIENT (enumerator->priv->client));
enumerator->priv->e = udev_enumerate_new (_g_udev_client_get_udev (enumerator->priv->client));
if (G_OBJECT_CLASS (g_udev_enumerator_parent_class)->constructed != NULL)
G_OBJECT_CLASS (g_udev_enumerator_parent_class)->constructed (object);
}
static void
g_udev_enumerator_class_init (GUdevEnumeratorClass *klass)
{
GObjectClass *gobject_class = (GObjectClass *) klass;
gobject_class->finalize = g_udev_enumerator_finalize;
gobject_class->set_property = g_udev_enumerator_set_property;
gobject_class->get_property = g_udev_enumerator_get_property;
gobject_class->constructed = g_udev_enumerator_constructed;
/**
* GUdevEnumerator:client:
*
* The #GUdevClient to enumerate devices from.
*
* Since: 165
*/
g_object_class_install_property (gobject_class,
PROP_CLIENT,
g_param_spec_object ("client",
"The client to enumerate devices from",
"The client to enumerate devices from",
G_UDEV_TYPE_CLIENT,
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_READWRITE));
g_type_class_add_private (klass, sizeof (GUdevEnumeratorPrivate));
}
static void
g_udev_enumerator_init (GUdevEnumerator *enumerator)
{
enumerator->priv = G_TYPE_INSTANCE_GET_PRIVATE (enumerator,
G_UDEV_TYPE_ENUMERATOR,
GUdevEnumeratorPrivate);
}
/**
* g_udev_enumerator_new:
* @client: A #GUdevClient to enumerate devices from.
*
* Constructs a #GUdevEnumerator object that can be used to enumerate
* and sort devices. Use the add_match_*() and add_nomatch_*() methods
* and execute the query to get a list of devices with
* g_udev_enumerator_execute().
*
* Returns: A new #GUdevEnumerator object. Free with g_object_unref().
*
* Since: 165
*/
GUdevEnumerator *
g_udev_enumerator_new (GUdevClient *client)
{
g_return_val_if_fail (G_UDEV_IS_CLIENT (client), NULL);
return G_UDEV_ENUMERATOR (g_object_new (G_UDEV_TYPE_ENUMERATOR, "client", client, NULL));
}
/**
* g_udev_enumerator_add_match_subsystem:
* @enumerator: A #GUdevEnumerator.
* @subsystem: Wildcard for subsystem name e.g. 'scsi' or 'a*'.
*
* All returned devices will match the given @subsystem.
*
* Returns: (transfer none): The passed in @enumerator.
*
* Since: 165
*/
GUdevEnumerator *
g_udev_enumerator_add_match_subsystem (GUdevEnumerator *enumerator,
const gchar *subsystem)
{
g_return_val_if_fail (G_UDEV_IS_ENUMERATOR (enumerator), NULL);
g_return_val_if_fail (subsystem != NULL, NULL);
udev_enumerate_add_match_subsystem (enumerator->priv->e, subsystem);
return enumerator;
}
/**
* g_udev_enumerator_add_nomatch_subsystem:
* @enumerator: A #GUdevEnumerator.
* @subsystem: Wildcard for subsystem name e.g. 'scsi' or 'a*'.
*
* All returned devices will not match the given @subsystem.
*
* Returns: (transfer none): The passed in @enumerator.
*
* Since: 165
*/
GUdevEnumerator *
g_udev_enumerator_add_nomatch_subsystem (GUdevEnumerator *enumerator,
const gchar *subsystem)
{
g_return_val_if_fail (G_UDEV_IS_ENUMERATOR (enumerator), NULL);
g_return_val_if_fail (subsystem != NULL, NULL);
udev_enumerate_add_nomatch_subsystem (enumerator->priv->e, subsystem);
return enumerator;
}
/**
* g_udev_enumerator_add_match_sysfs_attr:
* @enumerator: A #GUdevEnumerator.
* @name: Wildcard filter for sysfs attribute key.
* @value: Wildcard filter for sysfs attribute value.
*
* All returned devices will have a sysfs attribute matching the given @name and @value.
*
* Returns: (transfer none): The passed in @enumerator.
*
* Since: 165
*/
GUdevEnumerator *
g_udev_enumerator_add_match_sysfs_attr (GUdevEnumerator *enumerator,
const gchar *name,
const gchar *value)
{
g_return_val_if_fail (G_UDEV_IS_ENUMERATOR (enumerator), NULL);
g_return_val_if_fail (name != NULL, NULL);
g_return_val_if_fail (value != NULL, NULL);
udev_enumerate_add_match_sysattr (enumerator->priv->e, name, value);
return enumerator;
}
/**
* g_udev_enumerator_add_nomatch_sysfs_attr:
* @enumerator: A #GUdevEnumerator.
* @name: Wildcard filter for sysfs attribute key.
* @value: Wildcard filter for sysfs attribute value.
*
* All returned devices will not have a sysfs attribute matching the given @name and @value.
*
* Returns: (transfer none): The passed in @enumerator.
*
* Since: 165
*/
GUdevEnumerator *
g_udev_enumerator_add_nomatch_sysfs_attr (GUdevEnumerator *enumerator,
const gchar *name,
const gchar *value)
{
g_return_val_if_fail (G_UDEV_IS_ENUMERATOR (enumerator), NULL);
g_return_val_if_fail (name != NULL, NULL);
g_return_val_if_fail (value != NULL, NULL);
udev_enumerate_add_nomatch_sysattr (enumerator->priv->e, name, value);
return enumerator;
}
/**
* g_udev_enumerator_add_match_property:
* @enumerator: A #GUdevEnumerator.
* @name: Wildcard filter for property name.
* @value: Wildcard filter for property value.
*
* All returned devices will have a property matching the given @name and @value.
*
* Returns: (transfer none): The passed in @enumerator.
*
* Since: 165
*/
GUdevEnumerator *
g_udev_enumerator_add_match_property (GUdevEnumerator *enumerator,
const gchar *name,
const gchar *value)
{
g_return_val_if_fail (G_UDEV_IS_ENUMERATOR (enumerator), NULL);
g_return_val_if_fail (name != NULL, NULL);
g_return_val_if_fail (value != NULL, NULL);
udev_enumerate_add_match_property (enumerator->priv->e, name, value);
return enumerator;
}
/**
* g_udev_enumerator_add_match_name:
* @enumerator: A #GUdevEnumerator.
* @name: Wildcard filter for kernel name e.g. "sda*".
*
* All returned devices will match the given @name.
*
* Returns: (transfer none): The passed in @enumerator.
*
* Since: 165
*/
GUdevEnumerator *
g_udev_enumerator_add_match_name (GUdevEnumerator *enumerator,
const gchar *name)
{
g_return_val_if_fail (G_UDEV_IS_ENUMERATOR (enumerator), NULL);
g_return_val_if_fail (name != NULL, NULL);
udev_enumerate_add_match_sysname (enumerator->priv->e, name);
return enumerator;
}
/**
* g_udev_enumerator_add_sysfs_path:
* @enumerator: A #GUdevEnumerator.
* @sysfs_path: A sysfs path, e.g. "/sys/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda"
*
* Add a device to the list of devices, to retrieve it back sorted in dependency order.
*
* Returns: (transfer none): The passed in @enumerator.
*
* Since: 165
*/
GUdevEnumerator *
g_udev_enumerator_add_sysfs_path (GUdevEnumerator *enumerator,
const gchar *sysfs_path)
{
g_return_val_if_fail (G_UDEV_IS_ENUMERATOR (enumerator), NULL);
g_return_val_if_fail (sysfs_path != NULL, NULL);
udev_enumerate_add_syspath (enumerator->priv->e, sysfs_path);
return enumerator;
}
/**
* g_udev_enumerator_add_match_tag:
* @enumerator: A #GUdevEnumerator.
* @tag: A udev tag e.g. "udev-acl".
*
* All returned devices will match the given @tag.
*
* Returns: (transfer none): The passed in @enumerator.
*
* Since: 165
*/
GUdevEnumerator *
g_udev_enumerator_add_match_tag (GUdevEnumerator *enumerator,
const gchar *tag)
{
g_return_val_if_fail (G_UDEV_IS_ENUMERATOR (enumerator), NULL);
g_return_val_if_fail (tag != NULL, NULL);
udev_enumerate_add_match_tag (enumerator->priv->e, tag);
return enumerator;
}
/**
* g_udev_enumerator_add_match_is_initialized:
* @enumerator: A #GUdevEnumerator.
*
* All returned devices will be initialized.
*
* Returns: (transfer none): The passed in @enumerator.
*
* Since: 165
*/
GUdevEnumerator *
g_udev_enumerator_add_match_is_initialized (GUdevEnumerator *enumerator)
{
g_return_val_if_fail (G_UDEV_IS_ENUMERATOR (enumerator), NULL);
udev_enumerate_add_match_is_initialized (enumerator->priv->e);
return enumerator;
}
/**
* g_udev_enumerator_execute:
* @enumerator: A #GUdevEnumerator.
*
* Executes the query in @enumerator.
*
* 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.
*
* Since: 165
*/
GList *
g_udev_enumerator_execute (GUdevEnumerator *enumerator)
{
GList *ret;
struct udev_list_entry *l, *devices;
g_return_val_if_fail (G_UDEV_IS_ENUMERATOR (enumerator), NULL);
ret = NULL;
/* retrieve the list */
udev_enumerate_scan_devices (enumerator->priv->e);
devices = udev_enumerate_get_list_entry (enumerator->priv->e);
for (l = devices; l != NULL; l = udev_list_entry_get_next (l))
{
struct udev_device *udevice;
GUdevDevice *device;
udevice = udev_device_new_from_syspath (udev_enumerate_get_udev (enumerator->priv->e),
udev_list_entry_get_name (l));
if (udevice == NULL)
continue;
device = _g_udev_device_new (udevice);
udev_device_unref (udevice);
ret = g_list_prepend (ret, device);
}
ret = g_list_reverse (ret);
return ret;
}

View File

@ -1,106 +0,0 @@
/* -*- Mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
*
* Copyright (C) 2008-2010 David Zeuthen <davidz@redhat.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#if !defined (_GUDEV_COMPILATION) && !defined(_GUDEV_INSIDE_GUDEV_H)
#error "Only <gudev/gudev.h> can be included directly, this file may disappear or change contents."
#endif
#ifndef __G_UDEV_ENUMERATOR_H__
#define __G_UDEV_ENUMERATOR_H__
#include <gudev/gudevtypes.h>
G_BEGIN_DECLS
#define G_UDEV_TYPE_ENUMERATOR (g_udev_enumerator_get_type ())
#define G_UDEV_ENUMERATOR(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), G_UDEV_TYPE_ENUMERATOR, GUdevEnumerator))
#define G_UDEV_ENUMERATOR_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), G_UDEV_TYPE_ENUMERATOR, GUdevEnumeratorClass))
#define G_UDEV_IS_ENUMERATOR(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_UDEV_TYPE_ENUMERATOR))
#define G_UDEV_IS_ENUMERATOR_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), G_UDEV_TYPE_ENUMERATOR))
#define G_UDEV_ENUMERATOR_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), G_UDEV_TYPE_ENUMERATOR, GUdevEnumeratorClass))
typedef struct _GUdevEnumeratorClass GUdevEnumeratorClass;
typedef struct _GUdevEnumeratorPrivate GUdevEnumeratorPrivate;
/**
* GUdevEnumerator:
*
* The #GUdevEnumerator struct is opaque and should not be accessed directly.
*
* Since: 165
*/
struct _GUdevEnumerator
{
GObject parent;
/*< private >*/
GUdevEnumeratorPrivate *priv;
};
/**
* GUdevEnumeratorClass:
* @parent_class: Parent class.
*
* Class structure for #GUdevEnumerator.
*
* Since: 165
*/
struct _GUdevEnumeratorClass
{
GObjectClass parent_class;
/*< private >*/
/* Padding for future expansion */
void (*reserved1) (void);
void (*reserved2) (void);
void (*reserved3) (void);
void (*reserved4) (void);
void (*reserved5) (void);
void (*reserved6) (void);
void (*reserved7) (void);
void (*reserved8) (void);
};
GType g_udev_enumerator_get_type (void) G_GNUC_CONST;
GUdevEnumerator *g_udev_enumerator_new (GUdevClient *client);
GUdevEnumerator *g_udev_enumerator_add_match_subsystem (GUdevEnumerator *enumerator,
const gchar *subsystem);
GUdevEnumerator *g_udev_enumerator_add_nomatch_subsystem (GUdevEnumerator *enumerator,
const gchar *subsystem);
GUdevEnumerator *g_udev_enumerator_add_match_sysfs_attr (GUdevEnumerator *enumerator,
const gchar *name,
const gchar *value);
GUdevEnumerator *g_udev_enumerator_add_nomatch_sysfs_attr (GUdevEnumerator *enumerator,
const gchar *name,
const gchar *value);
GUdevEnumerator *g_udev_enumerator_add_match_property (GUdevEnumerator *enumerator,
const gchar *name,
const gchar *value);
GUdevEnumerator *g_udev_enumerator_add_match_name (GUdevEnumerator *enumerator,
const gchar *name);
GUdevEnumerator *g_udev_enumerator_add_match_tag (GUdevEnumerator *enumerator,
const gchar *tag);
GUdevEnumerator *g_udev_enumerator_add_match_is_initialized (GUdevEnumerator *enumerator);
GUdevEnumerator *g_udev_enumerator_add_sysfs_path (GUdevEnumerator *enumerator,
const gchar *sysfs_path);
GList *g_udev_enumerator_execute (GUdevEnumerator *enumerator);
G_END_DECLS
#endif /* __G_UDEV_ENUMERATOR_H__ */

View File

@ -1,48 +0,0 @@
/* -*- Mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
*
* Copyright (C) 2008 David Zeuthen <davidz@redhat.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#if !defined (_GUDEV_COMPILATION) && !defined(_GUDEV_INSIDE_GUDEV_H)
#error "Only <gudev/gudev.h> can be included directly, this file may disappear or change contents."
#endif
#ifndef __G_UDEV_ENUMS_H__
#define __G_UDEV_ENUMS_H__
#include <glib-object.h>
G_BEGIN_DECLS
/**
* GUdevDeviceType:
* @G_UDEV_DEVICE_TYPE_NONE: Device does not have a device file.
* @G_UDEV_DEVICE_TYPE_BLOCK: Device is a block device.
* @G_UDEV_DEVICE_TYPE_CHAR: Device is a character device.
*
* Enumeration used to specify a the type of a device.
*/
typedef enum
{
G_UDEV_DEVICE_TYPE_NONE = 0,
G_UDEV_DEVICE_TYPE_BLOCK = 'b',
G_UDEV_DEVICE_TYPE_CHAR = 'c',
} GUdevDeviceType;
G_END_DECLS
#endif /* __G_UDEV_ENUMS_H__ */

View File

@ -1,39 +0,0 @@
/*** BEGIN file-header ***/
#include <gudev.h>
/*** END file-header ***/
/*** BEGIN file-production ***/
/* enumerations from "@filename@" */
/*** END file-production ***/
/*** BEGIN value-header ***/
GType
@enum_name@_get_type (void)
{
static volatile gsize g_define_type_id__volatile = 0;
if (g_once_init_enter (&g_define_type_id__volatile))
{
static const G@Type@Value values[] = {
/*** END value-header ***/
/*** BEGIN value-production ***/
{ @VALUENAME@, "@VALUENAME@", "@valuenick@" },
/*** END value-production ***/
/*** BEGIN value-tail ***/
{ 0, NULL, NULL }
};
GType g_define_type_id =
g_@type@_register_static (g_intern_static_string ("@EnumName@"), values);
g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);
}
return g_define_type_id__volatile;
}
/*** END value-tail ***/
/*** BEGIN file-tail ***/
/*** END file-tail ***/

View File

@ -1,24 +0,0 @@
/*** BEGIN file-header ***/
#ifndef __GUDEV_ENUM_TYPES_H__
#define __GUDEV_ENUM_TYPES_H__
#include <glib-object.h>
G_BEGIN_DECLS
/*** END file-header ***/
/*** BEGIN file-production ***/
/* enumerations from "@filename@" */
/*** END file-production ***/
/*** BEGIN value-header ***/
GType @enum_name@_get_type (void) G_GNUC_CONST;
#define @ENUMPREFIX@_TYPE_@ENUMSHORT@ (@enum_name@_get_type ())
/*** END value-header ***/
/*** BEGIN file-tail ***/
G_END_DECLS
#endif /* __GUDEV_ENUM_TYPES_H__ */
/*** END file-tail ***/

View File

@ -1 +0,0 @@
VOID:STRING,OBJECT

View File

@ -1,40 +0,0 @@
/* -*- Mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
*
* Copyright (C) 2008 David Zeuthen <davidz@redhat.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#if !defined (_GUDEV_COMPILATION) && !defined(_GUDEV_INSIDE_GUDEV_H)
#error "Only <gudev/gudev.h> can be included directly, this file may disappear or change contents."
#endif
#ifndef __G_UDEV_PRIVATE_H__
#define __G_UDEV_PRIVATE_H__
#include <gudev/gudevtypes.h>
#include <libudev.h>
G_BEGIN_DECLS
GUdevDevice *
_g_udev_device_new (struct udev_device *udevice);
struct udev *_g_udev_client_get_udev (GUdevClient *client);
G_END_DECLS
#endif /* __G_UDEV_PRIVATE_H__ */

View File

@ -1,50 +0,0 @@
/* -*- Mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
*
* Copyright (C) 2008 David Zeuthen <davidz@redhat.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#if !defined (_GUDEV_COMPILATION) && !defined(_GUDEV_INSIDE_GUDEV_H)
#error "Only <gudev/gudev.h> can be included directly, this file may disappear or change contents."
#endif
#ifndef __G_UDEV_TYPES_H__
#define __G_UDEV_TYPES_H__
#include <gudev/gudevenums.h>
#include <sys/types.h>
G_BEGIN_DECLS
typedef struct _GUdevClient GUdevClient;
typedef struct _GUdevDevice GUdevDevice;
typedef struct _GUdevEnumerator GUdevEnumerator;
/**
* GUdevDeviceNumber:
*
* Corresponds to the standard #dev_t type as defined by POSIX (Until
* bug 584517 is resolved this work-around is needed).
*/
#ifdef _GUDEV_WORK_AROUND_DEV_T_BUG
typedef guint64 GUdevDeviceNumber; /* __UQUAD_TYPE */
#else
typedef dev_t GUdevDeviceNumber;
#endif
G_END_DECLS
#endif /* __G_UDEV_TYPES_H__ */

View File

@ -1,68 +0,0 @@
/***
This file is part of systemd.
systemd is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
***/
{
global:
g_udev_client_get_type;
g_udev_client_new;
g_udev_client_query_by_device_file;
g_udev_client_query_by_device_number;
g_udev_client_query_by_subsystem;
g_udev_client_query_by_subsystem_and_name;
g_udev_client_query_by_sysfs_path;
g_udev_device_get_action;
g_udev_device_get_device_file;
g_udev_device_get_device_file_symlinks;
g_udev_device_get_device_number;
g_udev_device_get_device_type;
g_udev_device_get_devtype;
g_udev_device_get_driver;
g_udev_device_get_is_initialized;
g_udev_device_get_name;
g_udev_device_get_number;
g_udev_device_get_parent;
g_udev_device_get_parent_with_subsystem;
g_udev_device_get_property;
g_udev_device_get_property_as_boolean;
g_udev_device_get_property_as_double;
g_udev_device_get_property_as_int;
g_udev_device_get_property_as_strv;
g_udev_device_get_property_as_uint64;
g_udev_device_get_property_keys;
g_udev_device_get_seqnum;
g_udev_device_get_subsystem;
g_udev_device_get_sysfs_attr;
g_udev_device_get_sysfs_attr_as_boolean;
g_udev_device_get_sysfs_attr_as_double;
g_udev_device_get_sysfs_attr_as_int;
g_udev_device_get_sysfs_attr_as_strv;
g_udev_device_get_sysfs_attr_as_uint64;
g_udev_device_get_sysfs_attr_keys;
g_udev_device_get_sysfs_path;
g_udev_device_get_tags;
g_udev_device_get_type;
g_udev_device_get_usec_since_initialized;
g_udev_device_has_property;
g_udev_device_has_sysfs_attr;
g_udev_device_type_get_type;
g_udev_enumerator_add_match_is_initialized;
g_udev_enumerator_add_match_name;
g_udev_enumerator_add_match_property;
g_udev_enumerator_add_match_subsystem;
g_udev_enumerator_add_match_sysfs_attr;
g_udev_enumerator_add_match_tag;
g_udev_enumerator_add_nomatch_subsystem;
g_udev_enumerator_add_nomatch_sysfs_attr;
g_udev_enumerator_add_sysfs_path;
g_udev_enumerator_execute;
g_udev_enumerator_get_type;
g_udev_enumerator_new;
local:
*;
};

View File

@ -1,38 +0,0 @@
#!/usr/bin/env seed
const GLib = imports.gi.GLib;
const GUdev = imports.gi.GUdev;
function print_device(device) {
print(" initialized: " + device.get_is_initialized());
print(" usec since initialized: " + device.get_usec_since_initialized());
print(" subsystem: " + device.get_subsystem());
print(" devtype: " + device.get_devtype());
print(" name: " + device.get_name());
print(" number: " + device.get_number());
print(" sysfs_path: " + device.get_sysfs_path());
print(" driver: " + device.get_driver());
print(" action: " + device.get_action());
print(" seqnum: " + device.get_seqnum());
print(" device type: " + device.get_device_type());
print(" device number: " + device.get_device_number());
print(" device file: " + device.get_device_file());
print(" device file symlinks: " + device.get_device_file_symlinks());
print(" tags: " + device.get_tags());
var keys = device.get_property_keys();
for (var n = 0; n < keys.length; n++) {
print(" " + keys[n] + "=" + device.get_property(keys[n]));
}
}
var client = new GUdev.Client({subsystems: []});
var enumerator = new GUdev.Enumerator({client: client});
enumerator.add_match_subsystem('b*')
var devices = enumerator.execute();
for (var n=0; n < devices.length; n++) {
var device = devices[n];
print_device(device);
print("");
}

View File

@ -1,72 +0,0 @@
#!/usr/bin/env seed
// seed example
const GLib = imports.gi.GLib;
const GUdev = imports.gi.GUdev;
function print_device (device) {
print (" subsystem: " + device.get_subsystem ());
print (" devtype: " + device.get_devtype ());
print (" name: " + device.get_name ());
print (" number: " + device.get_number ());
print (" sysfs_path: " + device.get_sysfs_path ());
print (" driver: " + device.get_driver ());
print (" action: " + device.get_action ());
print (" seqnum: " + device.get_seqnum ());
print (" device type: " + device.get_device_type ());
print (" device number: " + device.get_device_number ());
print (" device file: " + device.get_device_file ());
print (" device file symlinks: " + device.get_device_file_symlinks ());
print (" foo: " + device.get_sysfs_attr_as_strv ("stat"));
var keys = device.get_property_keys ();
for (var n = 0; n < keys.length; n++) {
print (" " + keys[n] + "=" + device.get_property (keys[n]));
}
}
function on_uevent (client, action, device) {
print ("action " + action + " on device " + device.get_sysfs_path());
print_device (device);
print ("");
}
var client = new GUdev.Client ({subsystems: ["block", "usb/usb_interface"]});
client.signal.connect ("uevent", on_uevent);
var block_devices = client.query_by_subsystem ("block");
for (var n = 0; n < block_devices.length; n++) {
print ("block device: " + block_devices[n].get_device_file ());
}
var d;
d = client.query_by_device_number (GUdev.DeviceType.BLOCK, 0x0810);
if (d == null) {
print ("query_by_device_number 0x810 -> null");
} else {
print ("query_by_device_number 0x810 -> " + d.get_device_file ());
dd = d.get_parent_with_subsystem ("usb", null);
print_device (dd);
print ("--------------------------------------------------------------------------");
while (d != null) {
print_device (d);
print ("");
d = d.get_parent ();
}
}
d = client.query_by_sysfs_path ("/sys/block/sda/sda1");
print ("query_by_sysfs_path (\"/sys/block/sda1\") -> " + d.get_device_file ());
d = client.query_by_subsystem_and_name ("block", "sda2");
print ("query_by_subsystem_and_name (\"block\", \"sda2\") -> " + d.get_device_file ());
d = client.query_by_device_file ("/dev/sda");
print ("query_by_device_file (\"/dev/sda\") -> " + d.get_device_file ());
d = client.query_by_device_file ("/dev/block/8:0");
print ("query_by_device_file (\"/dev/block/8:0\") -> " + d.get_device_file ());
var mainloop = GLib.main_loop_new ();
GLib.main_loop_run (mainloop);