External C/C++ functions must conform to the interface of the SAP Sybase Event Stream Processor by following the datatype, argument/return value, and output requirements.
Write the function signature to the Event Stream Processor interface:
int32_t funcName (int numargs, DataValue::DataValue * top, DataValue::DataValue * nextArgs, std::vector<void *> & arena)
The Event Stream Processor passes each function argument as a DataValue and expects to receive the return value as DataValue. The DataValue is a structure that includes all the datatypes understood by Event Stream Processor and is defined in DataValue.hpp, which is located in $ESP_HOME\include. The DataValue structure has this definition:
struct DataValue { union { bool booleanv; int16_t int16v; int32_t int32v; int64_t int64v; interval_t intervalv; money_t moneyv; double doublev; time_of_day_t timev; time_t datev; timestampval_t timestampv; const char * stringv; hirestime_t bigdatetimev; binary_t binaryv; fixeddecimal_t fixeddecimalv; void * objectv; } bool null; }
This variable points to the first byte of the data in the buffer.
This variable defines the length of data used in the buffer.
If the function allocates memory by calling malloc or calloc, the Event Stream Processor can release the memory after it has processed the record by adding the memory to the arena. The arena is the last argument to the function and is defined as vector of type void *. You cannot add a pointer to the memory allocated by new to the arena; doing so can corrupt the memory and cause an unrecoverable error.
Ensure the function returns an error code to indicate successful completion of the function. The return value is of type int32_t. A value of 0 indicates no error; any other values indicate an error. When an error occurs, Event Stream Processor rejects the current record.