libgphoto2 photo camera library (libgphoto2) Internals
2.5.23
|
Go to the documentation of this file.
26 #define _DEFAULT_SOURCE
46 # define _(String) dgettext (GETTEXT_PACKAGE, String)
48 # define N_(String) gettext_noop (String)
50 # define N_(String) (String)
53 # define _(String) (String)
54 # define N_(String) (String)
55 # define ngettext(String1,String2,Count) ((Count==1)?String1:String2)
58 #define CHECK_RESULT(result) {int r=(result); if (r<0) return (r);}
59 #define CHECK_SUPP(p,t,o) {if (!(o)) {gp_port_set_error ((p), _("The operation '%s' is not supported by this device"), (t)); return (GP_ERROR_NOT_SUPPORTED);}}
60 #define CHECK_INIT(p) {if (!(p)->pc->ops) {gp_port_set_error ((p), _("The port has not yet been initialized")); return (GP_ERROR_BAD_PARAMETERS);}}
62 #define LOG_DATA(DATA, SIZE, EXPECTED, MSG_PRE, MSG_POST, ...) \
63 if (SIZE != EXPECTED) \
64 GP_LOG_DATA (DATA, SIZE, MSG_PRE " %i = 0x%x out of %i bytes " MSG_POST, SIZE, SIZE, EXPECTED, ##__VA_ARGS__); \
66 GP_LOG_DATA (DATA, SIZE, MSG_PRE " %i = 0x%x bytes " MSG_POST, SIZE, SIZE, ##__VA_ARGS__)
98 GP_LOG_D (
"Creating new device...");
100 C_MEM (*port = calloc (1,
sizeof (
GPPort)));
170 free (port->
pc->
ops);
171 port->
pc->
ops = NULL;
174 #if !defined(VALGRIND)
175 lt_dlclose (port->
pc->
lh);
183 GP_LOG_E (
"Could not load '%s' ('%s').", info->
library_filename, lt_dlerror ());
189 ops_func = lt_dlsym (port->
pc->
lh,
"gp_port_library_operations");
191 GP_LOG_E (
"Could not find 'gp_port_library_operations' in '%s' ('%s')",
193 lt_dlclose (port->
pc->
lh);
198 port->
pc->
ops = ops_func ();
202 switch (info->
type) {
212 GP_LOG_E (
"Path is too long for static buffer '%s'.", info->
path);
227 strchr(info->
path,
':') + 1);
232 strchr(info->
path,
':') + 1);
257 C_PARAMS (port && info);
278 GP_LOG_D (
"Opening %s port...",
299 GP_LOG_D (
"Closing port...");
321 GP_LOG_D (
"Resetting port...");
343 GP_LOG_D (
"Freeing port...");
354 free (port->
pc->
ops);
355 port->
pc->
ops = NULL;
359 #if !defined(VALGRIND)
360 lt_dlclose (port->
pc->
lh);
396 gp_log (
GP_LOG_DATA, __func__,
"Writing %i = 0x%x bytes to port...", size, size);
398 C_PARAMS (port && data);
403 retval = port->
pc->
ops->
write (port, data, size);
405 GP_LOG_E (
"Writing %i = 0x%x bytes to port failed: %s (%d)",
409 LOG_DATA (data, retval, size,
"Wrote ",
"to port:");
431 gp_log (
GP_LOG_DATA, __func__,
"Reading %i = 0x%x bytes from port...", size, size);
438 retval = port->
pc->
ops->
read (port, data, size);
440 GP_LOG_E (
"Reading %i = 0x%x bytes from port failed: %s (%d)",
444 LOG_DATA (data, retval, size,
"Read ",
"from port:");
467 gp_log (
GP_LOG_DATA, __func__,
"Reading %i = 0x%x bytes from interrupt endpoint...", size, size);
476 LOG_DATA (data, retval, size,
"Read ",
"from interrupt endpoint:");
482 #define FAST_TIMEOUT 50
500 gp_log (
GP_LOG_DATA, __func__,
"Reading %i = 0x%x bytes from interrupt endpoint...", size, size);
510 #ifdef IGNORE_EMPTY_INTR_READS
516 LOG_DATA (data, retval, size,
"Read ",
"from interrupt endpoint (fast):");
538 GP_LOG_D (
"Setting port timeout to %i milliseconds.", timeout);
572 GP_LOG_D (
"Current port timeout is %i milliseconds.", port->
timeout);
592 GP_LOG_D (
"Setting settings...");
653 GP_LOG_D (
"Getting level of pin %i...",
pin);
655 C_PARAMS (port &&
level);
661 GP_LOG_D (
"Level of pin %i: %i",
pin, *
level);
674 {
GP_PIN_DTR , 4,
"DTR" ,
"Data Terminal Ready"},
677 {
GP_PIN_CD , 1,
"CD" ,
"Carrier Detect" },
707 for (i = 0;
PinTable[i].description_short; i++)
713 GP_LOG_D (
"Setting pin %i (%s: '%s') to '%s'...",
739 GP_LOG_D (
"Sending break (%i milliseconds)...", duration);
764 GP_LOG_D (
"Flushing port...");
838 GP_LOG_D (
"Clear USB halt...");
865 char *bytes,
int size)
869 GP_LOG_DATA (bytes, size,
"Writing message (request=0x%x value=0x%x index=0x%x size=%i=0x%x):",
870 request, value, index, size, size);
876 retval = port->
pc->
ops->
msg_write(port, request, value, index, bytes, size);
898 char *bytes,
int size)
902 gp_log (
GP_LOG_DATA, __func__,
"Reading message (request=0x%x value=0x%x index=0x%x size=%i=0x%x)...",
903 request, value, index, size, size);
909 retval = port->
pc->
ops->
msg_read (port, request, value, index, bytes, size);
912 LOG_DATA (bytes, retval, size,
"Read",
"USB message (request=0x%x value=0x%x index=0x%x size=%i=0x%x)",
913 request, value, index, size, size);
938 int value,
int index,
char *bytes,
int size)
942 GP_LOG_DATA (bytes, size,
"Writing message (request=0x%x value=0x%x index=0x%x size=%i=0x%x)...",
943 request, value, index, size, size);
950 value, index, bytes, size);
973 char *bytes,
int size)
977 gp_log (
GP_LOG_DATA, __func__,
"Reading message (request=0x%x value=0x%x index=0x%x size=%i=0x%x)...",
978 request, value, index, size, size);
985 value, index, bytes, size);
988 LOG_DATA (bytes, retval, size,
"Read",
"USB message (request=0x%x value=0x%x index=0x%x size=%i=0x%x)",
989 request, value, index, size, size);
1016 int value,
int index,
char *bytes,
int size)
1020 GP_LOG_DATA (bytes, size,
"Writing message (request=0x%x value=0x%x index=0x%x size=%i=0x%x):",
1021 request, value, index, size, size);
1028 value, index, bytes, size);
1051 char *bytes,
int size)
1055 gp_log (
GP_LOG_DATA, __func__,
"Reading message (request=0x%x value=0x%x index=0x%x size=%i=0x%x)...",
1056 request, value, index, size, size);
1063 value, index, bytes, size);
1066 LOG_DATA (bytes, retval, size,
"Read",
"USB message (request=0x%x value=0x%x index=0x%x size=%i=0x%x)",
1067 request, value, index, size, size);
1088 GP_LOG_D (
"Seeking to: %d whence: %d", offset, whence);
1094 retval = port->
pc->
ops->
seek (port, offset, whence);
1096 GP_LOG_D (
"Seek result: %d", retval);
1119 char *cmd,
int cmd_size,
1120 char *sense,
int sense_size,
1121 char *data,
int data_size)
1126 if (to_dev && data_size)
1127 GP_LOG_DATA (data, data_size,
"with scsi cmd data:");
1132 memset (sense, 0, sense_size);
1135 sense, sense_size, data, data_size);
1137 GP_LOG_D (
"scsi cmd result: %d", retval);
1139 if (sense[0] != 0) {
1142 GP_LOG_D (
"sense decided:");
1143 if ((sense[0]&0x7f)!=0x70) {
1144 GP_LOG_D (
"\tInvalid header.");
1146 GP_LOG_D (
"\tCurrent command read filemark: %s",(sense[2]&0x80)?
"yes":
"no");
1147 GP_LOG_D (
"\tEarly warning passed: %s",(sense[2]&0x40)?
"yes":
"no");
1148 GP_LOG_D (
"\tIncorrect blocklengt: %s",(sense[2]&0x20)?
"yes":
"no");
1149 GP_LOG_D (
"\tSense Key: %d",sense[2]&0xf);
1151 GP_LOG_D (
"\tResidual Length: %d",sense[3]*0x1000000+sense[4]*0x10000+sense[5]*0x100+sense[6]);
1152 GP_LOG_D (
"\tAdditional Sense Length: %d",sense[7]);
1153 GP_LOG_D (
"\tAdditional Sense Code: %d",sense[12]);
1154 GP_LOG_D (
"\tAdditional Sense Code Qualifier: %d",sense[13]);
1155 if (sense[15]&0x80) {
1156 GP_LOG_D (
"\tIllegal Param is in %s",(sense[15]&0x40)?
"the CDB":
"the Data Out Phase");
1157 if (sense[15]&0x8) {
1158 GP_LOG_D (
"Pointer at %d, bit %d",sense[16]*256+sense[17],sense[15]&0x7);
1163 if (!to_dev && data_size)
1187 va_start (args, format);
1190 GP_LOG_E (
"%s", port->
pc->
error);
1212 if (port && port->
pc && strlen (port->
pc->
error))
1215 return _(
"No error description available");
char * name
The name of this port (usb:)
int gp_port_usb_msg_write(GPPort *port, int request, int value, int index, char *bytes, int size)
Send a USB control message with output data.
int gp_port_get_timeout(GPPort *port, int *timeout)
Get the current port timeout.
int(* msg_interface_read)(GPPort *dev, int request, int value, int index, char *bytes, int size)
int gp_port_usb_msg_class_write(GPPort *port, int request, int value, int index, char *bytes, int size)
Send a USB class control message with output data.
GPPortSerialParity parity
#define CHECK_SUPP(p, t, o)
#define CHECK_RESULT(result)
int gp_port_check_int(GPPort *port, char *data, int size)
Check for intterupt.
GPPortType type
The type of this port.
@ GP_LOG_DATA
Log message is a data hex dump.
int gp_port_set_error(GPPort *port, const char *format,...)
Set verbose port error message.
int(* send_break)(GPPort *, int)
int gp_port_usb_msg_read(GPPort *port, int request, int value, int index, char *bytes, int size)
Send a USB control message with input data.
int gp_port_get_info(GPPort *port, GPPortInfo *info)
Retreives information about the port.
int gp_port_seek(GPPort *port, int offset, int whence)
Seek on a port (for usb disk direct ports)
int(* write)(GPPort *, const char *, int)
int gp_port_close(GPPort *port)
Close a port.
GPPortSettingsUsbDiskDirect usbdiskdirect
usb disk direct port specific settings
int gp_port_send_scsi_cmd(GPPort *port, int to_dev, char *cmd, int cmd_size, char *sense, int sense_size, char *data, int data_size)
Send a SCSI command to a port (for usb scsi ports)
int(* set_pin)(GPPort *, GPPin, GPLevel)
int gp_port_write(GPPort *port, const char *data, int size)
Writes a specified amount of data to a port.
GPPortPrivateCore * pc
Port library private data pointer.
int gp_port_usb_msg_interface_read(GPPort *port, int request, int value, int index, char *bytes, int size)
Send a USB interface control message with input data.
int(* msg_class_write)(GPPort *dev, int request, int value, int index, char *bytes, int size)
#define GP_ERROR_NO_MEMORY
Out of memory.
int gp_port_usb_clear_halt(GPPort *port, int ep)
Clear USB endpoint HALT condition.
int gp_port_new(GPPort **port)
Create new GPPort.
int gp_port_flush(GPPort *port, int direction)
Flush data on serial port.
int(* msg_interface_write)(GPPort *dev, int request, int value, int index, char *bytes, int size)
int gp_port_set_info(GPPort *port, GPPortInfo info)
Configure a port.
#define LOG_DATA(DATA, SIZE, EXPECTED, MSG_PRE, MSG_POST,...)
@ GP_PIN_RING
RING (Modem) line.
int gp_port_settings_set(GPPort *, GPPortSettings)
int config
USB bConfigurationValue used.
The GPhoto port structure.
int(* msg_write)(GPPort *dev, int request, int value, int index, char *bytes, int size)
GPPortSettings settings_pending
Settings to be committed.
int gp_port_usb_find_device_by_class(GPPort *port, int mainclass, int subclass, int protocol)
Find USB device by interface class.
const char * description_long
GPPortSettingsSerial serial
Serial specific settings.
int(* find_device_by_class)(GPPort *dev, int class, int subclass, int protocol)
int gp_port_get_settings(GPPort *port, GPPortSettings *settings)
Get the current port settings.
char * path
The path of this port (usb:001,023)
static int gp_port_exit(GPPort *port)
const char * description_short
@ GP_PIN_CD
Carrier Detect line.
GPPortSettingsUSB usb
USB specific settings.
@ GP_PORT_USB_SCSI
USB Mass Storage raw SCSI port.
Internal private libgphoto2_port data. This structure contains private data.
int(* msg_read)(GPPort *dev, int request, int value, int index, char *bytes, int size)
int inep
Bulk IN endpoint used.
#define GP_OK
Everything is OK.
int(* find_device)(GPPort *dev, int idvendor, int idproduct)
int(* msg_class_read)(GPPort *dev, int request, int value, int index, char *bytes, int size)
int gp_port_read(GPPort *port, char *data, int size)
Read data from port.
int gp_port_usb_msg_interface_write(GPPort *port, int request, int value, int index, char *bytes, int size)
Send a USB interface control message with output data.
int gp_port_check_int_fast(GPPort *port, char *data, int size)
Check for interrupt without wait.
static int gp_port_init(GPPort *port)
@ GP_PORT_USB_DISK_DIRECT
Direct IO to an usb mass storage device.
int(* flush)(GPPort *, int)
enum _GPLevel GPLevel
Level to pull specific lines.
static struct @2 PinTable[]
static struct @3 LevelTable[]
int outep
Bulk OUT endpoint used.
enum _GPPin GPPin
Serial pins.
@ GP_PORT_SERIAL
Serial port.
int gp_port_settings_get(GPPort *, GPPortSettings *)
char port[64]
USB Portname. Specific to lowlevel USB.
int gp_port_set_settings(GPPort *port, GPPortSettings settings)
Set port settings.
GPPortOperations *(* GPPortLibraryOperations)(void)
int gp_port_timeout_set(GPPort *, int)
int(* seek)(GPPort *dev, int offset, int whence)
int(* read)(GPPort *, char *, int)
int gp_port_timeout_get(GPPort *, int *)
@ GP_LEVEL_HIGH
Pull to high (nV)
GPPortSettingsUsbScsi usbscsi
usb scsi port specific settings
int gp_port_send_break(GPPort *port, int duration)
Send a break over a serial port.
int(* check_int)(GPPort *, char *, int, int)
int gp_port_set_pin(GPPort *port, GPPin pin, GPLevel level)
Set specified serial PIN to value.
int gp_port_open(GPPort *port)
Open a port.
int(* send_scsi_cmd)(GPPort *port, int to_dev, char *cmd, int cmd_size, char *sense, int sense_size, char *data, int data_size)
@ GP_LEVEL_LOW
Pull to low (0V)
int gp_port_free(GPPort *port)
Free the port structure.
int gp_port_usb_msg_class_read(GPPort *port, int request, int value, int index, char *bytes, int size)
Send a USB class control message with input data.
char * library_filename
Internal pathname of the port driver. Do not use outside of the port library.
#define GP_ERROR_LIBRARY
Error in the camera driver.
int gp_port_set_timeout(GPPort *port, int timeout)
Set timeout of port.
int altsetting
USB Alternative Setting used.
int(* clear_halt)(GPPort *dev, int ep)
int timeout
Port timeout in milliseconds.
void gp_log(GPLogLevel level, const char *domain, const char *format,...)
Log a debug or error message.
GPPortSettings settings
Current port settings.
GPPortType type
Actual type of this port.
const char * gp_port_get_error(GPPort *port)
Get verbose port error message.
int gp_port_get_pin(GPPort *port, GPPin pin, GPLevel *level)
Get setting of specific serial PIN.
int gp_port_usb_find_device(GPPort *port, int idvendor, int idproduct)
Find USB device by vendor/product.
int gp_port_reset(GPPort *port)
Reset a port.
int interface
USB Interface number used.
const char * gp_port_result_as_string(int result)
#define GP_ERROR_NOT_SUPPORTED
Functionality not supported.
int(* get_pin)(GPPort *, GPPin, GPLevel *)