nmos-ledger
Version:
NMOS discovery and registration APIs
168 lines (136 loc) • 6.58 kB
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: model/Device.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: model/Device.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>/* Copyright 2015 Christine S. MacNeill
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by appli cable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var Versionned = require('./Versionned.js');
var immutable = require('seamless-immutable');
var DeviceTypes = require('./DeviceTypes.js');
/**
* Describes a Device. Immutable value.
* @constructor
* @augments Versionned
* @param {String} id Globally unique UUID identifier for the Device.
* @param {string} version String formatted PTP timestamp
* (&lt;<em>seconds</em>&gt;:&lt;<em>nanoseconds</em>&gt;)
* indicating precisely when an attribute of the resource
* last changed.
* @param {string} label Freeform string label for the Device.
* @param {string} type [Device type]{@link deviceTypes} URN.
* @param {string} node_id Globally unique UUID identifier for the {@link Node}
* which initially created the Device.
* @param {string[]} senders UUIDs of {@link Senders} attached to the Device.
* @param {string[]} receivers UUIDs of Receivers attached to the Device
*/
function Device(id, version, label, type, node_id, senders, receivers) {
this.id = this.generateID(id);
this.version = this.generateVersion(version);
this.label = this.generateLabel(label);
/**
* [Device type]{@link deviceTypes} URN.
* @type {string}
* @readonly
*/
this.type = this.generateType(type);
/**
* Globally unique UUID identifier for the {@link Node} which initially created
* the Device.
* @type {string}
* @readonly
*/
this.node_id = this.generateNodeID(node_id);
/**
* UUIDs of [Senders]{@link Sender} attached to the Device.
* @type {string[]}
* @readonly
*/
this.senders = this.generateSenders(senders);
/**
* UUIDs of [Receivers]{@link Receiver} attached to the Device.
* @type {string[]}
* @readonly
*/
this.receivers = this.generateReceivers(receivers);
return immutable(this, { prototype: Device.prototype });
}
Device.prototype.validID = Versionned.prototype.validID;
Device.prototype.generateID = Versionned.prototype.generateID;
Device.prototype.validVersion = Versionned.prototype.validVersion;
Device.prototype.generateVersion = Versionned.prototype.generateVersion;
Device.prototype.validLabel = Versionned.prototype.validLabel;
Device.prototype.generateLabel = Versionned.prototype.generateLabel;
Device.prototype.validType = function (t) {
if (arguments.length === 0) return this.validType(this.type);
else return Versionned.prototype.validDeviceType(t);
}
Device.prototype.generateType = Versionned.prototype.generateDeviceType;
Device.prototype.validNodeID = Versionned.prototype.validID;
Device.prototype.generateNodeID = Versionned.prototype.generateID;
Device.prototype.validSenders = function(s) {
if (arguments.length === 0) return this.validSenders(this.senders);
else return Versionned.prototype.validUUIDArray(s);
}
Device.prototype.generateSenders = Versionned.prototype.generateUUIDArray;
Device.prototype.validReceivers = function (r) {
if (arguments.length === 0) return this.validReceivers(this.receivers);
else return Versionned.prototype.validUUIDArray(r);
}
Device.prototype.generateReceivers = Versionned.prototype.generateUUIDArray;
Device.prototype.valid = function () {
return this.validID(this.id) &&
this.validVersion(this.version) &&
this.validLabel(this.label) &&
this.validType(this.type) &&
this.validNodeID(this.node_id) &&
this.validSenders(this.senders) &&
this.validReceivers(this.receivers);
};
Device.prototype.stringify = function() { return JSON.stringify(this); }
Device.prototype.parse = function(json) {
if (json === null || json === undefined || arguments.length === 0 ||
typeof json !== 'string')
throw "Cannot parse JSON to a Device value because it is not a valid input.";
var parsed = JSON.parse(json);
return new Device(parsed.id, parsed.version, parsed.label, parsed.type,
parsed.node_id, parsed.senders, parsed.receivers);
};
module.exports = Device;
</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Device.html">Device</a></li><li><a href="Flow.html">Flow</a></li><li><a href="Node.html">Node</a></li><li><a href="NodeAPI.html">NodeAPI</a></li><li><a href="NodeRAMStore.html">NodeRAMStore</a></li><li><a href="Versionned.html">Versionned</a></li></ul><h3>Interfaces</h3><ul><li><a href="NodeStore.html">NodeStore</a></li></ul><h3>Global</h3><ul><li><a href="global.html#capabilities">capabilities</a></li><li><a href="global.html#deviceTypes">deviceTypes</a></li><li><a href="global.html#formats">formats</a></li><li><a href="global.html#statusError">statusError</a></li><li><a href="global.html#transports">transports</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Mon Dec 21 2015 17:19:49 GMT+0000 (GMT)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>