diff --git a/camlibs/barbie/barbie.c b/camlibs/barbie/barbie.c index 3d940ec5b..26999c14f 100644 --- a/camlibs/barbie/barbie.c +++ b/camlibs/barbie/barbie.c @@ -55,6 +55,7 @@ int camera_init(Camera *camera) { gp_port_settings settings; BarbieStruct *b; + int ret; /* First, set up all the function pointers */ camera->functions->id = camera_id; @@ -74,7 +75,9 @@ int camera_init(Camera *camera) { b = (BarbieStruct*)malloc(sizeof(BarbieStruct)); camera->camlib_data = b; - b->dev = gp_port_new(GP_PORT_SERIAL); + if ((ret = gp_port_new(&(b->dev), GP_PORT_SERIAL)) < 0) { + return (ret); + } gp_port_timeout_set(b->dev, 5000); strcpy(settings.serial.port, camera->port->path); diff --git a/camlibs/canon/serial.c b/camlibs/canon/serial.c index 524776896..d70804f8e 100644 --- a/camlibs/canon/serial.c +++ b/camlibs/canon/serial.c @@ -156,6 +156,7 @@ err: int canon_serial_init(Camera *camera, const char *devname) { struct canon_info *cs = (struct canon_info*)camera->camlib_data; + int ret; #ifdef GP_PORT_SUPPORTED_USB int i; char msg[65536]; @@ -171,11 +172,9 @@ int canon_serial_init(Camera *camera, const char *devname) switch (canon_comm_method) { case CANON_USB: #ifdef GP_PORT_SUPPORTED_USB - cs->gdev = gp_port_new(GP_PORT_USB); - if (!cs->gdev) { - return -1; - } - + if ((ret = gp_port_new(&(cs->gdev), GP_PORT_USB) != GP_OK) + return ret; + for (i = 0; i < sizeof(camera_to_usb) / sizeof(struct camera_to_usb); i++) { fprintf(stderr, "canon: %s, %s\n", camera->model, camera_to_usb[i].name); @@ -197,11 +196,11 @@ int canon_serial_init(Camera *camera, const char *devname) canon_read = canon_usb_read; */ gp_port_settings_set(cs->gdev, settings); - if (gp_port_open(cs->gdev) < 0) { + if (gp_port_open(cs->gdev) != GP_OK) { fprintf(stderr,"Camera used by other USB device!\n"); //exit(1); return -1; - } + } gp_port_usb_msg_read(cs->gdev,0x55,msg,1); // fprintf(stderr,"%c\n",msg[0]); @@ -230,11 +229,9 @@ int canon_serial_init(Camera *camera, const char *devname) gp_debug_printf(GP_DEBUG_LOW,"canon","canon_init_serial(): Using serial port on %s\n", devname); - cs->gdev = gp_port_new(GP_PORT_SERIAL); - - if (!cs->gdev) { - return -1; - } + if ((ret = gp_port_new(&(cs->gdev), GP_PORT_SERIAL)) != GP_OK) + return ret; + strcpy(settings.serial.port, devname); settings.serial.speed = 9600; settings.serial.bits = 8; diff --git a/camlibs/digita/serial.c b/camlibs/digita/serial.c index 065bb909f..65682e61f 100644 --- a/camlibs/digita/serial.c +++ b/camlibs/digita/serial.c @@ -170,14 +170,14 @@ static int digita_serial_read(struct digita_device *dev, void *_buffer, int len) int digita_serial_open(struct digita_device *dev, Camera *camera) { - gp_port_settings settings; + int ret; + gp_port_settings settings; struct beacon beacon; struct beacon_ack beacon_ack; struct beacon_comp beacon_comp; - dev->gpdev = gp_port_new(GP_PORT_SERIAL); - if (!dev->gpdev) - return -1; + if ((ret = gp_port_new(&(dev->gpdev), GP_PORT_SERIAL)) < 0) + return (ret); strcpy(settings.serial.port,camera->port->path); diff --git a/camlibs/digita/usb.c b/camlibs/digita/usb.c index 5538339dd..3cd317a21 100644 --- a/camlibs/digita/usb.c +++ b/camlibs/digita/usb.c @@ -56,13 +56,12 @@ err: int digita_usb_open(struct digita_device *dev, Camera *camera) { gp_port_settings settings; - int i; + int i, ret; fprintf(stderr, "digita: user selected %s\n", camera->model); - dev->gpdev = gp_port_new(GP_PORT_USB); - if (!dev->gpdev) - return -1; + if ((ret = gp_port_new(&(dev->gpdev), GP_PORT_USB)) < 0) + return (ret); for (i = 0; i < sizeof(camera_to_usb) / sizeof(struct camera_to_usb); i++) { fprintf(stderr, "digita: %s, %s\n", camera->model, camera_to_usb[i].name); diff --git a/camlibs/kodak/dc120/dc120.c b/camlibs/kodak/dc120/dc120.c index fd6440afc..1acc873f7 100644 --- a/camlibs/kodak/dc120/dc120.c +++ b/camlibs/kodak/dc120/dc120.c @@ -46,6 +46,7 @@ int camera_init (Camera *camera) { gp_port_settings settings; DC120Data *dd; + int ret; if (!camera) return (GP_ERROR); @@ -71,10 +72,9 @@ int camera_init (Camera *camera) { camera->functions->manual = camera_manual; camera->functions->about = camera_about; - dd->dev = gp_port_new(GP_PORT_SERIAL); - if (!dd->dev) { + if ((ret= gp_port_new(&(dd->dev), GP_PORT_SERIAL)) < 0) { free(dd); - return (GP_ERROR); + return (ret); } strcpy(settings.serial.port, camera->port->path); diff --git a/camlibs/kodak/dc240/dc240.c b/camlibs/kodak/dc240/dc240.c index 44a86d097..2125f2a1e 100644 --- a/camlibs/kodak/dc240/dc240.c +++ b/camlibs/kodak/dc240/dc240.c @@ -43,6 +43,7 @@ int camera_abilities (CameraAbilitiesList *list) { int camera_init (Camera *camera) { + int ret; gp_port_settings settings; DC240Data *dd; @@ -72,8 +73,7 @@ int camera_init (Camera *camera) { switch (camera->port->type) { case GP_PORT_SERIAL: - dd->dev = gp_port_new(GP_PORT_SERIAL); - if (!dd->dev) { + if ((ret = gp_port_new(&(dd->dev), GP_PORT_SERIAL)) < 0) { free(dd); return (GP_ERROR); } @@ -84,8 +84,7 @@ int camera_init (Camera *camera) { settings.serial.stopbits = 1; break; case GP_PORT_USB: - dd->dev = gp_port_new(GP_PORT_USB); - if (!dd->dev) { + if ((ret = gp_port_new(&(dd->dev), GP_PORT_USB)) < 0) { free(dd); return (GP_ERROR); } diff --git a/camlibs/konica/library.c b/camlibs/konica/library.c index ed5c5fc36..4794a8ead 100644 --- a/camlibs/konica/library.c +++ b/camlibs/konica/library.c @@ -147,7 +147,7 @@ camera_abilities (CameraAbilitiesList* list) gint camera_init (Camera* camera) { - gint i, j; + gint i, j, ret; guint test_bit_rate[10] = { 9600, 115200, 57600, 38400, 19200, 4800, 2400, 1200, 600, 300}; guint bit_rate[10] = { 300, 600, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200}; gboolean bit_rate_supported[10] = {FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE}; @@ -188,7 +188,8 @@ camera_init (Camera* camera) camera->functions->result_as_string = camera_result_as_string; /* Create device. */ - device = gp_port_new (GP_PORT_SERIAL); + if ((ret = gp_port_new(&device, GP_PORT_SERIAL)) < 0) + return (ret); /* Store some data we constantly need. */ konica_data = g_new (konica_data_t, 1); diff --git a/camlibs/minolta/dimagev/dimagev.c b/camlibs/minolta/dimagev/dimagev.c index f242be65f..09f9a0149 100644 --- a/camlibs/minolta/dimagev/dimagev.c +++ b/camlibs/minolta/dimagev/dimagev.c @@ -60,7 +60,9 @@ int camera_abilities (CameraAbilitiesList *list) { } int camera_init (Camera *camera) { - dimagev_t *dimagev = NULL; + + int ret; + dimagev_t *dimagev = NULL; /* First, set up all the function pointers */ camera->functions->id = camera_id; @@ -87,9 +89,9 @@ int camera_init (Camera *camera) { camera->camlib_data = dimagev; /* Now open a port. */ - if ( ( dimagev->dev = gp_port_new(GP_PORT_SERIAL) ) == NULL ) { + if (( ret = gp_port_new(&(dimagev->dev), GP_PORT_SERIAL)) < 0 ) { gp_debug_printf(GP_DEBUG_HIGH, "dimagev", "camera_init::unable to allocate gp_port_dev"); - return GP_ERROR; + return ret; } gp_port_timeout_set(dimagev->dev, 5000); diff --git a/camlibs/panasonic/dc1000.c b/camlibs/panasonic/dc1000.c index 7657a2303..f1f3d1029 100644 --- a/camlibs/panasonic/dc1000.c +++ b/camlibs/panasonic/dc1000.c @@ -347,8 +347,9 @@ int camera_abilities (CameraAbilitiesList *list) { } int camera_init (Camera *camera) { - - dsc_t *dsc = NULL; + + int ret; + dsc_t *dsc = NULL; dsc_print_status(camera, "Initializing camera %s", camera->model); @@ -380,7 +381,10 @@ int camera_init (Camera *camera) { camera->camlib_data = dsc; - dsc->dev = gp_port_new(GP_PORT_SERIAL); + if ((ret = gp_port_new(&(dsc->dev), GP_PORT_SERIAL)) < 0) { + free(dsc); + return (ret); + } gp_port_timeout_set(dsc->dev, 5000); strcpy(dsc->settings.serial.port, camera->port->path); diff --git a/camlibs/panasonic/dc1580.c b/camlibs/panasonic/dc1580.c index 0b746fec4..ad41949e8 100644 --- a/camlibs/panasonic/dc1580.c +++ b/camlibs/panasonic/dc1580.c @@ -440,6 +440,7 @@ int camera_abilities (CameraAbilitiesList *list) { int camera_init (Camera *camera) { + int ret; dsc_t *dsc = NULL; dsc_print_status(camera, "Initializing camera %s", camera->model); @@ -473,7 +474,10 @@ int camera_init (Camera *camera) { camera->camlib_data = dsc; - dsc->dev = gp_port_new(GP_PORT_SERIAL); + if ((ret = gp_port_new(&(dsc->dev), GP_PORT_SERIAL)) < 0) { + free (dsc); + return (ret); + } gp_port_timeout_set(dsc->dev, 5000); strcpy(dsc->settings.serial.port, camera->port->path); diff --git a/camlibs/sierra/library.c b/camlibs/sierra/library.c index bf9ade8a7..131f4166a 100644 --- a/camlibs/sierra/library.c +++ b/camlibs/sierra/library.c @@ -185,7 +185,7 @@ read_packet_again: done = 0; if (fd->type == GP_PORT_USB) - gp_port_usb_clear_halt(fd->dev, GP_PORT_USB_IN_ENDPOINT); + gp_port_usb_clear_halt(fd->dev, GP_PORT_USB_ENDPOINT_IN); while (!done && (r++type) { @@ -234,7 +234,7 @@ read_packet_again: sierra_dump_packet(camera, packet); if (fd->type == GP_PORT_USB) - gp_port_usb_clear_halt(fd->dev, GP_PORT_USB_IN_ENDPOINT); + gp_port_usb_clear_halt(fd->dev, GP_PORT_USB_ENDPOINT_IN); return (sierra_valid_packet(camera, packet)); } @@ -252,7 +252,7 @@ read_packet_again: sierra_dump_packet(camera, packet); if (fd->type == GP_PORT_USB) - gp_port_usb_clear_halt(fd->dev, GP_PORT_USB_IN_ENDPOINT); + gp_port_usb_clear_halt(fd->dev, GP_PORT_USB_ENDPOINT_IN); return (GP_OK); } @@ -317,12 +317,12 @@ int sierra_write_ack(Camera *camera) { buf[0] = ACK; if (sierra_write_packet(camera, buf)==GP_OK) { if (fd->type == GP_PORT_USB) - gp_port_usb_clear_halt(fd->dev, GP_PORT_USB_IN_ENDPOINT); + gp_port_usb_clear_halt(fd->dev, GP_PORT_USB_ENDPOINT_IN); return (GP_OK); } sierra_debug_print(fd, "Could not write ACK"); if (fd->type == GP_PORT_USB) - gp_port_usb_clear_halt(fd->dev, GP_PORT_USB_IN_ENDPOINT); + gp_port_usb_clear_halt(fd->dev, GP_PORT_USB_ENDPOINT_IN); return (GP_ERROR); } @@ -336,13 +336,13 @@ int sierra_write_nak(Camera *camera) { buf[0] = NAK; if (sierra_write_packet(camera, buf)==GP_OK) { if (fd->type == GP_PORT_USB) - gp_port_usb_clear_halt(fd->dev, GP_PORT_USB_IN_ENDPOINT); + gp_port_usb_clear_halt(fd->dev, GP_PORT_USB_ENDPOINT_IN); return (GP_OK); } sierra_debug_print(fd, "Could not write NAK"); if (fd->type == GP_PORT_USB) - gp_port_usb_clear_halt(fd->dev, GP_PORT_USB_IN_ENDPOINT); + gp_port_usb_clear_halt(fd->dev, GP_PORT_USB_ENDPOINT_IN); return (GP_ERROR); } diff --git a/camlibs/sierra/sierra.c b/camlibs/sierra/sierra.c index f16d69481..491a69524 100644 --- a/camlibs/sierra/sierra.c +++ b/camlibs/sierra/sierra.c @@ -134,7 +134,7 @@ int camera_abilities (CameraAbilitiesList *list) { int camera_init (Camera *camera) { int value=0, count; - int x=0; + int x=0, ret; int vendor=0, product=0, inep=0, outep=0; gp_port_settings settings; @@ -168,11 +168,9 @@ int camera_init (Camera *camera) { switch (camera->port->type) { case GP_PORT_SERIAL: sierra_debug_print(fd, "Serial Device"); - fd->dev = gp_port_new(GP_PORT_SERIAL); - if (!fd->dev) { - gp_port_free(fd->dev); + if ((ret = gp_port_new(&(fd->dev), GP_PORT_SERIAL)) < 0) { free(fd); - return (GP_ERROR); + return (ret); } strcpy(settings.serial.port, camera->port->path); settings.serial.speed = 19200; @@ -197,18 +195,15 @@ int camera_init (Camera *camera) { return (GP_ERROR); sierra_debug_print(fd, "USB Device"); - fd->dev = gp_port_new(GP_PORT_USB); - - if (!fd->dev) { - gp_port_free(fd->dev); + if ((ret = gp_port_new(&(fd->dev), GP_PORT_USB)) < 0) { free(fd); return (GP_ERROR); } - if (gp_port_usb_find_device(fd->dev, vendor, product) == GP_ERROR) { + if ((ret = gp_port_usb_find_device(fd->dev, vendor, product)) < 0) { gp_port_free(fd->dev); free (fd); - return (GP_ERROR); + return (ret); } gp_port_timeout_set (fd->dev, 5000); settings.usb.inep = inep; @@ -217,36 +212,36 @@ int camera_init (Camera *camera) { settings.usb.interface = 0; settings.usb.altsetting = 0; break; - default: + default: sierra_debug_print(fd, "Invalid Device"); free (fd); return (GP_ERROR); } - if (gp_port_settings_set(fd->dev, settings) == GP_ERROR) { + if ((ret = gp_port_settings_set(fd->dev, settings)) < 0) { gp_port_free(fd->dev); free (fd); - return (GP_ERROR); + return (ret); } gp_port_timeout_set(fd->dev, TIMEOUT); fd->type = camera->port->type; - if (gp_port_open(fd->dev)==GP_ERROR) { + if ((ret = gp_port_open(fd->dev)) < 0) { gp_port_free(fd->dev); free (fd); - return (GP_ERROR); + return (ret); } switch (camera->port->type) { case GP_PORT_SERIAL: - if (sierra_ping(camera)==GP_ERROR) { + if (sierra_ping(camera) < 0) { gp_port_free(fd->dev); free (fd); return (GP_ERROR); } - if (sierra_set_speed(camera, camera->port->speed)==GP_ERROR) { + if (sierra_set_speed(camera, camera->port->speed) < 0) { gp_port_free(fd->dev); free (fd); return (GP_ERROR); @@ -254,13 +249,13 @@ int camera_init (Camera *camera) { fd->speed = camera->port->speed; break; case GP_PORT_USB: - gp_port_usb_clear_halt(fd->dev, GP_PORT_USB_IN_ENDPOINT); + gp_port_usb_clear_halt(fd->dev, GP_PORT_USB_ENDPOINT_IN); break; default: break; } - if (sierra_get_int_register(camera, 1, &value)==GP_ERROR) { + if (sierra_get_int_register(camera, 1, &value)< 0) { gp_port_free(fd->dev); free (fd); return (GP_ERROR); @@ -269,7 +264,7 @@ int camera_init (Camera *camera) { sierra_set_int_register(camera, 83, -1); gp_port_timeout_set(fd->dev, 50); - if (sierra_set_string_register(camera, 84, "\\", 1)==GP_ERROR) + if (sierra_set_string_register(camera, 84, "\\", 1)< 0) fd->folders = 0; else fd->folders = 1; @@ -315,7 +310,7 @@ static int sierra_change_folder(Camera *camera, const char *folder) sierra_debug_print(fd, "Change dir called with relative path?"); i = 0; } else { - if (sierra_set_string_register(camera, 84, "\\", 1)==GP_ERROR) + if (sierra_set_string_register(camera, 84, "\\", 1)< 0) return GP_ERROR; } st = i; @@ -324,7 +319,7 @@ static int sierra_change_folder(Camera *camera, const char *folder) target[i] = '\0'; if (st == i-1) break; - if (sierra_set_string_register(camera, 84, target+st, strlen(target+st))==GP_ERROR) + if (sierra_set_string_register(camera, 84, target+st, strlen(target+st))< 0) return GP_ERROR; st = i+1; target[i] = '/'; @@ -341,7 +336,7 @@ int camera_start(Camera *camera) { SierraData *fd = (SierraData*)camera->camlib_data; if (fd->type == GP_PORT_SERIAL) { - if (sierra_set_speed(camera, fd->speed)==GP_ERROR) + if (sierra_set_speed(camera, fd->speed)< 0) return (GP_ERROR); sierra_folder_set(camera, fd->folder); } @@ -353,7 +348,7 @@ int camera_stop(Camera *camera) { SierraData *fd = (SierraData*)camera->camlib_data; if (fd->type == GP_PORT_SERIAL) { - if (sierra_set_speed(camera, -1)==GP_ERROR) + if (sierra_set_speed(camera, -1)< 0) return (GP_ERROR); } @@ -381,7 +376,7 @@ int camera_file_list(Camera *camera, CameraList *list, char *folder) { if ((!fd->folders)&&(strcmp("/", folder)!=0)) return (GP_ERROR); - if (camera_start(camera)==GP_ERROR) + if (camera_start(camera)< 0) return (GP_ERROR); if (fd->folders) { @@ -397,13 +392,13 @@ int camera_file_list(Camera *camera, CameraList *list, char *folder) { /* are all filenames *.jpg, or are there *.tif files too? */ /* Set the current picture number */ - if (sierra_set_int_register(camera, 4, x+1)==GP_ERROR) { + if (sierra_set_int_register(camera, 4, x+1)< 0) { sierra_debug_print(fd, "Could not set the picture number"); camera_stop(camera); return (GP_ERROR); } /* Get the picture filename */ - if (sierra_get_string_register(camera, 79, 0, NULL, buf, &length)==GP_ERROR) { + if (sierra_get_string_register(camera, 79, 0, NULL, buf, &length)< 0) { sierra_debug_print(fd, "Could not get filename"); camera_stop(camera); return (GP_ERROR); @@ -515,13 +510,13 @@ int camera_file_get_generic (Camera *camera, CameraFile *file, int regl, regd, file_number; SierraData *fd = (SierraData*)camera->camlib_data; -if (camera_start(camera)==GP_ERROR) +if (camera_start(camera)< 0) return (GP_ERROR); /* Get the file number from the CameraFileSystem */ file_number = gp_filesystem_number(fd->fs, folder, filename); - if (file_number == GP_ERROR) + if (file_number < 0) return GP_ERROR; if (thumbnail) { @@ -541,10 +536,10 @@ return (GP_ERROR); strcpy(file->name, filename); /* Get the picture data */ - if (sierra_get_string_register(camera, regd, file_number+1, file, NULL, NULL)==GP_ERROR) + if (sierra_get_string_register(camera, regd, file_number+1, file, NULL, NULL)< 0) return (GP_ERROR); -if (camera_stop(camera)==GP_ERROR) +if (camera_stop(camera)< 0) return (GP_ERROR); return (GP_OK); @@ -566,7 +561,7 @@ int camera_file_delete (Camera *camera, char *folder, char *filename) { char buf[4096]; SierraData *fd = (SierraData*)camera->camlib_data; -if (camera_start(camera)==GP_ERROR) +if (camera_start(camera)< 0) return (GP_ERROR); file_number = gp_filesystem_number(fd->fs, folder, filename); @@ -578,7 +573,7 @@ return (GP_ERROR); if (ret == GP_OK) gp_filesystem_delete(fd->fs, folder, filename); -if (camera_stop(camera)==GP_ERROR) +if (camera_stop(camera)< 0) return (GP_ERROR); return (ret); @@ -589,13 +584,13 @@ int camera_capture (Camera *camera, CameraFile *file, CameraCaptureInfo *info) { SierraData *fd = (SierraData*)camera->camlib_data; int retval; -if (camera_start(camera)==GP_ERROR) +if (camera_start(camera)< 0) return (GP_ERROR); sierra_debug_print(fd, "Capturing image"); retval = sierra_capture(camera, file, info); -if (camera_stop(camera)==GP_ERROR) +if (camera_stop(camera)< 0) return (GP_ERROR); return (retval); @@ -608,7 +603,7 @@ int camera_summary (Camera *camera, CameraText *summary) { char t[1024]; SierraData *fd = (SierraData*)camera->camlib_data; -if (camera_start(camera)==GP_ERROR) +if (camera_start(camera)< 0) return (GP_ERROR); sierra_debug_print(fd, "Getting camera summary"); @@ -749,7 +744,7 @@ return (GP_ERROR); strcpy(summary->text, buf); -if (camera_stop(camera)==GP_ERROR) +if (camera_stop(camera)< 0) return (GP_ERROR); return (GP_OK); diff --git a/camlibs/stv0680/stv0680.c b/camlibs/stv0680/stv0680.c index 76260c5fd..72dc4ab44 100644 --- a/camlibs/stv0680/stv0680.c +++ b/camlibs/stv0680/stv0680.c @@ -54,7 +54,8 @@ int camera_abilities (CameraAbilitiesList *list) { int camera_init (Camera *camera) { gp_port_settings gpiod_settings; - struct stv0680_s *device; + int ret; + struct stv0680_s *device; /* First, set up all the function pointers */ camera->functions->id = camera_id; @@ -81,8 +82,10 @@ int camera_init (Camera *camera) { camera->camlib_data = device; /* open and configure serial port */ - device->gpiod = gp_port_new(GP_PORT_SERIAL); - gp_port_timeout_set(device->gpiod, 1000); + if ((ret = gp_port_new(&(device->gpiod), GP_PORT_SERIAL)) < 0) + return (ret); + + gp_port_timeout_set(device->gpiod, 1000); strcpy(gpiod_settings.serial.port, camera->port->path); gpiod_settings.serial.speed = camera->port->speed; diff --git a/libgphoto2_port/include/gphoto2-port.h b/libgphoto2_port/include/gphoto2-port.h index ae801f93b..1ad9b3a8e 100644 --- a/libgphoto2_port/include/gphoto2-port.h +++ b/libgphoto2_port/include/gphoto2-port.h @@ -31,11 +31,34 @@ /* Return values */ /* Note: This lib should be allocated return values of 0 to -99 */ -#define GP_OK 0 +#define GP_OK 0 -#define GP_ERROR -1 -#define GP_ERROR_TIMEOUT -2 +#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_USB_CLEAR_HALT -21 +#define GP_ERROR_IO_USB_FIND -22 /* Debugging definitions for init */ #define GP_DEBUG_NONE 0 @@ -84,8 +107,8 @@ typedef union { } gp_port_settings; enum { - GP_PORT_USB_IN_ENDPOINT, - GP_PORT_USB_OUT_ENDPOINT + GP_PORT_USB_ENDPOINT_IN, + GP_PORT_USB_ENDPOINT_OUT }; struct gp_port; @@ -178,7 +201,7 @@ struct gp_port { unsuccessful: GP_ERROR */ -gp_port *gp_port_new (gp_port_type type); + int gp_port_new (gp_port **dev, gp_port_type type); /* Create a new device of type "type" return values: successful: valid gp_port struct diff --git a/libgphoto2_port/libgphoto2_port/gp_port.c b/libgphoto2_port/libgphoto2_port/gp_port.c index 6781e0ecd..46828623f 100644 --- a/libgphoto2_port/libgphoto2_port/gp_port.c +++ b/libgphoto2_port/libgphoto2_port/gp_port.c @@ -60,6 +60,10 @@ void gp_port_debug_printf (int target_debug_level, int debug_level, char *format } } +#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 */ @@ -67,23 +71,35 @@ char *gp_port_result_as_string (int result) { if ((result < -99) || (result > 0)) return (N_("Unknown error")); - switch (result) { - case 0: - return (N_("No error")); - break; - case -1: - return (N_("Generic error")); - break; - case -2: - return (N_("There was a timeout reading from or writing to the port")); - break; - default: - break; - } + 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 clearing a halt condition on the USB port"); + GP_ERR_RES(-22, "Could not find the requested device on the USB port"); return (N_("Unknown error")); } +#undef GP_ERR_RES + /* Required library functions ---------------------------------------------------------------- @@ -113,10 +129,9 @@ int gp_port_info_get(int device_number, gp_port_info *info) return GP_OK; } -gp_port *gp_port_new(gp_port_type type) +int gp_port_new(gp_port **dev, gp_port_type type) /* Create a new IO device */ { - gp_port *dev; gp_port_settings settings; char buf[1024]; @@ -125,54 +140,54 @@ gp_port *gp_port_new(gp_port_type type) switch(type) { case GP_PORT_SERIAL: #ifndef GP_PORT_SUPPORTED_SERIAL - return NULL; + return GP_ERROR_IO_SUPPORTED_SERIAL; #endif break; case GP_PORT_USB: #ifndef GP_PORT_SUPPORTED_USB - return NULL; + return GP_ERROR_IO_SUPPORTED_USB; #endif break; case GP_PORT_PARALLEL: #ifndef GP_PORT_SUPPORTED_PARALLEL - return NULL; + return GP_ERROR_IO_SUPPORTED_PARALLEL; #endif break; case GP_PORT_NETWORK: #ifndef GP_PORT_SUPPORTED_NETWORK - return NULL; + return GP_ERROR_IO_SUPPORTED_NETWORK; #endif break; case GP_PORT_IEEE1394: #ifndef GP_PORT_SUPPORTED_IEEE1394 - return NULL; + return GP_ERROR_IO_SUPPORTED_IEEE1394; #endif break; default: - return NULL; + return GP_ERROR_IO_UNKNOWN_PORT; } - dev = (gp_port *) malloc(sizeof(gp_port)); - if (!dev) { - gp_port_debug_printf(GP_DEBUG_LOW, glob_debug_level, "Can not allocate device!"); - return NULL; + *dev = (gp_port *) malloc(sizeof(gp_port)); + if (!(*dev)) { + gp_port_debug_printf(GP_DEBUG_LOW, glob_debug_level, "Can not allocate device!"); + return (GP_ERROR_IO_MEMORY); } - memset(dev, 0, sizeof(gp_port)); + memset(*dev, 0, sizeof(gp_port)); - if (gp_port_library_load(dev, type)) { - /* whoops! that type of device isn't supported */ - gp_port_debug_printf(GP_DEBUG_LOW, glob_debug_level, "Device type not supported! (%i)", type); - free(dev); - return NULL; + if (gp_port_library_load(*dev, type)) { + /* whoops! that type of device isn't supported */ + gp_port_debug_printf(GP_DEBUG_LOW, glob_debug_level, "Device library can't be loaded! (%i)", type); + free(*dev); + return (GP_ERROR_IO_LIBRARY); } - dev->debug_level = glob_debug_level; + (*dev)->debug_level = glob_debug_level; - dev->type = type; - dev->device_fd = 0; - dev->ops->init(dev); + (*dev)->type = type; + (*dev)->device_fd = 0; + (*dev)->ops->init(*dev); - switch (dev->type) { + switch ((*dev)->type) { case GP_PORT_SERIAL: sprintf(buf, GP_PORT_SERIAL_PREFIX, GP_PORT_SERIAL_RANGE_LOW); strcpy(settings.serial.port, buf); @@ -181,30 +196,31 @@ gp_port *gp_port_new(gp_port_type type) settings.serial.bits = 8; settings.serial.parity = 0; settings.serial.stopbits = 1; - gp_port_settings_set(dev, settings); - gp_port_timeout_set(dev, 500); + gp_port_settings_set(*dev, settings); + gp_port_timeout_set(*dev, 500); break; case GP_PORT_PARALLEL: sprintf(buf, GP_PORT_SERIAL_PREFIX, GP_PORT_SERIAL_RANGE_LOW); strcpy(settings.parallel.port, buf); break; case GP_PORT_NETWORK: - gp_port_timeout_set(dev, 50000); + gp_port_timeout_set(*dev, 50000); break; case GP_PORT_USB: - gp_port_timeout_set(dev, 5000); + gp_port_timeout_set(*dev, 5000); break; case GP_PORT_IEEE1394: /* blah ? */ break; default: /* ERROR! */ + return GP_ERROR_IO_UNKNOWN_PORT; break; } gp_port_debug_printf(GP_DEBUG_LOW, glob_debug_level, "Created device successfully..."); - return (dev); + return (GP_OK); } int gp_port_debug_set (gp_port *dev, int debug_level) @@ -292,7 +308,7 @@ int gp_port_write(gp_port *dev, char *bytes, int size) } retval = dev->ops->write(dev, bytes, size); - if (retval == GP_ERROR_TIMEOUT) + if (retval == GP_ERROR_IO_TIMEOUT) gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, "gp_port_write: write timeout"); if (retval == GP_ERROR) gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, "gp_port_write: write error"); @@ -323,7 +339,7 @@ int gp_port_read(gp_port *dev, char *bytes, int size) free(buf); } - if (retval == GP_ERROR_TIMEOUT) + if (retval == GP_ERROR_IO_TIMEOUT) gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, "gp_port_read: read timeout"); if (retval == GP_ERROR) gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, "gp_port_read: read error"); diff --git a/libgphoto2_port/po/cat-id-tbl.c b/libgphoto2_port/po/cat-id-tbl.c index af7fd310f..f09331e3a 100644 --- a/libgphoto2_port/po/cat-id-tbl.c +++ b/libgphoto2_port/po/cat-id-tbl.c @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2001-01-24 09:29-0800\n" +"POT-Creation-Date: 2001-01-24 10:51-0800\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -14,18 +14,6 @@ msgstr "" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: ENCODING\n" -#: libgphoto2_port/gp_port.c:68 libgphoto2_port/gp_port.c:84 +#: libgphoto2_port/gp_port.c:72 libgphoto2_port/gp_port.c:98 msgid "Unknown error" msgstr "" - -#: libgphoto2_port/gp_port.c:72 -msgid "No error" -msgstr "" - -#: libgphoto2_port/gp_port.c:75 -msgid "Generic error" -msgstr "" - -#: libgphoto2_port/gp_port.c:78 -msgid "There was a timeout reading from or writing to the port" -msgstr "" diff --git a/libgphoto2_port/serial/unix.c b/libgphoto2_port/serial/unix.c index 37f871291..f19437ca2 100644 --- a/libgphoto2_port/serial/unix.c +++ b/libgphoto2_port/serial/unix.c @@ -163,12 +163,12 @@ int gp_port_serial_init (gp_port *dev) { #if HAVE_TERMIOS_H if (tcgetattr(dev->device_fd, &term_old) < 0) { perror("tcgetattr"); - return GP_ERROR; + return GP_ERROR_IO_INIT; } #else if (ioctl(dev->device_fd, TIOCGETP, &term_old) < 0) { perror("ioctl(TIOCGETP)"); - return GP_ERROR; + return GP_ERROR_IO_INIT; } #endif return GP_OK; @@ -190,7 +190,7 @@ int gp_port_serial_open(gp_port * dev) if (dev->device_fd == -1) { fprintf(stderr, "gp_port_serial_open: failed to open "); perror(dev->settings.serial.port); - return GP_ERROR; + return GP_ERROR_IO_OPEN; } /* if (ioctl (dev->device_fd, TIOCMBIC, &RTS) <0) { @@ -204,7 +204,7 @@ int gp_port_serial_close(gp_port * dev) { if (close(dev->device_fd) == -1) { perror("gp_port_serial_close: tried closing device file descriptor"); - return GP_ERROR; + return GP_ERROR_IO_CLOSE; } return GP_OK; } @@ -224,7 +224,7 @@ int gp_port_serial_write(gp_port * dev, char *bytes, int size) break; default: perror("gp_port_serial_write"); - return GP_ERROR; + return GP_ERROR_IO_WRITE; } len += ret; } @@ -266,21 +266,21 @@ int gp_port_serial_read(gp_port * dev, char *bytes, int size) /* return GP_ERROR_TIMEOUT; */ /* } */ if (0 == rc) { - return GP_ERROR_TIMEOUT; + return GP_ERROR_IO_TIMEOUT; } if (FD_ISSET(dev->device_fd, &readfs)) { int now = read(dev->device_fd, bytes, size - readen); if (now < 0) { perror("gp_port_serial_read (read fails)"); - return GP_ERROR; + return GP_ERROR_IO_READ; } else { bytes += now; readen += now; } } else { perror("gp_port_serial_read (tty timeout)"); - return GP_ERROR; + return GP_ERROR_IO_TIMEOUT; } } return readen; @@ -314,12 +314,12 @@ int gp_port_serial_get_pin(gp_port * dev, int pin) bit = TIOCM_RNG; break; default: - return GP_ERROR; + return GP_ERROR_IO_PIN; } if (ioctl(dev->device_fd, TIOCMGET, &j) < 0) { perror("gp_port_serial_status (Getting hardware status bits)"); - return GP_ERROR; + return GP_ERROR_IO_PIN; } return (j & bit); } @@ -354,7 +354,7 @@ int gp_port_serial_set_pin(gp_port * dev, int pin, int level) bit = TIOCM_RNG; break; default: - return GP_ERROR; + return GP_ERROR_IO_PIN; } switch(level) { @@ -365,13 +365,13 @@ int gp_port_serial_set_pin(gp_port * dev, int pin, int level) request = TIOCMBIC; break; default: - return GP_ERROR; + return GP_ERROR_IO_PIN; } if (ioctl (dev->device_fd, request, &bit) <0) { - perror("ioctl(TIOCMBI[CS])"); - return GP_ERROR; - } + perror("ioctl(TIOCMBI[CS])"); + return GP_ERROR_IO_PIN; + } return GP_OK; } @@ -385,10 +385,10 @@ int gp_port_serial_update(gp_port * dev) memcpy(&dev->settings, &dev->settings_pending, sizeof(dev->settings)); if (dev->device_fd != 0) { - if (gp_port_serial_close(dev) == GP_ERROR) - return GP_ERROR; - if (gp_port_serial_open(dev) == GP_ERROR) - return GP_ERROR; + if (gp_port_serial_close(dev)) + return GP_ERROR_IO_CLOSE; + if (gp_port_serial_open(dev)) + return GP_ERROR_IO_OPEN; return gp_port_serial_set_baudrate(dev); } @@ -408,7 +408,7 @@ int gp_port_serial_set_baudrate(gp_port * dev) if (tcgetattr(dev->device_fd, &tio) < 0) { perror("tcgetattr"); - return GP_ERROR; + return GP_ERROR_IO_SERIAL_SPEED; } tio.c_cflag = (tio.c_cflag & ~CSIZE) | CS8; @@ -435,18 +435,18 @@ int gp_port_serial_set_baudrate(gp_port * dev) if (tcsetattr(dev->device_fd, TCSANOW, &tio) < 0) { perror("tcsetattr"); - return GP_ERROR; + return GP_ERROR_IO_SERIAL_SPEED; } if (fcntl(dev->device_fd, F_SETFL, 0) < 0) { /* clear O_NONBLOCK */ perror("fcntl F_SETFL"); - return -1; + return GP_ERROR_IO_SERIAL_SPEED; } #else struct sgttyb ttyb; if (ioctl(dev->device_fd, TIOCGETP, &ttyb) < 0) { perror("ioctl(TIOCGETP)"); - return GP_ERROR; + return GP_ERROR_IO_SERIAL_SPEED; } ttyb.sg_ispeed = dev->settings.serial.speed; ttyb.sg_ospeed = dev->settings.serial.speed; @@ -454,7 +454,7 @@ int gp_port_serial_set_baudrate(gp_port * dev) if (ioctl(dev->device_fd, TIOCSETP, &ttyb) < 0) { perror("ioctl(TIOCSETP)"); - return GP_ERROR; + return GP_ERROR_IO_SERIAL_SPEED; } #endif @@ -524,6 +524,7 @@ int gp_port_serial_send_break (gp_port *dev, int duration) { tcdrain(dev->device_fd); #else /* ioctl */ + return GP_ERROR_IO_SERIAL_BREAK; #endif - return 0; + return GP_OK; } diff --git a/libgphoto2_port/usb/libusb.c b/libgphoto2_port/usb/libusb.c index 054b36337..1d1e83a9c 100644 --- a/libgphoto2_port/usb/libusb.c +++ b/libgphoto2_port/usb/libusb.c @@ -116,20 +116,20 @@ int gp_port_usb_open(gp_port *dev) udev = dev->device_handle; dev->device_handle = usb_open(udev); if (!dev->device_handle) - return GP_ERROR; + return GP_ERROR_IO_OPEN; ret = usb_set_configuration(dev->device_handle, dev->settings.usb.config); if (ret < 0) { fprintf(stderr, "gp_port_usb_open: could not set config %d: %s\n", dev->settings.usb.config, strerror(errno)); - return GP_ERROR; + return GP_ERROR_IO_OPEN; } ret = usb_claim_interface(dev->device_handle, dev->settings.usb.interface); if (ret < 0) { fprintf(stderr, "gp_port_usb_open: could not claim intf %d: %s\n", dev->settings.usb.interface, strerror(errno)); - return GP_ERROR; + return GP_ERROR_IO_OPEN; } ret = usb_set_altinterface(dev->device_handle, dev->settings.usb.altsetting); @@ -137,7 +137,7 @@ int gp_port_usb_open(gp_port *dev) fprintf(stderr, "gp_port_usb_open: could not set intf %d/%d: %s\n", dev->settings.usb.interface, dev->settings.usb.altsetting, strerror(errno)); - return GP_ERROR; + return GP_ERROR_IO_OPEN; } return GP_OK; @@ -168,21 +168,22 @@ int gp_port_usb_clear_halt_lib(gp_port * dev, int ep) int ret=0; switch (ep) { - case GP_PORT_USB_IN_ENDPOINT : + case GP_PORT_USB_ENDPOINT_IN : ret=usb_clear_halt(dev->device_handle, dev->settings.usb.inep); break; - case GP_PORT_USB_OUT_ENDPOINT : + case GP_PORT_USB_ENDPOINT_OUT : ret=usb_clear_halt(dev->device_handle, dev->settings.usb.outep); break; default: fprintf(stderr,"gp_port_usb_clear_halt: bad EndPoint argument\n"); - return GP_ERROR; + return GP_ERROR_IO_USB_CLEAR_HALT; } - return (ret ? GP_ERROR : GP_OK); + return (ret ? GP_ERROR_IO_USB_CLEAR_HALT : GP_OK); } int gp_port_usb_write(gp_port * dev, char *bytes, int size) { + int ret; if (GP_PORT_USB_DEBUG) { int i; @@ -192,8 +193,11 @@ int gp_port_usb_write(gp_port * dev, char *bytes, int size) printf("\n"); } - return usb_bulk_write(dev->device_handle, dev->settings.usb.outep, - bytes, size, dev->timeout); + ret = usb_bulk_write(dev->device_handle, dev->settings.usb.outep, + bytes, size, dev->timeout); + if (ret < 0) + return (GP_ERROR_IO_WRITE); + return (ret); } int gp_port_usb_read(gp_port * dev, char *bytes, int size) @@ -203,7 +207,7 @@ int gp_port_usb_read(gp_port * dev, char *bytes, int size) ret = usb_bulk_read(dev->device_handle, dev->settings.usb.inep, bytes, size, dev->timeout); if (ret < 0) - return GP_ERROR; + return GP_ERROR_IO_READ; if (GP_PORT_USB_DEBUG) { int i; @@ -256,5 +260,5 @@ int gp_port_usb_find_device_lib(gp_port * d, int idvendor, int idproduct) } } - return GP_ERROR; + return GP_ERROR_IO_USB_FIND; }