Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private _start_sampling(recordInitialValue?: boolean) {
if (!this.node) {
throw new Error("Internal Error");
}
// make sure oldDataValue is scrapped so first data recording can happen
this.oldDataValue = new DataValue({ statusCode: StatusCodes.BadDataUnavailable }); // unset initially
this._stop_sampling();
const context = new SessionContext({
// xx server: this.server,
session: this._getSession()
});
if (this.itemToMonitor.attributeId === AttributeIds.EventNotifier) {
// istanbul ignore next
if (doDebug) {
debugLog("xxxxxx monitoring EventNotifier on",
this.node.nodeId.toString(), this.node.browseName.toString());
}
// we are monitoring OPCUA Event
this._on_opcua_event_received_callback = this._on_opcua_event.bind(this);
this.node.on("event", this._on_opcua_event_received_callback);
return;
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);
// invoke method on object
const context = new SessionContext({
session: session,
object: addressSpace.findNode(objectId),
server: server
});
methodObj.execute(inputArguments, context, function (err, callMethodResponse) {
/* istanbul ignore next */
if (err) {
return callback(err);
}
callMethodResponse.inputArgumentResults = response.inputArgumentResults || [];
assert(callMethodResponse.statusCode);
return sendError(StatusCodes.BadTooManyOperations);
}
}
// todo : handle
if (server.engine.serverCapabilities.operationLimits.maxNodesPerHistoryReadData > 0) {
if (request.nodesToRead.length > server.engine.serverCapabilities.operationLimits.maxNodesPerHistoryReadData) {
return sendError(StatusCodes.BadTooManyOperations);
}
}
if (server.engine.serverCapabilities.operationLimits.maxNodesPerHistoryReadEvents > 0) {
if (request.nodesToRead.length > server.engine.serverCapabilities.operationLimits.maxNodesPerHistoryReadEvents) {
return sendError(StatusCodes.BadTooManyOperations);
}
}
const context = new SessionContext({session, server});
// ask for a refresh of asynchronous variables
server.engine.refreshValues(request.nodesToRead, function (err) {
assert(!err, " error not handled here , fix me"); //TODO
server.engine.historyRead(context, request, function (err, results) {
assert(results[0]._schema.name === "HistoryReadResult");
assert(results.length === request.nodesToRead.length);
response = new HistoryReadResponse({
results: results,
diagnosticInfos: null
});
assert(response.diagnosticInfos.length === 0);
if (!request.nodesToWrite || request.nodesToWrite.length === 0) {
return sendError(StatusCodes.BadNothingToDo);
}
if (server.engine.serverCapabilities.operationLimits.maxNodesPerWrite > 0) {
if (request.nodesToWrite.length > server.engine.serverCapabilities.operationLimits.maxNodesPerWrite) {
return sendError(StatusCodes.BadTooManyOperations);
}
}
// proceed with registered nodes alias resolution
for (let i = 0; i < request.nodesToWrite.length; i++) {
request.nodesToWrite[i].nodeId = session.resolveRegisteredNode(request.nodesToWrite[i].nodeId);
}
const context = new SessionContext({session, server});
assert(request.nodesToWrite[0]._schema.name === "WriteValue");
server.engine.write(context, request.nodesToWrite, function (err, results) {
assert(!err);
assert(_.isArray(results));
assert(results.length === request.nodesToWrite.length);
response = new WriteResponse({
results: results,
diagnosticInfos: null
});
sendResponse(response);
});
});
};
this._apply_on_SessionObject(CreateSubscriptionResponse, message, channel, function (session, sendResponse, sendError) {
const context = new SessionContext({session, server});
if (session.currentSubscriptionCount >= OPCUAServer.MAX_SUBSCRIPTION) {
return sendError(StatusCodes.BadTooManySubscriptions);
}
const subscription = session.createSubscription(request);
subscription.on("monitoredItem", function (monitoredItem) {
prepareMonitoredItem(context, addressSpace, monitoredItem);
});
const response = new CreateSubscriptionResponse({
subscriptionId: subscription.id,
revisedPublishingInterval: subscription.publishingInterval,
revisedLifetimeCount: subscription.lifeTimeCount,
revisedMaxKeepAliveCount: subscription.maxKeepAliveCount
this._apply_on_SessionObject(ReadResponse, message, channel, function (session, sendResponse, sendError) {
const context = new SessionContext({session, server});
let response;
let results = [];
const timestampsToReturn = request.timestampsToReturn;
if (timestampsToReturn === TimestampsToReturn.Invalid) {
return sendError(StatusCodes.BadTimestampsToReturnInvalid);
}
if (request.maxAge < 0) {
return sendError(StatusCodes.BadMaxAgeInvalid);
}
request.nodesToRead = request.nodesToRead || [];