Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function add_ObjectWithMethod(namespace, parentFolder) {
const myObject = namespace.addObject({
nodeId: "s=ObjectWithMethods",
organizedBy: parentFolder,
browseName: "ObjectWithMethods"
});
const methodNoArgs = namespace.addMethod(myObject, {
browseName: "MethodNoArgs",
nodeId: "s=MethodNoArgs",
//xx inputArguments: [],
//xx outputArguments: []
});
assert(makeNodeId("MethodNoArgs", namespace.index).toString().match(/s=MethodNoArgs/));
assert(methodNoArgs.nodeId.toString().match(/s=MethodNoArgs/));
methodNoArgs.bindMethod(function(inputArguments, context, callback) {
// console.log(require("util").inspect(context).toString());
const callMethodResult = {
statusCode: StatusCodes.Good,
outputArguments: []
};
callback(null, callMethodResult);
});
const methodIO = namespace.addMethod(myObject, {
///xx modellingRule: "Mandatory",
if (doDebug) {
console.warn("ServerEngine#_getServerSubscriptionDiagnosticsArray : no addressSpace");
}
return null; // no addressSpace
}
const subscriptionDiagnosticsType = this.addressSpace.findVariableType("SubscriptionDiagnosticsType");
if (!subscriptionDiagnosticsType) {
if (doDebug) {
console.warn("ServerEngine#_getServerSubscriptionDiagnosticsArray " +
": cannot find SubscriptionDiagnosticsType");
}
}
// SubscriptionDiagnosticsArray = i=2290
const subscriptionDiagnosticsArray = this.addressSpace.findNode(
makeNodeId(VariableIds.Server_ServerDiagnostics_SubscriptionDiagnosticsArray))!;
return subscriptionDiagnosticsArray as UADynamicVariableArray;
}
}
assert(_.isNumber(id), "expecting id to be a number");
assert(_.isFunction(func));
assert(_.isFunction(setter_func) || !setter_func);
assert(dataType !== null); // check invalid dataType
let setter_func2 = null;
if (setter_func) {
setter_func2 = (variant: Variant) => {
const variable2 = !!variant.value;
setter_func(variable2);
return StatusCodes.Good;
};
}
const nodeId = makeNodeId(id);
// make sur the provided function returns a valid value for the variant type
// This test may not be exhaustive but it will detect obvious mistakes.
/* istanbul ignore next */
if (!isValidVariant(VariantArrayType.Scalar, dataType, func())) {
errorLog("func", func());
throw new Error("bindStandardScalar : func doesn't provide an value of type " + DataType[dataType]);
}
return bindVariableIfPresent(nodeId, {
get() {
return new Variant({
arrayType: VariantArrayType.Scalar,
dataType,
function bindStandardArray(id, variantDataType, dataType, func) {
assert(_.isFunction(func));
assert(variantDataType !== null); // check invalid dataType
const nodeId = makeNodeId(id);
// make sur the provided function returns a valid value for the variant type
// This test may not be exhaustive but it will detect obvious mistakes.
assert(isValidVariant(VariantArrayType.Array, dataType, func()));
bindVariableIfPresent(nodeId, {
get: function () {
const value = func();
assert(_.isArray(value));
return new Variant({
dataType: variantDataType,
arrayType: VariantArrayType.Array,
value: value
});
},
set: null // read only
engine.setServerState(ServerState.Running);
function bindVariableIfPresent(nodeId, opts) {
assert(nodeId instanceof NodeId);
assert(!nodeId.isEmpty());
const obj = engine.addressSpace.findNode(nodeId);
if (obj) {
__bindVariable(engine, nodeId, opts);
}
return obj;
}
// -------------------------------------------- install default get/put handler
const server_NamespaceArray_Id = makeNodeId(VariableIds.Server_NamespaceArray); // ns=0;i=2255
bindVariableIfPresent(server_NamespaceArray_Id, {
get: function () {
return new Variant({
dataType: DataType.String,
arrayType: VariantArrayType.Array,
value: engine.addressSpace.getNamespaceArray().map(x=>x.namespaceUri)
});
},
set: null // read only
});
const server_NameUrn_var = new Variant({
dataType: DataType.String,
arrayType: VariantArrayType.Array,
value: [
engine.serverNameUrn // this is us !
function bindStandardArray(
id: number,
variantDataType: DataType,
dataType: any,
func: () => any[]
) {
assert(_.isFunction(func));
assert(variantDataType !== null); // check invalid dataType
const nodeId = makeNodeId(id);
// make sur the provided function returns a valid value for the variant type
// This test may not be exhaustive but it will detect obvious mistakes.
assert(isValidVariant(VariantArrayType.Array, variantDataType, func()));
bindVariableIfPresent(nodeId, {
get() {
const value = func();
assert(_.isArray(value));
return new Variant({
arrayType: VariantArrayType.Array,
dataType: variantDataType,
value
});
},
set: null // read only
private _readOperationalLimits(callback: ErrorCallback) {
const n1 = makeNodeId(VariableIds.Server_ServerCapabilities_OperationLimits_MaxNodesPerRead);
const n2 = makeNodeId(VariableIds.Server_ServerCapabilities_OperationLimits_MaxNodesPerBrowse);
const nodesToRead = [
{nodeId: n1, attributeId: AttributeIds.Value},
{nodeId: n2, attributeId: AttributeIds.Value}
];
this.transactionCounter++;
this.session.read(nodesToRead, (err: Error | null, dataValues?: DataValue[]): void => {
if (err) {
return callback(err);
}
dataValues = dataValues!;
if (dataValues[0].statusCode.equals(StatusCodes.Good)) {
this.maxNodesPerRead = dataValues[0].value.value;
}
// ensure we have a sensible maxNodesPerRead value in case the server doesn't specify one
this.maxNodesPerRead = this.maxNodesPerRead || 500;
function _create_new_branch_id() {
return makeNodeId(randomGuid(), 1);
}