mirror of
https://github.com/nasa/openmct.git
synced 2025-06-23 09:25:29 +00:00
[Telemetry] Separate out delegator
Separate out handling of delegation related to telemetry, WTD-806.
This commit is contained in:
45
platform/telemetry/src/TelemetryDelegator.js
Normal file
45
platform/telemetry/src/TelemetryDelegator.js
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
/*global define*/
|
||||||
|
|
||||||
|
define(
|
||||||
|
[],
|
||||||
|
function () {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to handle telemetry delegation associated with a
|
||||||
|
* given domain object.
|
||||||
|
*/
|
||||||
|
function TelemetryDelegator($q) {
|
||||||
|
return {
|
||||||
|
/**
|
||||||
|
* Promise telemetry-providing objects associated with
|
||||||
|
* this domain object (either the domain object itself,
|
||||||
|
* or the objects it delegates)
|
||||||
|
* @returns {Promise.<DomainObject[]>} domain objects with
|
||||||
|
* a telemetry capability
|
||||||
|
*/
|
||||||
|
promiseTelemetryObjects: function (domainObject) {
|
||||||
|
// If object has been cleared, there are no relevant
|
||||||
|
// telemetry-providing domain objects.
|
||||||
|
if (!domainObject) {
|
||||||
|
return $q.when([]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise, try delegation first, and attach the
|
||||||
|
// object itself if it has a telemetry capability.
|
||||||
|
return $q.when(domainObject.useCapability(
|
||||||
|
"delegation",
|
||||||
|
"telemetry"
|
||||||
|
)).then(function (result) {
|
||||||
|
var head = domainObject.hasCapability("telemetry") ?
|
||||||
|
[ domainObject ] : [],
|
||||||
|
tail = result || [];
|
||||||
|
return head.concat(tail);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return TelemetryDelegator;
|
||||||
|
}
|
||||||
|
);
|
34
platform/telemetry/src/TelemetryRequester.js
Normal file
34
platform/telemetry/src/TelemetryRequester.js
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
/*global define*/
|
||||||
|
|
||||||
|
define(
|
||||||
|
['./TelemetryDelegator'],
|
||||||
|
function (TelemetryDelegator) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A TelemetryRequester provides an easy interface to request
|
||||||
|
* telemetry associated with a set of domain objects.
|
||||||
|
*
|
||||||
|
* @constructor
|
||||||
|
* @param $q Angular's $q
|
||||||
|
*/
|
||||||
|
function TelemetryRequester($q) {
|
||||||
|
var delegator = new TelemetryDelegator($q);
|
||||||
|
|
||||||
|
// Look up domain objects which have telemetry capabilities.
|
||||||
|
// This will either be the object in view, or object that
|
||||||
|
// this object delegates its telemetry capability to.
|
||||||
|
function promiseRelevantObjects(domainObject) {
|
||||||
|
return delegator.promiseTelemetryObjects(domainObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return TelemetryRequester;
|
||||||
|
|
||||||
|
}
|
||||||
|
);
|
@ -1,8 +1,8 @@
|
|||||||
/*global define*/
|
/*global define*/
|
||||||
|
|
||||||
define(
|
define(
|
||||||
['./TelemetryQueue', './TelemetryTable'],
|
['./TelemetryQueue', './TelemetryTable', './TelemetryDelegator'],
|
||||||
function (TelemetryQueue, TelemetryTable) {
|
function (TelemetryQueue, TelemetryTable, TelemetryDelegator) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
|
||||||
@ -31,7 +31,8 @@ define(
|
|||||||
* the callback once, with access to the latest data
|
* the callback once, with access to the latest data
|
||||||
*/
|
*/
|
||||||
function TelemetrySubscription($q, $timeout, domainObject, callback, lossless) {
|
function TelemetrySubscription($q, $timeout, domainObject, callback, lossless) {
|
||||||
var unsubscribePromise,
|
var delegator = new TelemetryDelegator($q),
|
||||||
|
unsubscribePromise,
|
||||||
latestValues = {},
|
latestValues = {},
|
||||||
telemetryObjects = [],
|
telemetryObjects = [],
|
||||||
pool = lossless ? new TelemetryQueue() : new TelemetryTable(),
|
pool = lossless ? new TelemetryQueue() : new TelemetryTable(),
|
||||||
@ -42,23 +43,7 @@ define(
|
|||||||
// This will either be the object in view, or object that
|
// This will either be the object in view, or object that
|
||||||
// this object delegates its telemetry capability to.
|
// this object delegates its telemetry capability to.
|
||||||
function promiseRelevantObjects(domainObject) {
|
function promiseRelevantObjects(domainObject) {
|
||||||
// If object has been cleared, there are no relevant
|
return delegator.promiseTelemetryObjects(domainObject);
|
||||||
// telemetry-providing domain objects.
|
|
||||||
if (!domainObject) {
|
|
||||||
return $q.when([]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Otherwise, try delegation first, and attach the
|
|
||||||
// object itself if it has a telemetry capability.
|
|
||||||
return $q.when(domainObject.useCapability(
|
|
||||||
"delegation",
|
|
||||||
"telemetry"
|
|
||||||
)).then(function (result) {
|
|
||||||
var head = domainObject.hasCapability("telemetry") ?
|
|
||||||
[ domainObject ] : [],
|
|
||||||
tail = result || [];
|
|
||||||
return head.concat(tail);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateValuesFromPool() {
|
function updateValuesFromPool() {
|
||||||
|
Reference in New Issue
Block a user