Logo Search packages:      
Sourcecode: libgphoto2 version File versions  Download package

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

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.

Definition at line 178 of file gphoto2-port-log.c.

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

Referenced by gp_port_check_int(), gp_port_check_int_fast(), gp_port_read(), gp_port_usb_msg_class_read(), gp_port_usb_msg_class_write(), gp_port_usb_msg_interface_read(), gp_port_usb_msg_interface_write(), gp_port_usb_msg_read(), gp_port_usb_msg_write(), and gp_port_write().

{
      static const char hexchars[16] = "0123456789abcdef";
      char *curline, *result;
      int x = HEXDUMP_INIT_X;
      int y = HEXDUMP_INIT_Y;
      int index;
      unsigned char value;

      if (!data) {
            gp_log (GP_LOG_DATA, domain, _("No hexdump (NULL buffer)"));
            return;
      }

      if (!size) {
            gp_log (GP_LOG_DATA, domain, _("Empty hexdump of empty buffer"));
            return;
      }

      if (size > 1024*1024) {
            /* Does not make sense for 200 MB movies */
            gp_log (GP_LOG_DATA, domain, _("Truncating dump from %d bytes to 1MB"), size);
            size = 1024*1024;
      }

      curline = result = malloc ((HEXDUMP_LINE_WIDTH+1)*(((size-1)/16)+1)+1);
      if (!result) {
            gp_log (GP_LOG_ERROR, "gphoto2-log", _("Malloc for %i bytes "
                  "failed"), (HEXDUMP_LINE_WIDTH+1)*(((size-1)/16)+1)+1);
            return;
      }

      for (index = 0; index < size; ++index) {
                value = (unsigned char)data[index];
                curline[x] = hexchars[value >> 4];
                curline[x+1] = hexchars[value & 0xf];
                curline[x+2] = ' ';
                curline[y++] = ((value>=32)&&(value<127))?value:'.';
                x += 3;
                if ((index & 0xf) == 0xf) { /* end of line */
                        x = HEXDUMP_INIT_X;
                        y = HEXDUMP_INIT_Y;
                        HEXDUMP_COMPLETE_LINE;
                }
        }
        if ((index & 0xf) != 0) { /* not at end of line yet? */
                /* if so, complete this line */
                while (y < HEXDUMP_INIT_Y + 16) {
                        curline[x+0] = ' ';
                        curline[x+1] = ' ';
                        curline[x+2] = ' ';
                        curline[y++] = ' ';
                        x += 3;
                }
                HEXDUMP_COMPLETE_LINE;
        }
        curline[0] = '\0';

      gp_log (GP_LOG_DATA, domain, _("Hexdump of %i = 0x%x bytes follows:\n%s"),
            size, size, result);
      free (result);
}


Generated by  Doxygen 1.6.0   Back to index