Skip to content

Commit

Permalink
make ServerEngine method async 1
Browse files Browse the repository at this point in the history
  • Loading branch information
erossignon committed Jun 17, 2023
1 parent 5b6228e commit f4dfe99
Show file tree
Hide file tree
Showing 8 changed files with 692 additions and 740 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export type HistoryReadFunc = (
callback: CallbackT<HistoryReadResult>
) => void;

export type GetFunc = (this: UAVariable) => Variant;
export type GetFunc = (this: UAVariable) => Variant | StatusCode;
export type SetFunc = VariableSetter | null;

export type VariableDataValueGetterSync = (this: UAVariable) => DataValue;
Expand Down
2 changes: 1 addition & 1 deletion packages/node-opcua-address-space/source/pseudo_session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export class PseudoSession implements IBasicSession {
const r = this[$addressSpace].browseSingleNode(nodeId, _browseDescription, this[$context]);
results.push(r);
}
callack(null, results);
callack!(null, results);
};

setImmediate(() => {
Expand Down
50 changes: 25 additions & 25 deletions packages/node-opcua-address-space/src/address_space.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,17 @@ import { ExtraDataTypeManager } from "node-opcua-client-dynamic-extension-object
import { DataTypeIds, VariableTypeIds } from "node-opcua-constants";
import { BrowseDirection, NodeClass, QualifiedName } from "node-opcua-data-model";
import { ExtensionObject } from "node-opcua-extension-object";
import { coerceExpandedNodeId, coerceNodeId, INodeId, makeNodeId, NodeId, NodeIdLike, NodeIdType, resolveNodeId, sameNodeId } from "node-opcua-nodeid";
import {
coerceExpandedNodeId,
coerceNodeId,
INodeId,
makeNodeId,
NodeId,
NodeIdLike,
NodeIdType,
resolveNodeId,
sameNodeId
} from "node-opcua-nodeid";
import { ObjectRegistry } from "node-opcua-object-registry";
import { BrowseResult } from "node-opcua-service-browse";
import { StatusCodes } from "node-opcua-status-code";
Expand Down Expand Up @@ -474,9 +484,9 @@ export class AddressSpace implements AddressSpacePrivate {
if (!(dataTypeNode instanceof UADataTypeImpl)) {
throw new Error(
"we are expecting an UADataType here : " +
_orig_dataTypeNode.toString() +
" should not refer to a " +
(dataTypeNode as BaseNode).browseName.name
_orig_dataTypeNode.toString() +
" should not refer to a " +
(dataTypeNode as BaseNode).browseName.name
);
}

Expand Down Expand Up @@ -768,18 +778,18 @@ export class AddressSpace implements AddressSpacePrivate {
// tslint:disable:no-console
console.log(
chalk.red("ERROR : AddressSpace#constructEventData(eventType,options) " + "cannot find property ") +
self.browseName.toString() +
" => " +
chalk.cyan(lowerName)
self.browseName.toString() +
" => " +
chalk.cyan(lowerName)
);
} else {
console.log(
chalk.yellow(
"Warning : AddressSpace#constructEventData(eventType,options)" + " cannot find property "
) +
self.browseName.toString() +
" => " +
chalk.cyan(lowerName)
self.browseName.toString() +
" => " +
chalk.cyan(lowerName)
);
}
}
Expand All @@ -796,11 +806,11 @@ export class AddressSpace implements AddressSpacePrivate {
if (!alreadyVisited(k)) {
throw new Error(
" cannot find property '" +
k +
"' in [ " +
Object.keys(visitedProperties).join(", ") +
"] when filling " +
eventTypeNode.browseName.toString()
k +
"' in [ " +
Object.keys(visitedProperties).join(", ") +
"] when filling " +
eventTypeNode.browseName.toString()
);
}
});
Expand Down Expand Up @@ -1090,16 +1100,6 @@ export class AddressSpace implements AddressSpacePrivate {
}
}

