Apama Documentation : Connecting Apama Applications to External Components : Developing Custom Adapters : C/C++ Codec Plug-in Development : The C/C++ codec Plug-in Development Specification : Defining the codec function tables : The codec encoder function table
The codec encoder function table
If the codec being implemented is to act as an encoder it needs to implement the encoder functions listed previously and map them in an encoder function table. This structure is defined in EventCodec.h as an AP_EventEncoder_Functions struct:
/**
* AP_EventEncoder_Functions
*
* Table of client visible functions exported by the encoder part of a
* codec library instance. These functions declare the only operations
* that may be performed by users of an encoder.
*
* Note that all of these functions take an initial AP_EventEncoder*
* argument; this is analogous to the (hidden) 'this' pointer passed to
* a C++ object when a member function is invoked on it.
*/
struct AP_EventEncoder_Functions {
  /**
  * sendNormalisedEvent
*
* Called by the Semantic Mapper to encode an event and send it on to the
* event transport.
*
* @param encoder The event encoder instance
* @param event The event to be encoded. Ownership is transferred to the
* callee.
* @param timeStamp Timestamps associated with this event. Ownership is
* transferred to the callee.
* @return Event codec error code. If this is not AP_EventCodec_OK, the
* getLastError() function of the encoder should be called to get a more
* detailed description of what went wrong.
  */
  AP_EventCodecError (*sendNormalisedEvent)(struct AP_EventEncoder* encoder,
    AP_NormalisedEvent* event, AP_TimestampSet* timeStamp);
  /**
  * flushUpstream
*
* Flush any pending normalized events into the attached event transport.
* If event processing in the encoder is synchronous (as it usually will
* be) this function need not do anything except return AP_EventCodec_OK.
*
* @param encoder The event encoder instance
* @return Event codec error code. If this is not AP_EventCodec_OK, the
* getLastError() function of the encoder should be called to get a more
* detailed description of what went wrong.
  */
  AP_EventCodecError (*flushUpstream)(struct AP_EventEncoder* encoder);
  /**
  * getLastError
*
* Return the encoder's stored error message, if any. The message string
* is owned by the encoder so should not be modified or freed by the
* caller.
*
* @param encoder The event encoder instance
* @return The last error message generated by the encoder
  */
  const AP_char8* (*getLastError)(struct AP_EventEncoder* encoder);
  /**
  * addEventTransport
*
* Add a named event transport to the set of transports known to the
* encoder.
*
* If the named transport already exists, it should be replaced.
*
* @param encoder The event encoder instance
* @param name The name of the transport to be added.
* @param transport The transport object itself
*/
  */
  void (*addEventTransport)(struct AP_EventEncoder* encoder,
    const AP_char8* name, struct AP_EventTransport* transport);
  /**
  * removeEventTransport
*
* Remove a named event transport from the set of transports known to the
* encoder.
*
* If the named transport does not exist, the function should do nothing.
*
* @param encoder The event encoder instance
* @param name The name of the transport to be removed
  */
  void (*removeEventTransport)(struct AP_EventEncoder* encoder,
    const AP_char8* name);
};
In the implementation of an encoding codec, this function table could be implemented as follows:
/**
* Function table for the AP_EventEncoder interface. The address of this
* structure will be placed in the 'functions' field of the embedded
* AP_EventEncoder object.
*/
static struct AP_EventEncoder_Functions EventEncoder_Functions = {
  sendNormalisedEvent,
  flushUpstream,
  getLastErrorEncoder,
  addEventTransport,
  removeEventTransport
};
This time, the library functions sendNormalisedEvent, flushUpstream,getLastErrorEncoder, addEventTransport and removeEventTransport are being defined as the implementations of the Codec Development Specification's sendNormalisedEvent, flushUpstream,getLastError, addEventTransport and removeEventTransport function definitions respectively.
Copyright © 2013-2016 Software AG, Darmstadt, Germany.

Product LogoContact Support   |   Community   |   Feedback