Skip to content

Commit

Permalink
make ServerEngine methods async 3
Browse files Browse the repository at this point in the history
  • Loading branch information
erossignon committed Jun 18, 2023
1 parent 8aa8944 commit 08024e5
Show file tree
Hide file tree
Showing 3 changed files with 219 additions and 165 deletions.
59 changes: 24 additions & 35 deletions packages/node-opcua-server/source/opcua_server.ts
Expand Up @@ -2663,7 +2663,7 @@ export class OPCUAServer extends OPCUABaseServer {
// ask for a refresh of asynchronous variables
this.engine.refreshValues(request.nodesToRead, request.maxAge, (err?: Error | null) => {
assert(!err, " error not handled here , fix me");
this.engine.readAsync(context, request).then((results) => {
this.engine.read(context, request).then((results) => {
assert(results[0].schema.name === "DataValue");
assert(results.length === request.nodesToRead!.length);

Expand Down Expand Up @@ -2732,25 +2732,23 @@ export class OPCUAServer extends OPCUABaseServer {
this.engine.refreshValues(request.nodesToRead, 0, (err?: Error | null) => {
assert(!err, " error not handled here , fix me"); // TODO

this.engine.historyRead(context, request, (err1: Error | null, results?: HistoryReadResult[]) => {
if (err1) {
return sendError(StatusCodes.BadHistoryOperationInvalid);
}
if (!results) {
this.engine
.historyRead(context, request)
.then((results: HistoryReadResult[]) => {
assert(results[0].schema.name === "HistoryReadResult");
assert(results.length === request.nodesToRead!.length);

response = new HistoryReadResponse({
diagnosticInfos: undefined,
results
});

assert(response.diagnosticInfos!.length === 0);
sendResponse(response);
})
.catch((err) => {
return sendError(StatusCodes.BadHistoryOperationInvalid);
}

assert(results[0].schema.name === "HistoryReadResult");
assert(results.length === request.nodesToRead!.length);

response = new HistoryReadResponse({
diagnosticInfos: undefined,
results
});

assert(response.diagnosticInfos!.length === 0);
sendResponse(response);
});
});
}
);
Expand Down Expand Up @@ -3368,26 +3366,17 @@ export class OPCUAServer extends OPCUABaseServer {
return sendError(StatusCodes.BadTooManyOperations);
}

const addressSpace = this.engine.addressSpace!;

const context = session.sessionContext;

async.map(
request.methodsToCall,
callMethodHelper.bind(null, context, addressSpace),
(err?: Error | null, results?: (CallMethodResultOptions | undefined)[]) => {
/* istanbul ignore next */
if (err) {
errorLog("ERROR in method Call !! ", err);
}
assert(Array.isArray(results));
response = new CallResponse({
results: results as CallMethodResultOptions[]
});
this.engine
.callMethods(context, request.methodsToCall)
.then((results) => {
const response = new CallResponse({ results });
filterDiagnosticInfo(request.requestHeader.returnDiagnostics, response);
sendResponse(response);
}
);
})
.catch((err) => {
sendError(StatusCodes.BadInternalError);
});
}
);
}
Expand Down

0 comments on commit 08024e5

Please sign in to comment.