diff options
-rw-r--r-- | libgphoto2_port/include/Makefile.am | 1 | ||||
-rw-r--r-- | libgphoto2_port/include/gphoto2-port-debug.h | 6 | ||||
-rw-r--r-- | libgphoto2_port/include/gphoto2-port-result.h | 62 | ||||
-rw-r--r-- | libgphoto2_port/include/gphoto2-port.h | 54 | ||||
-rw-r--r-- | libgphoto2_port/libgphoto2_port/.cvsignore | 4 | ||||
-rw-r--r-- | libgphoto2_port/libgphoto2_port/Makefile.am | 1 | ||||
-rw-r--r-- | libgphoto2_port/libgphoto2_port/debug.c | 9 | ||||
-rw-r--r-- | libgphoto2_port/libgphoto2_port/gp_port.c | 43 | ||||
-rw-r--r-- | libgphoto2_port/libgphoto2_port/library.c | 3 | ||||
-rw-r--r-- | libgphoto2_port/libgphoto2_port/portability.c | 1 | ||||
-rw-r--r-- | libgphoto2_port/libgphoto2_port/result.c | 87 | ||||
-rw-r--r-- | libgphoto2_port/test/test-gp-port.c | 2 |
12 files changed, 175 insertions, 98 deletions
diff --git a/libgphoto2_port/include/Makefile.am b/libgphoto2_port/include/Makefile.am index 0ae887a2a..d15480afa 100644 --- a/libgphoto2_port/include/Makefile.am +++ b/libgphoto2_port/include/Makefile.am @@ -2,6 +2,7 @@ gphoto2_port_incdir = $(includedir)/gphoto2 gphoto2_port_inc_HEADERS =\ gphoto2-port.h \ gphoto2-port-debug.h \ + gphoto2-port-result.h \ gphoto2-portability.h \ gphoto2-port-serial.h \ gphoto2-port-parallel.h \ diff --git a/libgphoto2_port/include/gphoto2-port-debug.h b/libgphoto2_port/include/gphoto2-port-debug.h index ee77d2eaa..0c9d5ad8f 100644 --- a/libgphoto2_port/include/gphoto2-port-debug.h +++ b/libgphoto2_port/include/gphoto2-port-debug.h @@ -21,6 +21,12 @@ #ifndef __GPHOTO2_PORT_DEBUG_H__ #define __GPHOTO2_PORT_DEBUG_H__ +/* Debug levels */ +#define GP_DEBUG_NONE 0 +#define GP_DEBUG_LOW 1 +#define GP_DEBUG_MEDIUM 2 +#define GP_DEBUG_HIGH 3 + void gp_port_debug_set_level (int level); void gp_port_debug_printf (int target_debug_level, int debug_level, char *format, ...); diff --git a/libgphoto2_port/include/gphoto2-port-result.h b/libgphoto2_port/include/gphoto2-port-result.h new file mode 100644 index 000000000..9d299199c --- /dev/null +++ b/libgphoto2_port/include/gphoto2-port-result.h @@ -0,0 +1,62 @@ +/* gphoto2-port-result.h + * + * Copyright (C) 2001 Lutz Müller <urc8@rz.uni-karlsruhe.de> + * + * This library 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 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. + */ + +#ifndef __GPHOTO2_PORT_RESULT_H__ +#define __GPHOTO2_PORT_RESULT_H__ + +/* Return values. gphoto2-port should only return values from 0 to -99 */ + +#define GP_OK 0 + +#define GP_ERROR -1 +#define GP_ERROR_TIMEOUT -2 +#define GP_ERROR_IO_SUPPORTED_SERIAL -3 +#define GP_ERROR_IO_SUPPORTED_USB -4 +#define GP_ERROR_IO_SUPPORTED_PARALLEL -5 +#define GP_ERROR_IO_SUPPORTED_NETWORK -6 +#define GP_ERROR_IO_SUPPORTED_IEEE1394 -7 +#define GP_ERROR_IO_UNKNOWN_PORT -8 + +#define GP_ERROR_IO_MEMORY -9 +#define GP_ERROR_IO_LIBRARY -10 + +#define GP_ERROR_IO_INIT -11 +#define GP_ERROR_IO_OPEN -12 +#define GP_ERROR_IO_TIMEOUT -13 +#define GP_ERROR_IO_READ -14 +#define GP_ERROR_IO_WRITE -15 +#define GP_ERROR_IO_CLOSE -16 +#define GP_ERROR_IO_UPDATE -17 +#define GP_ERROR_IO_PIN -18 + +#define GP_ERROR_IO_SERIAL_SPEED -19 +#define GP_ERROR_IO_SERIAL_BREAK -20 +#define GP_ERROR_IO_SERIAL_FLUSH -21 + +#define GP_ERROR_IO_USB_CLEAR_HALT -22 +#define GP_ERROR_IO_USB_FIND -23 +#define GP_ERROR_IO_USB_CLAIM -24 + +#define GP_ERROR_IO_LOCK -25 + +const char *gp_port_result_as_string (int result); + +#endif /* __GPHOTO2_PORT_RESULT_H__ */ + diff --git a/libgphoto2_port/include/gphoto2-port.h b/libgphoto2_port/include/gphoto2-port.h index 10aadf202..80c30e2d0 100644 --- a/libgphoto2_port/include/gphoto2-port.h +++ b/libgphoto2_port/include/gphoto2-port.h @@ -16,6 +16,9 @@ #include "gphoto2-port-usb.h" #include "gphoto2-port-ieee1394.h" +#include "gphoto2-port-result.h" +#include "gphoto2-port-debug.h" + #ifndef TRUE #define TRUE (0==0) #endif @@ -24,53 +27,7 @@ #define FALSE (1==0) #endif -/* Defines and enums - -------------------------------------------------------------- - Note: this is a base set of return values. */ - -/* Return values */ -/* Note: This lib should be allocated return values of 0 to -99 */ - -#define GP_OK 0 - -#define GP_ERROR -1 -#define GP_ERROR_TIMEOUT -2 -#define GP_ERROR_IO_SUPPORTED_SERIAL -3 -#define GP_ERROR_IO_SUPPORTED_USB -4 -#define GP_ERROR_IO_SUPPORTED_PARALLEL -5 -#define GP_ERROR_IO_SUPPORTED_NETWORK -6 -#define GP_ERROR_IO_SUPPORTED_IEEE1394 -7 -#define GP_ERROR_IO_UNKNOWN_PORT -8 - -#define GP_ERROR_IO_MEMORY -9 -#define GP_ERROR_IO_LIBRARY -10 - -#define GP_ERROR_IO_INIT -11 -#define GP_ERROR_IO_OPEN -12 -#define GP_ERROR_IO_TIMEOUT -13 -#define GP_ERROR_IO_READ -14 -#define GP_ERROR_IO_WRITE -15 -#define GP_ERROR_IO_CLOSE -16 -#define GP_ERROR_IO_UPDATE -17 -#define GP_ERROR_IO_PIN -18 - -#define GP_ERROR_IO_SERIAL_SPEED -19 -#define GP_ERROR_IO_SERIAL_BREAK -20 -#define GP_ERROR_IO_SERIAL_FLUSH -21 - -#define GP_ERROR_IO_USB_CLEAR_HALT -22 -#define GP_ERROR_IO_USB_FIND -23 -#define GP_ERROR_IO_USB_CLAIM -24 - -#define GP_ERROR_IO_LOCK -25 - -/* Debugging definitions for init */ -#define GP_DEBUG_NONE 0 -#define GP_DEBUG_LOW 1 -#define GP_DEBUG_MEDIUM 2 -#define GP_DEBUG_HIGH 3 - -#define GP_PORT_MAX_BUF_LEN 4096 /* max length of receive buffer */ +#define GP_PORT_MAX_BUF_LEN 4096 /* max length of receive buffer */ /* Specify the types of devices */ typedef enum { @@ -177,9 +134,6 @@ struct gp_port { /* Core functions -------------------------------------------------------------- */ - char *gp_port_result_as_string (int result); - /* Returns a string describing the error */ - int gp_port_init (int debug_level); /* Initializes the library. return values: diff --git a/libgphoto2_port/libgphoto2_port/.cvsignore b/libgphoto2_port/libgphoto2_port/.cvsignore index a89e8da75..78f298a59 100644 --- a/libgphoto2_port/libgphoto2_port/.cvsignore +++ b/libgphoto2_port/libgphoto2_port/.cvsignore @@ -2,7 +2,5 @@ Makefile.in Makefile .deps .libs -gp_port.lo -library.lo -portability.lo +*.lo libgphoto2_port.la diff --git a/libgphoto2_port/libgphoto2_port/Makefile.am b/libgphoto2_port/libgphoto2_port/Makefile.am index a70bc0afc..34848e139 100644 --- a/libgphoto2_port/libgphoto2_port/Makefile.am +++ b/libgphoto2_port/libgphoto2_port/Makefile.am @@ -12,5 +12,6 @@ libgphoto2_port_la_LDFLAGS = -version-info @LIBGPPORT_VERSION_INFO@ libgphoto2_port_la_SOURCES = \ gp_port.c \ debug.c \ + result.c \ library.c library.h \ portability.c diff --git a/libgphoto2_port/libgphoto2_port/debug.c b/libgphoto2_port/libgphoto2_port/debug.c index 9be3c3ddb..e5488d581 100644 --- a/libgphoto2_port/libgphoto2_port/debug.c +++ b/libgphoto2_port/libgphoto2_port/debug.c @@ -25,7 +25,7 @@ #include <stdarg.h> #include <stdio.h> -#include <gphoto2-port.h> +#include <gphoto2-port-result.h> int glob_debug_level = 0; @@ -91,6 +91,10 @@ gp_port_debug_history_append (const char *msg) memset (debug_history, 0, debug_history_size); } + /* First of all, skip the whole thing if the message is too long */ + if (strlen (msg) + 2 > debug_history_size) + return; + /* Do we have to forget parts of the debug history? */ while (debug_history_size - strlen (debug_history) < strlen (msg) + 1) { @@ -105,6 +109,7 @@ gp_port_debug_history_append (const char *msg) strlen (debug_history) - i); } + /* Append the message */ strcat (debug_history, msg); strcat (debug_history, "\n"); } @@ -117,7 +122,7 @@ gp_port_debug_history_set_size (unsigned int size) new_debug_history = realloc (debug_history, sizeof (char) * size); if (!new_debug_history) - return (GP_ERROR); + return (GP_ERROR_IO_MEMORY); debug_history_size = size; debug_history = new_debug_history; diff --git a/libgphoto2_port/libgphoto2_port/gp_port.c b/libgphoto2_port/libgphoto2_port/gp_port.c index cbb771efb..07af20d62 100644 --- a/libgphoto2_port/libgphoto2_port/gp_port.c +++ b/libgphoto2_port/libgphoto2_port/gp_port.c @@ -27,6 +27,7 @@ #include <gphoto2-port.h> #include <gphoto2-port-debug.h> +#include <gphoto2-port-result.h> #include "library.h" extern int glob_debug_level; @@ -50,48 +51,6 @@ int device_count; int initialized = 0; -#define GP_ERR_RES(num,str) \ - if (result == num) \ - return (N_(str)); - -char *gp_port_result_as_string (int result) { - - /* gp_port error range is -1 .. -99 */ - - if ((result < -99) || (result > 0)) - return (N_("Unknown error")); - - GP_ERR_RES( 0, "No error"); - GP_ERR_RES(-1, "Unspecified error"); - GP_ERR_RES(-2, "There was a timeout reading from or writing to the port"); - GP_ERR_RES(-3, "The serial port is not supported"); - GP_ERR_RES(-4, "The USB port is not supported"); - GP_ERR_RES(-5, "The parallel port is not supported"); - GP_ERR_RES(-6, "The network port is not supported"); - GP_ERR_RES(-7, "The IEEE1394 port is not supported"); - GP_ERR_RES(-8, "Unknown port"); - GP_ERR_RES(-9, "Out of memory"); - GP_ERR_RES(-10, "Error loading a required library"); - GP_ERR_RES(-11, "Error initializing the port"); - GP_ERR_RES(-12, "Error opening the port"); - GP_ERR_RES(-13, "Timeout reading from or writing to the port"); - GP_ERR_RES(-14, "Error reading from the port"); - GP_ERR_RES(-15, "Error writing to the port"); - GP_ERR_RES(-16, "Error closing the port"); - GP_ERR_RES(-17, "Error updating the port settings"); - GP_ERR_RES(-18, "Error with the port"); - GP_ERR_RES(-19, "Error setting the serial port speed"); - GP_ERR_RES(-20, "Error sending a break to the serial port"); - GP_ERR_RES(-21, "Error flushing the serial line"); - GP_ERR_RES(-22, "Error clearing a halt condition on the USB port"); - GP_ERR_RES(-23, "Could not find the requested device on the USB port"); - GP_ERR_RES(-24, "Could not lock the device"); - - return (N_("Unknown error")); -} - -#undef GP_ERR_RES - /* Required library functions ---------------------------------------------------------------- diff --git a/libgphoto2_port/libgphoto2_port/library.c b/libgphoto2_port/libgphoto2_port/library.c index bfbf5305a..d439c5b2a 100644 --- a/libgphoto2_port/libgphoto2_port/library.c +++ b/libgphoto2_port/libgphoto2_port/library.c @@ -2,7 +2,8 @@ #include <stdio.h> #include <gphoto2-port-debug.h> -#include "gphoto2-port.h" +#include <gphoto2-port-result.h> +#include <gphoto2-port.h> #include "library.h" extern int device_count; diff --git a/libgphoto2_port/libgphoto2_port/portability.c b/libgphoto2_port/libgphoto2_port/portability.c index 8dd0630aa..72f721ed4 100644 --- a/libgphoto2_port/libgphoto2_port/portability.c +++ b/libgphoto2_port/libgphoto2_port/portability.c @@ -1,5 +1,6 @@ #include <stdio.h> #include <gphoto2-port.h> +#include <gphoto2-port-result.h> /* Windows Portability ------------------------------------------------------------------ */ diff --git a/libgphoto2_port/libgphoto2_port/result.c b/libgphoto2_port/libgphoto2_port/result.c new file mode 100644 index 000000000..6ac725060 --- /dev/null +++ b/libgphoto2_port/libgphoto2_port/result.c @@ -0,0 +1,87 @@ +/* result.c + * + * Copyright (C) 2001 Lutz Müller <urc8@rz.uni-karlsruhe.de> + * + * This library 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 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. + */ + +#include <config.h> +#include <gphoto2-port-result.h> + +#ifdef ENABLE_NLS +# include <libintl.h> +# undef _ +# define _(String) dgettext (PACKAGE, String) +# ifdef gettext_noop +# define N_(String) gettext_noop (String) +# else +# define N_(String) (String) +# endif +#else +# define _(String) (String) +# define N_(String) (String) +#endif + +#define GP_ERR_RES(num,str) {if (result == (num)) return (N_(str));} + +const char * +gp_port_result_as_string (int result) +{ + if ((result < -99) || (result > 0)) + return (N_("Unknown error")); + + GP_ERR_RES (GP_OK, "No error"); + GP_ERR_RES (GP_ERROR, "Unspecified error"); + GP_ERR_RES (GP_ERROR_TIMEOUT, + "Timeout reading from or writing to the port"); + GP_ERR_RES (GP_ERROR_IO_SUPPORTED_SERIAL, "Serial port not supported"); + GP_ERR_RES (GP_ERROR_IO_SUPPORTED_USB, "USB port not supported"); + GP_ERR_RES (GP_ERROR_IO_SUPPORTED_PARALLEL, + "Parallel port not supported"); + GP_ERR_RES (GP_ERROR_IO_SUPPORTED_NETWORK, + "Network port not supported"); + GP_ERR_RES (GP_ERROR_IO_SUPPORTED_IEEE1394, + "IEEE1394 port not supported"); + GP_ERR_RES (GP_ERROR_IO_UNKNOWN_PORT, "Unknown port"); + GP_ERR_RES (GP_ERROR_IO_MEMORY, "Out of memory"); + GP_ERR_RES (GP_ERROR_IO_LIBRARY, "Error loading a required library"); + GP_ERR_RES (GP_ERROR_IO_INIT, "Error initializing the port"); + GP_ERR_RES (GP_ERROR_IO_OPEN, "Error opening the port"); + GP_ERR_RES (GP_ERROR_IO_TIMEOUT, + "Timeout reading from or writing to the port"); + GP_ERR_RES (GP_ERROR_IO_READ, "Error reading from the port"); + GP_ERR_RES (GP_ERROR_IO_WRITE, "Error writing to the port"); + GP_ERR_RES (GP_ERROR_IO_CLOSE, "Error closing the port"); + GP_ERR_RES (GP_ERROR_IO_UPDATE, "Error updating the port settings"); + GP_ERR_RES (GP_ERROR_IO_PIN, "Error with the port"); + GP_ERR_RES (GP_ERROR_IO_SERIAL_SPEED, + "Error setting the serial port speed"); + GP_ERR_RES (GP_ERROR_IO_SERIAL_BREAK, + "Error sending a break to the serial port"); + GP_ERR_RES (GP_ERROR_IO_SERIAL_FLUSH, + "Error flushing the serial line"); + GP_ERR_RES (GP_ERROR_IO_USB_CLEAR_HALT, + "Error clearing a halt condition on the USB port"); + GP_ERR_RES (GP_ERROR_IO_USB_FIND, + "Could not find the requested device on the USB port"); + GP_ERR_RES (GP_ERROR_IO_USB_CLAIM, + "Could not claim the USB device"); + GP_ERR_RES (GP_ERROR_IO_LOCK, "Could not lock the device"); + + return (N_("Unknown error")); +} + +#undef GP_ERR_RES diff --git a/libgphoto2_port/test/test-gp-port.c b/libgphoto2_port/test/test-gp-port.c index d35df2a8c..7239932b1 100644 --- a/libgphoto2_port/test/test-gp-port.c +++ b/libgphoto2_port/test/test-gp-port.c @@ -2,6 +2,8 @@ #include <stdio.h> #include <string.h> #include <gphoto2-port.h> +#include <gphoto2-port-debug.h> +#include <gphoto2-port-result.h> int main (int argc, char **argv) |