/** * 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); }
mama_status msgUtils_createSubscriptionMessage( mamaSubscription subscription, mamaSubscMsgType subscMsgType, mamaMsg* msg, const char* issueSymbol) { uint8_t appDataType = 0; char* ipaddr; mama_status status = mamaMsg_create (msg); if (status != MAMA_STATUS_OK) { return status; } if (subscription != NULL) { mamaBridgeImpl* bridge = mamaSubscription_getBridgeImpl (subscription); const char* source = NULL; const char* symbol = NULL; mamaSubscriptionType type = MAMA_SUBSC_TYPE_NORMAL; mamaMsgImpl_useBridgePayload (*msg, bridge); mamaSubscription_getSource (subscription, &source); /* For group subs the issue symbol needs to be passed in as it is not the same as the subscribe symbol */ if (issueSymbol) { symbol = issueSymbol; } else { mamaSubscription_getSubscSymbol (subscription, &symbol); } mamaSubscription_getSubscriptionType (subscription, &type); mamaSubscription_getAppDataType (subscription, &appDataType); status = mamaMsgImpl_setSubscInfo ( *msg, mamaSubscription_getSubscRoot (subscription), source, symbol, 1); if (status != MAMA_STATUS_OK) return status; status = mamaMsg_addI32 ( *msg, MamaFieldSubscriptionType.mName, MamaFieldSubscriptionType.mFid, type); if (status != MAMA_STATUS_OK) return status; } status = mamaMsg_addI32 ( *msg, MamaFieldSubscMsgType.mName, MamaFieldSubscMsgType.mFid, subscMsgType); if (status != MAMA_STATUS_OK) { return status; } status = mamaMsg_addU8 ( *msg, MamaFieldAppDataType.mName, MamaFieldAppDataType.mFid, appDataType); if (status != MAMA_STATUS_OK) { return status; } #ifndef IGNORE_DEPRECATED_FIELDS status = mamaMsg_addI32 ( *msg, MamaFieldSubscMsgTypeOld.mName, MamaFieldSubscMsgTypeOld.mFid, subscMsgType); if (status != MAMA_STATUS_OK) return status; #endif mama_getIpAddress ((const char**)&ipaddr); if (ipaddr != NULL && strlen( ipaddr ) > 0) { status = mamaMsg_addString ( *msg, MamaFieldSubscSourceHost.mName, MamaFieldSubscSourceHost.mFid, ipaddr); if (status != MAMA_STATUS_OK) return status; } return MAMA_STATUS_OK; }