static int camera_capture (Camera* camera, CameraCaptureType type, CameraFilePath* path, GPContext *context) { int r; CameraFile *file = NULL; CameraFileInfo info; KncCamRes cr; KncCntrlRes cntrl_res; KncImageInfo i; C_NULL (camera && path); /* We only support capturing of images */ if (type != GP_CAPTURE_IMAGE) return (GP_ERROR_NOT_SUPPORTED); /* Stop the timeout, take the picture, and restart the timeout. */ gp_camera_stop_timeout (camera, camera->pl->timeout); gp_file_new (&file); knc_cntrl_set_func_data (camera->pl->c, data_func, file); cntrl_res = knc_take_picture (camera->pl->c, &cr, KNC_SOURCE_CARD, &i); camera->pl->timeout = gp_camera_start_timeout (camera, PING_TIMEOUT, timeout_func); if (cntrl_res) gp_file_unref (file); CR (cntrl_res, context); sprintf (path->name, "%06i.jpeg", (int) i.id); strcpy (path->folder, "/"); r = gp_filesystem_append (camera->fs, path->folder, path->name, context); if (r < 0) { gp_file_unref (file); return r; } info.preview.fields = GP_FILE_INFO_SIZE | GP_FILE_INFO_TYPE; gp_file_get_data_and_size (file, NULL, &info.preview.size); strcpy (info.preview.type, GP_MIME_JPEG); info.file.fields = GP_FILE_INFO_SIZE | GP_FILE_INFO_PERMISSIONS | GP_FILE_INFO_TYPE | GP_FILE_INFO_NAME; info.file.size = i.size; info.file.permissions = GP_FILE_PERM_READ; if (!i.prot) info.file.permissions |= GP_FILE_PERM_DELETE; strcpy (info.file.type, GP_MIME_JPEG); snprintf (info.file.name, sizeof (info.file.name), "%06i.jpeg", (int) i.id); gp_filesystem_set_info_noop (camera->fs, path->folder, info, context); gp_file_set_name (file, info.file.name); gp_file_set_mime_type (file, GP_MIME_JPEG); gp_file_set_type (file, GP_FILE_TYPE_EXIF); gp_filesystem_set_file_noop (camera->fs, path->folder, file, context); gp_file_unref (file); return (GP_OK); }
static int get_file_func (CameraFilesystem *fs, const char *folder, const char *filename, CameraFileType type, CameraFile *file, void *data, GPContext *context) { Camera *camera = data; unsigned long image_id; char image_id_string[] = {0, 0, 0, 0, 0, 0, 0}; unsigned int size; CameraFileInfo info; int r; KncCamRes cr; KncCntrlRes cntrl_res = KNC_CNTRL_OK; if (strlen (filename) != 11) return (GP_ERROR_FILE_NOT_FOUND); if (strcmp (folder, "/")) return (GP_ERROR_DIRECTORY_NOT_FOUND); /* Check if we can get the image id from the filename. */ strncpy (image_id_string, filename, 6); image_id = atol (image_id_string); /* Get information about the image */ C (gp_filesystem_get_info (camera->fs, folder, filename, &info, context)); /* * Remove the timeout, get the image and start the timeout * afterwards. */ gp_camera_stop_timeout (camera, camera->pl->timeout); knc_cntrl_set_func_data (camera->pl->c, data_func, file); switch (type) { case GP_FILE_TYPE_PREVIEW: size = 2048; cntrl_res = knc_get_image (camera->pl->c, &cr, image_id, KNC_SOURCE_CARD, KNC_IMAGE_THUMB); break; case GP_FILE_TYPE_NORMAL: size = info.file.size; cntrl_res = knc_get_image (camera->pl->c, &cr, image_id, KNC_SOURCE_CARD, KNC_IMAGE_EXIF); break; default: r = GP_ERROR_NOT_SUPPORTED; } camera->pl->timeout = gp_camera_start_timeout (camera, PING_TIMEOUT, timeout_func); CR (cntrl_res, context); CCR (cr, context); C (gp_file_set_mime_type (file, GP_MIME_JPEG)); return (GP_OK); }
static int camera_exit (Camera* camera, GPContext *context) { if (camera->pl) { gp_camera_stop_timeout (camera, camera->pl->timeout); knc_cntrl_unref (camera->pl->c); free (camera->pl); camera->pl = NULL; } return (GP_OK); }
/** * Close connection to camera. * * @param camera a #Camera object * @param context a #GPContext object * @return a gphoto2 error code. * * Closes a connection to the camera and therefore gives other application * the possibility to access the camera, too. * * It is recommended that you * call this function when you currently don't need the camera. The camera * will get reinitialized by gp_camera_init() automatically if you try to * access the camera again. * */ int gp_camera_exit (Camera *camera, GPContext *context) { C_PARAMS (camera); GP_LOG_D ("Exiting camera ('%s')...", camera->pc->a.model); /* * We have to postpone this operation if the camera is currently * in use. gp_camera_exit will be called again if the * camera->pc->used will drop to zero. */ if (camera->pc->used) { camera->pc->exit_requested = 1; return (GP_OK); } /* Remove every timeout that is still pending */ while (camera->pc->timeout_ids_len) gp_camera_stop_timeout (camera, camera->pc->timeout_ids[0]); free (camera->pc->timeout_ids); camera->pc->timeout_ids = NULL; if (camera->functions->exit) { #ifdef HAVE_MULTI gp_port_open (camera->port); #endif camera->functions->exit (camera, context); } gp_port_close (camera->port); memset (camera->functions, 0, sizeof (CameraFunctions)); if (camera->pc->lh) { #if !defined(VALGRIND) lt_dlclose (camera->pc->lh); lt_dlexit (); #endif camera->pc->lh = NULL; } gp_filesystem_reset (camera->fs); return (GP_OK); }
static int get_info (Camera *camera, unsigned int n, CameraFileInfo *info, CameraFile *file, GPContext *context) { unsigned char *buffer = NULL; KncCamRes cr; KncCntrlRes cntrl_res; KncImageInfo i; /* * Remove the timeout, get the information and restart the * timeout afterwards. */ gp_camera_stop_timeout (camera, camera->pl->timeout); knc_cntrl_set_func_data (camera->pl->c, data_func, file); cntrl_res = knc_get_image_info (camera->pl->c, &cr, n, &i); camera->pl->timeout = gp_camera_start_timeout (camera, PING_TIMEOUT, timeout_func); CR (cntrl_res, context); info->audio.fields = GP_FILE_INFO_NONE; info->preview.fields = GP_FILE_INFO_TYPE; strcpy (info->preview.type, GP_MIME_JPEG); info->file.fields = GP_FILE_INFO_SIZE | GP_FILE_INFO_PERMISSIONS | GP_FILE_INFO_TYPE | GP_FILE_INFO_NAME; info->file.size = i.size * 1000; info->file.permissions = GP_FILE_PERM_READ; if (!i.prot) info->file.permissions |= GP_FILE_PERM_DELETE; strcpy (info->file.type, GP_MIME_JPEG); snprintf (info->file.name, sizeof (info->file.name), "%06i.jpeg", (int) i.id); if (file) { gp_file_set_type (file, GP_FILE_TYPE_EXIF); gp_file_set_name (file, info->file.name); } else free (buffer); return (GP_OK); }