API Documentation

Node Template

The PolySync Node Template API includes the main entry and exit points for PolySync nodes. The API defines a structure that holds the callback function pointers for each of the states in the PolySync node state machine.

Usage #include <polysync_node_template.h>

Functions

psync_node_main_entry ( … )

This will initialize the PolySync node template and the node state machine. It creates a new PolySync node for the template.

Nodes will gracefully terminate if given the SIGINT signal, either by another process or itself.

Clears node flag: NODE_FLAG_HANDLERS_ACTIVE.

Parameters
in/out type name description
in const ps_node_callbacks * const callbacks A pointer to ps_node_callbacks that specifies each of the node state callbacks.
in const int arg_cnt The argument count from the host.
in char ** const arg_list The argument list from the host.
Returns
  • DTC Code:
    • DTC_NONE - Node ran and was terminated successfully
    • DTC_USAGE - Callbacks or arguments were invalid
    • DTC_CONFIG - Node configuration was invalid
    • DTC_LICERR - No license available for the given configuration
    • DTC_PROTOCOL - API versions mismatch or other nodes on the domain with conflicting data models
    • DTC_OSERR - Failed to initialize system resources
    • DTC_MEMERR - Failed to allocate system resources

psync_node_signal_main_exit ( … )

This will signal the node template to terminate gracefully.

Parameters

This function takes no parameters.

Returns
  • void

Structures

ps_node_configuration_data

The node configuration data container.

Fields
Data Type Name Description
const int arg_cnt Count of arguments passed via command line.
const char ** arg_list Arguments passed via command line.
char[ PSYNC_DEFAULT_STRING_LEN ] node_name Node name set by user via psync_init.
ps_node_type node_type Node type set by user via psync_init.
unsigned long domain_id Node domain set by user via psync_init.
unsigned long sdf_key Node SDF key set by user via psync_init
unsigned long flags Node configuration flags set by user via psync_init.
void * user_data User data set by user.

ps_node_callbacks

The node template state machine callback data.

Fields
Data Type Name Description
psync_node_set_configuration_callback set_config Required function provided by user to set node configuration.
psync_node_on_state_callback on_init Required function provided by user to handle the node’s initialization state.
psync_node_on_state_callback on_ok Required function provided by user to handle the node’s OK state.
psync_node_on_state_callback on_warn Required function provided by user to handle the node’s WARN state.
psync_node_on_state_callback on_error Required function provided by user to handle the node’s ERROR state.
psync_node_on_state_callback on_fatal Required function provided by user to handle the node’s FATAL state.
psync_node_on_state_callback on_release Required function provided by user that is called once on node exit.

Typedefs

psync_node_on_state_callback

This is a convenient typedef of the function signature that is required for the node state handlers.

A node that implements the full node template does so by providing a psync_node_on_state_callback function for each of the following states:

Node State Description
on_init Called once after node transitions into the INIT state.
on_ok Called continuously while in OK state.
on_warn Called continuously while in WARN state.
on_error Called continuously while in ERROR state.
on_fatal Called continuously while in FATAL state.
on_release Called once on node exit.
Parameters
in/out type name description
in ps_node_ref node_ref Reference to the node.
in const ps_diagnostic_state * const state A pointer to ps_diagnostic_state that stores the current state of the node.
in void * const user_data A pointer to user data that is provided by the user during configuration.

psync_node_set_configuration_callback

This is a convenient typedef of the function signature that can be used once after the node transitions into the AUTH state. This will happen near the start of the program, before any PolySync related tasks.

If the host provides command line arguments, then they will be set and available for parsing (i.e. getopts).

The user data pointer should be set at this point if used.

Parameters
in/out type name description
in ps_node_configuration_data * const node_config A pointer to ps_node_configuration_data that specifies the configuration.
Returns