Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
UAConditionBase.with_condition_method = function(inputArguments, context, callback, inner_func) {
const conditionNode = context.object;
//xx console.log(inputArguments.map(function(a){return a.toString()}));
if (!(conditionNode instanceof UAConditionBase)) {
callback(null, {
statusCode: StatusCodes.BadNodeIdInvalid
});
return;
}
if (!conditionNode.getEnabledState()) {
callback(null, {
statusCode: StatusCodes.BadConditionDisabled
});
return;
}
// inputArguments has 2 arguments
// EventId => ByteString The Identifier of the event to comment
// Comment => LocalizedText The Comment to add to the condition
assert(inputArguments.length === 2);
assert(inputArguments[0].dataType === DataType.ByteString);
assert(inputArguments[1].dataType === DataType.LocalizedText);
const eventId = inputArguments[0].value;
assert(!eventId || eventId instanceof Buffer);
const comment = inputArguments[1].value;
assert(comment instanceof LocalizedText);
conditionNode: UAConditionBase
) => StatusCode
) {
const conditionNode = context.object;
// xx console.log(inputArguments.map(function(a){return a.toString()}));
if (!(conditionNode instanceof UAConditionBase)) {
callback(null, {
statusCode: StatusCodes.BadNodeIdInvalid
});
return;
}
if (!conditionNode.getEnabledState()) {
callback(null, {
statusCode: StatusCodes.BadConditionDisabled
});
return;
}
// inputArguments has 2 arguments
// EventId => ByteString The Identifier of the event to comment
// Comment => LocalizedText The Comment to add to the condition
assert(inputArguments.length === 2);
assert(inputArguments[0].dataType === DataType.ByteString);
assert(inputArguments[1].dataType === DataType.LocalizedText);
const eventId = inputArguments[0].value;
assert(!eventId || eventId instanceof Buffer);
const comment = inputArguments[1].value;
assert(comment instanceof LocalizedText);
// xx assert(conditionNode.enabledState.id.readValue().value.value === requestedEnabledState,"sanity check 1");
// xx assert(conditionNode.currentBranch().getEnabledState() === requestedEnabledState,"sanity check 2");
if (!requestedEnabledState) {
// as per Spec 1.0.3 part 9:
// * When the Condition instance enters the Disabled state, the Retain Property of this
// Condition shall be set to FALSE by the Server to indicate to the Client that the
// Condition instance is currently not of interest to Clients.
// TODO : shall we really set retain to false or artificially expose the retain false as false
// whist enabled state is false ?
this._previousRetainFlag = this.currentBranch().getRetain();
this.currentBranch().setRetain(false);
// todo: install the mechanism by which all condition values will be return
// as Null | BadConditionDisabled;
const statusCode = StatusCodes.BadConditionDisabled;
// a notification must be send
this.raiseConditionEvent(this.currentBranch(), true);
} else {
// * When the Condition instance enters the enabled state, the Condition shall be
// evaluated and all of its Properties updated to reflect the current values. If this
// evaluation causes the Retain Property to transition to TRUE for any ConditionBranch,
// then an Event Notification shall be generated for that ConditionBranch.
this.evaluateConditionsAfterEnabled();
// todo evaluate branches
// conditionNode.evaluateBranches();
// restore retain flag
if (this.hasOwnProperty("_previousRetainFlag")) {
//xx assert(conditionNode.enabledState.id.readValue().value.value === requestedEnabledState,"sanity check 1");
//xx assert(conditionNode.currentBranch().getEnabledState() === requestedEnabledState,"sanity check 2");
if (!requestedEnabledState) {
// as per Spec 1.0.3 part 9:
//* When the Condition instance enters the Disabled state, the Retain Property of this
// Condition shall be set to FALSE by the Server to indicate to the Client that the
// Condition instance is currently not of interest to Clients.
// TODO : shall we really set retain to false or artificially expose the retain false as false
// whist enabled state is false ?
conditionNode._previousRetainFlag = conditionNode.currentBranch().getRetain();
conditionNode.currentBranch().setRetain(false);
// install the mechanism by which all condition values will be return
// as Null | BadConditionDisabled;
const statusCode = StatusCodes.BadConditionDisabled;
// a notification must be send
conditionNode.raiseConditionEvent(conditionNode.currentBranch(), true);
} else {
//* When the Condition instance enters the enabled state, the Condition shall be
// evaluated and all of its Properties updated to reflect the current values. If this
// evaluation causes the Retain Property to transition to TRUE for any ConditionBranch,
// then an Event Notification shall be generated for that ConditionBranch.
conditionNode.evaluateConditionsAfterEnabled();
// todo evaluate branches
// conditionNode.evaluateBranches();
// restore retain flag
if (conditionNode.hasOwnProperty("_previousRetainFlag")) {
);
}
self._node_index[key] = aggregate;
_ensure_condition_values_correctness(self, aggregate, prefix + name + ".", error);
}
}
if (displayError && error.length) {
throw new Error(error.join("\n"));
}
}
const disabledVar = new Variant({
dataType: "StatusCode",
value: StatusCodes.BadConditionDisabled
});
// list of Condition variables that should not be published as BadConditionDisabled when the condition
// is in a disabled state.
const _varTable = {
"branchId": 1,
"conditionClassId": 1,
"conditionClassName": 1,
"conditionName": 1,
"enabledState": 1,
"enabledState.effectiveDisplayName": 1,
"enabledState.id": 1,
"enabledState.transitionTime": 1,
"eventId": 1,
"eventType": 1,
"localTime": 1,
// *
// * @return {ConditionSnapshot}
// */
// ConditionSnapshot.prototype.clone = function () {
// var self = this;
// var clone = new ConditionSnapshot();
// clone.branchId = self.branchId;
// clone.condition = self.condition;
// //xx clone.eventData = new EventData(clone.condition);
// clone._map = _.clone(self._map);
// return clone;
// };
const disabledVar = new Variant({
dataType: "StatusCode",
value: StatusCodes.BadConditionDisabled
});
ConditionSnapshot.prototype._constructEventData = function() {
const self = this;
const addressSpace = self.condition.addressSpace;
if (self.branchId === NodeId.nullNodeId) {
_ensure_condition_values_correctness(self, self.condition, "");
}
const isDisabled = !self.condition.getEnabledState();
const eventData = new EventData(self.condition);
Object.keys(self._map).forEach(function(key) {
const node = self._node_index[key];
if (isDisabled && !_varTable.hasOwnProperty(key)) {
eventData.setValue(key, node, disabledVar);