mirror of
https://github.com/nasa/openmct.git
synced 2025-06-17 14:48:13 +00:00
[Telemetry] Add subscriber service
Add a subscriber service to handle subscribing to whole sets of telemetry elements via delegation; this exposes TelemetrySubscription via a service which can be retrieved via dependency injection. Supports the use of this variety of subscription for autoflow tabular views, WTD-614.
This commit is contained in:
@ -28,6 +28,11 @@
|
|||||||
{
|
{
|
||||||
"key": "telemetryFormatter",
|
"key": "telemetryFormatter",
|
||||||
"implementation": "TelemetryFormatter.js"
|
"implementation": "TelemetryFormatter.js"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "telemetrySubscriber",
|
||||||
|
"implementation": "TelemetrySubscriber.js",
|
||||||
|
"depends": [ "$q", "$timeout" ]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -1,107 +1,23 @@
|
|||||||
/*global define*/
|
/*global define*/
|
||||||
|
|
||||||
define(
|
define(
|
||||||
[],
|
["./TelemetrySubscription"],
|
||||||
function () {
|
function (TelemetrySubscription) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
function TelemetrySubscriber($q, $timeout, domainObject, callback) {
|
function TelemetrySubscriber($q, $timeout) {
|
||||||
var unsubscribePromise,
|
|
||||||
latestValues = {},
|
|
||||||
telemetryObjects = [],
|
|
||||||
updatePending;
|
|
||||||
|
|
||||||
// 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) {
|
|
||||||
// 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);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function fireCallback(values) {
|
|
||||||
callback(values);
|
|
||||||
updatePending = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function update(domainObject, telemetry) {
|
|
||||||
var count = telemetry && telemetry.getPointCount();
|
|
||||||
|
|
||||||
if (!updatePending && count) {
|
|
||||||
updatePending = true;
|
|
||||||
$timeout(fireCallback, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count > 0) {
|
|
||||||
latestValues[domainObject.getId()] = {
|
|
||||||
domain: telemetry.getDomainValue(count - 1),
|
|
||||||
range: telemetry.getRangeValue(count - 1)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function subscribe(domainObject) {
|
|
||||||
var telemetryCapability =
|
|
||||||
domainObject.getCapability("telemetry");
|
|
||||||
return telemetryCapability.subscribe(function (telemetry) {
|
|
||||||
update(domainObject, telemetry);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function subscribeAll(domainObjects) {
|
|
||||||
return domainObjects.map(subscribe);
|
|
||||||
}
|
|
||||||
|
|
||||||
function cacheObjectReferences(objects) {
|
|
||||||
telemetryObjects = objects;
|
|
||||||
return objects;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get a reference to relevant objects (those with telemetry
|
|
||||||
// capabilities)
|
|
||||||
unsubscribePromise =
|
|
||||||
promiseRelevantObjects(domainObject)
|
|
||||||
.then(cacheObjectReferences)
|
|
||||||
.then(subscribeAll);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
unsubscribe: function () {
|
subscribe: function (domainObject, callback) {
|
||||||
return unsubscribePromise.then(function (unsubscribes) {
|
return new TelemetrySubscription(
|
||||||
return $q.all(unsubscribes.map(function (unsubscribe) {
|
$q,
|
||||||
return unsubscribe();
|
$timeout,
|
||||||
}));
|
domainObject,
|
||||||
});
|
callback
|
||||||
},
|
);
|
||||||
getDomainValue: function (domainObject) {
|
|
||||||
var id = domainObject.getId();
|
|
||||||
return (latestValues[id] || {}).domain;
|
|
||||||
},
|
|
||||||
getRangeValue: function (domainObject) {
|
|
||||||
var id = domainObject.getId();
|
|
||||||
return (latestValues[id] || {}).range;
|
|
||||||
},
|
|
||||||
getTelemetryObjects: function () {
|
|
||||||
return telemetryObjects;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return TelemetrySubscriber;
|
return TelemetrySubscriber;
|
||||||
|
|
||||||
}
|
}
|
||||||
);
|
);
|
107
platform/telemetry/src/TelemetrySubscription.js
Normal file
107
platform/telemetry/src/TelemetrySubscription.js
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
/*global define*/
|
||||||
|
|
||||||
|
define(
|
||||||
|
[],
|
||||||
|
function () {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
function TelemetrySubscription($q, $timeout, domainObject, callback) {
|
||||||
|
var unsubscribePromise,
|
||||||
|
latestValues = {},
|
||||||
|
telemetryObjects = [],
|
||||||
|
updatePending;
|
||||||
|
|
||||||
|
// 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) {
|
||||||
|
// 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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function fireCallback(values) {
|
||||||
|
callback(values);
|
||||||
|
updatePending = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function update(domainObject, telemetry) {
|
||||||
|
var count = telemetry && telemetry.getPointCount();
|
||||||
|
|
||||||
|
if (!updatePending && count) {
|
||||||
|
updatePending = true;
|
||||||
|
$timeout(fireCallback, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count > 0) {
|
||||||
|
latestValues[domainObject.getId()] = {
|
||||||
|
domain: telemetry.getDomainValue(count - 1),
|
||||||
|
range: telemetry.getRangeValue(count - 1)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function subscribe(domainObject) {
|
||||||
|
var telemetryCapability =
|
||||||
|
domainObject.getCapability("telemetry");
|
||||||
|
return telemetryCapability.subscribe(function (telemetry) {
|
||||||
|
update(domainObject, telemetry);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function subscribeAll(domainObjects) {
|
||||||
|
return domainObjects.map(subscribe);
|
||||||
|
}
|
||||||
|
|
||||||
|
function cacheObjectReferences(objects) {
|
||||||
|
telemetryObjects = objects;
|
||||||
|
return objects;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get a reference to relevant objects (those with telemetry
|
||||||
|
// capabilities)
|
||||||
|
unsubscribePromise =
|
||||||
|
promiseRelevantObjects(domainObject)
|
||||||
|
.then(cacheObjectReferences)
|
||||||
|
.then(subscribeAll);
|
||||||
|
|
||||||
|
return {
|
||||||
|
unsubscribe: function () {
|
||||||
|
return unsubscribePromise.then(function (unsubscribes) {
|
||||||
|
return $q.all(unsubscribes.map(function (unsubscribe) {
|
||||||
|
return unsubscribe();
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
},
|
||||||
|
getDomainValue: function (domainObject) {
|
||||||
|
var id = domainObject.getId();
|
||||||
|
return (latestValues[id] || {}).domain;
|
||||||
|
},
|
||||||
|
getRangeValue: function (domainObject) {
|
||||||
|
var id = domainObject.getId();
|
||||||
|
return (latestValues[id] || {}).range;
|
||||||
|
},
|
||||||
|
getTelemetryObjects: function () {
|
||||||
|
return telemetryObjects;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return TelemetrySubscription;
|
||||||
|
|
||||||
|
}
|
||||||
|
);
|
Reference in New Issue
Block a user