Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let method = programStateMachine.getMethodByName(methodName);
if (!method) {
// 'method' has ModellingRule=OptionalPlaceholder and should be created from the type definition
let methodToClone = programStateMachine.typeDefinitionObj.getMethodByName(methodName);
if (!methodToClone) {
methodToClone = programStateMachine.typeDefinitionObj!.subtypeOfObj!.getMethodByName(methodName)!;
}
methodToClone.clone({
componentOf: programStateMachine
});
method = programStateMachine.getMethodByName(methodName)!;
assert(method !== null, "Method clone should cause parent object to be extended");
}
assert(method.nodeClass === NodeClass.Method);
method._getExecutableFlag = function (/* sessionContext: SessionContext */) {
// must use a function here to capture 'this'
return MygetExecutableFlag(this as UAMethod, toState, methodName);
};
method.bindMethod(
function (
this: UAMethod,
inputArguments: VariantLike[],
context: SessionContext,
callback: (err: Error | null, callMethodResult: CallMethodResultOptions) => void
) {
const stateMachineW = this.parent! as StateMachine;
// tslint:disable-next-line:no-console
console.log("Boiler System : " + methodName + " about to process");
function _get_parent_as_VariableOrObjectType(
originalObject: BaseNodePublic
): UAVariableType | UAObjectType | null {
if (originalObject.nodeClass === NodeClass.Method) {
return null;
}
const addressSpace = originalObject.addressSpace;
const parents = originalObject.findReferencesEx("HasChild", BrowseDirection.Inverse);
// istanbul ignore next
if (parents.length > 1) {
console.warn(" object ", originalObject.browseName.toString(), " has more than one parent !");
console.warn(originalObject.toString());
console.warn(" parents : ");
for (const parent of parents) {
console.log(" ",
parent.toString(),
addressSpace.findNode(parent.nodeId)!.browseName.toString()
init(this: any, name: string, attrs: XmlAttributes) {
this.obj = {};
this.obj.nodeClass = NodeClass.Method;
// MethodDeclarationId
// ParentNodeId
this.obj.browseName = convertQualifiedName(attrs.BrowseName);
this.obj.parentNodeId = attrs.ParentNodeId || null;
this.obj.nodeId = convertToNodeId(attrs.NodeId) || null;
this.obj.methodDeclarationId = attrs.MethodDeclarationId ? resolveNodeId(attrs.MethodDeclarationId) : null;
},
finish(this: any) {
const BaseNode = require("./base_node").BaseNode;
const UAVariable = require("./ua_variable").UAVariable;
const SessionContext = require("./session_context").SessionContext;
function UAMethod(options) {
BaseNode.apply(this, arguments);
// assert(this.typeDefinition.value === resolveNodeId("MethodType").value);
this.value = options.value;
this.methodDeclarationId = options.methodDeclarationId;
}
util.inherits(UAMethod, BaseNode);
UAMethod.prototype.nodeClass = NodeClass.Method;
UAMethod.prototype.getExecutableFlag = function (context) {
assert(context instanceof SessionContext);
if (!_.isFunction(this._asyncExecutionFunction)) {
return false;
}
if (this._getExecutableFlag) {
return this._getExecutableFlag(context);
}
return true;
};
UAMethod.prototype.readAttribute = function (context, attributeId) {
assert(context instanceof SessionContext);
init: function (name, attrs) {
this.obj = {};
this.obj.nodeClass = NodeClass.Method;
// MethodDeclarationId
// ParentNodeId
this.obj.browseName = convertQualifiedName(attrs.BrowseName);
this.obj.parentNodeId = attrs.ParentNodeId || null;
this.obj.nodeId = convertToNodeId(attrs.NodeId) || null;
this.obj.methodDeclarationId = attrs.MethodDeclarationId ? resolveNodeId(attrs.MethodDeclarationId) : null;
},
finish: function () {
const obj = addressSpace.findNode(objectId) as UAObject;
if (!obj) {
// istanbul ignore next
if (doDebug) {
debugLog("cannot find node ", objectId.toString());
}
return { statusCode: StatusCodes.BadNodeIdUnknown };
}
let objectMethod = obj.getMethodById(methodId) as UAMethod;
if (!objectMethod) {
// the method doesn't belong to the object, nevertheless
// the method can be called
objectMethod = addressSpace.findNode(methodId) as UAMethod;
if (!objectMethod || objectMethod.nodeClass !== NodeClass.Method) {
return { statusCode: StatusCodes.BadMethodInvalid };
}
}
const methodDeclarationId = (objectMethod as any).methodDeclarationId;
const methodDeclaration = addressSpace.findNode(methodDeclarationId);
if (!methodDeclaration) {
// return {statusCode: StatusCodes.BadMethodInvalid};
return { statusCode: StatusCodes.Good, methodDeclaration: objectMethod };
}
return { statusCode: StatusCodes.Good, methodDeclaration };
}
if (response.statusCode !== StatusCodes.Good) {
return callback(null, { statusCode: response.statusCode });
}
const methodDeclaration = response.methodDeclaration;
// verify input Parameters
const methodInputArguments = methodDeclaration.getInputArguments();
response = verifyArguments_ArgumentList(addressSpace, methodInputArguments, inputArguments);
if (response.statusCode !== StatusCodes.Good) {
return callback(null, response);
}
const methodObj = addressSpace.findNode(methodId) as UAMethod;
if (methodObj.nodeClass !== NodeClass.Method) {
return callback(null, { statusCode: StatusCodes.BadNodeIdInvalid });
}
// invoke method on object
const context = new SessionContext({
object: addressSpace.findNode(objectId) as UAObject,
server,
session
});
let l_extraDataTypeManager: ExtraDataTypeManager;
ensureDatatypeExtractedWithCallback(addressSpace, (err2: Error|null, extraDataTypeManager: ExtraDataTypeManager) => {
l_extraDataTypeManager = extraDataTypeManager;
Namespace.prototype.addMethod = function (parentObject, options) {
const self = this;
const addressSpace = self.addressSpace;
assert(_.isObject(parentObject) && parentObject instanceof BaseNode,"expecting a valid parent object");
options.nodeClass = NodeClass.Method;
assert(options.hasOwnProperty("browseName"));
assert(!options.hasOwnProperty("inputArguments") || _.isArray(options.inputArguments));
assert(!options.hasOwnProperty("outputArguments") || _.isArray(options.outputArguments));
options.componentOf = parentObject;
const method = self._addMethod(options);
const propertyTypeId = addressSpace._coerce_VariableTypeIds("PropertyType");
const nodeId_ArgumentDataType = "Argument"; // makeNodeId(DataTypeIds.Argument);
if (options.inputArguments) {
const _inputArgs = new Variant({
dataType: DataType.ExtensionObject,
const self = this;
const addressSpace = self.addressSpace;
assert(isNonEmptyQualifiedName(options.browseName));
const references = [];
assert(isNonEmptyQualifiedName(options.browseName));
_handle_hierarchy_parent(addressSpace, references, options);
Namespace._process_modelling_rule(references, options.modellingRule);
const method = self._createNode({
nodeClass: NodeClass.Method,
nodeId: options.nodeId,
isAbstract: false,
browseName: options.browseName,
displayName: options.displayName,
description: options.description || "",
eventNotifier: +options.eventNotifier,
references: references
});
assert(method.nodeId !== null);
method.propagate_back_references();
assert(!method.typeDefinition);
return method;
};
assert(isNonEmptyQualifiedName(options.browseName));
const references: Reference[] = [];
assert(isNonEmptyQualifiedName(options.browseName));
_handle_hierarchy_parent(addressSpace, references, options);
UANamespace_process_modelling_rule(references, options.modellingRule);
const method = this._createNode({
browseName: options.browseName,
description: options.description || "",
displayName: options.displayName,
eventNotifier: +options.eventNotifier,
isAbstract: false,
nodeClass: NodeClass.Method,
nodeId: options.nodeId,
references
}) as UAMethod;
assert(method.nodeId !== null);
method.propagate_back_references();
assert(!method.typeDefinition);
return method;
}
}