Logo Search packages:      
Sourcecode: libgphoto2 version File versions  Download package

int gp_filesystem_set_file_noop ( CameraFilesystem fs,
const char *  folder,
CameraFile file,
GPContext context 
)

Attach file content to a specified file.

Parameters:
fs a CameraFilesystem
folder a folder in the filesystem
file a CameraFile
context,: a GPContext
Tells the fs about a file. Typically, camera drivers will call this function in case they get information about a file (i.e. preview) "for free" on gp_camera_capture() or gp_camera_folder_list_files().

Returns:
a gphoto2 error code.

Definition at line 2250 of file gphoto2-filesys.c.

References CHECK_NULL, _CameraFileInfoFile::fields, _CameraFileInfo::file, GP_ERROR, gp_file_get_data_and_size(), gp_file_get_mtime(), gp_file_get_name(), gp_file_get_type(), GP_FILE_INFO_MTIME, gp_file_ref(), gp_file_set_mtime(), GP_FILE_TYPE_AUDIO, GP_FILE_TYPE_EXIF, GP_FILE_TYPE_METADATA, GP_FILE_TYPE_NORMAL, GP_FILE_TYPE_PREVIEW, GP_FILE_TYPE_RAW, gp_file_unref(), gp_filesystem_get_info(), GP_OK, and _CameraFileInfoFile::mtime.

Referenced by gp_filesystem_get_file().

{
      CameraFileType type;
      CameraFileInfo info;
      CameraFilesystemFolder  *f;
      CameraFilesystemFile    *xfile;
      const char *filename;
      int r;
      time_t t;

      CHECK_NULL (fs && folder && file);
      CC (context);
      CA (folder, context);

      CR (gp_file_get_name (file, &filename));
      CR (gp_file_get_type (file, &type));
      GP_DEBUG ("Adding file '%s' to folder '%s' (type %i)...",
              filename, folder, type);

      /* Search folder and file */
      CR (lookup_folder_file (fs, folder, filename, &f, &xfile, context));

      /*
       * If we add a significant amount of data in the cache, we put (or
       * move) a reference to this file in the LRU linked list. We
       * assume that only GP_FILE_TYPE_[RAW,NORMAL,EXIF] will contain a
       * significant amount of data.
       */
      if ((type == GP_FILE_TYPE_RAW) || (type == GP_FILE_TYPE_NORMAL) ||
          (type == GP_FILE_TYPE_AUDIO))
            CR (gp_filesystem_lru_update (fs, folder, file, context));

      /* Redundant sanity check. */
      CR (gp_filesystem_lru_check (fs));

      switch (type) {
      case GP_FILE_TYPE_PREVIEW:
            if (xfile->preview)
                  gp_file_unref (xfile->preview);
            xfile->preview = file;
            gp_file_ref (file);
            break;
      case GP_FILE_TYPE_NORMAL:
            if (xfile->normal)
                  gp_file_unref (xfile->normal);
            xfile->normal = file;
            gp_file_ref (file);
            break;
      case GP_FILE_TYPE_RAW:
            if (xfile->raw)
                  gp_file_unref (xfile->raw);
            xfile->raw = file;
            gp_file_ref (file);
            break;
      case GP_FILE_TYPE_AUDIO:
            if (xfile->audio)
                  gp_file_unref (xfile->audio);
            xfile->audio = file;
            gp_file_ref (file);
            break;
      case GP_FILE_TYPE_EXIF:
            if (xfile->exif)
                  gp_file_unref (xfile->exif);
            xfile->exif = file;
            gp_file_ref (file);
            break;
      case GP_FILE_TYPE_METADATA:
            if (xfile->metadata)
                  gp_file_unref (xfile->metadata);
            xfile->metadata = file;
            gp_file_ref (file);
            break;
      default:
            gp_context_error (context, _("Unknown file type %i."), type);
            return (GP_ERROR);
      }

      /*
       * If we didn't get a mtime, try to get it from the CameraFileInfo.
       */
      CR (gp_file_get_mtime (file, &t));
      if (!t) {
            GP_DEBUG ("File does not contain mtime. Trying "
                    "information on the file...");
            r = gp_filesystem_get_info (fs, folder, filename, &info, NULL);
            if ((r == GP_OK) && (info.file.fields & GP_FILE_INFO_MTIME))
                  t = info.file.mtime;
      }

      /*
       * If we still don't have the mtime and this is a normal
       * file, check if there is EXIF data in the file that contains
       * information on the mtime.
       */
#ifdef HAVE_LIBEXIF
      if (!t && (type == GP_FILE_TYPE_NORMAL)) {
            unsigned long int size;
            const char *data;

            GP_DEBUG ("Searching data for mtime...");
            CR (gp_file_get_data_and_size (file, NULL, &size));
            if (size < 32*1024*1024) { /* just assume stuff above 32MB is not EXIF capable */
                  /* FIXME: Will leak on "fd" retrieval */
                  CR (gp_file_get_data_and_size (file, &data, &size));
                  t = get_exif_mtime ((unsigned char*)data, size);
            }
      }
      /*
       * Still no mtime? Let's see if the camera offers us data of type
       * GP_FILE_TYPE_EXIF that includes information on the mtime.
       */
      if (!t) {
            GP_DEBUG ("Trying EXIF information...");
            t = gp_filesystem_get_exif_mtime (fs, folder, filename);
      }
#endif

      if (t)
            CR (gp_file_set_mtime (file, t));

      return (GP_OK);
}


Generated by  Doxygen 1.6.0   Back to index