Source: struct.js

  1. /**
  2. * mtp struct types
  3. * @module mtp
  4. */
  5. /*jslint node:true */
  6. "use strict";
  7. // Require
  8. var ref = require('ref');
  9. var StructType = require('ref-struct');
  10. var pointer = require('./pointer');
  11. // Structs
  12. // Set all struct types to the struct object
  13. var struct = {};
  14. /**
  15. * A data structure to hold MTP device entries.
  16. * @typedef LIBMTP_device_entry_struct
  17. * @type {object}
  18. * @property {string} vendor - The vendor of this device
  19. * @property {uint16} vendor_id - Vendor ID for this device
  20. * @property {string} product - The product name of this device
  21. * @property {uint16} product_id - Product ID for this device
  22. * @property {uint32} device_flags - Bugs, device specifics etc
  23. */
  24. /**
  25. * LIBMTP_device_entry_struct
  26. * @type {LIBMTP_device_entry_struct}
  27. */
  28. struct.LIBMTP_device_entry_struct = new StructType({
  29. vendor: 'string',
  30. vendor_id: 'uint16',
  31. product: 'string',
  32. product_id: 'uint16',
  33. device_flags: 'uint32'
  34. });
  35. /**
  36. * A data structure to hold a raw MTP device connected
  37. * to the bus.
  38. */
  39. struct.LIBMTP_raw_device_struct = new StructType({
  40. 'device_entry': struct.LIBMTP_device_entry_struct,
  41. // The device entry for this raw device */
  42. 'bus_location': 'uint32',
  43. // Location of the bus, if device available */
  44. 'devnum': 'uint8' // Device number on the bus, if device available */
  45. });
  46. /**
  47. * LIBMTP Device Storage structure
  48. */
  49. struct.LIBMTP_devicestorage_struct = new StructType({
  50. // Unique ID for this storage */
  51. id: 'uint32',
  52. // Storage type */
  53. StorageType: 'uint16',
  54. // Filesystem type */
  55. FilesystemType: 'uint16',
  56. // Access capability */
  57. AccessCapability: 'uint16',
  58. // Maximum capability */
  59. MaxCapacity: 'uint64',
  60. // Free space in bytes */
  61. FreeSpaceInBytes: 'uint64',
  62. // Free space in objects */
  63. FreeSpaceInObjects: 'uint64',
  64. // A brief description of this storage */
  65. StorageDescription: 'string',
  66. // A volume identifier */
  67. VolumeIdentifier: 'string'
  68. // Next storage, follow this link until NULL */
  69. // next: ref.refType(LIBMTP_devicestorage_struct),
  70. // Previous storage */
  71. // prev: ref.refType(LIBMTP_devicestorage_struct)
  72. });
  73. struct.LIBMTP_devicestorage_struct.defineProperty('next',
  74. ref.refType(struct.LIBMTP_devicestorage_struct));
  75. struct.LIBMTP_devicestorage_struct.defineProperty('prev',
  76. ref.refType(struct.LIBMTP_devicestorage_struct));
  77. /**
  78. * A data structure to hold errors from the library.
  79. */
  80. struct.LIBMTP_error_struct = new StructType({
  81. errornumber: 'int',
  82. error_text: 'string'
  83. // next: ref.refType(LIBMTP_error_struct)
  84. });
  85. struct.LIBMTP_error_struct.defineProperty('next',
  86. ref.refType(struct.LIBMTP_error_struct));
  87. /**
  88. * MTP device extension holder struct
  89. */
  90. struct.LIBMTP_device_extension_struct = new StructType({
  91. /**
  92. * Name of extension e.g. "foo.com"
  93. */
  94. name: 'string',
  95. /**
  96. * Major revision of extension
  97. */
  98. major: 'int',
  99. /**
  100. * Minor revision of extension
  101. */
  102. minor: 'int'
  103. /**
  104. * Pointer to the next extension or NULL if this is the
  105. * last extension.
  106. */
  107. // next: ref.refType(LIBMTP_device_extension_struct)
  108. });
  109. struct.LIBMTP_device_extension_struct.defineProperty('next',
  110. ref.refType(struct.LIBMTP_device_extension_struct));
  111. /**
  112. * Main MTP device object struct
  113. */
  114. struct.LIBMTP_mtpdevice_struct = new StructType({
  115. /**
  116. * Object bitsize, typically 32 or 64.
  117. */
  118. object_bitsize: 'uint8',
  119. /**
  120. * Parameters for this device, must be cast into
  121. * \c (PTPParams*) before internal use.
  122. */
  123. params: pointer.voidPtr,
  124. /**
  125. * USB device for this device, must be cast into
  126. * \c (PTP_USB*) before internal use.
  127. */
  128. usbinfo: pointer.voidPtr,
  129. /**
  130. * The storage for this device, do not use strings in here without
  131. * copying them first, and beware that this list may be rebuilt at
  132. * any time.
  133. * @see LIBMTP_Get_Storage()
  134. */
  135. storage: ref.refType(struct.LIBMTP_devicestorage_struct),
  136. /**
  137. * The error stack. This shall be handled using the error getting
  138. * and clearing functions, not by dereferencing this list.
  139. */
  140. errorstack: ref.refType(struct.LIBMTP_error_struct),
  141. /** The maximum battery level for this device */
  142. maximum_battery_level: 'uint8',
  143. /** Default music folder */
  144. default_music_folder: 'uint32',
  145. /** Default playlist folder */
  146. default_playlist_folder: 'uint32',
  147. /** Default picture folder */
  148. default_picture_folder: 'uint32',
  149. /** Default video folder */
  150. default_video_folder: 'uint32',
  151. /** Default organizer folder */
  152. default_organizer_folder: 'uint32',
  153. /** Default ZENcast folder (only Creative devices...) */
  154. default_zencast_folder: 'uint32',
  155. /** Default Album folder */
  156. default_album_folder: 'uint32',
  157. /** Default Text folder */
  158. default_text_folder: 'uint32',
  159. /** Per device iconv() converters, only used internally */
  160. cd: pointer.voidPtr,
  161. /** Extension list */
  162. extensions: ref.refType(struct.LIBMTP_device_extension_struct),
  163. /** Whether the device uses caching, only used internally */
  164. cached: 'int'
  165. /** Pointer to next device in linked list; NULL if this is the last device */
  166. // next: ref.refType(LIBMTP_mtpdevice_struct)
  167. });
  168. struct.LIBMTP_mtpdevice_struct.defineProperty('next',
  169. ref.refType(struct.LIBMTP_mtpdevice_struct));
  170. /**
  171. * MTP file struct
  172. */
  173. struct.LIBMTP_file_struct = new StructType({
  174. // Unique item ID */
  175. item_id: 'uint32',
  176. // ID of parent folder */
  177. parent_id: 'uint32',
  178. // ID of storage holding this file */
  179. storage_id: 'uint32',
  180. // Filename of this file */
  181. filename: 'string',
  182. // Size of file in bytes */
  183. filesize: 'uint64',
  184. // Date of last alteration of the file */
  185. modificationdate: 'long',
  186. // LIBMTP_filetype_t Filetype used for the current file */
  187. filetype: 'int'
  188. // Next file in list or NULL if last file */
  189. // LIBMTP_file_t *next;
  190. });
  191. struct.LIBMTP_file_struct.defineProperty('next',
  192. ref.refType(struct.LIBMTP_file_struct));
  193. /**
  194. * A data structure to hold allowed ranges of values
  195. */
  196. struct.LIBMTP_allowed_values_struct = new StructType({
  197. u8max: 'uint8',
  198. u8min: 'uint8',
  199. u8step: 'uint8',
  200. u8vals: pointer.uint8Ptr,
  201. i8max: 'int8',
  202. i8min: 'int8',
  203. i8step: 'int8',
  204. i8vals: pointer.int8Ptr,
  205. u16max: 'uint16',
  206. u16min: 'uint16',
  207. u16step: 'uint16',
  208. u16vals: pointer.uint16Ptr,
  209. i16max: 'int16',
  210. i16min: 'int16',
  211. i16step: 'int16',
  212. i16vals: pointer.int16Ptr,
  213. u32max: 'uint32',
  214. u32min: 'uint32',
  215. u32step: 'uint32',
  216. u32vals: pointer.uint32Ptr,
  217. i32max: 'int32',
  218. i32min: 'int32',
  219. i32step: 'int32',
  220. i32vals: pointer.int32Ptr,
  221. u64max: 'uint64',
  222. u64min: 'uint64',
  223. u64step: 'uint64',
  224. u64vals: pointer.uint64Ptr,
  225. i64max: 'int64',
  226. i64min: 'int64',
  227. i64step: 'int64',
  228. i64vals: pointer.int64Ptr,
  229. /**
  230. * Number of entries in the vals array
  231. */
  232. num_entries: 'int16',
  233. /**
  234. * The datatype specifying which of the above is used.
  235. * LIBMTP_datatype_t
  236. */
  237. datatype: 'int',
  238. /**
  239. * Non zero for range, 0 for enum
  240. */
  241. is_range: 'int'
  242. });
  243. /**
  244. * MTP Playlist structure
  245. */
  246. struct.LIBMTP_playlist_struct = new StructType({
  247. // Unique playlist ID */
  248. playlist_id: 'uint32',
  249. // ID of parent folder */
  250. parent_id: 'uint32',
  251. // ID of storage holding this playlist */
  252. storage_id: 'uint32',
  253. // Name of playlist */
  254. name: 'string',
  255. // The tracks in this playlist */
  256. tracks: pointer.uint32Ptr,
  257. // The number of tracks in this playlist */
  258. no_tracks: 'uint32'
  259. // Next playlist or NULL if last playlist */
  260. // LIBMTP_playlist_t *next;
  261. });
  262. struct.LIBMTP_playlist_struct.defineProperty('next',
  263. ref.refType(struct.LIBMTP_playlist_struct));
  264. /**
  265. * MTP Album structure
  266. */
  267. struct.LIBMTP_album_struct = new StructType({
  268. // Unique playlist ID */
  269. album_id: 'uint32',
  270. // ID of parent folder */
  271. parent_id: 'uint32',
  272. // ID of storage holding this album */
  273. storage_id: 'uint32',
  274. // Name of album */
  275. name: 'string',
  276. // Name of album artist */
  277. artist: 'string',
  278. // Name of recording composer */
  279. composer: 'string',
  280. // Genre of album */
  281. genre: 'string',
  282. // The tracks in this album */
  283. tracks: pointer.uint32Ptr,
  284. // The number of tracks in this album */
  285. no_tracks: 'uint32'
  286. // Next album or NULL if last album */
  287. // LIBMTP_album_t *next;
  288. });
  289. struct.LIBMTP_album_struct.defineProperty('next',
  290. ref.refType(struct.LIBMTP_album_struct));
  291. /**
  292. * MTP Folder structure
  293. */
  294. struct.LIBMTP_folder_struct = new StructType({
  295. // Unique folder ID */
  296. folder_id: 'uint32',
  297. // ID of parent folder */
  298. parent_id: 'uint32',
  299. // ID of storage holding this folder */
  300. storage_id: 'uint32',
  301. // Name of folder */
  302. name: 'string'
  303. // Next folder at same level or NULL if no more */
  304. // LIBMTP_folder_t *sibling;
  305. // Child folder or NULL if no children */
  306. // LIBMTP_folder_t *child;
  307. });
  308. struct.LIBMTP_folder_struct.defineProperty('sibling',
  309. ref.refType(struct.LIBMTP_folder_struct));
  310. struct.LIBMTP_folder_struct.defineProperty('child',
  311. ref.refType(struct.LIBMTP_folder_struct));
  312. /**
  313. * LIBMTP Object RepresentativeSampleData Structure
  314. */
  315. struct.LIBMTP_filesampledata_struct = new StructType({
  316. // Width of sample if it is an image */
  317. width: 'uint32',
  318. // Height of sample if it is an image */
  319. height: 'uint32',
  320. // Duration in milliseconds if it is audio */
  321. duration: 'uint32',
  322. // LIBMTP_filetype_t Filetype used for the sample */
  323. filetype: 'int',
  324. // Size of sample data in bytes */
  325. size: 'uint64',
  326. // Sample data */
  327. data: pointer.charPtr
  328. });
  329. module.exports = struct;