tc-context
Version:
TwinCAT ADS Communication Library for creating an active TwinCAT Context, with automatic symbol and type mapping
209 lines • 9.84 kB
TypeScript
/**
* Module containing the Type Registry, responsible for fetching the ADS Type Data through the {@link TcContext} Component, processing it
* and building a Type Map, which can be used later for Symbol Generation.
*
*
* Licensed under MIT License.
*
* Copyright (c) 2020 Dmitrij Trifanov <d.v.trifanov@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* @packageDocumentation
*/
import { TcType } from './tc-type';
import { TcContext } from './tc-context';
import { TcEmitter, TcTypeRegistryCreatedEvent, TcTypeRegistryDestroyedEvent } from './tc-event';
/**
* Class responsible for creating and managing the TwinCAT Type Map, which is fetched
* from the TwinCAT's ADS layer.
*/
export declare class TcTypeRegistry extends TcEmitter {
/**
* Constructor, which uses the {@link TcContext}'s {@link TcCom} Object for ADS Communication
*
* @param context - Parent {@link TcContext}, of whom `TcTypeRegistry` is a part of, and whom to propagate events to
* @param debug - If enabled, will produce debug information
*/
constructor(context: TcContext, debug?: boolean);
/**
* Creates the Type Map, by querying data through {@link TcContext}'s {@link TcCom} Object and processing it.
* TcCom must be in a valid state before the Type Map creation can be made.
*
* @throws {@link TcComIsInvalidException} - TcCom has not been initialized before creating Type Map
* @throws {@link TcComTypeQueryException} - Failed to query Type Data
* @throws {@link TcComToRawException} - Error occurred when transforming value to raw data
*
*/
create(): Promise<void>;
/**
* Destroys the previously created Type Map
*/
destroy(): void;
/**
* Registers a {@link TcType} created Object as part of the Type Map, under the provided name
*
* @param name - The Type Name of the created `TcType` Object
* @param type - The created `TcType` Object to register with the Type Map
*
*/
register(name: string, type: TcType): void;
/**
* Returns a {@link TcType} of the provided name from the Type Map. If Type does not exist
* in the Type Map, returns undefined
*
* @param name - The name of the `TcType` to get
*
* @return - Either that Type Data under the provided name, or `undefined` if Type does not exist
*/
has(name: string): TcType | undefined;
/**
* Emitted when `TcTypeRegistry` creates the Type Map
* @event created
*/
on(event: 'created', listener: (e: TcTypeRegistryCreatedEvent) => void): any;
/**
* Emitted when `TcTypeRegistry` destroys the Type Map
* @event destroyed
*/
on(event: 'destroyed', listener: (e: TcTypeRegistryDestroyedEvent) => void): any;
/**
* Internal function for processing and registering a `TcType` based on the ADS Type Data collected
* previously. If Type is not bindable, it is ignored and not registered.
*
* @param adsTypeData - The ADS Type Data to process and potentially register
* @param adsTypeDataMap - The full map of ADS Type Data, for parent/child analysis
*
* @throws {@link TcComIsInvalidException} - Attempting to use an invalidated `TcCom` Object
* @throws {@link TcComToRawException} - Error occurred when transforming value to raw data
*
* @return - Either the newly registered `TcType`, or `undefined`, if registration failed
*/
private __adsTypeRegister;
/**
* Internal function for processing ADS Type Data, after it was initially filtered.
*
* @param adsTypeData - The ADS Type Data to process
* @param adsTypeDataMap - The full map of ADS Type Data, for parent/child analysis
*
* @throws {@link TcComIsInvalidException} - Attempting to use an invalidated `TcCom` Object
* @throws {@link TcComToRawException} - Error occurred when transforming value to raw data
*
* @return - Either the created `TcType` from the ADS Type Data, or `undefined`, if the Type is not bindable
*/
private __adsTypeProcess;
/**
* Internal function for checking if an ADS Type Data has a parent, and if so, will attempt to
* register that parent
*
* @param adsTypeData - The ADS Type, whose parent is evaluated
* @param adsTypeDataMap - The full map of ADS Type Data, for parent/child analysis
*
* @throws {@link TcComIsInvalidException} - Attempting to use an invalidated `TcCom` Object
* @throws {@link TcComToRawException} - Error occurred when transforming value to raw data
*
* @return - Either the processed parent's registered `TcType` Object, or `undefined` if that processing has failed
*/
private __adsTypeProcessParent;
/**
* Internal function for checking if an ADS Type Data has children, and if so, will attempt to
* register all the children associated with this ADS Type
*
* @param adsTypeData - The ADS Type, whose children are evaluated
* @param adsTypeDataMap - The full map of ADS Type Data, for parent/child analysis
*
* @throws {@link TcComIsInvalidException} - Attempting to use an invalidated `TcCom` Object
* @throws {@link TcComToRawException} - Error occurred when transforming value to raw data
*
* @return - List of registered `TcType` Children with their key. If no children were successfully registered - the list is empty
*/
private __adsTypeProcessChildren;
/**
* Internal function for deleting ADS Type Data entry from the full map of ADS Type Data
* Due to the non-linear pattern of registration, this is useful, as a means of preventing
* redundant looping
*
* @param adsTypeData - The ADS Type Data to delete from map
* @param adsTypeDataMap - The ADS Type Map from which the entry is deleted
*/
private __adsTypeDeleteEntry;
/**
* Internal function for deleting ADS Child Type Data from ADS Type.
* Due to the non-linear pattern of registration, this is useful, as a means of preventing
* redundant looping
*
* @param index - Index of the ADS Child Type to be deleted
* @param adsTypeData - The ADS Type from which the child is deleted
*/
private __adsTypeDeleteChild;
/**
* Internal function, which checks if the ADS Type Data is of type `Structure` or `Function_Block`
* @param adsTypeData - The ADS Type Data, which is checked for being of type `Structure` or `Function_Block`
*
* @return - Is true if ADS Type Data matched queried type
*/
private __adsTypeIsStruct;
/**
* Internal function, which checks if the ADS Type Data is of type `BOOL`
* @param adsTypeData - The ADS Type Data, which is checked for being of type `BOOL`
*
* @return - Is true if ADS Type Data matched queried type
*/
private __adsTypeIsBit;
/**
* Internal function, which checks if the ADS Type Data is of type `STRING`
* @param adsTypeData - The ADS Type Data, which is checked for being of type `STRING`
*
* @return - Is true if ADS Type Data matched queried type
*/
private __adsTypeIsString;
/**
* Internal function, which checks if the ADS Type Data is of type Integer or Floating Point Number
* @param adsTypeData - The ADS Type Data, which is checked for being of type Integer or Floating Point Number
*
* @return - Is true if ADS Type Data matched queried type
*/
private __adsTypeIsNumber;
/**
* Internal function, which check if the provided ADS Type Data, has a parent associated
* with it
*
* @param adsTypeData - The ADS Type to check for parent presence
* @param adsTypeDataMap - The full ADS Type Map, where the parent's existence is checked
*
* @return - The parents ADS Type Data if it exists, else `undefined`
*/
private __adsTypeHasParent;
/**
* Internal function, which filters out Pointers and References
*
* @param adsTypeData - The ADS Type Data, which is checked for being either a Pointer or a Reference
*
* @return - Is true if the passed ADS Type Data is of type Pointer or Reference
*/
private __adsTypeIsPointerOrReference;
/**
* Will store the created Type Map
* @internal
*/
private __map;
/**
* The `TcContext`, which acts as a parent to the `TcTypeRegistry` and to whom events are propagated
* @internal
*/
private __context;
/**
* @internal
*/
private __log;
}
//# sourceMappingURL=tc-type-registry.d.ts.map