The codec decoder function table
If the codec being implemented is to act as a decoder it needs to implement the decoder functions listed previously and map them in a decoder function table. This structure is defined in EventCodec.h as an AP_EventDecoder_Functions structure:
/**
* AP_EventDecoder_Functions
*
* Table of client visible functions exported by the decoder part of a
* codec library instance. These functions declare the only operations that
* may be performed by users of a decoder.
*
* Note that all of these functions take an initial AP_EventDecoder*
* argument; this is analogous to the (hidden) 'this' pointer passed to
* a C++ object when a member function is invoked on it.
*/
struct AP_EventDecoder_Functions {
/**
* sendTransportEvent
*
* Called by the event transport to decode an event and send it on to the
* Semantic Mapper. Ownership of the message is transferred to the
* decoder when this function is called. It is assumed that the encoder
* and transport share the same definition of the content of the event, so
* that the transport can effectively interpret the event and free any
* dynamically-allocated memory.
*
* @param decoder The event decoder instance
* @param event The event to be decoded
* @param timeStamp Timestamps associated with this event
* @return Event codec error code. If this is not AP_EventCodec_OK, the
* getLastError() function of the decoder should be called to get a more
* detailed description of what went wrong.
*/
AP_EventCodecError (*sendTransportEvent)(struct AP_EventDecoder* decoder,
AP_TransportEvent event, AP_TimestampSet* timeStamp);
/**
* setSemanticMapper
*
* Set the Semantic Mapper object to be used by the decoder. Currently
* only a single Semantic Mapper is supported in each adapter instance.
*
* @param decoder The event decoder instance
* @param mapper The Semantic Mapper to be used
*
*/
void (*setSemanticMapper)(struct AP_EventDecoder* decoder,
AP_SemanticMapper* mapper);
/**
* flushDownstream
*
* Flush any pending transport events into the attached Semantic Mapper.
* If event processing in the decoder is synchronous (as it usually will
* be) this function need not do anything except return AP_EventCodec_OK.
*
* @param decoder The event decoder instance
* @return Event codec error code. If this is not AP_EventCodec_OK, the
* getLastError() function of the decoder should be called to get a more
* detailed description of what went wrong.
*/
AP_EventCodecError (*flushDownstream)(struct AP_EventDecoder* decoder);
/**
* getLastError
*
* Return the decoder's stored error message, if any. The message string
* is owned by the decoder so should not be modified or freed by the
* caller.
*
* @param decoder The event decoder instance
* @return The last error message generated by the decoder
*/
const AP_char8* (*getLastError)(struct AP_EventDecoder* decoder);
};
In the implementation of a decoding codec, this function table could be implemented as follows:
/**
* EventDecoder_Functions
*
* Function table for the AP_EventDecoder interface. The address of this
* structure will be placed in the 'functions' field of the embedded
* AP_EventDecoder object.
*/
static struct AP_EventDecoder_Functions EventDecoder_Functions = {
sendTransportEvent,
setSemanticMapper,
flushDownstream,
getLastErrorDecoder
};
As before, this definition defines a number of library functions as the implementations of the function definitions specified in the Codec Development Specification.
Copyright © 2013
Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or Terracotta Inc., San Francisco, CA, USA, and/or Software AG (Canada) Inc., Cambridge, Ontario, Canada, and/or, Software AG (UK) Ltd., Derby, United Kingdom, and/or Software A.G. (Israel) Ltd., Or-Yehuda, Israel and/or their licensors.