mama_status avisBridgeMamaSubscription_destroy (subscriptionBridge subscriber) { mama_status status = MAMA_STATUS_OK; wombatQueue queue = NULL; CHECK_SUBSCRIBER(subscriber); elvin_subscription_remove_listener(avisSub(subscriber)->mAvisSubscription, avis_callback); if (!elvin_unsubscribe(avisSub(subscriber)->mAvis, avisSub(subscriber)->mAvisSubscription)) { // NOTE: elvin_unsubscribe sometimes returns failure for no apparent reason, so dont log errors here: // 2011-09-02 11:59:10: avis error code=2, error msg=Illegal frame size: 61 //log_avis_error(MAMA_LOG_LEVEL_ERROR, avisSub(subscriber)->mAvis); //status = MAMA_STATUS_PLATFORM; } free(avisSub(subscriber)->mAvisSubscription); mamaQueue_getNativeHandle(avisSub(subscriber)->mQueue, &queue); if (!queue) { mama_log (MAMA_LOG_LEVEL_ERROR, "avis_callback(): " "Could not get event queue."); return MAMA_STATUS_PLATFORM; } wombatQueue_enqueue (queue, destroy_callback, (void*)subscriber, NULL); return status; }
static void avis_callback( Subscription* subcription, Attributes* attributes, bool secure, void* subscriber) { wombatQueue queue = NULL; /* cant do anything without a subscriber */ if (!avisSub(subscriber)) { mama_log (MAMA_LOG_LEVEL_ERROR, "avis_callback(): called with NULL subscriber!"); return; } /*Make sure that the subscription is processing messages*/ if ((!avisSub(subscriber)->mIsNotMuted) || (!avisSub(subscriber)->mIsValid)) return; mamaQueue_getNativeHandle(avisSub(subscriber)->mQueue, &queue); if (!queue) { mama_log (MAMA_LOG_LEVEL_ERROR, "avis_callback(): " "Could not get event queue."); return; } wombatQueue_enqueue (queue, avis_queue_callback, attributes_clone(attributes), subscriber); return; }
static void MAMACALLTYPE destroy_callback(void* subscriber, void* closure) { // cant do anything without a subscriber if (!avisSub(subscriber)) { mama_log (MAMA_LOG_LEVEL_ERROR, "avis_callback(): called with NULL subscriber!"); return; } (*avisSub(subscriber)->mMamaCallback.onDestroy)(avisSub(subscriber)->mMamaSubscription, avisSub(subscriber)->mClosure); free(avisSub(subscriber)); }
mama_status avisBridgeMamaSubscription_mute (subscriptionBridge subscriber) { CHECK_SUBSCRIBER(subscriber); avisSub(subscriber)->mIsNotMuted = 0; return MAMA_STATUS_OK; }
mama_status avisBridgeMamaSubscription_getPlatformError (subscriptionBridge subscriber, void** error) { CHECK_SUBSCRIBER(subscriber); *error = &(avisSub(subscriber)->mAvis->error); return MAMA_STATUS_OK; }
static void avis_callback( Subscription* subcription, Attributes* attributes, bool secure, void* subscriber) { /* cant do anything without a subscriber */ if (!avisSub(subscriber)) { mama_log (MAMA_LOG_LEVEL_ERROR, "avis_callback(): called with NULL subscriber!"); return; } /*Make sure that the subscription is processing messages*/ if ((!avisSub(subscriber)->mIsNotMuted) || (!avisSub(subscriber)->mIsValid)) return; avisCallbackContext* ctx = (avisCallbackContext*) malloc (sizeof (avisCallbackContext)); ctx->attributes = attributes_clone (attributes); ctx->subscriber = subscriber; mamaQueue_enqueueEvent (avisSub (subscriber)->mQueue, avis_queue_callback, ctx); }
/** * 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); }
int avisBridgeMamaSubscription_isTportDisconnected (subscriptionBridge subscriber) { CHECK_SUBSCRIBER(subscriber); return elvin_is_open(avisSub(subscriber)->mAvis) ? 0 : 1; }
int avisBridgeMamaSubscription_isValid (subscriptionBridge subscriber) { if (!subscriber) return 0; return avisSub(subscriber)->mIsValid; }
mama_status avisBridgeMamaSubscription_destroy (subscriptionBridge subscriber) { mama_status status = MAMA_STATUS_OK; wombatQueue queue = NULL; avisTransportBridge* avisTransport = NULL; CHECK_SUBSCRIBER(subscriber); mamaTransport_getBridgeTransport ( avisSub(subscriber)->mTransport, (void*) &avisTransport); if (!avisTransport) return MAMA_STATUS_INVALID_ARG; if (avisTransportBridge_isDispatching (avisTransport)) { elvin_invoke (avisSub(subscriber)->mAvis, &unsubscribeAvis, avisSub(subscriber)->mAvisSubscription); } else { unsubscribeAvis (avisSub(subscriber)->mAvis, avisSub(subscriber)->mAvisSubscription); } avisSub(subscriber)->mAvisSubscription = NULL; mamaQueue_getNativeHandle(avisSub(subscriber)->mQueue, &queue); if (!queue) { mama_log (MAMA_LOG_LEVEL_ERROR, "avisBridgeMamaSubscription_destroy(): " "Could not get event queue."); return MAMA_STATUS_PLATFORM; } avisSub(subscriber)->mMamaCallback.onDestroy ( avisSub(subscriber)->mMamaSubscription, avisSub(subscriber)->mClosure); wsem_destroy(&avisSub(subscriber)->mCreateDestroySem); free(avisSub(subscriber)->mSubject); free(avisSub(subscriber)); return status; }
/** * 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); }