libgphoto2 photo camera library (libgphoto2) API: libgphoto2_port/libgphoto2_port/gphoto2-port-log.c File Reference

libgphoto2 photo camera library (libgphoto2) API 2.5.32

Loading...
Searching...
No Matches
gphoto2-port-log.c File Reference
`#include "config.h"`
`#include <gphoto2/gphoto2-port-log.h>`
`#include <stdlib.h>`
`#include <stdarg.h>`
`#include <string.h>`
`#include <stdio.h>`
`#include <gphoto2/gphoto2-port-result.h>`
`#include "libgphoto2_port/i18n.h"`
Include dependency graph for gphoto2-port-log.c:

## Data Structures
struct | LogFunc
| Internal logging function entry. More...

## Macros
#define | _DEFAULT_SOURCE
#define | HEXDUMP_OFFSET_WIDTH 4
#define | HEXDUMP_BLOCK_DISTANCE 2
#define | HEXDUMP_INIT_X (HEXDUMP_OFFSET_WIDTH + HEXDUMP_BLOCK_DISTANCE)
#define | HEXDUMP_INIT_Y (HEXDUMP_INIT_X + 3 * 16 - 1 + HEXDUMP_BLOCK_DISTANCE)
#define | HEXDUMP_LINE_WIDTH (HEXDUMP_INIT_Y + 16)
#define | HEXDUMP_MIDDLE (HEXDUMP_INIT_X + 3 * 8 - 1)
#define | HEXDUMP_COMPLETE_LINE

## Functions
char * | gpi_vsnprintf (const char *format, va_list args)
int | gp_log_add_func (GPLogLevel level, GPLogFunc func, void *data)
| Add a function to get logging information.
int | gp_log_remove_func (int id)
| Remove a logging receiving function.
void | gp_log_data (const char *domain, const char *data, unsigned int size, const char *format,...)
| Log data.
void | gp_logv (GPLogLevel level, const char *domain, const char *format, va_list args)
| Log a debug or error message with va_list.
void | gp_log (GPLogLevel level, const char *domain, const char *format,...)
| Log a debug or error message.
void | gp_log_with_source_location (GPLogLevel level, const char *file, int line, const char *func, const char *format,...)

## Detailed Description

Author
  Copyright 2001 Lutz Mueller lutz@.nosp@m.user.nosp@m.s.sf..nosp@m.net

License
  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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

## Macro Definition Documentation

## ◆ HEXDUMP_BLOCK_DISTANCE

#define HEXDUMP_BLOCK_DISTANCE 2

Distance between offset, hexdump and ascii blocks. Note that HEXDUMP_COMPLETE_LINE needs to be changed when this value is changed.

## ◆ HEXDUMP_COMPLETE_LINE

#define HEXDUMP_COMPLETE_LINE

Value:
{\
curline[HEXDUMP_OFFSET_WIDTH - 4] = hexchars[(index >> 12) & 0xf]; \
curline[HEXDUMP_OFFSET_WIDTH - 3] = hexchars[(index >> 8) & 0xf]; \
curline[HEXDUMP_OFFSET_WIDTH - 2] = hexchars[(index >> 4) & 0xf]; \
curline[HEXDUMP_OFFSET_WIDTH - 1] = '0'; \
curline[HEXDUMP_OFFSET_WIDTH + 0] = ' '; \
curline[HEXDUMP_OFFSET_WIDTH + 1] = ' '; \
curline[HEXDUMP_MIDDLE] = '-'; \
curline[HEXDUMP_INIT_Y-2] = ' '; \
curline[HEXDUMP_INIT_Y-1] = ' '; \
curline[HEXDUMP_LINE_WIDTH] = '\n'; \
curline = curline + (HEXDUMP_LINE_WIDTH + 1);}
HEXDUMP_OFFSET_WIDTH
#define HEXDUMP_OFFSET_WIDTH
Definition gphoto2-port-log.c:154
HEXDUMP_INIT_Y
#define HEXDUMP_INIT_Y
Definition gphoto2-port-log.c:166
HEXDUMP_LINE_WIDTH
#define HEXDUMP_LINE_WIDTH
Definition gphoto2-port-log.c:169
HEXDUMP_MIDDLE
#define HEXDUMP_MIDDLE
Definition gphoto2-port-log.c:172

