How to use the node-opcua-debug.checkDebugFlag function in node-opcua-debug

To help you get started, we’ve selected a few node-opcua-debug examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github node-opcua / node-opcua / packages / node-opcua-server / source / server_publish_engine.ts View on Github external
// tslint:disable:no-console
import * as chalk from "chalk";
import { EventEmitter } from "events";
import * as _ from "underscore";

import { assert } from "node-opcua-assert";
import { checkDebugFlag, make_debugLog } from "node-opcua-debug";
import { ObjectRegistry } from "node-opcua-object-registry";
import { StatusCode, StatusCodes } from "node-opcua-status-code";

import { PublishRequest, PublishResponse, SubscriptionAcknowledgement } from "node-opcua-types";
import { Subscription } from "./server_subscription";
import { SubscriptionState } from "./server_subscription";

const debugLog = make_debugLog(__filename);
const doDebug = checkDebugFlag(__filename);

function traceLog(...args: [any?, ...any[]]) {
    if (!doDebug) {
        return;
    }
    const a: string[] = args.map((x?: any) => x!);
    a.unshift(chalk.yellow(" TRACE "));
    console.log.apply(null, a as [any?, ...any[]]);
}

export interface ServerSidePublishEngineOptions {
    maxPublishRequestInQueue?: number;
}

interface PublishData {
    request: PublishRequest;
github node-opcua / node-opcua / packages / node-opcua-server / source / server_publish_engine_for_orphan_subscriptions.ts View on Github external
/**
 * @module node-opcua-server
 */
// tslint:disable:no-console
import * as chalk from "chalk";

import { checkDebugFlag, make_debugLog } from "node-opcua-debug";

import { ServerSidePublishEngine } from "./server_publish_engine";
import { Subscription } from "./server_subscription";

const debugLog = make_debugLog(__filename);
const doDebug = checkDebugFlag(__filename);

/**
 * the ServerSidePublishEngineForOrphanSubscription is keeping track of
 * live subscription that have been detached from timed out session.
 * It takes care of providing back those subscription to any session that
 * will claim them again with transferSubscription  service
 * It also make sure that subscription are properly disposed when  they expire.
 *
 * @internal
 */
export class ServerSidePublishEngineForOrphanSubscription extends  ServerSidePublishEngine {

