Unit ulibmtp_common;

{$MODE ObjFPC}{$H+}

Interface

Uses
  Classes, SysUtils, ctypes;

Const
  LIBMTP_FILES_AND_FOLDERS_ROOT = -1; // $FFFFFFFF;


{$IFDEF FPC}
{$PACKRECORDS C}
{$ENDIF}

  (**
   * These are the numbered error codes. You can also
   * get string representations for errors.
   *)
Type
  uint8_t = UInt8;
  uint16_t = uint16;
  uint32_t = UInt32;
  uint64_t = uint64;
  time_t = uint64;

  (*
   * These are the numbered error codes. You can also
   * get string representations for errors.
   *)
  LIBMTP_error_number_t = (
    LIBMTP_ERROR_NONE,
    LIBMTP_ERROR_GENERAL,
    LIBMTP_ERROR_PTP_LAYER,
    LIBMTP_ERROR_USB_LAYER,
    LIBMTP_ERROR_MEMORY_ALLOCATION,
    LIBMTP_ERROR_NO_DEVICE_ATTACHED,
    LIBMTP_ERROR_STORAGE_FULL,
    LIBMTP_ERROR_CONNECTING,
    LIBMTP_ERROR_CANCELLED
    );

  (*
   * The filetypes defined here are the external types used
   * by the libmtp library interface. The types used internally
   * as PTP-defined enumerator types is something different.
   *)
  LIBMTP_filetype_t = (
    LIBMTP_FILETYPE_FOLDER,
    LIBMTP_FILETYPE_WAV,
    LIBMTP_FILETYPE_MP3,
    LIBMTP_FILETYPE_WMA,
    LIBMTP_FILETYPE_OGG,
    LIBMTP_FILETYPE_AUDIBLE,
    LIBMTP_FILETYPE_MP4,
    LIBMTP_FILETYPE_UNDEF_AUDIO,
    LIBMTP_FILETYPE_WMV,
    LIBMTP_FILETYPE_AVI,
    LIBMTP_FILETYPE_MPEG,
    LIBMTP_FILETYPE_ASF,
    LIBMTP_FILETYPE_QT,
    LIBMTP_FILETYPE_UNDEF_VIDEO,
    LIBMTP_FILETYPE_JPEG,
    LIBMTP_FILETYPE_JFIF,
    LIBMTP_FILETYPE_TIFF,
    LIBMTP_FILETYPE_BMP,
    LIBMTP_FILETYPE_GIF,
    LIBMTP_FILETYPE_PICT,
    LIBMTP_FILETYPE_PNG,
    LIBMTP_FILETYPE_VCALENDAR1,
    LIBMTP_FILETYPE_VCALENDAR2,
    LIBMTP_FILETYPE_VCARD2,
    LIBMTP_FILETYPE_VCARD3,
    LIBMTP_FILETYPE_WINDOWSIMAGEFORMAT,
    LIBMTP_FILETYPE_WINEXEC,
    LIBMTP_FILETYPE_TEXT,
    LIBMTP_FILETYPE_HTML,
    LIBMTP_FILETYPE_FIRMWARE,
    LIBMTP_FILETYPE_AAC,
    LIBMTP_FILETYPE_MEDIACARD,
    LIBMTP_FILETYPE_FLAC,
    LIBMTP_FILETYPE_MP2,
    LIBMTP_FILETYPE_M4A,
    LIBMTP_FILETYPE_DOC,
    LIBMTP_FILETYPE_XML,
    LIBMTP_FILETYPE_XLS,
    LIBMTP_FILETYPE_PPT,
    LIBMTP_FILETYPE_MHT,
    LIBMTP_FILETYPE_JP2,
    LIBMTP_FILETYPE_JPX,
    LIBMTP_FILETYPE_ALBUM,
    LIBMTP_FILETYPE_PLAYLIST,
    LIBMTP_FILETYPE_UNKNOWN
    );

  (*
   * A data structure to hold MTP device entries.
   *)
  LIBMTP_device_entry_struct = Record
    vendor: Pchar; (*< The vendor of this device *)
    vendor_id: uint16_t; (*< Vendor ID for this device *)
    product: pchar; (*< The product name of this device *)
    product_id: uint16_t; (*< Product ID for this device *)
    device_flags: uint32_t; (*< Bugs, device specifics etc *)
  End;


  LIBMTP_device_entry_t = LIBMTP_device_entry_struct;

  (*
   * A data structure to hold a raw MTP device connected
   * to the bus.
   *)
  LIBMTP_raw_device_struct = Record
    device_entry: LIBMTP_device_entry_t; (*< The device entry for this raw device *)
    bus_location: uint32_t; (*< Location of the bus, if device available *)
    devnum: uint8_t; (*< Device number on the bus, if device available *)
  End;

  (*
   * LIBMTP Device Storage structure
   *)
  LIBMTP_devicestorage_struct = Record
    id: uint32_t; (*< Unique ID for this storage *)
    StorageType: uint16_t; (*< Storage type *)
    FilesystemType: uint16_t; (*< Filesystem type *)
    AccessCapability: uint16_t; (*< Access capability *)
    MaxCapacity: uint64_t; (*< Maximum capability *)
    FreeSpaceInBytes: uint64_t; (*< Free space in bytes *)
    FreeSpaceInObjects: uint64_t; (*< Free space in objects *)
    StorageDescription: PChar; (*< A brief description of this storage *)
    VolumeIdentifier: PChar; (*< A volume identifier *)
    next: ^LIBMTP_devicestorage_t; (*< Next storage, follow this link until NULL *)
    prev: ^LIBMTP_devicestorage_t; (*< Previous storage *)
  End;

  LIBMTP_devicestorage_t = LIBMTP_devicestorage_struct;

  (*
   * Main MTP device object struct
   *)
  LIBMTP_mtpdevice_struct = Record
    (*
     * Object bitsize, typically 32 or 64.
     *)
    object_bitsize: uint8_t;
    (*
     * Parameters for this device, must be cast into
     * \c (PTPParams* ) before internal use.
     *)
    params: Pointer;
    (*
     * USB device for this device, must be cast into
     * \c (PTP_USB* ) before internal use.
     *)
    usbinfo: Pointer;
    (*
     * The storage for this device, do not use strings in here without
     * copying them first, and beware that this list may be rebuilt at
     * any time.
     * @see LIBMTP_Get_Storage()
     *)
    storage: ^LIBMTP_devicestorage_t;
    (*
     * The error stack. This shall be handled using the error getting
     * and clearing functions, not by dereferencing this list.
     *)
    errorstack: ^LIBMTP_error_t;
    (* The maximum battery level for this device *)
    maximum_battery_level: uint8_t;
    (* Default music folder *)
    default_music_folder: uint32_t;
    (* Default playlist folder *)
    default_playlist_folder: uint32_t;
    (* Default picture folder *)
    default_picture_folder: uint32_t;
    (* Default video folder *)
    default_video_folder: uint32_t;
    (* Default organizer folder *)
    default_organizer_folder: uint32_t;
    (* Default ZENcast folder (only Creative devices...) *)
    default_zencast_folder: uint32_t;
    (* Default Album folder *)
    default_album_folder: uint32_t;
    (* Default Text folder *)
    default_text_folder: uint32_t;
    (* Per device iconv() converters, only used internally *)
    cd: Pointer;
    (* Extension list *)
    extensions: ^LIBMTP_device_extension_t;
    (* Whether the device uses caching, only used internally *)
    cached: cint;

    (* Pointer to next device in linked list; NULL if this is the last device *)
    next: ^LIBMTP_mtpdevice_t;
  End;



  (*
   * A data structure to hold errors from the library.
   *)
  LIBMTP_error_struct = Record
    errornumber: LIBMTP_error_number_t;
    error_text: Pchar;
    next: ^LIBMTP_error_t;
  End;

  (*
   * MTP device extension holder struct
   *)
  LIBMTP_device_extension_struct = Record
    (*
     * Name of extension e.g. "foo.com"
     *)
    name: Pchar;
    (*
     * Major revision of extension
     *)
    major: cint;
    (*
     * Minor revision of extension
     *)
    minor: cint;
    (*
     * Pointer to the next extension or NULL if this is the
     * last extension.
     *)
    next: ^LIBMTP_device_extension_t;
  End;

  PLIBMTP_file_t = ^LIBMTP_file_t;
  (*
   * MTP file struct
   *)
  LIBMTP_file_struct = Record
    item_id: uint32_t; (*< Unique item ID *)
    parent_id: uint32_t; (*< ID of parent folder *)
    storage_id: uint32_t; (*< ID of storage holding this file *)
    filename: Pchar; (*< Filename of this file *)
    filesize: uint64_t; (*< Size of file in bytes *)
    modificationdate: time_t; (*< Date of last alteration of the file *)
    filetype: LIBMTP_filetype_t; (*< Filetype used for the current file *)
    next: PLIBMTP_file_t; (*< Next file in list or NULL if last file *)
  End;

  LIBMTP_raw_device_t = LIBMTP_raw_device_struct;
  PLIBMTP_raw_device_t = ^LIBMTP_raw_device_t;
  LIBMTP_mtpdevice_t = LIBMTP_mtpdevice_struct;
  PLIBMTP_mtpdevice_t = ^LIBMTP_mtpdevice_t;

  LIBMTP_file_t = LIBMTP_file_struct;

  LIBMTP_error_t = LIBMTP_error_struct;
  LIBMTP_device_extension_t = LIBMTP_device_extension_struct;

Implementation

End.

