blob: 8935d62223db4ba7fcfceb9caa4f1039cfc67c2e [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 {
46 LIBMTP_CODEC_WAV,
47 LIBMTP_CODEC_MP3,
48 LIBMTP_CODEC_WMA,
49 LIBMTP_CODEC_UNKNOWN
50} LIBMTP_codec_t;
51typedef struct LIBMTP_mtpdevice_struct LIBMTP_mtpdevice_t; /**< @see LIBMTP_mtpdevice_struct */
52typedef struct LIBMTP_track_struct LIBMTP_track_t; /**< @see LIBMTP_mtptrack_t */
Linus Walleijeb8c6fe2006-02-03 09:46:22 +000053/** @} */
54
55/**
Linus Walleij15e344f2006-03-06 15:15:00 +000056 * Internal USB struct (TODO: discard for device struct?)
57 */
58typedef struct _PTP_USB PTP_USB;
59struct _PTP_USB {
60 usb_dev_handle* handle;
61 int inep;
62 int outep;
63 int intep;
64};
65
66/**
Linus Walleijeb8c6fe2006-02-03 09:46:22 +000067 * Main MTP device object struct
68 */
Linus Walleijb9256fd2006-02-15 09:40:43 +000069struct LIBMTP_mtpdevice_struct {
Linus Walleij9b28da32006-03-16 13:47:58 +000070 /** Interface number of this device */
71 uint8_t interface_number;
72 /**
73 * Parameters for this device, must be cast into
74 * \c (PTPParams*) before internal use.
75 */
76 void *params;
77 /** USB device for this device */
78 PTP_USB *ptp_usb;
79 /** The storage ID for this device */
80 unsigned storage_id;
81 /** The maximum battery level for this device */
82 uint8_t maximum_battery_level;
Linus Walleijeb8c6fe2006-02-03 09:46:22 +000083};
84
Linus Walleijb9256fd2006-02-15 09:40:43 +000085/**
86 * MTP track struct
87 */
88struct LIBMTP_track_struct {
89 uint32_t item_id; /**< Unique item ID */
90 char *title; /**< Track title */
91 char *artist; /**< Name of recording artist */
92 char *genre; /**< Genre name for track */
93 char *album; /**< Album name for track */
94 char *date; /**< Date of original recording as a string */
95 char *filename; /**< Original filename of this track */
96 uint16_t tracknumber; /**< Track number (in sequence on recording) */
97 uint32_t duration; /**< Duration in milliseconds */
98 uint64_t filesize; /**< Size of track file in bytes */
99 LIBMTP_codec_t codec; /**< Codec used for the current track */
100 LIBMTP_track_t *next; /**< Next track in list or NULL if last track */
101};
102
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000103/* Make functions available for C++ */
104#ifdef __cplusplus
105extern "C" {
106#endif
107
Linus Walleijdcde6082006-02-17 16:16:34 +0000108/**
109 * The callback type definition. Notice that a progress percentage ratio
110 * is easy to calculate by dividing <code>sent</code> by
111 * <code>total</code>.
112 * @param sent the number of bytes sent so far
113 * @param total the total number of bytes to send
Linus Walleijdcde6082006-02-17 16:16:34 +0000114 * @param data a user-defined dereferencable pointer
Linus Walleij394bbbe2006-02-22 16:10:53 +0000115 * @return if anything else than 0 is returned, the current transfer will be
Linus Walleij6946ac52006-03-21 06:51:22 +0000116 * interrupted / cancelled.
Linus Walleijdcde6082006-02-17 16:16:34 +0000117 */
Linus Walleij394bbbe2006-02-22 16:10:53 +0000118typedef int LIBMTP_progressfunc_t (uint64_t const sent, uint64_t const total,
Linus Walleij6946ac52006-03-21 06:51:22 +0000119 void const * const data);
Linus Walleijdcde6082006-02-17 16:16:34 +0000120
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000121/**
122 * @defgroup internals The libmtp internal state manipulation API.
123 * @{
124 */
125void LIBMTP_Init(void);
126/**
127 * @}
128 * @defgroup basic The basic device management API.
129 * @{
130 */
Linus Walleijb9256fd2006-02-15 09:40:43 +0000131LIBMTP_mtpdevice_t *LIBMTP_Get_First_Device(void);
132void LIBMTP_Release_Device(LIBMTP_mtpdevice_t*);
Linus Walleij80124062006-03-15 10:26:09 +0000133char *LIBMTP_Get_Modelname(LIBMTP_mtpdevice_t*);
134char *LIBMTP_Get_Serialnumber(LIBMTP_mtpdevice_t*);
135char *LIBMTP_Get_Deviceversion(LIBMTP_mtpdevice_t*);
Linus Walleijb9256fd2006-02-15 09:40:43 +0000136char *LIBMTP_Get_Ownername(LIBMTP_mtpdevice_t*);
Linus Walleijfa1374c2006-02-27 07:41:46 +0000137int LIBMTP_Get_Storageinfo(LIBMTP_mtpdevice_t *, uint64_t * const,
138 uint64_t * const, char ** const storage_description,
139 char ** const volume_label);
140int LIBMTP_Get_Batterylevel(LIBMTP_mtpdevice_t *,
141 uint8_t * const,
142 uint8_t * const);
Linus Walleijdcde6082006-02-17 16:16:34 +0000143/**
144 * @}
145 * @defgroup tracks The track management API.
146 * @{
147 */
Linus Walleij95698cd2006-02-24 10:40:40 +0000148LIBMTP_track_t *LIBMTP_new_track_t(void);
149void LIBMTP_destroy_track_t(LIBMTP_track_t*);
150LIBMTP_track_t *LIBMTP_Get_Tracklisting(LIBMTP_mtpdevice_t*);
Linus Walleij0cd85432006-02-20 14:37:50 +0000151int LIBMTP_Get_Track_To_File(LIBMTP_mtpdevice_t*, uint32_t, char const * const,
152 LIBMTP_progressfunc_t const * const, void const * const);
153int LIBMTP_Get_Track_To_File_Descriptor(LIBMTP_mtpdevice_t*, uint32_t const, int const,
154 LIBMTP_progressfunc_t const * const, void const * const);
Linus Walleij394bbbe2006-02-22 16:10:53 +0000155int LIBMTP_Send_Track_From_File(LIBMTP_mtpdevice_t *,
156 char const * const, LIBMTP_track_t * const,
157 LIBMTP_progressfunc_t const * const,
158 void const * const);
159int LIBMTP_Send_Track_From_File_Descriptor(LIBMTP_mtpdevice_t *,
160 int const, LIBMTP_track_t * const,
161 LIBMTP_progressfunc_t const * const,
162 void const * const);
Linus Walleij95698cd2006-02-24 10:40:40 +0000163int LIBMTP_Update_Track_Metadata(LIBMTP_mtpdevice_t *,
164 LIBMTP_track_t const * const);
165int LIBMTP_Delete_Track(LIBMTP_mtpdevice_t *, uint32_t);
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000166/** @} */
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000167/* End of C++ exports */
168#ifdef __cplusplus
169}
170#endif
171
172#endif /* LIBMTP_H_INCLUSION_GUARD */
173