We are lazy and do our typing only once. Please note that you have to add/remove some lines when increasing/decreasing the values of HEXDUMP_BLOCK_DISTANCE and/or HEXDUMP_OFFSET_WIDTH.

Referenced by gp_log_data().

## ◆ HEXDUMP_INIT_X

#define HEXDUMP_INIT_X (HEXDUMP_OFFSET_WIDTH + HEXDUMP_BLOCK_DISTANCE)

Initial value for x "pointer" (for hexdump)

Referenced by gp_log_data().

## ◆ HEXDUMP_INIT_Y

#define HEXDUMP_INIT_Y (HEXDUMP_INIT_X + 3 * 16 - 1 + HEXDUMP_BLOCK_DISTANCE)

Initial value for y "pointer" (for ascii values)

Referenced by gp_log_data().

## ◆ HEXDUMP_LINE_WIDTH

#define HEXDUMP_LINE_WIDTH (HEXDUMP_INIT_Y + 16)

Used to switch to next line

Referenced by gp_log_data().

## ◆ HEXDUMP_MIDDLE

#define HEXDUMP_MIDDLE (HEXDUMP_INIT_X + 3 * 8 - 1)

Used to put the '-' character in the middle of the hexdumps

## ◆ HEXDUMP_OFFSET_WIDTH

#define HEXDUMP_OFFSET_WIDTH 4

Width of offset field in characters. Note that HEXDUMP_COMPLETE_LINE needs to be changed when this value is changed.

## Function Documentation

## ◆ gp_log()

void gp_log | ( | GPLogLevel | level,
|  | const char * | domain,
|  | const char * | format,
|  |  | ... )

Log a debug or error message.

Parameters

  level | gphoto2 log level
  domain | the log domain
  format | a printf style format string
  ... | the variable argumentlist for above format string

Logs a message at the given log level. You would normally use this function to log general debug output in a printf way.

References gp_logv().

Referenced by gp_bayer_expand(), gp_init_localedir(), gp_log_data(), gp_port_check_int(), gp_port_check_int_fast(), gp_port_init_localedir(), gp_port_read(), gp_port_usb_msg_class_read(), gp_port_usb_msg_interface_read(), gp_port_usb_msg_read(), and gp_port_write().

## ◆ gp_log_add_func()

int gp_log_add_func | ( | GPLogLevel | level,
|  | GPLogFunc | func,
|  | void * | data )

Add a function to get logging information.

Parameters

  level | the maximum level of logging it will get, up to and including the passed value
  func | a GPLogFunc
  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).

Returns
  an id or a gphoto2 error code

## ◆ gp_log_data()

void gp_log_data | ( | const char * | domain,
|  | const char * | data,
|  | unsigned int | size,
|  | const char * | format,
|  |  | ... )

Log data.

domain the domain

data the data to be logged

size the size of the data

Takes the data and creates a formatted hexdump string. If you would like to log text messages, use gp_log instead.

References gp_log(), GP_LOG_DATA, HEXDUMP_COMPLETE_LINE, HEXDUMP_INIT_X, HEXDUMP_INIT_Y, and HEXDUMP_LINE_WIDTH.

## ◆ gp_log_remove_func()

int gp_log_remove_func | ( | int | id | ) |

Remove a logging receiving function.

Parameters

  id | an id (return value of gp_log_add_func)

Removes the log function with given id.

Returns
  a gphoto2 error code

References GP_ERROR_BAD_PARAMETERS, and GP_OK.

## ◆ gp_logv()

void gp_logv | ( | GPLogLevel | level,
|  | const char * | domain,
|  | const char * | format,
|  | va_list | args )

Log a debug or error message with va_list.

Parameters

  level | gphoto2 log level
  domain | the domain
  format | the format
  args | the va_list corresponding to format

Logs a message at the given log level. You would normally use this function to log as yet unformatted strings.

Referenced by gp_log().