/**
* Media transfer protocol module for Node.js
* @module mtp
*/
/*jslint node:true */
'use strict';
// Require
var ffi = require('ffi');
var ref = require('ref');
var struct = require('./struct');
var pointer = require('./pointer');
var constants = require('./constants');
var LIBMTP_raw_device_structPtr = ref.refType(struct.LIBMTP_raw_device_struct);
var LIBMTP_raw_device_structPtrPtr = ref.refType(LIBMTP_raw_device_structPtr);
/**
* The callback type definition. Notice that a progress percentage ratio
* is easy to calculate by dividing <code>sent</code> by
* <code>total</code>.
* @method
* @param {uint64} sent the number of bytes sent so far
* @param {uint64} total the total number of bytes to send
* @param {voidPtr} data a user-defined dereferencable pointer
* @return {int} if anything else than 0 is returned, the current transfer will be interrupted / cancelled.
*/
var LIBMTP_progressfunc_t = ffi.Function('int', ['uint64', 'uint64', ref.refType('void')]);
// libmtp definition
var mtp = new ffi.Library('libmtp', {
// 'Function name': [ 'return_type', [ 'param1', 'param2'] ]
/**
* LIBMTP_Init
* @method
* @returns {void}
*/
'LIBMTP_Init':
['void', []],
/**
* LIBMTP_Set_Debug
* @method
* @param {int}
* @returns {void}
*/
'LIBMTP_Set_Debug':
['void', ['int']],
/**
* LIBMTP_Detect_Raw_Devices
* @method
* @param {LIBMTP_raw_device_structPtrPtr}
* @param {intPtr}
* @returns {int}
*/
'LIBMTP_Detect_Raw_Devices':
['int', [LIBMTP_raw_device_structPtrPtr, pointer.intPtr]],
/**
* LIBMTP_Open_Raw_Device
* @method
* @param {LIBMTP_raw_device_structPtr}
* @returns {LIBMTP_mtpdevice_structPtr}
*/
'LIBMTP_Open_Raw_Device':
[ref.refType(struct.LIBMTP_mtpdevice_struct), [LIBMTP_raw_device_structPtr]],
/**
* LIBMTP_Dump_Errorstack
* @method
* @param {LIBMTP_mtpdevice_structPtr}
* @returns {void}
*/
'LIBMTP_Dump_Errorstack':
['void', [ref.refType(struct.LIBMTP_mtpdevice_struct)]],
/**
* LIBMTP_Clear_Errorstack
* @method
* @param {LIBMTP_mtpdevice_structPtr}
* @returns {void}
*/
'LIBMTP_Clear_Errorstack':
['void', [ref.refType(struct.LIBMTP_mtpdevice_struct)]],
/**
* LIBMTP_Dump_Device_Info'
* @method
* @param {LIBMTP_mtpdevice_structPtr}
* @returns {void}
*/
'LIBMTP_Dump_Device_Info':
['void', [ref.refType(struct.LIBMTP_mtpdevice_struct)]],
/**
* LIBMTP_Get_Friendlyname
* @method
* @param {LIBMTP_mtpdevice_structPtr}
* @returns {string}
*/
'LIBMTP_Get_Friendlyname':
['string', [ref.refType(struct.LIBMTP_mtpdevice_struct)]],
/**
* LIBMTP_Get_Manufacturername
* @method
* @param {LIBMTP_mtpdevice_structPtr}
* @returns {string}
*/
'LIBMTP_Get_Manufacturername':
['string', [ref.refType(struct.LIBMTP_mtpdevice_struct)]],
/**
* LIBMTP_Get_Modelname
* @method
* @param {LIBMTP_mtpdevice_structPtr}
* @returns {string}
*/
'LIBMTP_Get_Modelname':
['string', [ref.refType(struct.LIBMTP_mtpdevice_struct)]],
/**
* LIBMTP_Get_Serialnumber
* @method
* @param {LIBMTP_mtpdevice_structPtr}
* @returns {string}
*/
'LIBMTP_Get_Serialnumber':
['string', [ref.refType(struct.LIBMTP_mtpdevice_struct)]],
/**
* LIBMTP_Get_Deviceversion
* @method
* @param {LIBMTP_mtpdevice_structPtr}
* @returns {string}
*/
'LIBMTP_Get_Deviceversion':
['string', [ref.refType(struct.LIBMTP_mtpdevice_struct)]],
/**
* LIBMTP_Get_Syncpartner
* @method
* @param {LIBMTP_mtpdevice_structPtr}
* @returns {string}
*/
'LIBMTP_Get_Syncpartner':
['string', [ref.refType(struct.LIBMTP_mtpdevice_struct)]],
/**
* LIBMTP_Get_Batterylevel
* @method
* @param {LIBMTP_mtpdevice_structPtr}
* @param {uint8Ptr}
* @param {uint8Ptr}
* @returns {int}
*/
'LIBMTP_Get_Batterylevel':
['int', [ref.refType(struct.LIBMTP_mtpdevice_struct), pointer.uint8Ptr, pointer.uint8Ptr]],
/**
* LIBMTP_Get_Supported_Filetypes
* @method
* @param {LIBMTP_mtpdevice_structPtr}
* @param {uint16PtrPtr}
* @param {uint16Ptr}
* @returns {int}
*/
'LIBMTP_Get_Supported_Filetypes':
['int', [ref.refType(struct.LIBMTP_mtpdevice_struct), pointer.uint16PtrPtr, pointer.uint16Ptr]],
/**
* LIBMTP_Get_Filetype_Description
* @method
* @param {int}
* @returns {string}
*/
'LIBMTP_Get_Filetype_Description':
['string', [ 'int' ]],
/**
* LIBMTP_Get_Secure_Time
* Crashes Samsung Galaxy S5.
* @method
* @param {LIBMTP_mtpdevice_structPtr}
* @param {stringPtr}
* @returns {int}
*/
'LIBMTP_Get_Secure_Time':
['int', [ref.refType(struct.LIBMTP_mtpdevice_struct), ref.refType('string') ]],
/**
* LIBMTP_Get_Device_Certificate
* @method
* @param {LIBMTP_mtpdevice_structPtr}
* @param {stringPtr}
* @returns {int}
*/
'LIBMTP_Get_Device_Certificate':
['int', [ref.refType(struct.LIBMTP_mtpdevice_struct), ref.refType('string')]],
/**
* LIBMTP_Release_Device
* @method
* @param {LIBMTP_mtpdevice_structPtr}
* @returns {void}
*/
'LIBMTP_Release_Device':
['void', [ref.refType(struct.LIBMTP_mtpdevice_struct)]],
/**
* LIBMTP_Get_Filelisting_With_Callback
* @method
* @param {LIBMTP_mtpdevice_structPtr}
* @param {LIBMTP_progressfunc_t}
* @param {voidPtr}
* @returns {LIBMTP_file_structPtr}
*/
'LIBMTP_Get_Filelisting_With_Callback':
[ref.refType(struct.LIBMTP_file_struct),
[ref.refType(struct.LIBMTP_mtpdevice_struct), LIBMTP_progressfunc_t, ref.refType('void')]],
/**
* LIBMTP_Get_Track_To_File_Descriptor
* @method
* @param {LIBMTP_mtpdevice_structPtr}
* @param {uint32}
* @param {int}
* @param {LIBMTP_progressfunc_t}
* @param {voidPtr}
* @returns {int}
*/
'LIBMTP_Get_Track_To_File_Descriptor':
['int',
[ref.refType(struct.LIBMTP_mtpdevice_struct), 'uint32', 'int', LIBMTP_progressfunc_t, ref.refType('void')]]
});
// Set structs
Object.keys(struct).forEach(function (structName) {
mtp[structName] = struct[structName];
});
// Set pointers
Object.keys(pointer).forEach(function (pointerName) {
mtp[pointerName] = pointer[pointerName];
});
mtp.LIBMTP_raw_device_structPtr = LIBMTP_raw_device_structPtr;
mtp.LIBMTP_raw_device_structPtrPtr = LIBMTP_raw_device_structPtrPtr;
// Set constants
constants(mtp);
module.exports = mtp;