/** * Copyright© 2016, Oracle and/or its affiliates. All rights reserved. */ /** * Base class for platform-specific capabilities. Users may derive from this class to * provide implementations specific to their platform. * @constructor * @abstract * @global */ function Platform(logger, utils) { var _deviceId = utils.uuid(); this._deviceState = deviceState.unrestricted; this._deviceStateChangedCallbacks = []; /** * Returns a device ID used by [Diagnostics]{@link Diagnostics}. * @returns {String} The device ID. */ this.getDeviceId = function() { return _deviceId; }; this.initGPSLocation = function () {}; /** * Sets the current state of the device. Platform implementations should call this function * when the state changes. The state is inspected before background operations * like synchronization are performed. * @param state {mcs.deviceState} The new state of the device. */ this.setDeviceState = function(state) { if(this._deviceState != state) { logger.info("Device state changing from " + this._deviceState + " to " + state); this._deviceState = state; for(var i=0; i<this._deviceStateChangedCallbacks.length; i++) { this._deviceStateChangedCallbacks[i](this._deviceState); } } }; } /** * Class that provides the current GPS location of the device. * @typedef {Object} Platform~GPSLocation * @property {String} latitude - The device's current latitude. * @property {String} longitude - The device's current longitude. */ /** * Returns an object that has the current GPS location of the device or null. * @returns {Platform~GPSLocation} The GPS location is available. */ Platform.prototype.getGPSLocation = function() { return { "latitude": null, "longitude": null }; }; /** * Class that provides information about the device. * @typedef {Object} Platform~DeviceInformation * @property {String} model - The device's model. * @property {String} manufacturer - The device's manufacturer. * @property {String} osName - The operating system. * @property {String} osVersion - The operating system's version. * @property {String} osBuild - The operating system's build number. * @property {String} carrier - The device's wireless carrier. */ /** * Returns an object with device information used by [Analytics]{@link Analytics} * @returns {Platform~DeviceInformation} The device specific information. */ Platform.prototype.getDeviceInformation = function() { return { "model": "<unknown>", "manufacturer": "<unknown>", "osName": "<unknown>", "osVersion": "<unknown>", "osBuild": "<unknown>", "carrier": "<unknown>" }; }; /** * Performs an HTTP request. * @param request {Object} The format of the request parameter is identical to the settings parameter in * [JQuery's ajax]{@link http://api.jquery.com/jQuery.ajax/} method. However, only the method, url, headers ,data, success * and error properties are used. * @abstract */ Platform.prototype.invokeService = function(request) { throw Error("invokeService() not implemented in Platform!"); }; /** * Implementors can override this function to allow offline login. [cacheCredentials()]{Platform#cacheCredentials} * Should also be overridden to cache the credentials. The default implementation returns false. * * @param username {String} The user name. * @param password {String} The password. * @returns {Boolean} True if the username and password are valid, false otherwise. */ Platform.prototype.validateCachedCredentials = function(username, password) { return false; }; /** * Implementors can override this function to cache user credentials for offline login. The default implementation * is a no-op. * @param username {String} The user name. * @param password {String} The password. */ Platform.prototype.cacheCredentials = function(username, password) { throw Error("cacheCredentials() not implemented in Platform!"); };