2001-09-02 Lutz M�ller <urc8@rz.uni-karlsruhe.de>
* include/gphoto2-filesys.h:
* libgphoto2/filesys.c: Cache files, too.
* libgphoto2/camera.c: Use cached files if exist.
* camlibs/konica/library.c:
* camlibs/sierra/sierra.c: Cache files in the filesystem.
git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@2175 67ed7778-7388-44ab-90cf-0a291f65f57c
This commit is contained in:
@@ -424,13 +424,14 @@ camera_folder_delete_all (Camera* camera, const gchar* folder)
|
||||
}
|
||||
|
||||
static int
|
||||
camera_file_get (Camera* camera, const gchar* folder, const gchar* filename,
|
||||
CameraFileType type, CameraFile *file)
|
||||
get_file_func (CameraFilesystem *fs, const char *folder, const char *filename,
|
||||
CameraFileType type, CameraFile *file, void *data)
|
||||
{
|
||||
Camera *camera = data;
|
||||
gulong image_id;
|
||||
gchar* image_id_string;
|
||||
KonicaData* kd;
|
||||
char *data = NULL;
|
||||
KonicaData *kd = camera->camlib_data;
|
||||
unsigned char *fdata = NULL;
|
||||
long int size;
|
||||
|
||||
if (strlen (filename) != 11)
|
||||
@@ -440,12 +441,6 @@ camera_file_get (Camera* camera, const gchar* folder, const gchar* filename,
|
||||
if (strcmp (folder, "/"))
|
||||
return (GP_ERROR_DIRECTORY_NOT_FOUND);
|
||||
|
||||
gp_debug_printf (GP_DEBUG_LOW, "konica", "*** Entering camera_file_get_generic ***");
|
||||
gp_debug_printf (GP_DEBUG_LOW, "konica", "*** folder: %s", folder);
|
||||
gp_debug_printf (GP_DEBUG_LOW, "konica", "*** file: %s", filename);
|
||||
|
||||
kd = (KonicaData *) camera->camlib_data;
|
||||
|
||||
/* Check if we can get the image id from the filename. */
|
||||
image_id_string = g_strndup (filename, 6);
|
||||
image_id = atol (image_id_string);
|
||||
@@ -455,23 +450,21 @@ camera_file_get (Camera* camera, const gchar* folder, const gchar* filename,
|
||||
switch (type) {
|
||||
case GP_FILE_TYPE_PREVIEW:
|
||||
CHECK (k_get_image (camera->port, kd->image_id_long, image_id,
|
||||
K_THUMBNAIL, (guchar **) &data,
|
||||
K_THUMBNAIL, (guchar **) &fdata,
|
||||
(guint *) &size));
|
||||
break;
|
||||
case GP_FILE_TYPE_NORMAL:
|
||||
CHECK (k_get_image (camera->port, kd->image_id_long, image_id,
|
||||
K_IMAGE_EXIF, (guchar **) &data,
|
||||
K_IMAGE_EXIF, (guchar **) &fdata,
|
||||
(guint *) &size));
|
||||
break;
|
||||
default:
|
||||
return (GP_ERROR_NOT_SUPPORTED);
|
||||
}
|
||||
|
||||
gp_file_set_data_and_size (file, data, size);
|
||||
gp_file_set_name (file, filename);
|
||||
gp_file_set_mime_type (file, "image/jpeg");
|
||||
CHECK (gp_file_set_data_and_size (file, fdata, size));
|
||||
CHECK (gp_file_set_mime_type (file, GP_MIME_JPEG));
|
||||
|
||||
gp_debug_printf (GP_DEBUG_LOW, "konica", "*** Leaving camera_file_get_generic ***");
|
||||
return (GP_OK);
|
||||
}
|
||||
|
||||
@@ -1197,7 +1190,6 @@ camera_init (Camera* camera)
|
||||
/* First, set up all the function pointers. */
|
||||
camera->functions->exit = camera_exit;
|
||||
camera->functions->folder_delete_all = camera_folder_delete_all;
|
||||
camera->functions->file_get = camera_file_get;
|
||||
camera->functions->file_delete = camera_file_delete;
|
||||
camera->functions->get_config = camera_get_config;
|
||||
camera->functions->set_config = camera_set_config;
|
||||
@@ -1261,6 +1253,7 @@ camera_init (Camera* camera)
|
||||
set_info_func, camera);
|
||||
gp_filesystem_set_list_funcs (camera->fs, file_list_func,
|
||||
NULL, camera);
|
||||
gp_filesystem_set_file_func (camera->fs, get_file_func, camera);
|
||||
|
||||
gp_debug_printf (GP_DEBUG_LOW, "konica", "*** EXIT: "
|
||||
"camera_init ***");
|
||||
|
||||
@@ -298,9 +298,10 @@ camera_exit (Camera *camera)
|
||||
}
|
||||
|
||||
static int
|
||||
camera_file_get (Camera *camera, const char *folder, const char *filename,
|
||||
CameraFileType type, CameraFile *file)
|
||||
get_file_func (CameraFilesystem *fs, const char *folder, const char *filename,
|
||||
CameraFileType type, CameraFile *file, void *user_data)
|
||||
{
|
||||
Camera *camera = user_data;
|
||||
int regl, regd, n;
|
||||
char *jpeg_data = NULL;
|
||||
int jpeg_size;
|
||||
@@ -1268,7 +1269,6 @@ int camera_init (Camera *camera)
|
||||
|
||||
/* First, set up all the function pointers */
|
||||
camera->functions->exit = camera_exit;
|
||||
camera->functions->file_get = camera_file_get;
|
||||
camera->functions->file_delete = camera_file_delete;
|
||||
camera->functions->folder_delete_all = camera_folder_delete_all;
|
||||
camera->functions->capture_preview = camera_capture_preview;
|
||||
@@ -1383,6 +1383,8 @@ int camera_init (Camera *camera)
|
||||
CHECK_STOP_FREE (camera, gp_filesystem_set_info_funcs (camera->fs,
|
||||
get_info_func, set_info_func,
|
||||
camera));
|
||||
CHECK_STOP_FREE (camera, gp_filesystem_set_file_func (camera->fs,
|
||||
get_file_func, camera));
|
||||
|
||||
gp_debug_printf (GP_DEBUG_LOW, "sierra", "************************");
|
||||
gp_debug_printf (GP_DEBUG_LOW, "sierra", "*** camera_init done ***");
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#define __GPHOTO2_FILESYS_H__
|
||||
|
||||
#include <gphoto2-list.h>
|
||||
#include <gphoto2-file.h>
|
||||
|
||||
typedef enum {
|
||||
GP_FILE_INFO_NONE = 0,
|
||||
@@ -111,6 +112,19 @@ int gp_filesystem_get_info (CameraFilesystem *fs, const char *folder,
|
||||
int gp_filesystem_set_info (CameraFilesystem *fs, const char *folder,
|
||||
const char *filename, CameraFileInfo *info);
|
||||
|
||||
/* Files */
|
||||
typedef int (*CameraFilesystemGetFileFunc) (CameraFilesystem *fs,
|
||||
const char *folder,
|
||||
const char *filename,
|
||||
CameraFileType type,
|
||||
CameraFile *file, void *data);
|
||||
int gp_filesystem_set_file_func (CameraFilesystem *fs,
|
||||
CameraFilesystemGetFileFunc get_file_func,
|
||||
void *data);
|
||||
int gp_filesystem_get_file (CameraFilesystem *fs, const char *folder,
|
||||
const char *filename, CameraFileType type,
|
||||
CameraFile *file);
|
||||
|
||||
int gp_filesystem_dump (CameraFilesystem *fs);
|
||||
|
||||
#endif /* __GPHOTO2_FILESYS_H__ */
|
||||
|
||||
@@ -754,19 +754,29 @@ int
|
||||
gp_camera_file_get (Camera *camera, const char *folder, const char *file,
|
||||
CameraFileType type, CameraFile *camera_file)
|
||||
{
|
||||
int result;
|
||||
|
||||
GP_DEBUG ("ENTER: gp_camera_file_get");
|
||||
CHECK_NULL (camera && folder && file && camera_file);
|
||||
|
||||
if (camera->functions->file_get == NULL)
|
||||
return (GP_ERROR_NOT_SUPPORTED);
|
||||
|
||||
/* Did we get reasonable foldername/filename? */
|
||||
if (strlen (folder) == 0)
|
||||
return (GP_ERROR_DIRECTORY_NOT_FOUND);
|
||||
if (strlen (file) == 0)
|
||||
return (GP_ERROR_FILE_NOT_FOUND);
|
||||
|
||||
CHECK_OPEN (camera);
|
||||
result = gp_filesystem_get_file (camera->fs, folder, file, type,
|
||||
camera_file);
|
||||
CHECK_CLOSE (camera);
|
||||
if (result != GP_ERROR_NOT_SUPPORTED)
|
||||
return (result);
|
||||
|
||||
if (camera->functions->file_get == NULL)
|
||||
return (GP_ERROR_NOT_SUPPORTED);
|
||||
|
||||
CHECK_RESULT (gp_file_set_type (camera_file, type));
|
||||
CHECK_RESULT (gp_file_set_name (camera_file, file));
|
||||
|
||||
CHECK_RESULT_OPEN_CLOSE (camera, camera->functions->file_get (camera,
|
||||
folder, file, type, camera_file));
|
||||
|
||||
@@ -315,12 +315,14 @@ gp_file_copy (CameraFile *destination, CameraFile *source)
|
||||
|
||||
if (destination->data)
|
||||
free (destination->data);
|
||||
|
||||
memcpy (destination, source, sizeof (CameraFile));
|
||||
|
||||
destination->data = malloc (sizeof (char) * source->size);
|
||||
if (!destination->data)
|
||||
return (GP_ERROR_NO_MEMORY);
|
||||
|
||||
memcpy (destination->data, source->data, source->size);
|
||||
destination->size = source->size;
|
||||
|
||||
return (GP_OK);
|
||||
}
|
||||
|
||||
@@ -26,11 +26,15 @@
|
||||
|
||||
#include "gphoto2-core.h"
|
||||
#include "gphoto2-result.h"
|
||||
#include "gphoto2-file.h"
|
||||
|
||||
typedef struct {
|
||||
char name [128];
|
||||
int info_dirty;
|
||||
CameraFileInfo info;
|
||||
CameraFile *preview;
|
||||
CameraFile *normal;
|
||||
CameraFile *raw;
|
||||
} CameraFilesystemFile;
|
||||
|
||||
typedef struct {
|
||||
@@ -52,6 +56,9 @@ struct _CameraFilesystem {
|
||||
CameraFilesystemListFunc file_list_func;
|
||||
CameraFilesystemListFunc folder_list_func;
|
||||
void *list_data;
|
||||
|
||||
CameraFilesystemGetFileFunc get_file_func;
|
||||
void *file_data;
|
||||
};
|
||||
|
||||
#define CHECK_NULL(r) {if (!(r)) return (GP_ERROR_BAD_PARAMETERS);}
|
||||
@@ -80,6 +87,9 @@ gp_filesystem_new (CameraFilesystem **fs)
|
||||
(*fs)->folder_list_func = NULL;
|
||||
(*fs)->list_data = NULL;
|
||||
|
||||
(*fs)->get_file_func = NULL;
|
||||
(*fs)->file_data = NULL;
|
||||
|
||||
result = gp_filesystem_append_folder (*fs, "/");
|
||||
if (result != GP_OK) {
|
||||
free (*fs);
|
||||
@@ -251,6 +261,9 @@ gp_filesystem_append (CameraFilesystem *fs, const char *folder,
|
||||
fs->folder[x].count++;
|
||||
strcpy (fs->folder[x].file[fs->folder[x].count - 1].name, filename);
|
||||
fs->folder[x].file[fs->folder[x].count - 1].info_dirty = 1;
|
||||
fs->folder[x].file[fs->folder[x].count - 1].preview = NULL;
|
||||
fs->folder[x].file[fs->folder[x].count - 1].normal = NULL;
|
||||
fs->folder[x].file[fs->folder[x].count - 1].raw = NULL;
|
||||
|
||||
/*
|
||||
* If people manually add files, they probably know the contents of
|
||||
@@ -521,8 +534,11 @@ gp_filesystem_delete (CameraFilesystem *fs, const char *folder,
|
||||
|
||||
if (filename) {
|
||||
|
||||
/* Search the file */
|
||||
/* Search the file and get rid of cached files */
|
||||
CHECK_RESULT (y = gp_filesystem_number (fs, folder, filename));
|
||||
gp_file_unref (fs->folder[x].file[y].preview);
|
||||
gp_file_unref (fs->folder[x].file[y].normal);
|
||||
gp_file_unref (fs->folder[x].file[y].raw);
|
||||
|
||||
/* Move all files behind one position up */
|
||||
for (; y < fs->folder[x].count - 1; y++)
|
||||
@@ -583,19 +599,12 @@ gp_filesystem_format (CameraFilesystem *fs)
|
||||
|
||||
gp_debug_printf (GP_DEBUG_HIGH, "core", "Formatting file system...");
|
||||
|
||||
for (x = 0; x < fs->count; x++)
|
||||
if (fs->folder[x].count)
|
||||
free (fs->folder[x].file);
|
||||
CHECK_RESULT (gp_filesystem_delete (fs, "/", NULL));
|
||||
CHECK_RESULT (x = gp_filesystem_folder_number (fs, "/"));
|
||||
|
||||
if (fs->count)
|
||||
free (fs->folder);
|
||||
fs->count = 0;
|
||||
|
||||
/*
|
||||
* Append the root folder so that list_[folders,files] will stop
|
||||
* there when recursively looking up parent folders.
|
||||
*/
|
||||
CHECK_RESULT (gp_filesystem_append_folder (fs, "/"));
|
||||
/* Set dirty flag so that file_list and folder_list will be called */
|
||||
fs->folder[x].files_dirty = 1;
|
||||
fs->folder[x].folders_dirty = 1;
|
||||
|
||||
return (GP_OK);
|
||||
}
|
||||
@@ -710,6 +719,86 @@ gp_filesystem_set_list_funcs (CameraFilesystem *fs,
|
||||
return (GP_OK);
|
||||
}
|
||||
|
||||
int
|
||||
gp_filesystem_set_file_func (CameraFilesystem *fs,
|
||||
CameraFilesystemGetFileFunc get_file_func,
|
||||
void *data)
|
||||
{
|
||||
CHECK_NULL (fs);
|
||||
|
||||
fs->get_file_func = get_file_func;
|
||||
fs->file_data = data;
|
||||
|
||||
return (GP_OK);
|
||||
}
|
||||
|
||||
int
|
||||
gp_filesystem_get_file (CameraFilesystem *fs, const char *folder,
|
||||
const char *filename, CameraFileType type,
|
||||
CameraFile *file)
|
||||
{
|
||||
int x, y, result;
|
||||
CameraFile *tmp;
|
||||
|
||||
CHECK_NULL (fs && folder && file && filename);
|
||||
|
||||
if (!fs->get_file_func)
|
||||
return (GP_ERROR_NOT_SUPPORTED);
|
||||
|
||||
/* Search folder and file */
|
||||
CHECK_RESULT (x = gp_filesystem_folder_number (fs, folder));
|
||||
CHECK_RESULT (y = gp_filesystem_number (fs, folder, filename));
|
||||
|
||||
switch (type) {
|
||||
case GP_FILE_TYPE_PREVIEW:
|
||||
if (fs->folder[x].file[y].preview)
|
||||
return (gp_file_copy (file,
|
||||
fs->folder[x].file[y].preview));
|
||||
break;
|
||||
case GP_FILE_TYPE_NORMAL:
|
||||
if (fs->folder[x].file[y].normal)
|
||||
return (gp_file_copy (file,
|
||||
fs->folder[x].file[y].normal));
|
||||
break;
|
||||
case GP_FILE_TYPE_RAW:
|
||||
if (fs->folder[x].file[y].raw)
|
||||
return (gp_file_copy (file,
|
||||
fs->folder[x].file[y].raw));
|
||||
break;
|
||||
default:
|
||||
return (GP_ERROR);
|
||||
}
|
||||
|
||||
CHECK_RESULT (gp_file_new (&tmp));
|
||||
result = fs->get_file_func (fs, folder, filename, type, tmp,
|
||||
fs->file_data);
|
||||
if (result != GP_OK) {
|
||||
gp_file_unref (tmp);
|
||||
return (result);
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case GP_FILE_TYPE_PREVIEW:
|
||||
fs->folder[x].file[y].preview = tmp;
|
||||
break;
|
||||
case GP_FILE_TYPE_NORMAL:
|
||||
fs->folder[x].file[y].normal = tmp;
|
||||
break;
|
||||
case GP_FILE_TYPE_RAW:
|
||||
fs->folder[x].file[y].raw = tmp;
|
||||
break;
|
||||
default:
|
||||
gp_file_unref (tmp);
|
||||
return (GP_ERROR);
|
||||
}
|
||||
|
||||
CHECK_RESULT (gp_file_set_type (tmp, type));
|
||||
CHECK_RESULT (gp_file_set_name (tmp, filename));
|
||||
CHECK_RESULT (gp_file_copy (file, tmp));
|
||||
|
||||
return (GP_OK);
|
||||
}
|
||||
|
||||
int
|
||||
gp_filesystem_set_info_funcs (CameraFilesystem *fs,
|
||||
CameraFilesystemInfoFunc get_info_func,
|
||||
|
||||
Reference in New Issue
Block a user