External C/C++ Function Requirements

External C/C++ functions must conform to the interface of the Sybase Event Stream Processor by following the datatype, argument/return value, and output requirements.

Syntax

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)

Datatype Requirements

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_t	datev;
		timestampval_t	timestampv;
		const char * stringv;
		hirestime_t	bigdatetimev;
		binary_t	binaryv;
		void * objectv;
	}
	bool null;
}
When the Boolean flag null is set to true, the value of the argument is NULL (the argument does not have a value). binary_t is a class with two public member variables defined as:
  • const uint8 t * _data;.

    This variable points to the first byte of the data in the buffer.

  • byte_size_t _used;.

    This variable defines the length of data used in the buffer.

    Note: Assign memory to _data using malloc or calloc, not new.
moneyv is a generic placeholder for money arguments with any scale; it must be told what scale a particular money argument has.

Argument and Return Value Requirements

Since the Event Stream Processor internal processing engine is a bytecode stack machine that keeps the top of the stack in a special location, ensure the Event Stream Processor splits function arguments into two:
  • A pointer to the top of the stack of type DataValue. The top of the stack points to the last argument when more than one argument is passed to the function and to the first argument if only one argument is passed. The first argument in the interface indicates the number of arguments passed.
  • A pointer to the rest of the arguments of type DataValue. The pointer points to the first argument when there is more than one argument passed to the function. It is undefined if the function has only one argument.
    Note: Write the return value of the function to the top of the stack.

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.

Output Requirement

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.