/** * \brief Retrieve the camera abilities of entry with supplied index number. * * \param list a CameraAbilitiesList * \param index index * \param abilities pointer to CameraAbilities for returned data. * \return a gphoto2 error code * * Retrieves the camera abilities of entry with supplied * index number. Typically, you would call gp_camera_set_abilities() * afterwards in order to prepare the initialization of a camera. */ int gp_abilities_list_get_abilities (CameraAbilitiesList *list, int index, CameraAbilities *abilities) { C_PARAMS (list && abilities); C_PARAMS (0 <= index && index < list->count); memcpy (abilities, &list->abilities[index], sizeof (CameraAbilities)); return (GP_OK); }
/** * \brief Count the entries in the supplied list. * \param list a #CameraAbilitiesList * \returns The number of entries or a gphoto2 error code */ int gp_abilities_list_count (CameraAbilitiesList *list) { C_PARAMS (list); return (list->count); }
/** * \brief Check for interrupt without wait * \param port a GPPort * \param data a pointer to an allocated buffer * \param size the number of bytes that should be read * * Reads a specified number of bytes from the inerrupt endpoint * into the supplied buffer. * Function waits 50 miliseconds for data on interrupt endpoint. * * \return a gphoto2 error code **/ int gp_port_check_int_fast (GPPort *port, char *data, int size) { int retval; gp_log (GP_LOG_DATA, __func__, "Reading %i = 0x%x bytes from interrupt endpoint...", size, size); C_PARAMS (port); CHECK_INIT (port); /* Check if we read as many bytes as expected */ CHECK_SUPP (port, "check_int", port->pc->ops->check_int); retval = port->pc->ops->check_int (port, data, size, FAST_TIMEOUT); CHECK_RESULT (retval); #ifdef IGNORE_EMPTY_INTR_READS /* For Canon cameras, we will make lots of reads that will return zero length. Don't bother to log them as errors. */ if (retval != 0 ) #endif LOG_DATA (data, retval, size, "Read ", "from interrupt endpoint (fast):"); return (retval); }
/** * Retrieve the current speed. * * @param camera a #Camera * @return The current speed or a gphoto2 error code * */ int gp_camera_get_port_speed (Camera *camera) { C_PARAMS (camera); return (camera->pc->speed); }
/** * Set the camera speed. * * @param camera a #Camera * @param speed the speed * @return a gphoto2 error code * * This function is typically used prior first initialization * using #gp_camera_init for debugging purposes. Normally, a camera driver * will try to figure out the current speed of the camera and set the speed * to the optimal one automatically. Note that this function only works with * serial ports. In other words, you have to set the camera's port to a * serial one (using #gp_camera_set_port_path or #gp_camera_set_port_name) * prior calling this function. * */ int gp_camera_set_port_speed (Camera *camera, int speed) { GPPortSettings settings; C_PARAMS (camera); C_PARAMS_MSG (camera->port, "You need to set a port prior trying to set the speed"); C_PARAMS_MSG (camera->port->type == GP_PORT_SERIAL, "You can specify a speed only with serial ports"); /* * If the camera is currently initialized, terminate that connection. * We don't care if we are successful or not. */ if (camera->pc->lh) gp_camera_exit (camera, NULL); CR (camera, gp_port_get_settings (camera->port, &settings), NULL); settings.serial.speed = speed; CR (camera, gp_port_set_settings (camera->port, settings), NULL); camera->pc->speed = speed; return (GP_OK); }
static int gp_libusb1_clear_halt_lib(GPPort *port, int ep) { unsigned char internal_ep; C_PARAMS (port && port->pl->dh); switch (ep) { case GP_PORT_USB_ENDPOINT_IN : internal_ep = port->settings.usb.inep; break; case GP_PORT_USB_ENDPOINT_OUT : internal_ep = port->settings.usb.outep; break; case GP_PORT_USB_ENDPOINT_INT : internal_ep = port->settings.usb.intep; break; default: gp_port_set_error (port, "bad EndPoint argument 0x%x", ep); return GP_ERROR_BAD_PARAMETERS; } C_LIBUSB (libusb_clear_halt(port->pl->dh, internal_ep), GP_ERROR_IO_USB_CLEAR_HALT); return GP_OK; }
static int gp_libusb1_check_int (GPPort *port, char *bytes, int size, int timeout) { int ret; struct timeval tv; C_PARAMS (port && port->pl->dh && timeout >= 0); if (port->pl->nrofirqs) goto handleirq; tv.tv_sec = timeout/1000; tv.tv_usec = (timeout%1000)*1000; ret = LOG_ON_LIBUSB_E (libusb_handle_events_timeout(port->pl->ctx, &tv)); if (port->pl->nrofirqs) goto handleirq; if (ret < LIBUSB_SUCCESS) return translate_libusb_error(ret, GP_ERROR_IO_READ); return GP_ERROR_TIMEOUT; handleirq: if (size > port->pl->irqlens[0]) size = port->pl->irqlens[0]; memcpy(bytes, port->pl->irqs[0], size); memmove(port->pl->irqs,port->pl->irqs+1,sizeof(port->pl->irqs[0])*(port->pl->nrofirqs-1)); memmove(port->pl->irqlens,port->pl->irqlens+1,sizeof(port->pl->irqlens[0])*(port->pl->nrofirqs-1)); port->pl->nrofirqs--; return size; }
/** * Allocates the memory for a #Camera. * * @param camera the #Camera object to initialize. * @return a gphoto2 error code * */ int gp_camera_new (Camera **camera) { int result; C_PARAMS (camera); C_MEM (*camera = calloc (1, sizeof (Camera))); (*camera)->functions = calloc (1, sizeof (CameraFunctions)); (*camera)->pc = calloc (1, sizeof (CameraPrivateCore)); if (!(*camera)->functions || !(*camera)->pc) { result = GP_ERROR_NO_MEMORY; goto error; } (*camera)->pc->ref_count = 1; /* Create the filesystem */ result = gp_filesystem_new (&(*camera)->fs); if (result < GP_OK) goto error; /* Create the port */ result = gp_port_new (&(*camera)->port); if (result < GP_OK) goto error; return(GP_OK); error: gp_camera_free (*camera); return result; }
/** * @param camera a #Camera * @param timeout number of seconds that should pass between each call to * \c func * @param func the function that should be called each \c timeout seconds * @return The id of the background process or a gphoto2 error code * * This function should be called by the camera driver during camera_init() * if the camera needs to be sent messages periodically in order to prevent * it from shutting down. * */ int gp_camera_start_timeout (Camera *camera, unsigned int timeout, CameraTimeoutFunc func) { int id; C_PARAMS (camera && camera->pc); if (!camera->pc->timeout_start_func) return (GP_ERROR_NOT_SUPPORTED); /* * We remember the id here in order to automatically remove * the timeout on gp_camera_exit. */ C_MEM (camera->pc->timeout_ids = realloc (camera->pc->timeout_ids, sizeof (int) * (camera->pc->timeout_ids_len + 1))); id = camera->pc->timeout_start_func (camera, timeout, func, camera->pc->timeout_data); if (id < 0) return (id); camera->pc->timeout_ids[camera->pc->timeout_ids_len] = id; camera->pc->timeout_ids_len++; return (id); }
/** * Reads a file partially from the #Camera. * * @param camera a #Camera * @param folder a folder * @param file the name of a file * @param type the #CameraFileType * @param offset the offset into the camera file * @param data the buffer receiving the data * @param size the size to be read and that was read * @param context a #GPContext * @return a gphoto2 error code * **/ int gp_camera_file_read (Camera *camera, const char *folder, const char *file, CameraFileType type, uint64_t offset, char *buf, uint64_t *size, GPContext *context) { GP_LOG_D ("Getting file '%s' in folder '%s'...", file, folder); C_PARAMS (camera && folder && file && buf && size); CHECK_INIT (camera, context); /* Did we get reasonable foldername/filename? */ if (strlen (folder) == 0) { CAMERA_UNUSED (camera, context); return (GP_ERROR_DIRECTORY_NOT_FOUND); } if (strlen (file) == 0) { CAMERA_UNUSED (camera, context); return (GP_ERROR_FILE_NOT_FOUND); } CHECK_RESULT_OPEN_CLOSE (camera, gp_filesystem_read_file (camera->fs, folder, file, type, offset, buf, size, context), context); CAMERA_UNUSED (camera, context); return (GP_OK); }
/** * Captures a preview that won't be stored on the camera but returned in * supplied file. * * @param camera a #Camera * @param file a #CameraFile * @param context a #GPContext * @return a gphoto2 error code * * For example, you could use gp_capture_preview() for taking some sample * pictures before calling gp_capture(). * **/ int gp_camera_capture_preview (Camera *camera, CameraFile *file, GPContext *context) { char *xname; C_PARAMS (camera && file); CHECK_INIT (camera, context); CR (camera, gp_file_clean (file), context); if (!camera->functions->capture_preview) { gp_context_error (context, _("This camera can " "not capture previews.")); CAMERA_UNUSED (camera, context); return (GP_ERROR_NOT_SUPPORTED); } CHECK_RESULT_OPEN_CLOSE (camera, camera->functions->capture_preview ( camera, file, context), context); gp_file_get_name_by_type (file, "capture_preview", GP_FILE_TYPE_NORMAL, &xname); /* FIXME: Marcus ... will go away, just keep compatible now. */ gp_file_set_name (file, xname); free (xname); CAMERA_UNUSED (camera, context); return (GP_OK); }
static int gp_port_vusb_clear_halt_lib(GPPort *port, int ep) { unsigned char internal_ep; gp_log(GP_LOG_DEBUG,__FUNCTION__,"()"); C_PARAMS (port && port->pl); switch (ep) { case GP_PORT_USB_ENDPOINT_IN : internal_ep = port->settings.usb.inep; break; case GP_PORT_USB_ENDPOINT_OUT : internal_ep = port->settings.usb.outep; break; case GP_PORT_USB_ENDPOINT_INT : internal_ep = port->settings.usb.intep; break; default: gp_port_set_error (port, "Bad EndPoint argument 0x%x", ep); return GP_ERROR_BAD_PARAMETERS; } gp_log(GP_LOG_DEBUG,"gp_port_vusb_clear_halt_lib","clearing halt on ep 0x%x", internal_ep); /* now clear halt */ return GP_OK; }
static int gp_abilities_list_sort (CameraAbilitiesList *list) { C_PARAMS (list); qsort (list->abilities, list->count, sizeof(CameraAbilities), cmp_abilities); return (GP_OK); }
static int gp_port_vusb_check_int (GPPort *port, char *bytes, int size, int timeout) { gp_log(GP_LOG_DEBUG,__FUNCTION__,"()"); C_PARAMS (port && port->pl && timeout >= 0); return port->pl->vcamera->readint(port->pl->vcamera, (unsigned char*)bytes, size, timeout); }
static int gp_port_vusb_reset(GPPort *port) { gp_log(GP_LOG_DEBUG,__FUNCTION__,"()"); C_PARAMS (port && port->pl); return GP_OK; }
static int gp_port_vusb_write (GPPort *port, const char *bytes, int size) { gp_log(GP_LOG_DEBUG,__FUNCTION__,"()"); C_PARAMS (port && port->pl && port->pl->vcamera); return port->pl->vcamera->write(port->pl->vcamera, 0x02, (unsigned char*)bytes, size); }
/** * \brief Retreives information about the port. * * Retrieves the informations set by gp_port_set_info(). * * \param port a GPPort * \param info GPPortInfo * \return a gphoto2 error code **/ int gp_port_get_info (GPPort *port, GPPortInfo *info) { C_PARAMS (port && info); *info = &port->pc->info; return (GP_OK); }
static int gp_port_usbscsi_find_device(GPPort *port, int idvendor, int idproduct) { unsigned short vendor_id, product_id; const char *sg; C_PARAMS (port); sg = strrchr (port->settings.usbscsi.path, '/'); C_PARAMS (sg); sg++; CHECK (gp_port_usbscsi_get_usb_id (sg, &vendor_id, &product_id)) if (vendor_id != idvendor || product_id != idproduct) return GP_ERROR_IO_USB_FIND; return GP_OK; }
/** * Retrieve the \c abilities of the \c camera. * * @param camera a #Camera * @param abilities * @return a gphoto2 error code * */ int gp_camera_get_abilities (Camera *camera, CameraAbilities *abilities) { C_PARAMS (camera && abilities); memcpy (abilities, &camera->pc->a, sizeof (CameraAbilities)); return (GP_OK); }
int gp_camera_get_port_info (Camera *camera, GPPortInfo *info) { C_PARAMS (camera && info); CR (camera, gp_port_get_info (camera->port, info), NULL); return (GP_OK); }
/** * \brief Get the current port settings. * \param port a #GPPort * \param settings pointer to the retrieved settings * * Retreives the current settings of a port. * * \return a gphoto2 error code **/ int gp_port_get_settings (GPPort *port, GPPortSettings *settings) { C_PARAMS (port); memcpy (settings, &(port->settings), sizeof (gp_port_settings)); return GP_OK; }
/** * Increment the reference count of a \c camera. * * @param camera a #Camera * @return a gphoto2 error code * */ int gp_camera_ref (Camera *camera) { C_PARAMS (camera); camera->pc->ref_count += 1; return (GP_OK); }
static int gp_port_usbscsi_update (GPPort *port) { C_PARAMS (port); memcpy (&port->settings, &port->settings_pending, sizeof (port->settings)); return GP_OK; }
static int gp_port_usbscsi_exit (GPPort *port) { C_PARAMS (port); free (port->pl); port->pl = NULL; return GP_OK; }
static int gp_port_usbdiskdirect_find_device(GPPort *port, int idvendor, int idproduct) { unsigned short vendor_id, product_id; const char *disk; C_PARAMS (port); disk = strrchr (port->settings.usbdiskdirect.path, '/'); C_PARAMS (disk); disk++; CHECK (gp_port_usbdiskdirect_get_usb_id (disk, &vendor_id, &product_id)) if (vendor_id != idvendor || product_id != idproduct) return GP_ERROR_IO_USB_FIND; return GP_OK; }
/** * \brief Get the current port timeout. * \param port a #GPPort * \param timeout pointer to timeout * * Retreives the current timeout of the port. * * \return a gphoto2 error code **/ int gp_port_get_timeout (GPPort *port, int *timeout) { C_PARAMS (port); GP_LOG_D ("Current port timeout is %i milliseconds.", port->timeout); *timeout = port->timeout; return GP_OK; }
/** * \brief Set timeout of port * \param port a #GPPort * \param timeout the timeout * * Sets the timeout of a port. #gp_port_read will wait timeout milliseconds * for data. If no data will be received in that period, %GP_ERROR_TIMEOUT * will be returned. * * \return a gphoto2 error code **/ int gp_port_set_timeout (GPPort *port, int timeout) { C_PARAMS (port); GP_LOG_D ("Setting port timeout to %i milliseconds.", timeout); port->timeout = timeout; return GP_OK; }
/** * \brief Find USB device by interface class * * \param port a GPPort * \param mainclass the USB interface class * \param subclass the USB interface subclass * \param protocol the USB interface protocol * * Find the USB device with the specified vendor:product id pair. * * \return a gphoto2 error code */ int gp_port_usb_find_device_by_class (GPPort *port, int mainclass, int subclass, int protocol) { C_PARAMS (port); CHECK_INIT (port); CHECK_SUPP (port, "find_device_by_class", port->pc->ops->find_device_by_class); CHECK_RESULT (port->pc->ops->find_device_by_class (port, mainclass, subclass, protocol)); return (GP_OK); }
/** * \brief Find USB device by vendor/product * * \param port a GPPort * \param idvendor USB vendor id * \param idproduct USB product id * * Find the USB device with the specified vendor:product id pair. * * \return a gphoto2 error code */ int gp_port_usb_find_device (GPPort *port, int idvendor, int idproduct) { C_PARAMS (port); CHECK_INIT (port); CHECK_SUPP (port, "find_device", port->pc->ops->find_device); CHECK_RESULT (port->pc->ops->find_device (port, idvendor, idproduct)); return (GP_OK); }
static int gp_port_exit (GPPort *port) { C_PARAMS (port); CHECK_INIT (port); if (port->pc->ops->exit) CHECK_RESULT (port->pc->ops->exit (port)); return (GP_OK); }