sysConnect()

The function allows to connect to specific system events.

Synopsis

int sysConnect([class object,] string|function_ptr work, string event]);

Parameters

Parameter Description
object Class in which the work function is located. Only necessary if sysConnect function is called from outside of the class.
work Work function that is called in case of the event being triggered
event Event on which should be connected

Return value

Returns 0, in case of an error -1 is returned.

Errors

missing/incorrect arguments

Description

The function allows to connect to specific system events and trigger a user defined callback function.

Following events are currently available:

Anmerkung: If a mapping is returned, the mapping key is always a string and the value data type is stated in () next to the mapping description.
"exitRequested"

This event is triggered the first time a CTRL manager is requested to exit, e.g. either by losing the connection to the event manager or by a stop request from pmon (e.g. project shutdown) or a SIGTERM signal.

Exiting is done in the following steps:

  1. stop all running scripts (threads/CTRL-modules)
  2. start "exitRequested" event callback threads
  3. disconnect everything (e.g. dpConnect, query connects, alertConnect, sysConnect)

When the last thread started for the exitRequest event will stop, the manager stops as well. Be careful that the started threads will not take too long, since on a project shutdown pmon will kill the CTRL manager when it does not terminate in the defined number of seconds (set via console panel). When a second exit request happens while the "exit requested" threads are still running, the manager will terminate immediately without starting any threads again.

The callback receives the exit code (int) as an argument

Anmerkung: Can only be used within the context of a CTRL manager.

Example

callback(string event, int exitCode)
"dpCreated", "dpDeleted"

The callback gets a mapping as data argument, which holds the following key/value pairs.

  • "dp"/(string) ... the datapoint name including the system
  • "dpType"/(string) ... the datapoint type name

Example

callback(string event, mapping data);
"dpRenamed"

Triggered when a name of a DP was changed. The callback gets a mapping as data argument, which holds the following key/value pairs.

  • "oldName"/(string)
  • "newName"/(string)
  • "dpType"/(string) ... the datapoint type name

The DP names include the system name.

"dpTypeCreated", "dpTypeDeleted"

The callback gets a mapping as data argument, which holds the following key/value pairs.

  • "system"/(int) ... the system number on which the dpType resides
  • "systemName"/(string) ... the system name on which the dpType resides
  • "dpType"/(string) ... the name of the dpType
"dpTypeChanged"

The callback gets a mapping as data argument, which holds the following key/value pairs.

  • "system"/(int) ... the system number on which the dpType resides
  • "systemName"/(string) ... the system name on which the dpType resides
  • "oldName"/(string) ... in case the dpType's name was changed, contains the old name
  • "newName"/(string) ... the current (new) name of the dpType
  • "dpType"/(string) ... the current (new) name of the dpType
"redu"

In a redundant system this event is always triggered when the active/passive status is changed. The callback receives a mapping as data argument with the following key/value pairs:

  • "reason"/(string) ... can be: "active", "passive"
  • "hostNum"/(int) ... 1 or 2 (1 = first redu host, 2 = second redu host), from which the status changed.

A manager which is connected to both redu event managers (UI or a CTRL with -connectToRedundantHosts) will trigger 2 callbacks, one for each connection.

"dist"

In a distributed system, this event is triggered when the status of any connection to another system changes. The callback receives a mapping as data argument with the following key/value pairs.

  • "reason"/(string) ... can be: "connected", "disconnected", "allDisconnected" when the reason is "allDisconnected", no other member is given in the mapping. For "allDisconnected" the local Dist manager also needs to be stopped.

For connected/disconnected 2 other keys will be present:

  • "systemName"/(string) ... the name of the other system
  • "system"/(int) ... the system number of the other system
"dpAlias"

The callback gets a mapping as data argument, which holds the following key/value pairs.

  • "dp"/(string) ... name of the dp element
  • "dpType"/(string) ... the datapoint type name
  • "oldName"/(string)
  • "newName"/(string)
"dpDescription"

The callback gets a mapping as data argument, which holds the following key/value pairs.

  • "dp"/(string) ... name of the dp element
  • "dpType"/(string) ... the datapoint type name
  • "oldText"/(langString)
  • "newText"/(langString)
"dpFormatUnit"

The callback gets a mapping as data argument, which holds the following key/value pairs.

  • "dp"/(string) ... name of the dp element
  • "dpType"/(string) ... the datapoint type name
  • "oldFormat"/(string)
  • "newFormat"/(string)
  • "oldUnit"/(string)
  • "newUnit"/(string)
"fswPathChanged"

The "fswPathChanged" is triggered of a file or folder that is monitored by the FileSystemWatcher is changed, renamed or removed and will return the path of the changed file or folder.

If a file or folder is renamed or removed the FileSystemWatcher will no longer monitor the file/folder. The renamed files or folders must be readded to the FileSystemWatcher by using the function fswAddPath().

For folders the event is triggered if:

  • A new file is added to the folder
  • A file is renamed within the folder
  • A file is removed from within the folder

For files the event is triggered if:

  • The content of a file changed
  • The file is renamed
  • The file is deleted
  • The folder containing the file is deleted

Example

main()
{
 fswAddPath("/tmp");
 fswAddPath("/someDir/someFile");
 sysConnect("pathChanged", "fswPathChanged");
}
pathChanged(string eventName, string path)
{
 DebugN(__FUNCTION__, path);
}

Assignment

Miscellaneous functions

Availability

UI, CTRL