s7webserverapi
Version:
Unofficial Simatic-S7-Webserver JSON-RPC-API Client for S7-1200/1500 PLCs
105 lines (104 loc) • 3.68 kB
TypeScript
import { Subject } from "rxjs";
import { FlattenKeys, S7DataTypes } from "../util/types";
/**
* Prefix-Trie implementation for storing subscribers.
* Since we call the PLC/HMI-Vars with a flattened-key e.g. "test.key.value" but we also are able to subscribe to an object instead of a leaf value, we store the subscribers in a trie.
*
* With that we call all subscribers of a key, when either the key itself or a children changes.
*
* @export
* @class SubscriberTrie
* @typedef {SubscriberTrie}
* @template FlattenKeyType
*/
export declare class SubscriberTrie<FlattenKeyType> {
/**
* Root node of the trie
*
* @type {SubscriberTrieNode<FlattenKeyType>}
*/
root: SubscriberTrieNode<FlattenKeyType>;
/**
* Creates an instance of SubscriberTrie.
*
* @constructor
*/
constructor();
private parseFlattenedKey;
/**
* returns the subscriber at that key, if it exists.
*
* @param {FlattenKeys<FlattenKeyType>} keyString
* @returns {Subject<{value:PLCConnectorDataTypes, changedKey: string}> | undefined}
*/
get(keyString: FlattenKeys<FlattenKeyType>): Subject<{
value: S7DataTypes;
changedKey: string;
}>;
getSubscriptionCountMap(): Map<string, number>;
getSubscriptionCountMapRecursive(value: SubscriberTrieNode<FlattenKeyType>, key: string | number, map: Map<string, number>): void;
incrementSubscriberCount(key: FlattenKeys<FlattenKeyType>): void;
decrementSubscriberCount(key: FlattenKeys<FlattenKeyType>): void;
/**
* Checks if a subscriber at the key exists.
* Important: It checks for the subscriber, not if the key exists in the trie.
*
* @param {FlattenKeys<FlattenKeyType>} key
* @returns {boolean}
*/
has(key: FlattenKeys<FlattenKeyType>): boolean;
/**
* Inserts a new key into the trie and automatically creates a subscriber.
* Every key only has one subscriber.
*
* @param {FlattenKeys<FlattenKeyType>} key
*/
insert(key: FlattenKeys<FlattenKeyType>): void;
/**
* Notifies all subscriber of the key with all its parent-prefixes.
*
* E.g if we call notifySubscriber("test.key.value"); We call the subscribers for test, for test.key and for test.key.value (if they exist)
*
* The data key is put into this function as a helper, because we need to notify the subscriber with the respective data.
* The data-object has to follow the strucutre of the trie or rather of the key that is notified.
*
* If the key is "test.key.value" and the data is {test: {key: {value:1}}}. test.key is notified with {value: 1} and test.key.value is notified with 1
*
*
* @param {FlattenKeys<FlattenKeyType>} key
* @param {PLCConnectorKeys<PLCConnectorDataTypes>} data
*/
notifySubscriber(key: FlattenKeys<FlattenKeyType>, data: S7DataTypes): void;
}
/**
* Node of the subscriber trie
*
* @export
* @class SubscriberTrieNode
* @typedef {SubscriberTrieNode}
* @template FlattenKeyType
*/
export declare class SubscriberTrieNode<FlattenKeyType> {
/**
* The subscriber-subject
*
* @type {(Subject<PLCConnectorDataTypes> | undefined)}
*/
subscriber: Subject<{
value: S7DataTypes;
changedKey: string;
}> | undefined;
/**
* Map of the children for the trie
*
* @type {Map<string | number, SubscriberTrieNode<FlattenKeyType>>}
*/
children: Map<string | number, SubscriberTrieNode<FlattenKeyType>>;
subscriberCount: number;
/**
* Creates an instance of SubscriberTrieNode.
*
* @constructor
*/
constructor();
}