static void* updateTimeZones (void* ptr) { wList timeZones; /* Interval is in milliseconds */ unsigned int checkInterval = 60000; wsem_init (&sTzSem, 0, 0); /* Until interrupted */ do { /* Lock access to the list of timezones while we recheck. */ wthread_static_mutex_lock (&sVector_mutex); timeZones = getTimeZones(); list_for_each (timeZones, checkTzIter, NULL); wthread_static_mutex_unlock (&sVector_mutex); if (sScanningThreadInterval) { checkInterval = sScanningThreadInterval * 1000; } } while (0 != wsem_timedwait (&sTzSem, checkInterval) && sThreadStarted); /* The return value is not applicable. */ return NULL; }
/* Description: Load the middleware bridge, initialize MAMA, begin * processing messages in a non-default thread, stop * processing on the non-default thread, close MAMA. * * Expected Result: MAMA_STATUS_OK */ TEST_F (MamaOpenCloseTestC, StartStopDifferentThreads) { mamaBridge bridge; ASSERT_EQ (MAMA_STATUS_OK, mama_loadBridge (&bridge, getMiddleware())); ASSERT_EQ (MAMA_STATUS_OK, mama_open()); /* Start mama in the background so it uses a different thread */ wsem_t sem; mamaQueue defaultQueue; ASSERT_EQ (0, wsem_init (&sem, 0, 0)); ASSERT_EQ (MAMA_STATUS_OK, mama_getDefaultEventQueue (bridge, &defaultQueue)); ASSERT_EQ (MAMA_STATUS_OK, mamaQueue_enqueueEvent (defaultQueue, onEventStop, bridge)); ASSERT_EQ (MAMA_STATUS_OK, mama_startBackgroundEx (bridge, startCallback, &sem)); ASSERT_EQ (0, wsem_wait (&sem)); ASSERT_EQ (MAMA_STATUS_OK, mama_close()); }
mama_status avisBridgeMamaTransport_create (transportBridge* result, const char* name, mamaTransport mamaTport ) { mama_status status; avisBridgeImpl* avisBridge = NULL; avisTransportBridge* transport = NULL; mamaBridgeImpl* bridgeImpl = NULL; const char* url = NULL; transport = (avisTransportBridge*)calloc( 1, sizeof( avisTransportBridge ) ); if (transport == NULL) return MAMA_STATUS_NOMEM; transport->mTransport = (mamaTransport) mamaTport; bridgeImpl = mamaTransportImpl_getBridgeImpl(mamaTport); if (!bridgeImpl) { mama_log (MAMA_LOG_LEVEL_ERROR, "avisBridgeMamaTransport_create(): Could not get bridge"); free(transport); return MAMA_STATUS_PLATFORM; } status = mamaBridgeImpl_getClosure((mamaBridge) bridgeImpl, (void**) &avisBridge); if (MAMA_STATUS_OK != status) { mama_log (MAMA_LOG_LEVEL_ERROR, "avisBridgeMamaTransport_create(): Could not get Avis bridge object"); free(transport); return status; } /* create the Elvin object */ transport->mAvis = (Elvin*)calloc (1, sizeof (Elvin)); if (transport->mAvis == NULL) { mama_log (MAMA_LOG_LEVEL_ERROR, "avisBridge_createImpl(): Could not create Elvin object"); free(transport); return MAMA_STATUS_PLATFORM; } /* open the server connection */ url = getURL(name); if (url == NULL) { mama_log (MAMA_LOG_LEVEL_NORMAL, "No %s property defined for transport : %s", TPORT_PARAM, name); return MAMA_STATUS_INVALID_ARG; } if (!elvin_open(transport->mAvis, url)) { mama_log (MAMA_LOG_LEVEL_ERROR, "open failed for %s: %s", TPORT_PARAM, name); log_avis_error(MAMA_LOG_LEVEL_ERROR, transport->mAvis); avisBridgeMamaTransport_destroy((transportBridge)transport); return MAMA_STATUS_PLATFORM; } wInterlocked_initialize (&transport->mDispatching); elvin_add_close_listener(transport->mAvis, closeListener, transport); wsem_init(&transport->mAvisDispatchSem, 0, 0); *result = (transportBridge) transport; return avisTransportBridge_start(transport); }
mama_status avisBridgeMamaSubscription_create (subscriptionBridge* subscriber, const char* source, const char* symbol, mamaTransport transport, mamaQueue queue, mamaMsgCallbacks callback, mamaSubscription subscription, void* closure) { avisSubscription* impl = NULL; avisTransportBridge* avisTransport = NULL; if (!subscriber || !subscription || !transport ) return MAMA_STATUS_NULL_ARG; impl = (avisSubscription*)calloc (1, sizeof(avisSubscription)); if (impl == NULL) return MAMA_STATUS_NOMEM; impl->mAvis = getAvis(transport); if (!impl->mAvis) return MAMA_STATUS_INVALID_ARG; mamaTransport_getBridgeTransport ( transport, (void*) &avisTransport); if (!avisTransport) return MAMA_STATUS_INVALID_ARG; /* Use a standard centralized method to determine a topic key */ avisBridgeMamaSubscriptionImpl_generateSubjectKey (NULL, source, symbol, &impl->mSubject); impl->mMamaCallback = callback; impl->mMamaSubscription = subscription; impl->mQueue = queue; impl->mTransport = transport; impl->mClosure = closure; impl->mIsNotMuted = 1; impl->mIsValid = 1; impl->mAvisSubscription = NULL; wsem_init(&impl->mCreateDestroySem, 0, 0); *subscriber = (subscriptionBridge) impl; if (avisTransportBridge_isDispatching (avisTransport)) { elvin_invoke (impl->mAvis, &subscribeAvis, impl); wsem_wait (&impl->mCreateDestroySem); } else { subscribeAvis (impl->mAvis, impl); } return MAMA_STATUS_OK; }