/**
*
* @method browseSingleNode
* @param nodeId {NodeId|String} : the nodeid of the element to browse
* @param browseDescription
* @param browseDescription.browseDirection {BrowseDirection} :
* @param browseDescription.referenceTypeId {String|NodeId}
* @param [session]
* @return {BrowseResult}
*/
public browseSingleNode(nodeId: NodeIdLike, browseDescription: BrowseDescription, context?: ISessionContext): BrowseResult {
const browseResult: BrowseResultOptions = {
continuationPoint: undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ export function subtest_analog_item_type(maintest: any): void {
referenceTypeId: 0,
resultMask: 0x3f
});
// xx var browseResult = engine.browseSingleNode(analogItem.nodeId, browseDescription);
const references = analogItem.browseNode(browseDescription);

references.length.should.eql(6);
Expand Down
6 changes: 6 additions & 0 deletions packages/node-opcua-server/source/addressSpace_accessor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@


interface AddressSpaceAccessor {


}
43 changes: 22 additions & 21 deletions packages/node-opcua-server/source/opcua_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ export class OPCUAServer extends OPCUABaseServer {
* the maximum number of subscription that can be created per server
* @deprecated
*/
public static deprectated_MAX_SUBSCRIPTION = 50;
public static deprecated_MAX_SUBSCRIPTION = 50;

/**
* the maximum number of concurrent sessions allowed on the server
Expand Down Expand Up @@ -1156,7 +1156,7 @@ export class OPCUAServer extends OPCUABaseServer {
const hostname = getFullyQualifiedDomainName();

endpointDefinitions.push({
port: options.port === undefined ? 26543 : options.port,
port: options.port === undefined ? 26543 : options.port,

allowAnonymous: options.allowAnonymous,
alternateHostname: options.alternateHostname,
Expand Down Expand Up @@ -1328,7 +1328,7 @@ export class OPCUAServer extends OPCUABaseServer {
const shutdownTime = new Date(Date.now() + timeout);
this.engine.setShutdownTime(shutdownTime);

debugLog("OPCUAServer is now unregistering itself from the discovery server " + this.buildInfo);
debugLog("OPCUAServer is now un-registering itself from the discovery server " + this.buildInfo);
this.registerServerManager!.stop((err?: Error | null) => {
debugLog("OPCUAServer unregistered from discovery server", err);
setTimeout(async () => {
Expand Down Expand Up @@ -2667,19 +2667,20 @@ 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");
results = this.engine.read(context, request);

assert(results[0].schema.name === "DataValue");
assert(results.length === request.nodesToRead!.length);
this.engine.readAsync(context, request).then((results) => {
assert(results[0].schema.name === "DataValue");
assert(results.length === request.nodesToRead!.length);

response = new ReadResponse({
diagnosticInfos: undefined,
results: undefined
response = new ReadResponse({
diagnosticInfos: undefined,
results: undefined
});
// set it here for performance
response.results = results;
assert(response.diagnosticInfos!.length === 0);
sendResponse(response);

});
// set it here for performance
response.results = results;
assert(response.diagnosticInfos!.length === 0);
sendResponse(response);
});
}
);
Expand Down Expand Up @@ -3534,7 +3535,7 @@ export class OPCUAServer extends OPCUABaseServer {
}
const hostname = getFullyQualifiedDomainName();
endpointOptions.hostname = endpointOptions.hostname || hostname;
endpointOptions.port = endpointOptions.port === undefined ? 26543 : endpointOptions.port ;
endpointOptions.port = endpointOptions.port === undefined ? 26543 : endpointOptions.port;

/* istanbul ignore next */
if (
Expand Down Expand Up @@ -3697,7 +3698,7 @@ export interface RaiseEventAuditActivateSessionEventData extends RaiseEventAudit
}

// tslint:disable:no-empty-interface
export interface RaiseEventTransitionEventData extends RaiseEventData { }
export interface RaiseEventTransitionEventData extends RaiseEventData {}

export interface RaiseEventAuditUrlMismatchEventTypeData extends RaiseEventData {
endpointUrl: PseudoVariantString;
Expand Down Expand Up @@ -3727,7 +3728,7 @@ export interface RaiseAuditCertificateDataMismatchEventData extends RaiseAuditCe
*/
invalidUri: PseudoVariantString;
}
export interface RaiseAuditCertificateUntrustedEventData extends RaiseAuditCertificateEventData { }
export interface RaiseAuditCertificateUntrustedEventData extends RaiseAuditCertificateEventData {}
/**
* This EventType inherits all Properties of the AuditCertificateEventType.
*
Expand All @@ -3739,7 +3740,7 @@ export interface RaiseAuditCertificateUntrustedEventData extends RaiseAuditCerti
* There are no additional Properties defined for this EventType.
*
*/
export interface RaiseAuditCertificateExpiredEventData extends RaiseAuditCertificateEventData { }
export interface RaiseAuditCertificateExpiredEventData extends RaiseAuditCertificateEventData {}
/**
* This EventType inherits all Properties of the AuditCertificateEventType.
*
Expand All @@ -3749,7 +3750,7 @@ export interface RaiseAuditCertificateExpiredEventData extends RaiseAuditCertifi
*
* There are no additional Properties defined for this EventType.
*/
export interface RaiseAuditCertificateInvalidEventData extends RaiseAuditCertificateEventData { }
export interface RaiseAuditCertificateInvalidEventData extends RaiseAuditCertificateEventData {}
/**
* This EventType inherits all Properties of the AuditCertificateEventType.
*
Expand All @@ -3759,7 +3760,7 @@ export interface RaiseAuditCertificateInvalidEventData extends RaiseAuditCertifi
* If a trust chain is involved then the certificate that failed in the trust chain should be described.
* There are no additional Properties defined for this EventType.
*/
export interface RaiseAuditCertificateUntrustedEventData extends RaiseAuditCertificateEventData { }
export interface RaiseAuditCertificateUntrustedEventData extends RaiseAuditCertificateEventData {}
/**
* This EventType inherits all Properties of the AuditCertificateEventType.
*
Expand All @@ -3782,7 +3783,7 @@ export interface RaiseAuditCertificateRevokedEventData extends RaiseAuditCertifi
*
* There are no additional Properties defined for this EventType
*/
export interface RaiseAuditCertificateMismatchEventData extends RaiseAuditCertificateEventData { }
export interface RaiseAuditCertificateMismatchEventData extends RaiseAuditCertificateEventData {}
export interface OPCUAServer {
/**
* @internal
Expand Down

0 comments on commit f4dfe99

Please sign in to comment.