void RMDSBridgeSubscription::OnMessage( mamaMsg msg, mamaMsgType msgType )
{
	if (isShutdown_ || ((0 != source_) && source_->IsPausedUpdates()))
	{
		// just don't bother with making the callback
		return;
	}

	// send the message
	mama_status status = MAMA_STATUS_OK;

	if (msgType == MAMA_MSG_TYPE_INITIAL || msgType == MAMA_MSG_TYPE_REFRESH || msgType == MAMA_MSG_TYPE_RECAP || msgType == MAMA_MSG_TYPE_BOOK_INITIAL || msgType == MAMA_MSG_TYPE_BOOK_RECAP)
	{
		gotImage_ = true;
	}
	else if (msgType == MAMA_MSG_TYPE_SEC_STATUS)
	{
		// Let status go through
	}
	else
	{
		if (!gotImage_)
		{
			t42log_debug("Ignoring Update type %d with no image for %s : %s \n", msgType, symbol_.c_str(), sourceName_.c_str() );
			return;
		}
	}

	try
	{
		status = mamaSubscription_processMsg(subscription_, msg);
	}
	catch (...)
	{
		t42log_error("RMDSBridgeSubscription::OnMessage - caught exception calling mamaSubscription_processMsg for %s", symbol_.c_str());
	}

	if (MAMA_STATUS_OK != status)
	{
		mama_log (MAMA_LOG_LEVEL_ERROR,
			"RMDSBridgeSubscription::OnMessage: "
			"mamaSubscription_processMsg() failed. [%d]",
			status);
	}
}
void RMDSBridgeSubscription::SendStatusMessage( mamaMsgStatus secStatus )
{
	if (isShutdown_)
	{
		// just don't bother making the callback
		return;
	}
	// create and send a message containing the (failed) status
	mamaMsg msg;
	mamaMsg_createForPayload(&msg, MAMA_PAYLOAD_TICK42RMDS);

	mamaMsg_addI32(msg, MamaFieldMsgType.mName, MamaFieldMsgType.mFid, MAMA_MSG_TYPE_SEC_STATUS);
	mamaMsg_addI32(msg, MamaFieldMsgStatus.mName, MamaFieldMsgStatus.mFid, secStatus);

    const CommonFields &commonFields = UpaMamaCommonFields::CommonFields();
	mamaMsg_addString(msg, commonFields.wIssueSymbol.mama_field_name.c_str(),commonFields.wIssueSymbol.mama_fid, symbol_.c_str());
	mamaMsg_addString(msg, commonFields.wSymbol.mama_field_name.c_str(), commonFields.wSymbol.mama_fid, symbol_.c_str());

	mama_status status = MAMA_STATUS_OK;
	try
	{
		status = mamaSubscription_processMsg(subscription_, msg);
	}
	catch (...)
	{
		mamaMsg_destroy(msg);	
		t42log_error("RMDSBridgeSubscription::OnMessage - caught exception calling mamaSubscription_processMsg for %s", symbol_.c_str());
	}


	if (MAMA_STATUS_OK != status)
	{
		mama_log (MAMA_LOG_LEVEL_ERROR,
			"RMDSBridgeSubscription::OnMessage: "
			"mamaSubscription_processMsg() failed. [%d]",
			status);
	}

	mamaMsg_destroy(msg);	
}
Beispiel #3
0
/**
 * Called when message removed from queue by dispatch thread
 *
 * @param data The Avis Attributes* clone (must be freed)
 * @param closure The subscriber
 */
static void MAMACALLTYPE
avis_queue_callback (void* data, void* closure)
{
    mama_status status;
    mamaMsg tmpMsg;
    msgBridge bridgeMsg;

    /* cant do anything without a subscriber */
    if (!avisSub(closure)) {
        mama_log (MAMA_LOG_LEVEL_ERROR, "avis_callback(): called with NULL subscriber!");
        return;
    }

    /*Make sure that the subscription is processing messages*/
    if ((!avisSub(closure)->mIsNotMuted) || (!avisSub(closure)->mIsValid)) return;


    /*This is the reuseable message stored on the associated MamaQueue*/
    tmpMsg = mamaQueueImpl_getMsg(avisSub(closure)->mQueue);
    if (!tmpMsg)
    {
        mama_log (MAMA_LOG_LEVEL_ERROR, "avis_callback(): "
                  "Could not get cached mamaMsg from event queue.");
        return;
    }

    /*Get the bridge message from the mamaMsg*/
    if (MAMA_STATUS_OK!=(status=mamaMsgImpl_getBridgeMsg (tmpMsg,
                    &bridgeMsg)))
    {
        mama_log (MAMA_LOG_LEVEL_ERROR, "avis_callback(): "
                  "Could not get bridge message from cached"
                  " queue mamaMsg [%d]", status);
        return;
    }

    /*Set the buffer and the reply handle on the bridge message structure*/
    avisBridgeMamaMsgImpl_setAttributesAndSecure (bridgeMsg, data, 0);

    if (MAMA_STATUS_OK!=(status=mamaMsgImpl_setMsgBuffer (tmpMsg,
                                data,
                                0, MAMA_PAYLOAD_AVIS)))
    {
        mama_log (MAMA_LOG_LEVEL_ERROR,
                  "avis_callback(): mamaMsgImpl_setMsgBuffer() failed. [%d]",
                  status);
        return;
    }

    /*Process the message as normal*/
    if (MAMA_STATUS_OK != (status=mamaSubscription_processMsg
                (avisSub(closure)->mMamaSubscription, tmpMsg)))
    {
        mama_log (MAMA_LOG_LEVEL_ERROR,
                  "avis_callback(): "
                  "mamaSubscription_processMsg() failed. [%d]",
                  status);
    }

    attributes_free ((Attributes*)data);
    free ((Attributes*)data);
}
Beispiel #4
0
/**
 * Called when message removed from queue by dispatch thread
 *
 * @param data The Avis Attributes* clone (must be freed)
 * @param closure The subscriber
 */
