2001-10-04 Lutz M�ller <urc8@rz.uni-karlsruhe.de>
* include/Makefile.am
* include/gphoto2-port-debug.h
* libgphoto2_port/Makefile.am
* libgphoto2_port/debug.c: New files
* libgphoto2_port/gp_port.c: Move debugging stuff out of here.
git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@2377 67ed7778-7388-44ab-90cf-0a291f65f57c
This commit is contained in:
@@ -1,3 +1,11 @@
|
||||
2001-10-04 Lutz Müller <urc8@rz.uni-karlsruhe.de>
|
||||
|
||||
* include/Makefile.am
|
||||
* include/gphoto2-port-debug.h
|
||||
* libgphoto2_port/Makefile.am
|
||||
* libgphoto2_port/debug.c: New files
|
||||
* libgphoto2_port/gp_port.c: Move debugging stuff out of here.
|
||||
|
||||
2001-10-04 Lutz Müller <urc8@rz.uni-karlsruhe.de>
|
||||
|
||||
* include/gphoto2-port.h:
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
gphoto2_port_incdir = $(includedir)/gphoto2
|
||||
gphoto2_port_inc_HEADERS = gphoto2-port.h \
|
||||
gphoto2-portability.h \
|
||||
gphoto2-port-serial.h \
|
||||
gphoto2-port-parallel.h \
|
||||
gphoto2-port-usb.h \
|
||||
gphoto2-port-ieee1394.h \
|
||||
gphoto2-port-network.h
|
||||
gphoto2_port_inc_HEADERS =\
|
||||
gphoto2-port.h \
|
||||
gphoto2-port-debug.h \
|
||||
gphoto2-portability.h \
|
||||
gphoto2-port-serial.h \
|
||||
gphoto2-port-parallel.h \
|
||||
gphoto2-port-usb.h \
|
||||
gphoto2-port-ieee1394.h \
|
||||
gphoto2-port-network.h
|
||||
|
||||
37
libgphoto2_port/include/gphoto2-port-debug.h
Normal file
37
libgphoto2_port/include/gphoto2-port-debug.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/* gphoto2-port-debug.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_DEBUG_H__
|
||||
#define __GPHOTO2_PORT_DEBUG_H__
|
||||
|
||||
void gp_port_debug_set_level (int level);
|
||||
void gp_port_debug_printf (int target_debug_level, int debug_level,
|
||||
char *format, ...);
|
||||
|
||||
/* Custom debugging function */
|
||||
typedef void (* GPPortDebugFunc) (const char *msg, void *data);
|
||||
void gp_port_debug_set_func (GPPortDebugFunc func, void *data);
|
||||
|
||||
/* History */
|
||||
void gp_port_debug_history_append (const char *msg);
|
||||
int gp_port_debug_history_set_size (unsigned int size);
|
||||
const char *gp_port_debug_history_get (void);
|
||||
|
||||
#endif /* __GPHOTO2_PORT_DEBUG_H__ */
|
||||
@@ -177,9 +177,6 @@ struct gp_port {
|
||||
/* Core functions
|
||||
-------------------------------------------------------------- */
|
||||
|
||||
void gp_port_debug_printf (int target_debug_level, int debug_level, char *format, ...);
|
||||
/* issues debugging messages */
|
||||
|
||||
char *gp_port_result_as_string (int result);
|
||||
/* Returns a string describing the error */
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ LDFLAGS = @LDFLAGS@ -g -ldl
|
||||
lib_LTLIBRARIES = libgphoto2_port.la
|
||||
libgphoto2_port_la_LDFLAGS = -version-info @LIBGPPORT_VERSION_INFO@
|
||||
libgphoto2_port_la_SOURCES = \
|
||||
gp_port.c \
|
||||
library.c library.h \
|
||||
portability.c
|
||||
gp_port.c \
|
||||
debug.c \
|
||||
library.c library.h \
|
||||
portability.c
|
||||
|
||||
132
libgphoto2_port/libgphoto2_port/debug.c
Normal file
132
libgphoto2_port/libgphoto2_port/debug.c
Normal file
@@ -0,0 +1,132 @@
|
||||
/* debug.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 "gphoto2-port-debug.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <gphoto2-port.h>
|
||||
|
||||
int glob_debug_level = 0;
|
||||
|
||||
static GPPortDebugFunc debug_func = NULL;
|
||||
static void *debug_func_data = NULL;
|
||||
|
||||
static unsigned int debug_history_size = 0;
|
||||
static char *debug_history = NULL;
|
||||
|
||||
void
|
||||
gp_port_debug_set_level (int level)
|
||||
{
|
||||
glob_debug_level = level;
|
||||
}
|
||||
|
||||
void
|
||||
gp_port_debug_set_func (GPPortDebugFunc func, void *data)
|
||||
{
|
||||
debug_func = func;
|
||||
debug_func_data = data;
|
||||
}
|
||||
|
||||
void
|
||||
gp_port_debug_printf (int target_debug_level, int debug_level,
|
||||
char *format, ...)
|
||||
{
|
||||
char buffer[2048];
|
||||
va_list arg;
|
||||
|
||||
va_start (arg, format);
|
||||
vsprintf (buffer, format, arg);
|
||||
va_end (arg);
|
||||
|
||||
gp_port_debug_history_append (buffer);
|
||||
|
||||
if ((debug_level > 0) && (debug_level >= target_debug_level)) {
|
||||
if (debug_func) {
|
||||
|
||||
/* Custom debug function */
|
||||
debug_func (buffer, debug_func_data);
|
||||
|
||||
} else {
|
||||
|
||||
/* Own implementation */
|
||||
fprintf(stderr, "gp_port: ");
|
||||
va_start(arg, format);
|
||||
vfprintf(stderr, format, arg);
|
||||
va_end(arg);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gp_port_debug_history_append (const char *msg)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* Create history if needed */
|
||||
if (!debug_history) {
|
||||
debug_history_size = 1024;
|
||||
debug_history = malloc (sizeof (char) * debug_history_size);
|
||||
memset (debug_history, 0, debug_history_size);
|
||||
}
|
||||
|
||||
/* Do we have to forget parts of the debug history? */
|
||||
while (debug_history_size - strlen (debug_history) <
|
||||
strlen (msg) + 1) {
|
||||
|
||||
/* Determine len of first entry */
|
||||
for (i = 0; debug_history[i] != '\0'; i++)
|
||||
if (debug_history[i] == '\n')
|
||||
break;
|
||||
|
||||
/* Remove the first entry */
|
||||
memmove (debug_history, debug_history + i + 1,
|
||||
strlen (debug_history) - i);
|
||||
}
|
||||
|
||||
strcat (debug_history, msg);
|
||||
strcat (debug_history, "\n");
|
||||
}
|
||||
|
||||
int
|
||||
gp_port_debug_history_set_size (unsigned int size)
|
||||
{
|
||||
char *new_debug_history;
|
||||
|
||||
new_debug_history = realloc (debug_history, sizeof (char) * size);
|
||||
|
||||
if (!new_debug_history)
|
||||
return (GP_ERROR);
|
||||
|
||||
debug_history_size = size;
|
||||
debug_history = new_debug_history;
|
||||
|
||||
return (GP_OK);
|
||||
}
|
||||
|
||||
const char *
|
||||
gp_port_debug_history_get (void)
|
||||
{
|
||||
return (debug_history);
|
||||
}
|
||||
@@ -24,9 +24,13 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "../include/gphoto2-port.h"
|
||||
|
||||
#include <gphoto2-port.h>
|
||||
#include <gphoto2-port-debug.h>
|
||||
#include "library.h"
|
||||
|
||||
extern int glob_debug_level;
|
||||
|
||||
#ifdef ENABLE_NLS
|
||||
# include <libintl.h>
|
||||
# undef _
|
||||
@@ -46,22 +50,6 @@ int device_count;
|
||||
|
||||
int initialized = 0;
|
||||
|
||||
/* Toggle to turn on/off debugging */
|
||||
int glob_debug_level=0;
|
||||
|
||||
void gp_port_debug_printf (int target_debug_level, int debug_level, char *format, ...)
|
||||
{
|
||||
va_list arg;
|
||||
if ((debug_level > 0)&&(debug_level >= target_debug_level)) {
|
||||
|
||||
fprintf(stderr, "gp_port: ");
|
||||
va_start(arg, format);
|
||||
vfprintf(stderr, format, arg);
|
||||
va_end(arg);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
#define GP_ERR_RES(num,str) \
|
||||
if (result == num) \
|
||||
return (N_(str));
|
||||
@@ -114,7 +102,7 @@ int gp_port_init(int debug)
|
||||
gp_port_debug_printf(GP_DEBUG_LOW, glob_debug_level, "Initializing...");
|
||||
/* Enumerate all the available devices */
|
||||
device_count = 0;
|
||||
glob_debug_level = debug;
|
||||
gp_port_debug_set_level (debug);
|
||||
initialized = 1;
|
||||
return (gp_port_library_list(device_list, &device_count));
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <gphoto2-port-debug.h>
|
||||
#include "gphoto2-port.h"
|
||||
#include "library.h"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user