    constructor(options: any) {
        super(options);
    }
github node-opcua / node-opcua / packages / node-opcua-schemas / source / dynamic_extension_object.ts View on Github external
import {
    BaseUAObject,
    check_options_correctness_against_schema,
    ConstructorFuncWithSchema,
    FieldCategory,
    FieldType,
    initialize_field,
    initialize_field_array,
    StructuredTypeSchema
} from "node-opcua-factory";

import { ExpandedNodeId, NodeIdType } from "node-opcua-nodeid";
import { TypeDictionary } from "./parse_binary_xsd";

const debugLog = make_debugLog(__filename);
const doDebug = checkDebugFlag(__filename);

export function getOrCreateConstructor(
    fieldType: string,
    typeDictionary: TypeDictionary,
    encodingDefaultBinary?: ExpandedNodeId,
    encodingDefaultXml?: ExpandedNodeId
): AnyConstructorFunc {

    if (typeDictionary.hasStructuredType(fieldType)) {
        return typeDictionary.getStructureTypeConstructor(fieldType);
    }
    const schema = typeDictionary.structuredTypes[fieldType];

    // istanbul ignore next
    if (!schema) {
        throw new Error("Unknown type in dictionary " + fieldType);
github node-opcua / node-opcua / packages / node-opcua-client / src / client_base.js View on Github external
const _ = require("underscore");
const assert = require("node-opcua-assert").assert;
const once = require("once");
const delayed = require("delayed");


const endpoints_service = require("node-opcua-service-endpoints");

const GetEndpointsRequest = endpoints_service.GetEndpointsRequest;
const GetEndpointsResponse = endpoints_service.GetEndpointsResponse;
const MessageSecurityMode = require("node-opcua-service-secure-channel").MessageSecurityMode;
const toURI = require("node-opcua-secure-channel").toURI;
const SecurityPolicy = require("node-opcua-secure-channel").SecurityPolicy;

const debugLog = require("node-opcua-debug").make_debugLog(__filename);
const doDebug = require("node-opcua-debug").checkDebugFlag(__filename);

const OPCUASecureObject = require("node-opcua-common").OPCUASecureObject;

const ClientSecureChannelLayer = require("node-opcua-secure-channel/src/client/client_secure_channel_layer").ClientSecureChannelLayer;
const ClientSession = require("./client_session").ClientSession;


const defaultConnectionStrategy = {
    initialDelay: 1000,
    maxDelay: 20*1000,// 20 seconds
    maxRetry: -1, // infinite
    randomisationFactor: 0.1
};

/**
 * @class OPCUAClientBase
github node-opcua / node-opcua / packages / node-opcua-address-space / src / alarms_and_conditions / condition.js View on Github external
const BaseNode = require("../base_node").BaseNode;
const AttributeIds = require("node-opcua-data-model").AttributeIds;
const NodeClass = require("node-opcua-data-model").NodeClass;
const TimeZoneDataType = require("node-opcua-common").TimeZoneDataType;
const StateMachine = require("../state_machine/finite_state_machine").StateMachine;
const UATwoStateVariable = require("../ua_two_state_variable").UATwoStateVariable;

const resolveNodeId = require("node-opcua-nodeid").resolveNodeId;
const coerceLocalizedText = require("node-opcua-data-model").coerceLocalizedText;
const LocalizedText = require("node-opcua-data-model").LocalizedText;
const NodeId = require("node-opcua-nodeid").NodeId;

const EventData = require("../address_space_add_event_type").EventData;

const debugLog = require("node-opcua-debug").make_debugLog(__filename);
const doDebug = require("node-opcua-debug").checkDebugFlag(__filename);

const AddressSpace = require("../address_space").AddressSpace;
const Namespace = require("../namespace").Namespace;

const SessionContext = require("../session_context").SessionContext;

const utils = require("node-opcua-utils");

function _visit(self, node, prefix) {
    const aggregates = node.getAggregates();

    aggregates.forEach(function(aggregate) {
        if (aggregate instanceof UAVariable) {
            let name = aggregate.browseName.toString();
            name = utils.lowerFirstLetter(name);
github node-opcua / node-opcua / packages / node-opcua-client / source / client_session_keepalive_manager.ts View on Github external
import * as chalk from "chalk";
import { EventEmitter } from "events";
import { assert } from "node-opcua-assert";
import { ServerState } from "node-opcua-common";
import { VariableIds } from "node-opcua-constants";
import { DataValue } from "node-opcua-data-value";
import { checkDebugFlag, make_debugLog } from "node-opcua-debug";
import { coerceNodeId } from "node-opcua-nodeid";
import { ErrorCallback } from "node-opcua-secure-channel";
import { StatusCodes } from "node-opcua-status-code";
import { ClientSessionImpl } from "./private/client_session_impl";

const serverStatusStateNodeId = coerceNodeId(VariableIds.Server_ServerStatus_State);

const debugLog = make_debugLog(__filename);
const doDebug = checkDebugFlag(__filename);
const warningLog = debugLog;

const emptyCallback = (err?: Error) => {
};

export interface ClientSessionKeepAliveManagerEvents {
    on(event: "keepalive", eventHandler: (lastKnownServerState: ServerState) => void): ClientSessionKeepAliveManager;
}

export class ClientSessionKeepAliveManager extends EventEmitter implements ClientSessionKeepAliveManagerEvents {

    private readonly session: ClientSessionImpl;
    private timerId?: NodeJS.Timer;
    private pingTimeout: number;
    private lastKnownState?: ServerState;
    private checkInterval: number;
github node-opcua / node-opcua / packages / node-opcua-secure-channel / src / client / client_secure_channel_layer.js View on Github external
const ClientTCP_transport = require("node-opcua-transport").ClientTCP_transport;

const hexDump = require("node-opcua-debug").hexDump;

const StatusCodes = require("node-opcua-status-code").StatusCodes;
const crypto_utils = require("node-opcua-crypto");

const verify_message_chunk = require("node-opcua-chunkmanager").verify_message_chunk;
const MessageSecurityMode = require("node-opcua-service-secure-channel").MessageSecurityMode;

const backoff = require("backoff");

const debug = require("node-opcua-debug");
const debugLog = debug.make_debugLog(__filename);
const doDebug = debug.checkDebugFlag(__filename);

const get_clock_tick = require("node-opcua-utils").get_clock_tick;

const readMessageHeader = require("node-opcua-chunkmanager").readMessageHeader;

const MessageBuilder = require("../message_builder").MessageBuilder;
const messageHeaderToString = require("../message_header_to_string").messageHeaderToString;
const MessageChunker = require("../message_chunker").MessageChunker;
const secure_channel_service = require("../services");
const securityPolicy_m = require("../security_policy");
const SecurityPolicy = securityPolicy_m.SecurityPolicy;

const OpenSecureChannelRequest = secure_channel_service.OpenSecureChannelRequest;
const CloseSecureChannelRequest = secure_channel_service.CloseSecureChannelRequest;
const OpenSecureChannelResponse = secure_channel_service.OpenSecureChannelResponse;
const AsymmetricAlgorithmSecurityHeader = secure_channel_service.AsymmetricAlgorithmSecurityHeader;
github node-opcua / node-opcua / packages / node-opcua-client / source / private / client_publish_engine.ts View on Github external
import chalk from "chalk";
import { EventEmitter } from "events";
import * as _ from "underscore";

import { assert } from "node-opcua-assert";
import { checkDebugFlag, make_debugLog } from "node-opcua-debug";
import { PublishRequest, PublishResponse, RepublishRequest, RepublishResponse } from "node-opcua-service-subscription";
import { StatusCodes } from "node-opcua-status-code";

import { ClientSession, SubscriptionId } from "../client_session";
import { ClientSubscription } from "../client_subscription";
import { ClientSessionImpl } from "../private/client_session_impl";
import { ClientSubscriptionImpl } from "./client_subscription_impl";

const debugLog = make_debugLog(__filename);
const doDebug = checkDebugFlag(__filename);

/**
 * A client side implementation to deal with publish service.
 *
 * @class ClientSidePublishEngine
 * The ClientSidePublishEngine encapsulates the mechanism to
 * deal with a OPCUA Server and constantly sending PublishRequest
 * The ClientSidePublishEngine also performs  notification acknowledgements.
 * Finally, ClientSidePublishEngine dispatch PublishResponse to the correct
 * Subscription id callback
 *
 * @param session {ClientSession} - the client session
 *
 *
 * @constructor
 */
github node-opcua / node-opcua / packages / node-opcua-client / source / client_monitored_item_toolbox.ts View on Github external
MonitoredItemModifyRequest,
    MonitoredItemModifyResult,
    MonitoringMode, SetMonitoringModeResponse
} from "node-opcua-service-subscription";
import { StatusCode, StatusCodes } from "node-opcua-status-code";

import { MonitoredItemCreateRequestOptions } from "node-opcua-types";
import { ClientMonitoredItemBase } from "./client_monitored_item_base";
import { SetMonitoringModeRequestLike } from "./client_session";
import { ClientSubscription } from "./client_subscription";
import { Callback, ErrorCallback } from "./common";
import { ClientMonitoredItemImpl } from "./private/client_monitored_item_impl";
import { ClientSessionImpl } from "./private/client_session_impl";

const debugLog = make_debugLog(__filename);
const doDebug = checkDebugFlag(__filename);

/**
 * @internal
 */
export class ClientMonitoredItemToolbox {

    public static _toolbox_monitor(
        subscription: ClientSubscription,
        timestampsToReturn: TimestampsToReturn,
        monitoredItems: ClientMonitoredItemBase[],
        done: ErrorCallback
    ) {
        assert(_.isFunction(done));
        const itemsToCreate: MonitoredItemCreateRequestOptions[] = [];
        for (const monitoredItem of monitoredItems) {
github node-opcua / node-opcua / packages / node-opcua-factory / source / factories_factories.ts View on Github external
import { checkDebugFlag, make_debugLog } from "node-opcua-debug";
import { ExpandedNodeId } from "node-opcua-nodeid";

import { 
    DataTypeFactory, 
} from "./datatype_factory";
import { 
    ConstructorFuncWithSchema,
    ConstructorFunc 
} from "./constructor_type";

import { BaseUAObject } from "./factories_baseobject";
import { StructuredTypeSchema } from "./factories_structuredTypeSchema";

const debugLog = make_debugLog(__filename);
const doDebug = checkDebugFlag(__filename);

let globalFactory: DataTypeFactory;
export function getStandartDataTypeFactory(): DataTypeFactory {
    if (!globalFactory) {
        globalFactory = new DataTypeFactory([]);
        globalFactory.targetNamespace = "http://opcfoundation.org/UA/";
    }
    return globalFactory;
}
export function getStructureTypeConstructor(typeName: string): ConstructorFuncWithSchema {
    return getStandartDataTypeFactory().getStructureTypeConstructor(typeName);
}
export function hasStructuredType(typeName: string): boolean {
    return getStandartDataTypeFactory().hasStructuredType(typeName);
}
export function getStructuredTypeSchema(typeName: string): StructuredTypeSchema {