Transformer SDK For C  7.1.9.29929-d422075
demo-delete.c

This example demonstrates how to publish a derived symbol when a base symbol has a field value within a configured range. If the field value is outside of the range the symbol is deleted.

Note
This example has been written using the legacy API.

Sample configuration:

symbols    /DEMO/*

check-field     Bid

check-upper     10
check-lower     5

Source code:

/*
* Transformer - Sample Module
*
* Copyright CAPLIN Systems Ltd 2000-2006
*
* This module example demonstrates how to publish a derived symbol when the base
* symbol has a field value with certain criteria. When the field value is outside
* the configured ranges, the symbol is deleted.
*
* The module will send out duplcate DELETEOBJECT messages if the field value is
* outside of the configured range for consecutive updates.
*
*/
#include "transformer.h"
static char **symbols = NULL;
static int symbols_num = 0;
static char *check_field = "dBestBid";
static double check_upper = 2.0;
static double check_lower = 1.0;
static void demo_recv_update(int feed, ds_data_t *pkt, time_t arr_tim, int id, void *data);
void mod_init(char *module_name)
{
char buf[FILENAME_MAX+1];
int i;
/* Add config option for the symbols we want to receive */
ds_config_add_array_option("symbols","Symbols to process",DS_CONFIG_STR_ARRAY,&symbols,&symbols_num);
/* Add a config option for which field to check */
ds_config_add_option(0,"check-field","Fieldname to modify",DS_CONFIG_STR,&check_field);
/* Add a config option for the ranges */
ds_config_add_option(0,"check-upper","Upper value for range",DS_CONFIG_FLOAT,&check_upper);
ds_config_add_option(0,"check-lower","Lower value for range",DS_CONFIG_FLOAT,&check_lower);
/* Load a config file based on the name of the module */
snprintf(buf,sizeof(buf),"%s.conf",module_name);
/* Check whether any symbols are required, if not then log this condition to the main Transformer
log file
*/
if ( symbols_num == 0 ) {
ds_printf_time(rtas_log,"(%s) No symbols required\n",module_name);
return;
}
/* Now register an interest in the symbols */
for ( i = 0; i < symbols_num; i++ ) {
register_interest(symbols[i],demo_recv_update,0,NULL);
}
return;
}
static void demo_recv_update(int feed, ds_data_t *pkt, time_t arr_tim, int id, void *data)
{
char derived_subject[1024];
ds_data_t *dsdata;
char *value_str;
double value;
/* Check to see if the update packet has a F_DELETEOBJECT flag on it, if so then
* we should perform no processing on it. Our interest is automatically deregistered
* by the Transformer core
*/
if ( pkt->flags & F_DELETEOBJECT ) {
return;
}
/* Prepare the derived subject */
snprintf(derived_subject,sizeof(derived_subject),"%s-DERIVED",pkt->subject);
/* Pick out the required field within this update */
if ( ( value_str = packet_get_field_byname(pkt,check_field) ) != NULL ) {
value = atof(value_str);
/* Check to see if the field value is out of range */
if ( value < check_lower || value > check_upper ) {
/* If it was out of range then send a delete object through. If the Transformer
* is in active move then a F_DELETEOBJECT message will be sent to interested peers.
*/
return;
} else {
/* We had the field within the update so, publish the entire update out under the
* derived symbol name
*/
/* Create a duplicate of the input packet */
dsdata = packet_clone(pkt);
/* And make the subject the derived name */
free(dsdata->subject);
dsdata->subject = strdup(derived_subject);
/* Publish the derived update to Datasource and cache within the Transformer core
* memory
*/
}
}
return;
}

Generated on Mon Jul 20 2020 19:17:22 for Transformer SDK For C