blob: 2eeeff06086ade9473ca5dc92a34880efb87b38a [file] [log] [blame]
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00001/**
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 Walleijeb8c6fe2006-02-03 09:46:22 +000015/* 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 Walleij15e344f2006-03-06 15:15:00 +000023#include <stdio.h>
24#include <usb.h>
Linus Walleij9b28da32006-03-16 13:47:58 +000025#include <stdint.h>
Linus Walleijeb8c6fe2006-02-03 09:46:22 +000026
27#ifdef __WIN32__
28/*
29 * Windows specific code, types that do not exist in Windows
30 * sys/types.h
31 */
32typedef char int8_t;
33typedef unsigned char uint8_t;
34typedef __int16 int16_t;
35typedef unsigned __int16 uint16_t;
36typedef __int32 int32_t;
37typedef unsigned __int32 uint32_t;
38typedef unsigned __int64 uint64_t;
39#endif
Linus Walleijeb8c6fe2006-02-03 09:46:22 +000040
41/**
42 * @defgroup types libnjb global type definitions
43 * @{
44 */
Linus Walleijb9256fd2006-02-15 09:40:43 +000045typedef enum {
Linus Walleijf6bc1782006-03-24 15:12:47 +000046 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 Walleijb9256fd2006-02-15 09:40:43 +000062typedef struct LIBMTP_mtpdevice_struct LIBMTP_mtpdevice_t; /**< @see LIBMTP_mtpdevice_struct */
Linus Walleijf6bc1782006-03-24 15:12:47 +000063typedef struct LIBMTP_file_struct LIBMTP_file_t; /**< @see LIBMTP_file_struct */
64typedef struct LIBMTP_track_struct LIBMTP_track_t; /**< @see LIBMTP_track_struct */
Linus Walleijeb8c6fe2006-02-03 09:46:22 +000065/** @} */
66
67/**
68 * Main MTP device object struct
69 */
Linus Walleijb9256fd2006-02-15 09:40:43 +000070struct LIBMTP_mtpdevice_struct {
Linus Walleij9b28da32006-03-16 13:47:58 +000071 /** Interface number of this device */
72 uint8_t interface_number;
73 /**
74 * Parameters for this device, must be cast into
75 * \c (PTPParams*) before internal use.
76 */
77 void *params;
Linus Walleij2d411db2006-03-22 12:13:09 +000078 /**
79 * USB device for this device, must be cast into
80 * \c (PTP_USB*) before internal use.
81 */
82 void *usbinfo;
Linus Walleij9b28da32006-03-16 13:47:58 +000083 /** The storage ID for this device */
84 unsigned storage_id;
85 /** The maximum battery level for this device */
86 uint8_t maximum_battery_level;
Linus Walleijeb8c6fe2006-02-03 09:46:22 +000087};
88
Linus Walleijb9256fd2006-02-15 09:40:43 +000089/**
Linus Walleijf6bc1782006-03-24 15:12:47 +000090 * MTP file struct
91 */
92struct LIBMTP_file_struct {
93 uint32_t item_id; /**< Unique item ID */
94 char *filename; /**< Filename of this file */
95 uint64_t filesize; /**< Size of file in bytes */
96 LIBMTP_filetype_t filetype; /**< Filetype used for the current file */
97 LIBMTP_file_t *next; /**< Next file in list or NULL if last file */
98};
99
100/**
Linus Walleijb9256fd2006-02-15 09:40:43 +0000101 * MTP track struct
102 */
103struct LIBMTP_track_struct {
104 uint32_t item_id; /**< Unique item ID */
105 char *title; /**< Track title */
106 char *artist; /**< Name of recording artist */
107 char *genre; /**< Genre name for track */
108 char *album; /**< Album name for track */
109 char *date; /**< Date of original recording as a string */
110 char *filename; /**< Original filename of this track */
111 uint16_t tracknumber; /**< Track number (in sequence on recording) */
112 uint32_t duration; /**< Duration in milliseconds */
113 uint64_t filesize; /**< Size of track file in bytes */
Linus Walleijf6bc1782006-03-24 15:12:47 +0000114 LIBMTP_filetype_t filetype; /**< Filetype used for the current track */
Linus Walleijb9256fd2006-02-15 09:40:43 +0000115 LIBMTP_track_t *next; /**< Next track in list or NULL if last track */
116};
117
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000118/* Make functions available for C++ */
119#ifdef __cplusplus
120extern "C" {
121#endif
122
Linus Walleijdcde6082006-02-17 16:16:34 +0000123/**
124 * The callback type definition. Notice that a progress percentage ratio
125 * is easy to calculate by dividing <code>sent</code> by
126 * <code>total</code>.
127 * @param sent the number of bytes sent so far
128 * @param total the total number of bytes to send
Linus Walleijdcde6082006-02-17 16:16:34 +0000129 * @param data a user-defined dereferencable pointer
Linus Walleij394bbbe2006-02-22 16:10:53 +0000130 * @return if anything else than 0 is returned, the current transfer will be
Linus Walleij6946ac52006-03-21 06:51:22 +0000131 * interrupted / cancelled.
Linus Walleijdcde6082006-02-17 16:16:34 +0000132 */
Linus Walleij394bbbe2006-02-22 16:10:53 +0000133typedef int LIBMTP_progressfunc_t (uint64_t const sent, uint64_t const total,
Linus Walleij6946ac52006-03-21 06:51:22 +0000134 void const * const data);
Linus Walleijdcde6082006-02-17 16:16:34 +0000135
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000136/**
137 * @defgroup internals The libmtp internal state manipulation API.
138 * @{
139 */
140void LIBMTP_Init(void);
141/**
142 * @}
143 * @defgroup basic The basic device management API.
144 * @{
145 */
Linus Walleijb9256fd2006-02-15 09:40:43 +0000146LIBMTP_mtpdevice_t *LIBMTP_Get_First_Device(void);
147void LIBMTP_Release_Device(LIBMTP_mtpdevice_t*);
Linus Walleij80124062006-03-15 10:26:09 +0000148char *LIBMTP_Get_Modelname(LIBMTP_mtpdevice_t*);
149char *LIBMTP_Get_Serialnumber(LIBMTP_mtpdevice_t*);
150char *LIBMTP_Get_Deviceversion(LIBMTP_mtpdevice_t*);
Linus Walleijb9256fd2006-02-15 09:40:43 +0000151char *LIBMTP_Get_Ownername(LIBMTP_mtpdevice_t*);
Linus Walleijfa1374c2006-02-27 07:41:46 +0000152int LIBMTP_Get_Storageinfo(LIBMTP_mtpdevice_t *, uint64_t * const,
153 uint64_t * const, char ** const storage_description,
154 char ** const volume_label);
155int LIBMTP_Get_Batterylevel(LIBMTP_mtpdevice_t *,
156 uint8_t * const,
157 uint8_t * const);
Linus Walleijf6bc1782006-03-24 15:12:47 +0000158
159
160/**
161 * @}
162 * @defgroup files The file management API.
163 * @{
164 */
165LIBMTP_file_t *LIBMTP_new_file_t(void);
166void LIBMTP_destroy_file_t(LIBMTP_file_t*);
167LIBMTP_file_t *LIBMTP_Get_Filelisting(LIBMTP_mtpdevice_t *device);
168int LIBMTP_Delete_File(LIBMTP_mtpdevice_t *, uint32_t);
169int LIBMTP_Get_File_To_File(LIBMTP_mtpdevice_t*, uint32_t, char const * const,
170 LIBMTP_progressfunc_t const * const, void const * const);
171int LIBMTP_Get_File_To_File_Descriptor(LIBMTP_mtpdevice_t*, uint32_t const, int const,
172 LIBMTP_progressfunc_t const * const, void const * const);
173
Linus Walleijdcde6082006-02-17 16:16:34 +0000174/**
175 * @}
176 * @defgroup tracks The track management API.
177 * @{
178 */
Linus Walleij95698cd2006-02-24 10:40:40 +0000179LIBMTP_track_t *LIBMTP_new_track_t(void);
180void LIBMTP_destroy_track_t(LIBMTP_track_t*);
181LIBMTP_track_t *LIBMTP_Get_Tracklisting(LIBMTP_mtpdevice_t*);
Linus Walleij0cd85432006-02-20 14:37:50 +0000182int LIBMTP_Get_Track_To_File(LIBMTP_mtpdevice_t*, uint32_t, char const * const,
183 LIBMTP_progressfunc_t const * const, void const * const);
184int LIBMTP_Get_Track_To_File_Descriptor(LIBMTP_mtpdevice_t*, uint32_t const, int const,
185 LIBMTP_progressfunc_t const * const, void const * const);
Linus Walleij394bbbe2006-02-22 16:10:53 +0000186int LIBMTP_Send_Track_From_File(LIBMTP_mtpdevice_t *,
187 char const * const, LIBMTP_track_t * const,
188 LIBMTP_progressfunc_t const * const,
189 void const * const);
190int LIBMTP_Send_Track_From_File_Descriptor(LIBMTP_mtpdevice_t *,
191 int const, LIBMTP_track_t * const,
192 LIBMTP_progressfunc_t const * const,
193 void const * const);
Linus Walleij95698cd2006-02-24 10:40:40 +0000194int LIBMTP_Update_Track_Metadata(LIBMTP_mtpdevice_t *,
195 LIBMTP_track_t const * const);
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000196/** @} */
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000197/* End of C++ exports */
198#ifdef __cplusplus
199}
200#endif
201
202#endif /* LIBMTP_H_INCLUSION_GUARD */
203