summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcus Meissner <marcus@jet.franken.de>2010-03-13 11:26:56 +0000
committerMarcus Meissner <marcus@jet.franken.de>2010-03-13 11:26:56 +0000
commit966b176c62a686572c55aba6975aebdaab1c9e77 (patch)
tree118e46850b7dd2a6ae3563d84c6a2e66f971589f
parentb4a0fa7cfa4856cbd12a0a8aeb6fbd6100e4d35a (diff)
downloadlibgphoto2-966b176c62a686572c55aba6975aebdaab1c9e77.tar.gz
- added usb disk direct driver.
- make gp_log_add_func/remove_func use non-format string - remove gp_log_simple_add_func/remove_func again git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@12752 67ed7778-7388-44ab-90cf-0a291f65f57c
-rw-r--r--libgphoto2_port/Makefile.am1
-rw-r--r--libgphoto2_port/configure.ac2
-rw-r--r--libgphoto2_port/gphoto2/gphoto2-port-info-list.h3
-rw-r--r--libgphoto2_port/gphoto2/gphoto2-port-library.h3
-rw-r--r--libgphoto2_port/gphoto2/gphoto2-port-log.h14
-rw-r--r--libgphoto2_port/gphoto2/gphoto2-port.h10
-rw-r--r--libgphoto2_port/libgphoto2_port/gphoto2-port-log.c119
-rw-r--r--libgphoto2_port/libgphoto2_port/gphoto2-port.c34
-rw-r--r--libgphoto2_port/libgphoto2_port/libgphoto2_port.ver3
9 files changed, 71 insertions, 118 deletions
diff --git a/libgphoto2_port/Makefile.am b/libgphoto2_port/Makefile.am
index c5fb5aeac..9e8c5bb41 100644
--- a/libgphoto2_port/Makefile.am
+++ b/libgphoto2_port/Makefile.am
@@ -50,6 +50,7 @@ include disk/Makefile-files
include ptpip/Makefile-files
include serial/Makefile-files
include usb/Makefile-files
+include usbdiskdirect/Makefile-files
########################################################################
diff --git a/libgphoto2_port/configure.ac b/libgphoto2_port/configure.ac
index 640480489..3351aef80 100644
--- a/libgphoto2_port/configure.ac
+++ b/libgphoto2_port/configure.ac
@@ -357,7 +357,7 @@ dnl ---------------------------------------------------------------------------
GP_CONFIG_MSG([USB ports])
GP_CHECK_LIBRARY([LIBUSB],[libusb],[>= 0.1.5],
[usb.h],[usb_open],[
- IOLIB_LIST="$IOLIB_LIST usb"
+ IOLIB_LIST="$IOLIB_LIST usb usbdiskdirect"
],[],
[disable-explicitly],
[http://libusb.sourceforge.net/]
diff --git a/libgphoto2_port/gphoto2/gphoto2-port-info-list.h b/libgphoto2_port/gphoto2/gphoto2-port-info-list.h
index 3d3414931..498474463 100644
--- a/libgphoto2_port/gphoto2/gphoto2-port-info-list.h
+++ b/libgphoto2_port/gphoto2/gphoto2-port-info-list.h
@@ -36,7 +36,8 @@ typedef enum {
GP_PORT_SERIAL = 1 << 0, /**< \brief Serial port. */
GP_PORT_USB = 1 << 2, /**< \brief USB port. */
GP_PORT_DISK = 1 << 3, /**< \brief Disk / local mountpoint port. */
- GP_PORT_PTPIP = 1 << 4 /**< \brief PTP/IP port. */
+ GP_PORT_PTPIP = 1 << 4, /**< \brief PTP/IP port. */
+ GP_PORT_USB_DISK_DIRECT = 1 << 5, /**< \brief Direct IO to an usb mass storage device. */
} GPPortType;
/**
diff --git a/libgphoto2_port/gphoto2/gphoto2-port-library.h b/libgphoto2_port/gphoto2/gphoto2-port-library.h
index 226f946b3..837f2bffc 100644
--- a/libgphoto2_port/gphoto2/gphoto2-port-library.h
+++ b/libgphoto2_port/gphoto2/gphoto2-port-library.h
@@ -71,6 +71,9 @@ typedef struct _GPPortOperations {
int value, int index, char *bytes, int size);
int (*msg_class_read) (GPPort * dev, int request,
int value, int index, char *bytes, int size);
+
+ /* For USB disk direct IO devices */
+ int (*seek) (GPPort * dev, int offset, int whence);
} GPPortOperations;
typedef GPPortType (* GPPortLibraryType) (void);
diff --git a/libgphoto2_port/gphoto2/gphoto2-port-log.h b/libgphoto2_port/gphoto2/gphoto2-port-log.h
index b59850e21..7357be784 100644
--- a/libgphoto2_port/gphoto2/gphoto2-port-log.h
+++ b/libgphoto2_port/gphoto2/gphoto2-port-log.h
@@ -55,26 +55,16 @@ typedef enum {
*
* \param level the log level of the passed message, as set by the camera driver or libgphoto2
* \param domain the logging domain as set by the camera driver, or libgphoto2 function
- * \param format the printf style format string of the logmessage, without linefeed
- * \param args the arguments as va_list, depending on the format string
+ * \param str the logmessage, without linefeed
* \param data the caller private data that was passed to gp_log_add_func()
*/
-typedef void (* GPLogFunc) (GPLogLevel level, const char *domain,
- const char *format, va_list args, void *data)
-#if (__GNUC__ >= 3)
- __attribute__((__format__(printf,3,0)))
-#endif
-;
-typedef void (* GPLogSimpleFunc) (GPLogLevel level, const char *domain, const char *str, void *data);
+typedef void (* GPLogFunc) (GPLogLevel level, const char *domain, const char *str, void *data);
#ifndef DISABLE_DEBUGGING
int gp_log_add_func (GPLogLevel level, GPLogFunc func, void *data);
int gp_log_remove_func (int id);
-int gp_log_simple_add_func (GPLogLevel level, GPLogSimpleFunc func, void *data);
-int gp_log_simple_remove_func (int id);
-
/* Logging */
void gp_log (GPLogLevel level, const char *domain,
const char *format, ...)
diff --git a/libgphoto2_port/gphoto2/gphoto2-port.h b/libgphoto2_port/gphoto2/gphoto2-port.h
index 69fca9410..7ca367b43 100644
--- a/libgphoto2_port/gphoto2/gphoto2-port.h
+++ b/libgphoto2_port/gphoto2/gphoto2-port.h
@@ -92,6 +92,13 @@ typedef struct _GPPortSettingsUSB {
} GPPortSettingsUSB;
/**
+ * \brief Port settings for USB mass storage direct IO ports.
+ */
+typedef struct _GPPortSettingsUsbDiskDirect {
+ char path[128]; /**< /brief The ports device node path (/dev/sdX)*/
+} GPPortSettingsUsbDiskDirect;
+
+/**
* \brief Union of port settings.
*
* This contains a shared union of possible settings for ports needing
@@ -100,6 +107,7 @@ typedef struct _GPPortSettingsUSB {
typedef union _GPPortSettings {
GPPortSettingsSerial serial; /**< \brief Serial specific settings */
GPPortSettingsUSB usb; /**< \brief USB specific settings */
+ GPPortSettingsUsbDiskDirect usbdiskdirect; /**< \brief usb disk direct port specific settings */
} GPPortSettings;
enum {
@@ -204,6 +212,8 @@ int gp_port_usb_msg_class_write (GPPort *port, int request,
int gp_port_usb_msg_class_read (GPPort *port, int request,
int value, int index, char *bytes, int size);
+int gp_port_seek (GPPort *port, int offset, int whence);
+
/* Error reporting */
int gp_port_set_error (GPPort *port, const char *format, ...)
#ifdef __GNUC__
diff --git a/libgphoto2_port/libgphoto2_port/gphoto2-port-log.c b/libgphoto2_port/libgphoto2_port/gphoto2-port-log.c
index 843c96d4c..26572469e 100644
--- a/libgphoto2_port/libgphoto2_port/gphoto2-port-log.c
+++ b/libgphoto2_port/libgphoto2_port/gphoto2-port-log.c
@@ -58,19 +58,10 @@ typedef struct {
GPLogFunc func; /**< Internal function pointer to call */
void *data; /**< Private data supplied by caller */
} LogFunc;
-typedef struct {
- unsigned int id; /**< Internal id */
- GPLogLevel level; /**< Internal loglevel */
- GPLogSimpleFunc func; /**< Internal function pointer to call */
- void *data; /**< Private data supplied by caller */
-} LogSimpleFunc;
static LogFunc *log_funcs = NULL;
static unsigned int log_funcs_count = 0;
-static LogSimpleFunc *log_simple_funcs = NULL;
-static unsigned int log_simple_funcs_count = 0;
-
/**
* \brief Add a function to get logging information
*
@@ -133,67 +124,6 @@ gp_log_remove_func (int id)
}
/**
- * \brief Add a function to get logging information
- *
- * \param level the maximum level of logging it will get, up to and including the passed value
- * \param func a #GPLogSimpleFunc
- * \param data data
- *
- * Adds a log function that will be called for each log message that is flagged
- * with a log level that appears in given log level. This function returns
- * an id that you can use for removing the log function again (using
- * #gp_log_remove_func).
- *
- * \return an id or a gphoto2 error code
- **/
-int
-gp_log_simple_add_func (GPLogLevel level, GPLogSimpleFunc func, void *data)
-{
- LogSimpleFunc *new_log_funcs;
-
- if (!func)
- return (GP_ERROR_BAD_PARAMETERS);
-
- if (!log_simple_funcs)
- new_log_funcs = malloc (sizeof (LogSimpleFunc));
- else
- new_log_funcs = realloc (log_simple_funcs, sizeof (LogSimpleFunc) *
- (log_simple_funcs_count + 1));
- if (!new_log_funcs)
- return (GP_ERROR_NO_MEMORY);
-
- log_simple_funcs = new_log_funcs;
- log_simple_funcs_count++;
-
- log_simple_funcs[log_simple_funcs_count - 1].id = log_simple_funcs_count;
- log_simple_funcs[log_simple_funcs_count - 1].level = level;
- log_simple_funcs[log_simple_funcs_count - 1].func = func;
- log_simple_funcs[log_simple_funcs_count - 1].data = data;
-
- return (log_simple_funcs_count);
-}
-
-/**
- * \brief Remove a logging receiving function
- * \param id an id (return value of #gp_log_add_func)
- *
- * Removes the log function with given id.
- *
- * \return a gphoto2 error code
- **/
-int
-gp_log_simple_remove_func (int id)
-{
- if (id < 1 || id > log_simple_funcs_count)
- return (GP_ERROR_BAD_PARAMETERS);
-
- memmove (log_simple_funcs + id - 1, log_simple_funcs + id, log_simple_funcs_count - id);
- log_simple_funcs_count--;
-
- return (GP_OK);
-}
-
-/**
* Width of offset field in characters. Note that HEXDUMP_COMPLETE_LINE
* needs to be changed when this value is changed.
*/
@@ -334,48 +264,33 @@ gp_logv (GPLogLevel level, const char *domain, const char *format,
#ifdef HAVE_VA_COPY
va_list xargs;
#endif
+ int strsize = 1000;
+ char *str;
+ int n;
- for (i = 0; i < log_funcs_count; i++) {
- if (log_funcs[i].level >= level) {
-#ifdef HAVE_VA_COPY
- va_copy (xargs, args);
- log_funcs[i].func (level, domain, format, xargs,
- log_funcs[i].data);
-#else
- log_funcs[i].func (level, domain, format, args,
- log_funcs[i].data);
-#endif
- }
- }
+ if (!log_funcs_count)
+ return;
- if (log_simple_funcs_count) {
+ str = malloc(strsize);
+ if (!str) return;
#ifdef HAVE_VA_COPY
- va_list xargs;
+ va_copy (xargs, args);
#endif
- int strsize = 1000;
- char *str = malloc(strsize);
- int n;
-
+ n = vsnprintf (str, strsize, format, xargs);
+ if (n+1>strsize) {
+ free (str);
+ str = malloc(n+1);
if (!str) return;
+ strsize = n+1;
#ifdef HAVE_VA_COPY
va_copy (xargs, args);
#endif
n = vsnprintf (str, strsize, format, xargs);
- if (n+1>strsize) {
- free (str);
- str = malloc(n+1);
- if (!str) return;
- strsize = n+1;
-#ifdef HAVE_VA_COPY
- va_copy (xargs, args);
-#endif
- n = vsnprintf (str, strsize, format, xargs);
- }
- for (i = 0; i < log_simple_funcs_count; i++)
- if (log_simple_funcs[i].level >= level)
- log_simple_funcs[i].func (level, domain, str, log_simple_funcs[i].data);
- free (str);
}
+ for (i = 0; i < log_funcs_count; i++)
+ if (log_funcs[i].level >= level)
+ log_funcs[i].func (level, domain, str, log_funcs[i].data);
+ free (str);
}
/**
diff --git a/libgphoto2_port/libgphoto2_port/gphoto2-port.c b/libgphoto2_port/libgphoto2_port/gphoto2-port.c
index 62818fb9c..ee85a00f1 100644
--- a/libgphoto2_port/libgphoto2_port/gphoto2-port.c
+++ b/libgphoto2_port/libgphoto2_port/gphoto2-port.c
@@ -208,6 +208,11 @@ gp_port_set_info (GPPort *port, GPPortInfo info)
port->settings.usb.altsetting = -1;
gp_port_set_timeout (port, 5000);
break;
+ case GP_PORT_USB_DISK_DIRECT:
+ snprintf(port->settings.usbdiskdirect.path,
+ sizeof(port->settings.usbdiskdirect.path), "%s",
+ strchr(info->path, ':') + 1);
+ break;
default:
/* Nothing in here */
break;
@@ -1064,6 +1069,35 @@ gp_port_usb_msg_class_read (GPPort *port, int request, int value, int index,
return (retval);
}
+/**
+ * \brief Seek on a port (for usb disk direct ports)
+ *
+ * \param port a #GPPort
+ * \param offset offset to seek to
+ * \param whence the underlying lseek call whence parameter
+ *
+ * Seeks to a specific offset on the usb disk
+ *
+ * \return a gphoto2 error code
+ **/
+int
+gp_port_seek (GPPort *port, int offset, int whence)
+{
+ int retval;
+
+ gp_log (GP_LOG_DEBUG, "gphoto2-port", "Seeking to: %d whence: %d",
+ offset, whence);
+
+ CHECK_NULL (port);
+ CHECK_INIT (port);
+
+ CHECK_SUPP (port, "seek", port->pc->ops->seek);
+ retval = port->pc->ops->seek (port, offset, whence);
+
+ gp_log (GP_LOG_DEBUG, "gphoto2-port", "Seek result: %d", retval);
+
+ return retval;
+}
/**
* \brief Set verbose port error message
diff --git a/libgphoto2_port/libgphoto2_port/libgphoto2_port.ver b/libgphoto2_port/libgphoto2_port/libgphoto2_port.ver
index 3e1a90f5d..6684883d3 100644
--- a/libgphoto2_port/libgphoto2_port/libgphoto2_port.ver
+++ b/libgphoto2_port/libgphoto2_port/libgphoto2_port.ver
@@ -4,8 +4,6 @@ LIBGPHOTO2_5_0 {
gp_log_add_func;
gp_log_data;
gp_log_remove_func;
- gp_log_simple_add_func;
- gp_log_simple_remove_func;
gp_logv;
gp_port_check_int;
gp_port_check_int_fast;
@@ -34,6 +32,7 @@ LIBGPHOTO2_5_0 {
gp_port_open;
gp_port_read;
gp_port_result_as_string;
+ gp_port_seek;
gp_port_send_break;
gp_port_set_error;
gp_port_set_info;