commit 04709ec0bafce4e95875412f54472960f4593d16 Author: Christophe Fergeau <cferg...@mandriva.com> Date: Tue May 12 23:08:32 2009 +0200
Add udev callout (similar to hal callout) configure.ac | 25 +++++ tools/Makefile.am | 72 +++++++++------ tools/libgpod.rules.in | 1 + tools/udev-backend.c | 245 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 314 insertions(+), 29 deletions(-) --- diff --git a/configure.ac b/configure.ac index 1fb414b..681309f 100644 --- a/configure.ac +++ b/configure.ac @@ -187,6 +187,22 @@ if test "x$with_libimobiledevice" != "xno"; then fi AM_CONDITIONAL(HAVE_LIBIMOBILEDEVICE, test x"$enable_libimobiledevice" = xyes) +dnl *********************************************************************** +dnl * udev can be used to run a callout as an alternative to the hal callout +dnl * nowadays (2009), it's the recommended way of having callouts, so +dnl * it should be preferred over HAL +dnl *********************************************************************** +AC_ARG_ENABLE(udev, + [AC_HELP_STRING([--enable-udev],[Enable udev callout])], + [if test $enableval = "yes" ; then + enable_udev=yes + else + enable_udev=no + fi], + [enable_udev=no]) +AM_CONDITIONAL(USE_UDEV, test x"$enable_udev" = xyes) +AC_SUBST([udevdir], [/lib/udev]) + dnl ************************************************** dnl * TagLib is only used by test-rebuild-db dnl ************************************************** @@ -360,6 +376,7 @@ src/Makefile tools/Makefile tests/Makefile libgpod-1.0.pc +tools/libgpod.rules ]) AC_OUTPUT @@ -396,3 +413,11 @@ if test x"$have_gdkpixbuf" = xno; then to read or write artwork (covers, photos, ...) from/to the iPod " fi + +if test x"$enable_udev" = xyes -a x"$enable_hal" = xyes; then + echo " +**WARNING** HAL and udev callouts have been enabled at the same time. +While this should be harmless, this isn't recommended. The udev +callout is the recommended one. +" +fi diff --git a/tools/Makefile.am b/tools/Makefile.am index 55ccba4..57e1535 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -18,50 +18,64 @@ ipod_read_sysinfo_extended_CFLAGS+=$(LIBUSB_CFLAGS) ipod_read_sysinfo_extended_LDADD+=$(LIBUSB_LIBS) endif -if HAVE_HAL -haldir = $(HALCALLOUTSDIR) -hal_PROGRAMS = libgpod-callout -libgpod_callout_SOURCES = \ - generic-callout.c \ - hal-backend.c \ +COMMON_SOURCES = \ + generic-callout.c \ $(top_srcdir)/src/itdb_sysinfo_extended_parser.c \ $(top_srcdir)/src/itdb_plist.c -libgpod_callout_CFLAGS = \ - $(LIBGPOD_CFLAGS) \ - $(HAL_CFLAGS) \ - -I$(top_srcdir)/src +COMMON_CFLAGS = $(LIBGPOD_CFLAGS) -I$(top_srcdir)/src +COMMON_LIBS = $(top_builddir)/src/libgpod.la $(LIBGPOD_LIBS) -#libgpod_callout_LDADD=$(LIBGPOD_LIBS) $(HAL_LIBS) $(SGUTILS_LIBS) -libgpod_callout_LDADD = \ - $(top_builddir)/src/libgpod.la \ - $(LIBGPOD_LIBS) \ - $(HAL_LIBS) +if HAVE_SGUTILS +COMMON_SOURCES += ipod-scsi.c +COMMON_CFLAGS += $(SGUTILS_CFLAGS) +COMMON_LIBS += $(SGUTILS_LIBS) +endif -if HAVE_LIBIMOBILEDEVICE -hal_PROGRAMS+=iphone-callout -iphone_callout_SOURCES = iphone-callout.c ipod-lockdown.c -iphone_callout_CFLAGS = $(LIBIMOBILEDEVICE_CFLAGS) -iphone_callout_LDADD = $(LIBIMOBILEDEVICE_LIBS) +if HAVE_LIBUSB +COMMON_SOURCES +=ipod-usb.c +COMMON_CFLAGS +=$(LIBUSB_CFLAGS) +COMMON_LIBS +=$(LIBUSB_LIBS) endif +if HAVE_HAL +haldir = $(HALCALLOUTSDIR) +hal_PROGRAMS = libgpod-callout +libgpod_callout_SOURCES = $(COMMON_SOURCES) hal-backend.c +libgpod_callout_CFLAGS = $(HAL_CFLAGS) $(COMMON_CFLAGS) +libgpod_callout_LDADD = $(HAL_LIBS) $(COMMON_LIBS) + fdidir = $(HALFDIDIR)/policy/20thirdparty fdi_DATA = 20-libgpod-sysinfo-extended.fdi EXTRA_DIST = $(fdi_DATA) +endif # HAVE_HAL -if HAVE_SGUTILS -libgpod_callout_SOURCES += ipod-scsi.c -libgpod_callout_CFLAGS += $(SGUTILS_CFLAGS) -libgpod_callout_LDADD += $(SGUTILS_LIBS) +if USE_UDEV +libudevd...@udevdir@ +libudev_PROGRAMS=ipod-set-info +ipod_set_info_SOURCES = $(COMMON_SOURCES) udev-backend.c +ipod_set_info_CFLAGS = $(COMMON_CFLAGS) +ipod_set_info_LDADD = $(COMMON_LIBS) + +rulesdir=${libudevdir}/rules.d +rules_DATA= libgpod.rules +endif # USE_UDEV + +if HAVE_LIBIPHONE +if HAVE_HAL +hal_PROGRAMS+=iphone-callout endif -if HAVE_LIBUSB -libgpod_callout_SOURCES+=ipod-usb.c -libgpod_callout_CFLAGS+=$(LIBUSB_CFLAGS) -libgpod_callout_LDADD+=$(LIBUSB_LIBS) +if USE_UDEV +libudev_PROGRAMS+=iphone-callout endif -endif +if HAVE_LIBIMOBILEDEVICE +hal_PROGRAMS+=iphone-callout +iphone_callout_SOURCES = iphone-callout.c ipod-lockdown.c +iphone_callout_CFLAGS = $(LIBIMOBILEDEVICE_CFLAGS) +iphone_callout_LDADD = $(LIBIMOBILEDEVICE_LIBS) +endif # HAVE_LIBIPHONE if HAVE_SGUTILS noinst_PROGRAMS=ipod-time-sync diff --git a/tools/libgpod.rules.in b/tools/libgpod.rules.in new file mode 100644 index 0000000..b5ffd44 --- /dev/null +++ b/tools/libgpod.rules.in @@ -0,0 +1 @@ +ACTION=="add|change", SUBSYSTEM=="block", ENV{ID_FS_USAGE}=="filesystem", ATTRS{idVendor}=="05ac", ENV{ID_MODEL}=="iPod", IMPORT{program}="@udevdir@/ipod-set-info $tempnode $attr{busnum} $attr{devnum}" diff --git a/tools/udev-backend.c b/tools/udev-backend.c new file mode 100644 index 0000000..8bc49b2 --- /dev/null +++ b/tools/udev-backend.c @@ -0,0 +1,245 @@ +/* Copyright (c) 2010, Christophe Fergeau <t...@gnome.org> + * Part of the libgpod project. + * + * URL: http://www.gtkpod.org/ + * URL: http://gtkpod.sourceforge.net/ + * + * The code contained in this file 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. + * + * This file 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 code; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * iTunes and iPod are trademarks of Apple + * + * This product is not supported/written/published by Apple! + * + */ +#include "config.h" +#include "backends.h" + +#include <stdlib.h> +#include <itdb_device.h> +#include <glib-object.h> + +#define LIBGPOD_UDEV_NS "LIBGPOD_" + +struct _UdevBackend { + ItdbBackend parent; +}; +typedef struct _UdevBackend UdevBackend; + + +static void udev_backend_destroy (ItdbBackend *itdb_backend) +{ + UdevBackend *backend = (UdevBackend *)itdb_backend; + g_free (backend); +} + +static gboolean +udev_backend_set_version (ItdbBackend *itdb_backend, unsigned int version) +{ + g_print (LIBGPOD_UDEV_NS"VERSION=%u\n", version); + return TRUE; +} + +static gboolean +udev_backend_set_is_unknown (ItdbBackend *itdb_backend, gboolean unknown) +{ + g_print (LIBGPOD_UDEV_NS"IS_UNKNOWN=%u\n", !!unknown); + return TRUE; +} + +static gboolean +udev_backend_set_icon_name (ItdbBackend *itdb_backend, const char *icon_name) +{ + g_print ("DKD_PRESENTATION_ICON_NAME=%s\n", icon_name); + return TRUE; +} + +static gboolean +udev_backend_set_firewire_id (ItdbBackend *itdb_backend, const char *fwid) +{ + g_print (LIBGPOD_UDEV_NS"FIREWIRE_ID=%s\n", fwid); + return TRUE; +} + +static gboolean +udev_backend_set_serial_number (ItdbBackend *itdb_backend, const char *serial_number) +{ + g_print (LIBGPOD_UDEV_NS"SERIAL_NUMBER=%s\n", serial_number); + return TRUE; +} + +static gboolean udev_backend_set_firmware_version (ItdbBackend *itdb_backend, + const char *firmware_version) +{ + g_print (LIBGPOD_UDEV_NS"FIRMWARE_VERSION=%s\n", firmware_version); + return TRUE; +} + +static gboolean +udev_backend_set_model_name (ItdbBackend *itdb_backend, const char *model_name) +{ + g_print (LIBGPOD_UDEV_NS"DEVICE_CLASS=%s\n", model_name); + return TRUE; +} + +static gboolean +udev_backend_set_generation (ItdbBackend *itdb_backend, gdouble generation) +{ + g_print (LIBGPOD_UDEV_NS"MODEL_GENERATION=%f\n", generation); + return TRUE; +} + +static gboolean +udev_backend_set_color (ItdbBackend *itdb_backend, const char *color_name) +{ + g_print (LIBGPOD_UDEV_NS"MODEL_SHELL_COLOR=%s\n", color_name); + return TRUE; +} + +static gboolean +udev_backend_set_factory_id (ItdbBackend *itdb_backend, + const char *factory_id) +{ + g_print (LIBGPOD_UDEV_NS"PRODUCTION_FACTORY_ID=%s\n", factory_id); + return TRUE; +} + +static gboolean +udev_backend_set_production_year (ItdbBackend *itdb_backend, guint year) +{ + g_print (LIBGPOD_UDEV_NS"PRODUCTION_YEAR=%u\n", year); + return TRUE; +} + +static gboolean +udev_backend_set_production_week (ItdbBackend *itdb_backend, guint week) +{ + g_print (LIBGPOD_UDEV_NS"PRODUCTION_WEEK=%u\n", week); + return TRUE; +} + +static gboolean +udev_backend_set_production_index (ItdbBackend *itdb_backend, guint index) +{ + g_print (LIBGPOD_UDEV_NS"PRODUCTION_INDEX=%u\n", index); + return TRUE; +} + +static gboolean +udev_backend_set_control_path (ItdbBackend *itdb_backend, const char *control_path) +{ + g_print (LIBGPOD_UDEV_NS"MODEL_CONTROL_PATH=%s\n", control_path); + return TRUE; +} + +static gboolean +udev_backend_set_name (ItdbBackend *itdb_backend, const char *name) +{ + g_print ("DKD_PRESENTATION_NAME=%s\n", name); + return TRUE; +} + +static gboolean udev_backend_set_artwork_type_supported (ItdbBackend *itdb_backend, + enum ArtworkType type, + gboolean supported) +{ + char *propname; + switch (type) { + case ALBUM: + propname = LIBGPOD_UDEV_NS"IMAGES_ALBUM_ART_SUPPORTED=%d\n"; + break; + case PHOTO: + propname = LIBGPOD_UDEV_NS"IMAGES_PHOTOS_SUPPORTED=%d\n"; + break; + case CHAPTER: + propname = LIBGPOD_UDEV_NS"IMAGES_CHAPTER_IMAGES_SUPPORTED=%d\n"; + break; + default: + g_return_val_if_reached (FALSE); + } + g_print (propname, !!supported); + return TRUE; +} + +static gboolean udev_backend_set_artwork_formats (ItdbBackend *itdb_backend, + enum ArtworkType type, + const GList *formats) +{ + udev_backend_set_artwork_type_supported (itdb_backend, type, + (formats != NULL)); + + return TRUE; +} + +static ItdbBackend *udev_backend_new (void) +{ + UdevBackend *backend; + + backend = g_new0 (UdevBackend, 1); + + backend->parent.destroy = udev_backend_destroy; + backend->parent.set_version = udev_backend_set_version; + backend->parent.set_is_unknown = udev_backend_set_is_unknown; + backend->parent.set_icon_name = udev_backend_set_icon_name; + backend->parent.set_firewire_id = udev_backend_set_firewire_id; + backend->parent.set_serial_number = udev_backend_set_serial_number; + backend->parent.set_firmware_version = udev_backend_set_firmware_version; + backend->parent.set_model_name = udev_backend_set_model_name; + backend->parent.set_generation = udev_backend_set_generation; + backend->parent.set_color = udev_backend_set_color; + backend->parent.set_factory_id = udev_backend_set_factory_id; + backend->parent.set_production_year = udev_backend_set_production_year; + backend->parent.set_production_week = udev_backend_set_production_week; + backend->parent.set_production_index = udev_backend_set_production_index; + backend->parent.set_control_path = udev_backend_set_control_path; + backend->parent.set_name = udev_backend_set_name; + backend->parent.set_artwork_formats = udev_backend_set_artwork_formats; + + return (ItdbBackend *)backend; +} + +int main (int argc, char **argv) +{ + ItdbBackend *backend; + int result; + const char *fstype; + gint usb_bus_number; + gint usb_dev_number; + + if (argc != 4) { + return -1; + } + g_type_init (); + + backend = udev_backend_new (); + if (backend == NULL) { + return -1; + } + + fstype = g_getenv ("ID_FS_TYPE"); + if (fstype == NULL) { + return -1; + } + + usb_bus_number = atoi (argv[2]); + usb_dev_number = atoi (argv[3]); + + result = itdb_callout_set_ipod_properties (backend, argv[1], + usb_bus_number, + usb_dev_number, + fstype); + backend->destroy (backend); + + return result; +} ------------------------------------------------------------------------------ SOLARIS 10 is the OS for Data Centers - provides features such as DTrace, Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW http://p.sf.net/sfu/solaris-dev2dev _______________________________________________ gtkpod-cvs2 mailing list gtkpod-cvs2@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2