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

This example modifies a field by a configurable factor, affecting its value in the update packet sent between modules and then published onto DataSource

Note
This example has been written using the legacy API.

Sample configuration:

symbols         /DEMO/*
modify-field    Bid
modify-factor   2.0

Source code:

/*
* Transformer - Sample Module
*
* Copyright CAPLIN Systems Ltd 2000-2006
*
* This module modifies the value of a field by a certain factor. This
* modified value is then published onto DataSource by the Transformer core
*
*/
#include "transformer.h"
static char **symbols = NULL;
static int symbols_num = 0;
static char *modify_field = "dBestBid";
static double modify_factor = 2.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 modify */
ds_config_add_option(0,"modify-field","Fieldname to modify",DS_CONFIG_STR,&modify_field);
/* Add a config option for the modification factor */
ds_config_add_option(0,"modify-factor","Modification factor",DS_CONFIG_FLOAT,&modify_factor);
/* 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 newvalue_buf[256];
char *value_str;
double value;
/* If the Transformer is running in broadcast mode then we must indicate that any update received
by the Transformer from the source of data is sent onto its peers. We can do this
by setting the SYMBOL_PUBLISH flag on the flags within the Core. We achieve this
using the symbol_create() function call which creates the object if it doesn't
exist (it does in this case) and then sets the flags.
This flag implies that all packets generated by the core for this particular symbol
are meant to be published (automatically in the case of broadcast, or upon peer
request for active mode)
*/
/* Pick out the required field within this received update */
if ( ( value_str = packet_get_field_byname(pkt,modify_field) ) != NULL ) {
value = atof(value_str);
/* Now scale the value appropriately */
value *= modify_factor;
/* Print the (scaled) value into a buffer */
snprintf(newvalue_buf,sizeof(newvalue_buf),"%f",value);
/* Now, update the field in the original packet. This value will then
be propogated through the subsequent modules in the Transformer system. This
packet will then be published onto DataSource (if broadcast or active and requested)
*/
packet_update_field_byname(pkt,modify_field,newvalue_buf);
}
return;
}

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