mirror of
https://github.com/nasa/openmct.git
synced 2025-04-16 07:26:53 +00:00
[Telemetry] Separate out delegator
Separate out handling of delegation related to telemetry, WTD-806.
This commit is contained in:
parent
d16340ac4e
commit
774c4dec1d
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*/
|
||||
|
||||
define(
|
||||
['./TelemetryQueue', './TelemetryTable'],
|
||||
function (TelemetryQueue, TelemetryTable) {
|
||||
['./TelemetryQueue', './TelemetryTable', './TelemetryDelegator'],
|
||||
function (TelemetryQueue, TelemetryTable, TelemetryDelegator) {
|
||||
"use strict";
|
||||
|
||||
|
||||
@ -31,7 +31,8 @@ define(
|
||||
* the callback once, with access to the latest data
|
||||
*/
|
||||
function TelemetrySubscription($q, $timeout, domainObject, callback, lossless) {
|
||||
var unsubscribePromise,
|
||||
var delegator = new TelemetryDelegator($q),
|
||||
unsubscribePromise,
|
||||
latestValues = {},
|
||||
telemetryObjects = [],
|
||||
pool = lossless ? new TelemetryQueue() : new TelemetryTable(),
|
||||
@ -42,23 +43,7 @@ define(
|
||||
// This will either be the object in view, or object that
|
||||
// this object delegates its telemetry capability to.
|
||||
function promiseRelevantObjects(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 delegator.promiseTelemetryObjects(domainObject);
|
||||
}
|
||||
|
||||
function updateValuesFromPool() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user