mirror of
https://github.com/nasa/openmct.git
synced 2025-06-23 09:25:29 +00:00
[Telemetry] Listen for mutation
Listen for mutation from telemetry subscriptions, WTD-1329.
This commit is contained in:
@ -59,6 +59,7 @@ define(
|
|||||||
telemetryObjects = [],
|
telemetryObjects = [],
|
||||||
pool = lossless ? new TelemetryQueue() : new TelemetryTable(),
|
pool = lossless ? new TelemetryQueue() : new TelemetryTable(),
|
||||||
metadatas,
|
metadatas,
|
||||||
|
unlistenToMutation,
|
||||||
updatePending;
|
updatePending;
|
||||||
|
|
||||||
// Look up domain objects which have telemetry capabilities.
|
// Look up domain objects which have telemetry capabilities.
|
||||||
@ -153,16 +154,41 @@ define(
|
|||||||
return objects;
|
return objects;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get a reference to relevant objects (those with telemetry
|
function initialize() {
|
||||||
// capabilities) and subscribe to their telemetry updates.
|
// Get a reference to relevant objects (those with telemetry
|
||||||
// Keep a reference to their promised return values, as these
|
// capabilities) and subscribe to their telemetry updates.
|
||||||
// will be unsubscribe functions. (This must be a promise
|
// Keep a reference to their promised return values, as these
|
||||||
// because delegation is supported, and retrieving delegate
|
// will be unsubscribe functions. (This must be a promise
|
||||||
// telemetry-capable objects may be an asynchronous operation.)
|
// because delegation is supported, and retrieving delegate
|
||||||
telemetryObjectPromise = promiseRelevantObjects(domainObject);
|
// telemetry-capable objects may be an asynchronous operation.)
|
||||||
unsubscribePromise = telemetryObjectPromise
|
telemetryObjectPromise = promiseRelevantObjects(domainObject);
|
||||||
.then(cacheObjectReferences)
|
unsubscribePromise = telemetryObjectPromise
|
||||||
.then(subscribeAll);
|
.then(cacheObjectReferences)
|
||||||
|
.then(subscribeAll);
|
||||||
|
}
|
||||||
|
|
||||||
|
function idsMatch(ids) {
|
||||||
|
return ids.every(function (id, index) {
|
||||||
|
return telemetryObjects[index].getId() === id;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function modelChange(model) {
|
||||||
|
if (!idsMatch((model || {}).composition || [])) {
|
||||||
|
// Reinitialize if composition has changed
|
||||||
|
initialize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function addMutationListener() {
|
||||||
|
var mutation = domainObject.getCapability('mutation');
|
||||||
|
if (mutation) {
|
||||||
|
return mutation.listen(modelChange);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
initialize();
|
||||||
|
unlistenToMutation = addMutationListener();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
/**
|
/**
|
||||||
@ -172,6 +198,9 @@ define(
|
|||||||
* @memberof TelemetrySubscription
|
* @memberof TelemetrySubscription
|
||||||
*/
|
*/
|
||||||
unsubscribe: function () {
|
unsubscribe: function () {
|
||||||
|
if (unlistenToMutation) {
|
||||||
|
unlistenToMutation();
|
||||||
|
}
|
||||||
return unsubscribePromise.then(function (unsubscribes) {
|
return unsubscribePromise.then(function (unsubscribes) {
|
||||||
return $q.all(unsubscribes.map(function (unsubscribe) {
|
return $q.all(unsubscribes.map(function (unsubscribe) {
|
||||||
return unsubscribe();
|
return unsubscribe();
|
||||||
|
Reference in New Issue
Block a user