Source: stbDownloadManager.js

/**
 * STB object declaration and documentation.
 * JSDoc specification ({@link http://usejsdoc.org/}).
 * An introduction to JSDoc ({@link http://www.2ality.com/2011/08/jsdoc-intro.html}).
 *
 * @fileOverview Provides API for download manager.
 */

'use strict';

/* jshint unused:false */

//noinspection JSUnusedGlobalSymbols

/**
 * The object provides API to download manager.
 *
 * Download manager allows adding and scheduling download tasks, which will try to download and store remote file into local storage.
 *
 * stbDownloadManager object itself does not require any additional initialization. It is always accessible from JavaScript context.
 *
 * <br>
 *
 * Job states table:
 *
 *  Value | Description
 * -------|-------------
 *  0     | stopped
 *  1     | waiting for queue
 *  2     | running
 *  3     | completed
 *  4     | temporary error
 *  5     | permanent error
 *
 * @namespace
 */
var stbDownloadManager = {

	/**
	 * Information about a job in **JSON** format.
	 *
	 * @typedef {string} stbDownloadManager.JobInfo
	 *
	 * @property {number} id unique task identifier of the job
	 * @property {number} state current job state (see job states table)
	 * @property {string} stateStr state string (localization is supported for this string resource)
	 * @property {string} url remote file address
	 * @property {string} filePath path to a local storage
	 * @property {string} tempFile temporary file
	 * @property {string} mountPoint folder where storage device content mounted
	 * @property {number} progressPct progress of downloading process in percents [0..100]
	 * @property {number} sizeDone size of already downloaded data
	 * @property {number} sizeTotal total file size (value -1 if undefined)
	 * @property {number} prio priority of the job
	 * @property {number} prioLevel priority of the job expressed in levels (allowed values 1,2,3,4,5)
	 * @property {number} attempt number of the download attempt
	 * @property {number} timeWasted time elapsed since job start (ms)
	 *
	 * @example
	 * // parsed JSON data
	 * {
	 *     id: 1,
	 *     state: 3,
	 *     stateStr: "Completed",
	 *     url: "http://somehost/Hawking (BBC).avi"
	 *     mountPoint: "/media/HDD-SATA-1",
	 *     filePath: "Hawking (BBC).avi",
	 *     progressPct: 100,
	 *     sizeDone: 739287040,
	 *     sizeTotal: 739287040,
	 *     prio: 1,
	 *     prioLevel: 5,
	 *     attempt: 0,
	 *     tempFile: "Hawking (BBC).avi-a528f.temp",
	 *     timeWasted: 310728,
	 * }
	 */


	/**
	 * Add a job for file downloading using URL "`urlToDownload`".
	 *
	 * In case of success local file will be stored in filePath.
	 * By the time of the operation local file should not exist.
	 *
	 * @param {string} urlToDownload address of the file
	 * @param {string} filePath path to local storage pointing to a non-existed file
	 *
	 * downloaded file will be stored using this path to the local storage
	 *
	 * @return {boolean} operation status:
	 *
	 *  Value | Description
	 * -------|-------------
	 *  true  | job was added successfully
	 *  false | failure
	 *
	 * @since 0.2.16
	 */
	AddJob:
		function ( urlToDownload, filePath ) { return true; },


	/**
	 * Similar to {@link stbDownloadManager.AddJob}.
	 *
	 * Create a special job, that will download given file without saving the result to file storage.
	 *
	 * This job is using as connection test facility.
	 * You can calculate download speed (once job is finished) using "`timeWasted`" and "`sizeDone`" attributes.
	 *
	 * You can only create one such connection at the moment. So, you have to delete it each time you want to create next one.
	 *
	 * @param {string} urlToDownload address must point to a remote file
	 *
	 * @return {boolean} operation status:
	 *
	 *  Value | Description
	 * -------|-------------
	 *  true  | job was added successfully
	 *  false | failure
	 */
	AddMeasureJob:
		function ( urlToDownload ) { return true; },


	/**
	 * Change priority of the given job.
	 *
	 * Priority can either be increased or decreased.
	 *
	 * @param {number} id unique identifier of a job assigned for this operation [-1, 0..4294967295]
	 * @param {boolean} direction possible values:
	 *
	 *  Value | Description
	 * -------|-------------
	 *  true  | increase priority
	 *  false | decrease priority
	 */
	AdjustJobPriority:
		function ( id, direction ) {},


	/**
	 * Same as AdjustJobPriority but receive priority level.
	 *
	 * @param {number} id unique identifier of a job assigned for this operation [-1, 0..4294967295]
	 * @param {boolean} prioLevel new priority of the job expressed in levels (allowed values 1,2,3,4,5)
	 */
	AdjustJobPriorityV2:
		function ( id, prioLevel ) {},


	/**
	 * Delete given job.
	 *
	 * @param {number} id unique identifier of a job assigned for this operation [-1, 0..4294967295]
	 * @param {boolean} deleteFile keep or remove the downloaded file:
	 *
	 *  Value | Description
	 * -------|-------------
	 *  true  | delete associated local file
	 *  false | just delete the job and keep local file
	 *
	 * @return {boolean} operation status:
	 *
	 *  Value | Description
	 * -------|-------------
	 *  true  | job was removed successfully
	 *  false | failure
	 */
	DeleteJob:
		function ( id, deleteFile ) { return true; },


	/**
	 * Similar to {@link stbDownloadManager.GetQueueInfo}.
	 *
	 * Get information about special (test) job. If test job does not exist then return empty list.
	 *
	 * See {@link stbDownloadManager.JobInfo}, {@link stbDownloadManager.AddMeasureJob}.
	 *
	 * @return {Array.<stbDownloadManager.JobInfo>} list of jobs in **JSON** format
	 */
	GetMeasureInfo:
		function () { return '[]'; },


	/**
	 * Get info about queue of jobs.
	 *
	 * See {@link stbDownloadManager.JobInfo}, {@link stbDownloadManager.AddJob}.
	 *
	 * @param {string} [idList] list of ids in **JSON** format
	 *
	 * If list is not empty information for given jobs will be returned. Whole queue will be returned in other case.
	 *
	 * @return {Array.<stbDownloadManager.JobInfo>} list of jobs in **JSON** format
	 *
	 * @example
	 * // get the particular jobs info
	 * stbDownloadManager.GetQueueInfo('[1, 2, 3]');
	 * // get all jobs data
	 * stbDownloadManager.GetQueueInfo();
	 */
	GetQueueInfo:
		function ( idList ) { return '[]'; },


	/**
	 * Invalidate jobs for selected mount point.
	 *
	 * @param {string} mountPoint folder where storage device content mounted
	 *
	 * @since 0.2.16
	 */
	InvalidateCatalog:
		function ( mountPoint ) {},


	/**
	 * Play the given job in dedicated "media player" window of the internal portal.
	 *
	 * This effectively generate {@link stbEvent.onMediaAvailable} event.
	 *
	 * @param {number} id unique identifier of a job assigned for this operation [-1, 0..4294967295]
	 */
	PlayDownloadedMedia:
		function ( id ) {},


	/**
	 * Restore jobs using local catalog on selected device.
	 *
	 * @param {string} mountPoint folder where storage device content mounted
	 *
	 * @since 0.2.16
	 */
	RestoreJobs:
		function ( mountPoint ) {},


	/**
	 * Change state of the given job to "waiting for queue".
	 *
	 * This will cause job to start downloading process once queue will be ready to schedule the job.
	 *
	 * @param {number} id unique identifier of a job assigned for this operation [-1, 0..4294967295]
	 *
	 * @return {boolean} operation status:
	 *
	 *  Value | Description
	 * -------|-------------
	 *  true  | job was started successfully
	 *  false | failure
	 */
	StartJob:
		function ( id ) { return true; },


	/**
	 * Change state of the given job to "stopped".
	 *
	 * This state will cause the job will never be selected by scheduler for downloading.
	 *
	 * @param {number} id unique identifier of a job assigned for this operation [-1, 0..4294967295]
	 *
	 * @return {boolean} operation status:
	 *
	 *  Value | Description
	 * -------|-------------
	 *  true  | job was stopped successfully
	 *  false | failure
	 */
	StopJob:
		function ( id ) { return true; }

};