static void MAMACALLTYPE
avis_queue_callback (mamaQueue queue,
                     void*     closure)
{
    mama_status status     = MAMA_STATUS_OK;
    mamaMsg     tmpMsg     = NULL;
    msgBridge   bridgeMsg  = NULL;
    const void* buf        = NULL;
    mama_size_t bufSize    = 0;

    avisCallbackContext* ctx = (avisCallbackContext*) closure;

    void* data       = ctx->attributes;
    void* subscriber = ctx->subscriber;

    /* cant do anything without a subscriber */
    if (!subscriber)
    {
        mama_log (MAMA_LOG_LEVEL_ERROR,
                  "avis_callback(): called with NULL subscriber!");

        attributes_destroy (data);
        free (ctx);
        return;
    }

    /*Make sure that the subscription is processing messages*/
    if ((!avisSub(subscriber)->mIsNotMuted) || 
        (!avisSub(subscriber)->mIsValid))
    {
        attributes_destroy (data);
        free (ctx);
        return;
    }

    /*This is the reuseable message stored on the associated MamaQueue*/
    tmpMsg = mamaQueueImpl_getMsg(avisSub(subscriber)->mQueue);
    if (!tmpMsg)
    {
        mama_log (MAMA_LOG_LEVEL_ERROR, "avis_callback(): "
                  "Could not get cached mamaMsg from event queue.");

        attributes_destroy (data);
        free (ctx);
        return;
    }

    /*Get the bridge message from the mamaMsg*/
    if (MAMA_STATUS_OK!=(status=mamaMsgImpl_getBridgeMsg (tmpMsg,
                    &bridgeMsg)))
    {
        mama_log (MAMA_LOG_LEVEL_ERROR, "avis_callback(): "
                  "Could not get bridge message from cached"
                  " queue mamaMsg [%d]", status);

        attributes_destroy (data);
        free (ctx);
        return;
    }

    /*Set the buffer and the reply handle on the bridge message structure*/
    if (MAMA_STATUS_OK!=(status=mamaMsgImpl_setMsgBuffer (tmpMsg,
                                data,
                                0, MAMA_PAYLOAD_AVIS)))
    {
        mama_log (MAMA_LOG_LEVEL_ERROR,
                  "avis_callback(): mamaMsgImpl_setMsgBuffer() failed. [%d]",
                  status);

        attributes_destroy (data);
        free (ctx);
        return;
    }

    if (MAMA_STATUS_OK == mamaMsg_getOpaque (
            tmpMsg, ENCLOSED_MSG_FIELD_NAME, 0, &buf, &bufSize) && 
            bufSize > 0)
    {
        mamaMsg         encMsg = NULL;
        mamaBridgeImpl* bridge = 
            mamaSubscription_getBridgeImpl (avisSub(subscriber)->mMamaSubscription);

        status = mamaMsg_createFromByteBuffer (&encMsg, buf, bufSize);

        if (MAMA_STATUS_OK != status)
        {
            mama_log (MAMA_LOG_LEVEL_ERROR,
                      "avis_callback(): "
                      "Could not create message from enclosed byte buffer. [%d]",
                      status);

            attributes_destroy (data);
            free (ctx);
            return;
        }

        mamaMsgImpl_useBridgePayload (encMsg, bridge);
        mamaMsgImpl_getBridgeMsg (encMsg, &bridgeMsg);

        /*Set the buffer and the reply handle on the bridge message structure*/
        avisBridgeMamaMsgImpl_setAttributesAndSecure (bridgeMsg, data, 0);

        if (gMamaLogLevel >= MAMA_LOG_LEVEL_FINEST)
        {
            mama_log (MAMA_LOG_LEVEL_FINEST, "avis_callback(): "
                      "Received enclosed message: %s", mamaMsg_toString (encMsg));
        }

        if (MAMA_STATUS_OK != (status=mamaSubscription_processMsg
                    (avisSub(subscriber)->mMamaSubscription, encMsg)))
        {
            mama_log (MAMA_LOG_LEVEL_ERROR,
                      "avis_callback(): "
                      "mamaSubscription_processMsg() failed. [%d]",
                      status);
        }

        mamaMsg_destroy (encMsg);
    }
    else
    {
        avisBridgeMamaMsgImpl_setAttributesAndSecure (bridgeMsg, data, 0);

        if (gMamaLogLevel >= MAMA_LOG_LEVEL_FINEST)
        {
            mama_log (MAMA_LOG_LEVEL_FINEST, "avis_callback(): "
                           "Received message: %s", mamaMsg_toString (tmpMsg));
        }

        /*Process the message as normal*/
        if (MAMA_STATUS_OK != (status=mamaSubscription_processMsg
                    (avisSub(subscriber)->mMamaSubscription, tmpMsg)))
        {
            mama_log (MAMA_LOG_LEVEL_ERROR,
                      "avis_callback(): "
                      "mamaSubscription_processMsg() failed. [%d]",
                      status);
        }
    }

    free (ctx);
}