Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1 | /** |
| 2 | * \file libmtp.h |
| 3 | * |
| 4 | * Interface to the Media Transfer Protocol library. |
| 5 | * |
| 6 | * <code> |
| 7 | * #include <libmtp.h> |
| 8 | * </code> |
| 9 | */ |
| 10 | #ifndef LIBMTP_H_INCLUSION_GUARD |
| 11 | #define LIBMTP_H_INCLUSION_GUARD |
| 12 | |
| 13 | #define LIBMTP_VERSION @VERSION@ |
| 14 | |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 15 | /* This handles MSVC pecularities */ |
| 16 | #ifdef _MSC_VER |
| 17 | #include <windows.h> |
| 18 | #define __WIN32__ |
| 19 | #define snprintf _snprintf |
| 20 | #define ssize_t SSIZE_T |
| 21 | #endif |
| 22 | |
Linus Walleij | 15e344f | 2006-03-06 15:15:00 +0000 | [diff] [blame] | 23 | #include <stdio.h> |
| 24 | #include <usb.h> |
Linus Walleij | 9b28da3 | 2006-03-16 13:47:58 +0000 | [diff] [blame] | 25 | #include <stdint.h> |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 26 | |
| 27 | #ifdef __WIN32__ |
| 28 | /* |
| 29 | * Windows specific code, types that do not exist in Windows |
| 30 | * sys/types.h |
| 31 | */ |
| 32 | typedef char int8_t; |
| 33 | typedef unsigned char uint8_t; |
| 34 | typedef __int16 int16_t; |
| 35 | typedef unsigned __int16 uint16_t; |
| 36 | typedef __int32 int32_t; |
| 37 | typedef unsigned __int32 uint32_t; |
| 38 | typedef unsigned __int64 uint64_t; |
| 39 | #endif |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 40 | |
| 41 | /** |
| 42 | * @defgroup types libnjb global type definitions |
| 43 | * @{ |
| 44 | */ |
Linus Walleij | b9256fd | 2006-02-15 09:40:43 +0000 | [diff] [blame] | 45 | typedef enum { |
Linus Walleij | f6bc178 | 2006-03-24 15:12:47 +0000 | [diff] [blame] | 46 | LIBMTP_FILETYPE_WAV, |
| 47 | LIBMTP_FILETYPE_MP3, |
| 48 | LIBMTP_FILETYPE_WMA, |
| 49 | LIBMTP_FILETYPE_WMV, |
| 50 | LIBMTP_FILETYPE_AVI, |
| 51 | LIBMTP_FILETYPE_MPEG, |
| 52 | LIBMTP_FILETYPE_ASF, |
| 53 | LIBMTP_FILETYPE_QT, |
| 54 | LIBMTP_FILETYPE_JFIF, |
| 55 | LIBMTP_FILETYPE_TIFF, |
| 56 | LIBMTP_FILETYPE_BMP, |
| 57 | LIBMTP_FILETYPE_GIF, |
| 58 | LIBMTP_FILETYPE_PICT, |
| 59 | LIBMTP_FILETYPE_PNG, |
| 60 | LIBMTP_FILETYPE_UNKNOWN |
| 61 | } LIBMTP_filetype_t; |
Linus Walleij | 6fd2f08 | 2006-03-28 07:19:22 +0000 | [diff] [blame^] | 62 | typedef struct LIBMTP_device_entry_struct LIBMTP_device_entry_t; /**< @see LIBMTP_device_entry_struct */ |
Linus Walleij | b9256fd | 2006-02-15 09:40:43 +0000 | [diff] [blame] | 63 | typedef struct LIBMTP_mtpdevice_struct LIBMTP_mtpdevice_t; /**< @see LIBMTP_mtpdevice_struct */ |
Linus Walleij | f6bc178 | 2006-03-24 15:12:47 +0000 | [diff] [blame] | 64 | typedef struct LIBMTP_file_struct LIBMTP_file_t; /**< @see LIBMTP_file_struct */ |
| 65 | typedef struct LIBMTP_track_struct LIBMTP_track_t; /**< @see LIBMTP_track_struct */ |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 66 | /** @} */ |
| 67 | |
| 68 | /** |
Linus Walleij | 6fd2f08 | 2006-03-28 07:19:22 +0000 | [diff] [blame^] | 69 | * A data structure to hold MTP device entries |
| 70 | */ |
| 71 | struct LIBMTP_device_entry_struct { |
| 72 | char *name; /**< The descriptive name of this device */ |
| 73 | uint16_t vendor_id; /**< Vendor ID for this device */ |
| 74 | uint16_t product_id; /**< Product ID for this device */ |
| 75 | LIBMTP_device_entry_t *next; /**< Pointer to the next device entry or NULL if the last one */ |
| 76 | }; |
| 77 | |
| 78 | /** |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 79 | * Main MTP device object struct |
| 80 | */ |
Linus Walleij | b9256fd | 2006-02-15 09:40:43 +0000 | [diff] [blame] | 81 | struct LIBMTP_mtpdevice_struct { |
Linus Walleij | 9b28da3 | 2006-03-16 13:47:58 +0000 | [diff] [blame] | 82 | /** Interface number of this device */ |
| 83 | uint8_t interface_number; |
| 84 | /** |
| 85 | * Parameters for this device, must be cast into |
| 86 | * \c (PTPParams*) before internal use. |
| 87 | */ |
| 88 | void *params; |
Linus Walleij | 2d411db | 2006-03-22 12:13:09 +0000 | [diff] [blame] | 89 | /** |
| 90 | * USB device for this device, must be cast into |
| 91 | * \c (PTP_USB*) before internal use. |
| 92 | */ |
| 93 | void *usbinfo; |
Linus Walleij | 9b28da3 | 2006-03-16 13:47:58 +0000 | [diff] [blame] | 94 | /** The storage ID for this device */ |
| 95 | unsigned storage_id; |
| 96 | /** The maximum battery level for this device */ |
| 97 | uint8_t maximum_battery_level; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 98 | }; |
| 99 | |
Linus Walleij | b9256fd | 2006-02-15 09:40:43 +0000 | [diff] [blame] | 100 | /** |
Linus Walleij | f6bc178 | 2006-03-24 15:12:47 +0000 | [diff] [blame] | 101 | * MTP file struct |
| 102 | */ |
| 103 | struct LIBMTP_file_struct { |
| 104 | uint32_t item_id; /**< Unique item ID */ |
| 105 | char *filename; /**< Filename of this file */ |
| 106 | uint64_t filesize; /**< Size of file in bytes */ |
| 107 | LIBMTP_filetype_t filetype; /**< Filetype used for the current file */ |
| 108 | LIBMTP_file_t *next; /**< Next file in list or NULL if last file */ |
| 109 | }; |
| 110 | |
| 111 | /** |
Linus Walleij | b9256fd | 2006-02-15 09:40:43 +0000 | [diff] [blame] | 112 | * MTP track struct |
| 113 | */ |
| 114 | struct LIBMTP_track_struct { |
| 115 | uint32_t item_id; /**< Unique item ID */ |
| 116 | char *title; /**< Track title */ |
| 117 | char *artist; /**< Name of recording artist */ |
| 118 | char *genre; /**< Genre name for track */ |
| 119 | char *album; /**< Album name for track */ |
| 120 | char *date; /**< Date of original recording as a string */ |
| 121 | char *filename; /**< Original filename of this track */ |
| 122 | uint16_t tracknumber; /**< Track number (in sequence on recording) */ |
| 123 | uint32_t duration; /**< Duration in milliseconds */ |
| 124 | uint64_t filesize; /**< Size of track file in bytes */ |
Linus Walleij | f6bc178 | 2006-03-24 15:12:47 +0000 | [diff] [blame] | 125 | LIBMTP_filetype_t filetype; /**< Filetype used for the current track */ |
Linus Walleij | b9256fd | 2006-02-15 09:40:43 +0000 | [diff] [blame] | 126 | LIBMTP_track_t *next; /**< Next track in list or NULL if last track */ |
| 127 | }; |
| 128 | |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 129 | /* Make functions available for C++ */ |
| 130 | #ifdef __cplusplus |
| 131 | extern "C" { |
| 132 | #endif |
| 133 | |
Linus Walleij | dcde608 | 2006-02-17 16:16:34 +0000 | [diff] [blame] | 134 | /** |
| 135 | * The callback type definition. Notice that a progress percentage ratio |
| 136 | * is easy to calculate by dividing <code>sent</code> by |
| 137 | * <code>total</code>. |
| 138 | * @param sent the number of bytes sent so far |
| 139 | * @param total the total number of bytes to send |
Linus Walleij | dcde608 | 2006-02-17 16:16:34 +0000 | [diff] [blame] | 140 | * @param data a user-defined dereferencable pointer |
Linus Walleij | 394bbbe | 2006-02-22 16:10:53 +0000 | [diff] [blame] | 141 | * @return if anything else than 0 is returned, the current transfer will be |
Linus Walleij | 6946ac5 | 2006-03-21 06:51:22 +0000 | [diff] [blame] | 142 | * interrupted / cancelled. |
Linus Walleij | dcde608 | 2006-02-17 16:16:34 +0000 | [diff] [blame] | 143 | */ |
Linus Walleij | 394bbbe | 2006-02-22 16:10:53 +0000 | [diff] [blame] | 144 | typedef int LIBMTP_progressfunc_t (uint64_t const sent, uint64_t const total, |
Linus Walleij | 6946ac5 | 2006-03-21 06:51:22 +0000 | [diff] [blame] | 145 | void const * const data); |
Linus Walleij | dcde608 | 2006-02-17 16:16:34 +0000 | [diff] [blame] | 146 | |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 147 | /** |
Linus Walleij | 6fd2f08 | 2006-03-28 07:19:22 +0000 | [diff] [blame^] | 148 | * @defgroup internals The libmtp internals API. |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 149 | * @{ |
| 150 | */ |
| 151 | void LIBMTP_Init(void); |
Linus Walleij | 6fd2f08 | 2006-03-28 07:19:22 +0000 | [diff] [blame^] | 152 | int LIBMTP_Get_Supported_Devices_List(LIBMTP_device_entry_t ** const, int * const); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 153 | /** |
| 154 | * @} |
| 155 | * @defgroup basic The basic device management API. |
| 156 | * @{ |
| 157 | */ |
Linus Walleij | b9256fd | 2006-02-15 09:40:43 +0000 | [diff] [blame] | 158 | LIBMTP_mtpdevice_t *LIBMTP_Get_First_Device(void); |
| 159 | void LIBMTP_Release_Device(LIBMTP_mtpdevice_t*); |
Linus Walleij | 8012406 | 2006-03-15 10:26:09 +0000 | [diff] [blame] | 160 | char *LIBMTP_Get_Modelname(LIBMTP_mtpdevice_t*); |
| 161 | char *LIBMTP_Get_Serialnumber(LIBMTP_mtpdevice_t*); |
| 162 | char *LIBMTP_Get_Deviceversion(LIBMTP_mtpdevice_t*); |
Linus Walleij | b9256fd | 2006-02-15 09:40:43 +0000 | [diff] [blame] | 163 | char *LIBMTP_Get_Ownername(LIBMTP_mtpdevice_t*); |
Linus Walleij | fa1374c | 2006-02-27 07:41:46 +0000 | [diff] [blame] | 164 | int LIBMTP_Get_Storageinfo(LIBMTP_mtpdevice_t *, uint64_t * const, |
| 165 | uint64_t * const, char ** const storage_description, |
| 166 | char ** const volume_label); |
| 167 | int LIBMTP_Get_Batterylevel(LIBMTP_mtpdevice_t *, |
| 168 | uint8_t * const, |
| 169 | uint8_t * const); |
Linus Walleij | f6bc178 | 2006-03-24 15:12:47 +0000 | [diff] [blame] | 170 | |
| 171 | |
| 172 | /** |
| 173 | * @} |
| 174 | * @defgroup files The file management API. |
| 175 | * @{ |
| 176 | */ |
| 177 | LIBMTP_file_t *LIBMTP_new_file_t(void); |
| 178 | void LIBMTP_destroy_file_t(LIBMTP_file_t*); |
| 179 | LIBMTP_file_t *LIBMTP_Get_Filelisting(LIBMTP_mtpdevice_t *device); |
| 180 | int LIBMTP_Delete_File(LIBMTP_mtpdevice_t *, uint32_t); |
| 181 | int LIBMTP_Get_File_To_File(LIBMTP_mtpdevice_t*, uint32_t, char const * const, |
| 182 | LIBMTP_progressfunc_t const * const, void const * const); |
| 183 | int LIBMTP_Get_File_To_File_Descriptor(LIBMTP_mtpdevice_t*, uint32_t const, int const, |
| 184 | LIBMTP_progressfunc_t const * const, void const * const); |
| 185 | |
Linus Walleij | dcde608 | 2006-02-17 16:16:34 +0000 | [diff] [blame] | 186 | /** |
| 187 | * @} |
| 188 | * @defgroup tracks The track management API. |
| 189 | * @{ |
| 190 | */ |
Linus Walleij | 95698cd | 2006-02-24 10:40:40 +0000 | [diff] [blame] | 191 | LIBMTP_track_t *LIBMTP_new_track_t(void); |
| 192 | void LIBMTP_destroy_track_t(LIBMTP_track_t*); |
| 193 | LIBMTP_track_t *LIBMTP_Get_Tracklisting(LIBMTP_mtpdevice_t*); |
Linus Walleij | 0cd8543 | 2006-02-20 14:37:50 +0000 | [diff] [blame] | 194 | int LIBMTP_Get_Track_To_File(LIBMTP_mtpdevice_t*, uint32_t, char const * const, |
| 195 | LIBMTP_progressfunc_t const * const, void const * const); |
| 196 | int LIBMTP_Get_Track_To_File_Descriptor(LIBMTP_mtpdevice_t*, uint32_t const, int const, |
| 197 | LIBMTP_progressfunc_t const * const, void const * const); |
Linus Walleij | 394bbbe | 2006-02-22 16:10:53 +0000 | [diff] [blame] | 198 | int LIBMTP_Send_Track_From_File(LIBMTP_mtpdevice_t *, |
| 199 | char const * const, LIBMTP_track_t * const, |
| 200 | LIBMTP_progressfunc_t const * const, |
| 201 | void const * const); |
| 202 | int LIBMTP_Send_Track_From_File_Descriptor(LIBMTP_mtpdevice_t *, |
| 203 | int const, LIBMTP_track_t * const, |
| 204 | LIBMTP_progressfunc_t const * const, |
| 205 | void const * const); |
Linus Walleij | 95698cd | 2006-02-24 10:40:40 +0000 | [diff] [blame] | 206 | int LIBMTP_Update_Track_Metadata(LIBMTP_mtpdevice_t *, |
| 207 | LIBMTP_track_t const * const); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 208 | /** @} */ |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 209 | /* End of C++ exports */ |
| 210 | #ifdef __cplusplus |
| 211 | } |
| 212 | #endif |
| 213 | |
| 214 | #endif /* LIBMTP_H_INCLUSION_GUARD */ |
| 215 | |