diff options
author | Philipp Schmidt <philschmidt@gmx.net> | 2013-07-15 17:13:16 +0200 |
---|---|---|
committer | Philipp Schmidt <philschmidt@gmx.net> | 2013-07-15 17:13:16 +0200 |
commit | a95767784288fe61bf6aee2966b61573d84f9613 (patch) | |
tree | c5ad65fc41f15ba877ed8867f8e327b34ef4f1c5 | |
parent | 8a3ae1df2bacd9d356ec02c58e8f9623753532c0 (diff) | |
download | libmtp-a95767784288fe61bf6aee2966b61573d84f9613.tar.gz |
Update makefile to link udev, compile fixes
-rw-r--r-- | daemon/Makefile.am | 5 | ||||
-rw-r--r-- | daemon/mtpd.c | 24 | ||||
-rw-r--r-- | daemon/udev_listener.c | 38 | ||||
-rw-r--r-- | daemon/udev_listener.h | 5 |
4 files changed, 42 insertions, 30 deletions
diff --git a/daemon/Makefile.am b/daemon/Makefile.am index c655d26..726c214 100644 --- a/daemon/Makefile.am +++ b/daemon/Makefile.am @@ -10,6 +10,7 @@ INCLUDES = \ libraries = \ $(top_builddir)/src/libmtp.la \ $(GLIB_LIBS) \ + -ludev $(NULL) dbus_built_sources = mtp-dbus.c mtp-dbus.h @@ -21,14 +22,12 @@ $(dbus_built_sources) : Makefile.am dbus-interface.xml --c-namespace MTPD \ --c-generate-object-manager \ --generate-c-code mtp-dbus \ - --generate-docbook generated-docs \ - --generate-c-code mtp-dbus \ $(srcdir)/dbus-interface.xml \ $(NULL) sbin_PROGRAMS = mtpd -mtpd_SOURCES = mtpd.c udev_listener.c +mtpd_SOURCES = mtpd.c udev_listener.c dbus_service.c mtp_manager.c mtpd_LDADD = $(libraries) # D-BUS service file diff --git a/daemon/mtpd.c b/daemon/mtpd.c index 04db940..bb2d8aa 100644 --- a/daemon/mtpd.c +++ b/daemon/mtpd.c @@ -1,5 +1,10 @@ /** * \file mtpd.c + * \short Main program for the daemon + * + * Initializes the actual daemon. Sets up the udev, dbus and mtp + * managing parts and then listens to signals to shut the daemon + * down if required. * * Copyright (C) 2013 Philip Langdale <philipl@overt.org> * Copyright (C) 2013 Philipp Schmidt <philschmidt@gmx.net> @@ -20,12 +25,13 @@ * Boston, MA 02111-1307, USA. */ - +#include <stdint.h> #include <unistd.h> #include <signal.h> #include <syslog.h> #include "udev_listener.h" +#include "mtp_manager.h" void signal_handler(int sig) { @@ -52,7 +58,7 @@ signal_handler(int sig) { int main(int argc, char **argv) { - + // Set up signal handlers signal(SIGHUP, signal_handler); signal(SIGTERM, signal_handler); @@ -60,18 +66,16 @@ main(int argc, char **argv) { signal(SIGQUIT, signal_handler); openlog( "LIBMTP_daemon", - LOG_PID | LOG_CONS | LOG_NDELAY, LOG_DAEMON ); + LOG_PID | LOG_PERROR | LOG_NDELAY, LOG_DAEMON ); syslog(LOG_INFO, "Daemoninsing"); - int daemon_err = daemon(0, 0); - - if (daemon_err < 0) - syslog(LOG_ERR, "Error daemonising"); +// int daemon_err = daemon(0, 0); +// +// if (daemon_err < 0) +// syslog(LOG_ERR, "Error daemonising"); - /* - * Set up the actual stuff. E.g. dbus service, udev service, init connected devices (if any) - */ + MTPD_start_udev_listener(device_added, device_removed); pause(); diff --git a/daemon/udev_listener.c b/daemon/udev_listener.c index fe4928a..a286d97 100644 --- a/daemon/udev_listener.c +++ b/daemon/udev_listener.c @@ -1,5 +1,10 @@ /** * \file udev_listener.c + * \short Implementation of the udev listener + * + * Implementation of the thread listening to udev for new or removed + * devices. Uses callbacks to inform the daemon about them if they are + * indeed MTP devices. * * Copyright (C) 2013 Philipp Schmidt <philschmidt@gmx.net> * @@ -30,19 +35,20 @@ #include <string.h> #include <stdbool.h> -#include <glib.h> +#include <glib-2.0/glib.h> +#include <syslog.h> -struct device_ident_t +typedef struct { int busnum; int devnum; -}; +} device_ident_t; -struct callbacks_t +typedef struct { - const MTPD_device_added_t device_added_callback; - const MTPD_device_removed_t device_removed_callback; -}; + MTPD_device_added_t device_added_callback; + MTPD_device_removed_t device_removed_callback; +} callbacks_t; pthread_t thread; @@ -61,7 +67,7 @@ void MTPD_run_udev_listener(void *arg) if (!udev) { - stderr << "Can't create udev"; + syslog(LOG_ERR, "Can't create udev"); return; } @@ -93,11 +99,9 @@ void MTPD_run_udev_listener(void *arg) { dev = udev_monitor_receive_device(mon); - device_identificator ident; const char* action = udev_device_get_action(dev); - + device_ident_t ident; - ident.busnum = atoi(udev_device_get_property_value(dev, "BUSNUM")); pthread_t thread; ident.devnum = atoi(udev_device_get_property_value(dev, "DEVNUM")); @@ -108,15 +112,15 @@ void MTPD_run_udev_listener(void *arg) if (isMtpDevice == 1) { // Add to internal device list - g_array_append_vals(ident_list, ident); + g_array_append_vals(ident_list, &ident, sizeof(device_ident_t*)); callbacks->device_added_callback( ident.busnum, ident.devnum ); } } if (strcmp("remove", action) == 0) - { my_struct* foo = (my_struct*)arg; - int device_index = -1; - for ( int i = 0; i < ident_list->len; i++ ) + { + int device_index = -1, i; + for ( i = 0; i < ident_list->len; i++ ) { device_ident_t current = g_array_index( ident_list, device_ident_t, i ); @@ -129,7 +133,7 @@ void MTPD_run_udev_listener(void *arg) if (device_index >= 0) { - g_array_remove_index(device_index); + g_array_remove_index(ident_list, device_index); callbacks->device_removed_callback(ident.busnum, ident.devnum); } } @@ -138,7 +142,7 @@ void MTPD_run_udev_listener(void *arg) } } - g_array_free( ident_list ); + g_array_free( ident_list, false ); } void MTPD_start_udev_listener(const MTPD_device_added_t device_added_callback, const MTPD_device_removed_t device_removed_callback) diff --git a/daemon/udev_listener.h b/daemon/udev_listener.h index 74ead54..d08c6cf 100644 --- a/daemon/udev_listener.h +++ b/daemon/udev_listener.h @@ -1,5 +1,10 @@ /** * \file udev_listener.h + * \short Definition of the udev listener + * + * Header file of the thread listening to udev for new or removed + * devices. Uses callbacks to inform the daemon about them if they are + * indeed MTP devices. * * Copyright (C) 2013 Philipp Schmidt <philschmidt@gmx.net> * |