Files
externals/linux/include/celoxica/ade.h
T

429 lines
15 KiB
C

/*
* Accelerated Input Library
*
* ai.h
*
* Created on: Nov 20, 2009
* Author: pb
*
*
* The application using ADE should be designed to call ALL the api functions
* from the same context.
*
* The ADELatencyTick is an exception.
*/
#ifndef ADE_H_
#define ADE_H_
#include "ade_version.h"
#include "config_file.h""
#include "register.h"
typedef enum {
ADE_STATUS_OK,
ADE_STATUS_CHANNEL_EOF,
ADE_STATUS_MALLOC_ERROR,
ADE_STATUS_NO_LINK,
ADE_STATUS_INIT_ERROR,
ADE_STATUS_PARAM_ERROR,
ADE_STATUS_RESOURCE_BUSY,
ADE_STATUS_UNHANDLED_STATE,
ADE_STATUS_BUFFER_FULL,
ADE_STATUS_EMULATION_FAILED,
ADE_STATUS_CHANNEL_DROPPED,
ADE_STATUS_NOT_READY,
ADE_STATUS_NO_CHANNELS,
ADE_STATUS_ARB_ERROR,
ADE_STATUS_NOT_SUPPORTED,
ADE_STATUS_CHANNEL_CLOSED,
ADE_STATUS_ACCEPTED,
ADE_STATUS_PACKET_DROPPED
} ADEStatus;
struct __ADEChannel;
typedef struct __ADEChannel ADEChannel;
struct __ADEHandle;
typedef struct __ADEHandle ADEHandle;
typedef ADEStatus (*ADEErrorHandler)(ADEHandle* _adeh, const char* _fnc, ADEStatus _status, const char* _message);
typedef struct {
uint64_t BytesRead; /** \brief Total bytes read on the channel */
uint64_t PacketsRead; /** \brief Total packets read on the channel */
uint64_t BytesWritten; /** \brief Total bytes written on the channel */
uint64_t PacketsWritten; /** \brief Total packets written on the channel */
//WARNING: to save computing resources, the following are computed
//only if ADE core was compiled with ADE_EXTENDED_CHANNEL_STATS defined
uint64_t BytesReadSquared;
uint64_t BytesWrittenSquared;
} ADEStats;
#ifdef __cplusplus
extern "C"
{
#endif
typedef uint64_t ADETimestamp;
struct __ADEPlugin;
typedef struct __ADEPlugin ADEPlugin;
typedef struct
{
unsigned int ID;
int Interface;
int QueueDescriptor;
int BoardNum;
int FirstMulticast;
ADEPlugin *Plugin;
ADEHandle *Handle;
const char *Market;
}
ADEPrealloc;
typedef unsigned ADEQueueID_t;
typedef enum
{
ADE_PROP_STOP = 0,
ADE_LLDT_GLOBAL_PROPS = 100,
ADE_AC_MAX_BOARDS,
ADE_AC_CUR_BOARD,
ADE_AC_REVERSION,
ADE_AC_VERSION_MAJOR,
ADE_AC_VERSION_MINOR,
ADE_AC_NAME,
ADE_AC_EMU_THREAD_CPU,
ADE_GLOBAL_PROPS_END,
ADE_QUEUE_PROPS = 1000,
ADE_QUEUE_LOG_VERBOSITY,
ADE_QUEUE_LOG_MASK,
ADE_LLDT_PROPS = 4000,
ADE_LLDT_CREDIT,
ADE_CLX_NG_PROPS = 5000,
ADE_CLX_NG_COOKIES,
ADE_CLX_NG_OPRA_VENUES,
ADE_CLX_NG_SHARED_PROPS = 6000,
ADE_CLX_NG_SHARED_COOKIES,
ADE_CLX_NG_SHARED_OPRA_VENUES,
ADE_FILE_PROPS = 8000,
ADE_SOCKET_PROPS = 9000,
ADE_PROP_MAX
} ADEProps_t;
typedef enum
{
ADE_PROP_TYPE_VOID,
ADE_PROP_TYPE_CHAR,
ADE_PROP_TYPE_UINT8,
ADE_PROP_TYPE_UINT16,
ADE_PROP_TYPE_UINT32,
ADE_PROP_TYPE_ENUM,
ADE_PROP_TYPE_UINT64,
ADE_PROP_TYPE_INT8,
ADE_PROP_TYPE_INT16,
ADE_PROP_TYPE_INT32,
ADE_PROP_TYPE_INT64,
ADE_PROP_TYPE_DOUBLE,
ADE_PROP_TYPE_STRING
} ADEPropType_t;
typedef struct
{
ADEProps_t Prop;
const char* Description;
ADEPropType_t Type;
} ADEPropDesc_t;
static const ADEPropDesc_t ADEPropToString [] __attribute__((unused)) = {
{ ADE_AC_MAX_BOARDS, "AC_MAX-BOARD", ADE_PROP_TYPE_UINT32 },
{ ADE_AC_CUR_BOARD, "AC_CURRENT-BOARD", ADE_PROP_TYPE_UINT32 },
{ ADE_AC_REVERSION, "AC-Reversion", ADE_PROP_TYPE_UINT32 },
{ ADE_AC_VERSION_MAJOR, "AC-Major", ADE_PROP_TYPE_UINT32 },
{ ADE_AC_VERSION_MINOR, "AC-Minor", ADE_PROP_TYPE_UINT32 },
{ ADE_AC_NAME, "AC-NAME", ADE_PROP_TYPE_STRING },
{ ADE_AC_EMU_THREAD_CPU, "EMU-Thread-CPU", ADE_PROP_TYPE_UINT64 },
{ ADE_QUEUE_LOG_VERBOSITY, "Verbosity", ADE_PROP_TYPE_UINT8 },
{ ADE_QUEUE_LOG_MASK, "DEBUG-Mask", ADE_PROP_TYPE_UINT64 },
{ ADE_LLDT_CREDIT, "Credit", ADE_PROP_TYPE_UINT32 },
{ ADE_CLX_NG_COOKIES, "Cookies" , ADE_PROP_TYPE_UINT32 },
{ ADE_CLX_NG_OPRA_VENUES, "Opra_Venues" , ADE_PROP_TYPE_UINT64 },
{ ADE_CLX_NG_SHARED_COOKIES, "Cookies(shared)" , ADE_PROP_TYPE_UINT32 },
{ ADE_CLX_NG_SHARED_OPRA_VENUES, "Opra_Venues(shared)" , ADE_PROP_TYPE_UINT64 },
{ ADE_PROP_MAX, "", ADE_PROP_TYPE_VOID }
};
typedef enum
{
ADE_OPRA_VENUE_NONE = 0,
ADE_OPRA_VENUE_NYSE_AMEX = 1 << 1,
ADE_OPRA_VENUE_BOX = 1 << 2,
ADE_OPRA_VENUE_CBOE = 1 << 3,
ADE_OPRA_VENUE_EDGX = 1 << 4,
ADE_OPRA_VENUE_ISE_GEMINI = 1 << 5,
ADE_OPRA_VENUE_ISE = 1 << 6,
ADE_OPRA_VENUE_ISE_MERCURY = 1 << 7,
ADE_OPRA_VENUE_MIAMI = 1 << 8,
ADE_OPRA_VENUE_NYSE_ARCA = 1 << 9,
ADE_OPRA_VENUE_OPRA = 1 << 10,
ADE_OPRA_VENUE_NASDAQ = 1 << 11,
ADE_OPRA_VENUE_OMX_BX = 1 << 12,
ADE_OPRA_VENUE_C2 = 1 << 13,
ADE_OPRA_VENUE_PHLX = 1 << 14,
ADE_OPRA_VENUE_BATS = 1 << 15,
ADE_OPRA_VENUE_MIAX_PEARL = 1 << 16
} ADEOpraVenue_t;
typedef enum
{
ADE_PLUGIN_CLXNG,
ADE_PLUGIN_CLXNG_SHARED,
ADE_PLUGIN_LLDT,
ADE_PLUGIN_SOCKET,
ADE_PLUGIN_FILE,
ADE_PLUGIN_NULL,
ADE_PLUGIN_DUMP,
ADE_PLUGIN_MAX
} ADEPluginType_t;
typedef struct
{
ADEPluginType_t type;
const char* desc;
} ADEPluginDesc_t;
static const ADEPluginDesc_t ADEPluginDesc[] __attribute__((unused)) = {
{ ADE_PLUGIN_CLXNG, "clxng" },
{ ADE_PLUGIN_CLXNG_SHARED, "clxng_shared" },
{ ADE_PLUGIN_LLDT, "lldt" },
{ ADE_PLUGIN_SOCKET, "socket" },
{ ADE_PLUGIN_FILE, "file" },
{ ADE_PLUGIN_NULL, "null" },
{ ADE_PLUGIN_DUMP, "dump" },
{ ADE_PLUGIN_MAX, "" }
};
ADEStatus ADEOpen(ADEHandle** _outHandle,
const ADEQueueID_t _queueId,
const int _verbosity);
ADEStatus ADEClose(ADEHandle* _handle);
ADEStatus ADEGetPropertyGlobal( ADEProps_t _firstProp, ...) __attribute__((sentinel));
ADEStatus ADESetPropertyGlobal( ADEProps_t _firstProp, ...) __attribute__((sentinel));
ADEStatus ADEGetProperty(ADEHandle* _handle, ADEProps_t _firstProp, ...) __attribute__((sentinel));
ADEStatus ADESetProperty(ADEHandle* _handle, ADEProps_t _firstProp, ...) __attribute__((sentinel));
/**
* \brief Attempt to read next ADE item
*
* This function is a used to read data from any ADEChannel owned by a single ADE handle.
*
* \note If the status returned is ADE_STATUS_CHANNEL_DROPPED or ADE_STATUS_CHANNEL_EOF the channel will be closed before
* this function returns.
*
* Socket plugin notes: Sockets can be opened in both server (listening) and client modes. When running in server mode
* this function will return an ADE status ADE_STATUS_OK and a length of zero while waiting for a
* client to connect. When a client connection is accepted this function will return ADE_STATUS_ACCEPTED.
* Once a client is connected the length returned should always be non-zero.
*
* Similarly client mode sockets are started in an asynchronous manner. Therefore, the socket may not
* be have reached the connected state when this function is called. Moreover, the socket may not
* start to receive data immediately when the socket reaches a connected state. Therefore, this function
* will return status ADE_STATUS_OK, length zero and a NULL data pointer until the connection reaches a
* connected state. When the connection reaches the connected state ADE_STATUS_OK will be returned
* with a non-NULL data pointer. If there is no data the length will be set to zero.
*
* Sockets have a timeout to ensure they reach a connected state in a timely manner. If a socket does
* not reach a connected state before the timeout expires this function will return
* ADE_STATUS_CHANNEL_DROPPED and the channel will be closed automatically (see note above). If the
* connection is dropped for any other reason the same is true. It is the users responsibility
* to reopen the channel if required.
*
* @param [in] H The ADE handle.
* @param [out] Channel The channel from which the data and/or status originates.
* @param [out] ChannelPrivate The private data for the channel.
* @param [out] Data The data returned if any.
* @param [out] Length The size of the data.
* @param [out] Timestamp ADE timestamp information.
*
* @return ADE_STATUS_OK on success, or applicable status code on error.
*/
ADEStatus ADERead(ADEHandle* _handle, ADEChannel** _channel, void** _channelPrivate,
void** _data, int* _length, ADETimestamp* _timestamp);
/**
* Checks is the plugin name is loaded
*/
ADEStatus ADEPluginIsLoaded(ADEHandle *H, char *Plugin, int *IsLoaded);
/**
* Uses the Log, for logging instead of standard output, if set
*/
ADEStatus ADEArbGroupOpen (const char *MarketName, int *GroupPtr);
ADEStatus ADEArbGroupClose (int Group);
ADEStatus ADEChannelOpen(ADEHandle* handle, ADEChannel** ch_ptr, const char* plugin, const char* interface, const char* additionalInfo);
ADEStatus ADEChannelOpenEx(ADEHandle* handle, ADEChannel** ch_ptr, const char* plugin, const char* interface, const char* additionalInfo, int Group);
/**
* \brief Preallocate resources on the hardware.
*
* This function will reserve a channel on the hardware to be used for this channel. This allows a user to setup additional functionality
* on a channel before the route is used.
*
* @param [in] H The ADE handle.
* @param [out] PH The preallocation handle. This contains the data needed to configure the channel before opening.
* @param [in] Plugin The plugin name.
* @param [in] Interface The interface to be used when the connection is opened.
* @param [in] AdditionalInfo Additional configuration information. The exact nature of this data is plugin specific.
*
* @return ADE_STATUS_OK on success, or ADE_STATUS_NOT_SUPPORTED if not supported.
*/
ADEStatus ADEChannelPrealloc (ADEHandle* handle, ADEPrealloc *PH, char *Plugin, const char *Interface,
const char *AdditionalInfo);
/**
* \brief Release preallocated resources.
*
* This function will release any preallocated resources and should be used if an error occurs when opening a preallocated channel.
*
* \note This function does NOT need to be called to cleanup channel that have been successfully opened. The close routine will
* do this.
*
* @param [in] H The ADE handle.
* @param [in] PH The preallocation handle.
*
* @return ADE_STATUS_OK on success, or ADE_STATUS_NOT_SUPPORTED if not supported.
*/
ADEStatus ADEChannelClearPrealloced (ADEHandle *H, const ADEPrealloc *PH);
/**
* \brief Enable pre-filtering behaviour on a preallocated channel.
*
* This function is used to enable pre-filtering behaviour for a channel and should be called before the channel is opened.
*
* \note This function does NOT need to be called to cleanup channel that have been successfully opened. The close routine will
* do this.
*
* @param [in] H The ADE handle.
* @param [in] Market The market name.
* @param [in] PH The preallocation handle.
*
* @return ADE_STATUS_OK on success, or ADE_STATUS_NOT_SUPPORTED if not supported.
*/
ADEStatus ADEChannelEnablePreFilteringBehaviour (ADEHandle *H, const char *Market, const ADEPrealloc *PH);
/**
* \brief Enable filtering on channel.
*
* This function is used to enable filtering on a channel.
*
* \note The symbols to be filtered should be set using \ref ADEChannelFilterSymbol() before calling this function.
* Otherwise no symbols will be forwarded.
*
* @param [in] C The ADE Channel handle.
*
* @return ADE_STATUS_OK on success, or ADE_STATUS_NOT_SUPPORTED if not supported.
*/
ADEStatus ADEChannelEnableFiltering (ADEChannel *C);
/**
* \brief Add a symbol to the filtered set.
*
* This function set a symbol to be filtered by the hardware. When filtering is enabled this the symbols sent to the
* hardware using this function will be the only symbols forwarded to the user.
*
* \note \ref ADEChannelEnablePreFilteringBehaviour() should be called before opening a channel if filtering is required.
* This will enable any feature required for filtering on a market and will prevent inconsistent data being forwarded.
*
* @param [in] C The ADE Channel handle.
* @param [in] symbol The symbol to be filtered. Any hashing required should already have been performed on this symbol.
*
* @return ADE_STATUS_OK on success, or ADE_STATUS_NOT_SUPPORTED if not supported.
*/
ADEStatus ADEChannelFilterSymbol (ADEChannel *C, uint32_t Symbol, const char *Market);
ADEStatus ADEChannelClose(ADEChannel *C);
ADEStatus ADEChannelSubscribe(ADEHandle *H, ADEChannel *C, int Enable);
ADEStatus ADEChannelResubscribe(ADEHandle *H, ADEChannel *C);
/**
* \brief Query if subscription is supported for a given ADE channel
*
* @param [in] H The ADE handle.
* @param [in] C The ADE Channel handle.
*
* @return ADE_STATUS_OK if supported, ADE_STATUS_NOT_SUPPORTED if not supported, or another status on error.
*/
ADEStatus ADEChannelCanSubscribe(ADEHandle *H, ADEChannel *C);
ADEStatus ADEChannelLog(ADEChannel *C, int Enable, char *FileName);
void ADEChannelSetPrivate(ADEChannel *C, void *Private);
void* ADEChannelGetPrivate(ADEChannel *C);
ADEStatus ADEChannelWrite(ADEChannel *C, void *Data, int Length);
ADEStatus ADEChannelStats(ADEChannel *C, ADEStats **Stats);
ADEStatus ADELatencyFeed(ADEHandle *H, char *Plugin, int Enable, char *Info);
ADEStatus ADELatencyTick(ADEChannel *C, ADETimestamp TS);
ADEStatus ADELatencyRead(ADEHandle *H, char *Plugin, uint64_t *LatencyTotal, uint64_t *LatencyTicks, int Reset);
ADEStatus ADELatencyReadLive(ADEHandle *H, char *Plugin, uint64_t *LatencyLive, uint64_t *LatencyTicks);
ADEStatus ADEDroppedRead(ADEHandle *H, char *Plugin, uint64_t *Dropped, uint64_t *Error);
/* used for handling all plugin specific data reading
*
* For file plugin, property 0, function returns the time stamp of lastly read packet
* as recorder in the PCAP file, that is being read. It returns pointer to timespec defined in time.h.
* The pointer target is valid until next ADERead call.
*/
ADEStatus ADEChannelGetProperty(ADEChannel *C, int Property, void **Result);
/* Supported just for lldt plugin. Index is a board number index, when Index == -1 the credit is returned for the first board open */
ADEStatus ADECreditRead(ADEHandle *H, char *Plugin, uint64_t *CreditAvail, uint64_t *CreditMax, int Index);
ADEStatus ADEDefaultErrorHandler(ADEHandle* _adeh, const char* _fnc, ADEStatus _status, const char* _msessage);
ADEStatus ADERegisterErrorHandler(ADEHandle *H, ADEErrorHandler Fnc);
const char * ADEStatusToString(ADEStatus _status);
/**
* \brief Write the contents of the inbound buffer to a file pointer
*
* @param C The channel we want to dump
* @param max_packets The maximum number of UDP packets to dump. 0 for all.
* @param f File pointer to which the data will be written.
*
* @return ADE_STATUS_OK if supported, ADE_STATUS_NOT_SUPPORTED if not supported, or another status on error.
*/
ADEStatus ADEDumpBuffer (ADEChannel *C, unsigned int max_packets, FILE *f);
/**
* \brief Run post channel open operations at a per plugin level
*
* @param H The ADE handle for the group of plugins/channels
*
* @return ADE_STATUS_OK if supported, ADE_STATUS_NO_SUPPORTED if not supported, or another status or error.
*/
ADEStatus ADEPostChannelOpen(ADEHandle* _handle);
#ifdef __cplusplus
}
#endif
#endif /* AI_H_ */