Writing a Message Handler Plug-in Initialize Function

The plug-in initialize function (ffh_mh_init_function) for the message handler prepares the plug-in for use.

  1. Initialize the RAP publisher API by invoking the pub_initialize() function. Use the initParams argument to pass information needed to initialize the publisher API to your plug-in (for example, the publisher configuration directory and the RDS templates directory). InitParams are specified in the configuration file.
  2. Set the PUB_STARTUP.callbacks.shutdown field to your publisherShutdown() function.
  3. Create PUB_SEND_MESSAGE_CONTEXT, which will be shared by publisher API calls.
  4. Perform any other initialization required by your plug-in.

    For example, you can create an instance of a message handling class and store the pointer to this instance in the info->user_data member. You can use that pointer later to invoke your class from the ffh_mh_fini_function and the ffh_mh_process_function functions.

  5. Store a global reference to the ffh_mh_info * info parameter for future access in your publisherShutdown() function.

Sample initialize function

extern "C“ int32_t initializeHandler( 
    ffh_mh_info * info,
    ffh_init_param * initParams,
    int32_t initParamLen )
{
    info->user_data = new FIXMessageHandler();
    return (( FIXMessageHandler* )
				    info->user_data)->initialize(
	           info, initParams, initParamLen );
}

int32_t FIXMessageHandler::initialize(
    ffh_mh_info * info,
    ffh_init_param * initParams,
    int32_t initParamLen )
{
    // initialize the logger by using external context
    log_init_from_context( info->loggerCtx );

    // initialize Publisher API
    PUB_STARTUP startupSettings;
    startupSettings.component_subtype  = "FAST Feed Handler";
    startupSettings.strict_check       = false;
    startupSettings.own_logger         = true;
    startupSettings.callbacks.shutdown = publisherShutdown;

    for( int i = 0; i < initParamLen; i++ ) {
        if( strcmp( initParams[i].name,
                    "PublisherConfigDir" ) == 0 ) {
            startupSettings.config_dir = initParams[i].value;
        } else if( strcmp( initParams[i].name,
                           "RDSTemplateDir" ) == 0 ) {
            startupSettings.template_dir =
               initParams[i].value;
        }
    }
    
    int32_t error_code = pub_initialize( &startupSettings );
    if( error_code != ERR_NONE ) {
        log_message( LOGGER_ERROR, error_code,
                     “Initialization failed." );
        return error_code;
    }

    // create Publisher API message context 
    _msg_ctx = new PUB_SEND_MESSAGE_CONTEXT();

    // store the ffh_mh_info so that it can be used
    // by publisherShutdown()
    setHandlerInfo( info );

    return ERR_NONE;
}

where:

Returns:

int32_t 0 if the initialization succeeded; otherwise, a nonzero error code.

Related concepts
Message Handler Plug-ins
Related tasks
Writing a Message Handler Plug-in for the FAST Feed Handler
Writing a Message Handler Plug-in Process Function
Writing a Message Handler Plug-in Finalize Function
Implementing the Shutdown Callback Method
Related reference
Arguments of the Message Handler Plug-in Initialize Function
Arguments of the Message Handler Process Function
Arguments of the Message Handler Finalize Function
C API Definitions of Function Signatures for Building a Message Handler
C API Definition of ffh_fast_message and its Related Structures
FAST Templates