[PATCH 1.1] mama.c: Add mama_openWithPropertiesCount() and mama_closeCount()
John Gray <jgray@...>
These methods take an additonal unsigned int* parameter that upon return contains the the reference count for mama_openXXX() and mama_closeXXX(). This allows applications to performa one-time global initialization when the int is 1 and mama_openWithPropertiesCount() returns MAMA_STATUS_OK. Likewise applications can clean up global data when the count is zero and mama_closeCount() returns MAMA_STATUS_OK.
Index: c_cpp/src/c/mama.c =================================================================== RCS file: /cvsroot/products/mama/c_cpp/src/c/mama.c,v retrieving revision 1.128.4.7.2.2.4.19.4.6 diff -u -r1.128.4.7.2.2.4.19.4.6 mama.c --- c_cpp/src/c/mama.c 7 Jan 2012 03:42:40 -0000 1.128.4.7.2.2.4.19.4.6 +++ c_cpp/src/c/mama.c 8 Jan 2012 03:48:20 -0000 @@ -643,8 +643,9 @@ }
mama_status -mama_openWithProperties (const char* path, - const char* filename) +mama_openWithPropertiesCount (const char* path, + const char* filename, + unsigned int* count) { mama_status result = MAMA_STATUS_OK; mama_size_t numBridges = 0; @@ -695,6 +696,10 @@ { if (MAMA_STATUS_OK == result) gImpl.myRefCount++; + + if (count) + *count = gImpl.myRefCount; + pthread_mutex_unlock (&gImpl.myLock); return result; } @@ -757,6 +762,9 @@ mama_log (MAMA_LOG_LEVEL_ERROR, "mama_openWithProperties(): " "Could not create stats generator."); + if (count) + *count = gImpl.myRefCount; + pthread_mutex_unlock (&gImpl.myLock); return result; } @@ -874,6 +882,9 @@ mama_log (MAMA_LOG_LEVEL_SEVERE, "mama_openWithProperties(): " "At least one bridge must be specified"); + if (count) + *count = gImpl.myRefCount; + pthread_mutex_unlock (&gImpl.myLock); return MAMA_STATUS_NO_BRIDGE_IMPL; } @@ -883,6 +894,9 @@ mama_log (MAMA_LOG_LEVEL_SEVERE, "mama_openWithProperties(): " "At least one payload must be specified"); + if (count) + *count = gImpl.myRefCount; + pthread_mutex_unlock (&gImpl.myLock); return MAMA_STATUS_NO_BRIDGE_IMPL; } @@ -901,6 +915,10 @@ "mama_openWithProperties(): " "Error connecting to Entitlements Server"); mama_close(); + + if (count) + *count = gImpl.myRefCount; + pthread_mutex_unlock (&gImpl.myLock); return result; } @@ -938,6 +956,8 @@ if (MAMA_STATUS_OK != (result = mamaBridgeImpl_getInternalEventQueue (bridge, &statsGenQueue))) { + if (count) + *count = gImpl.myRefCount; pthread_mutex_unlock (&gImpl.myLock); return result; } @@ -948,6 +968,8 @@ mama_log (MAMA_LOG_LEVEL_ERROR, "mama_openWithProperties(): " "Could not set queue for stats generator."); + if (count) + *count = gImpl.myRefCount; pthread_mutex_unlock (&gImpl.myLock); return result; } @@ -957,12 +979,16 @@ mama_log (MAMA_LOG_LEVEL_ERROR, "mama_openWithProperties(): " "Failed to enable stats logging"); + if (count) + *count = gImpl.myRefCount; pthread_mutex_unlock (&gImpl.myLock); return result; } }
gImpl.myRefCount++; + if (count) + *count = gImpl.myRefCount; pthread_mutex_unlock (&gImpl.myLock); return result; } @@ -972,7 +998,14 @@ { /*Passing NULL as path and filename will result in the default behaviour - mama.properties on $WOMBAT_PATH*/ - return mama_openWithProperties (NULL, NULL); + return mama_openWithPropertiesCount (NULL, NULL, NULL); +} + +mama_status +mama_openWithProperties (const char* path, + const char* filename) +{ + return mama_openWithPropertiesCount (path, filename, NULL); }
mama_status @@ -1079,7 +1112,7 @@ }
mama_status -mama_close () +mama_closeCount (unsigned int* count) { mama_status result = MAMA_STATUS_OK; mamaMiddleware middleware = 0; @@ -1088,6 +1121,8 @@ pthread_mutex_lock (&gImpl.myLock); if (gImpl.myRefCount == 0) { + if (count) + *count = gImpl.myRefCount; pthread_mutex_unlock (&gImpl.myLock); return MAMA_STATUS_OK; } @@ -1113,11 +1148,8 @@ /* Look for a bridge for each of the payloads and close them */ for (payload = 0; payload != MAMA_PAYLOAD_MAX; ++payload) { - mamaPayloadBridgeImpl* impl = (mamaPayloadBridgeImpl*) gImpl.myPayloads [(uint8_t)payload]; - if (impl) - { - - } + /* mamaPayloadBridgeImpl* impl = (mamaPayloadBridgeImpl*) + * gImpl.myPayloads [(uint8_t)payload];*/ gImpl.myPayloads[(uint8_t)payload] = NULL; }
@@ -1244,10 +1276,18 @@ mama_freeAppContext(&appContext);
} + if (count) + *count = gImpl.myRefCount; pthread_mutex_unlock (&gImpl.myLock); return result; }
+mama_status +mama_close (void) +{ + return mama_closeCount (NULL); +} + /** * Start processing messages. */ Index: c_cpp/src/c/mama/mama.h =================================================================== RCS file: /cvsroot/products/mama/c_cpp/src/c/mama/mama.h,v retrieving revision 1.74.4.4.8.10 diff -u -r1.74.4.4.8.10 mama.h --- c_cpp/src/c/mama/mama.h 2 Oct 2011 19:02:18 -0000 1.74.4.4.8.10 +++ c_cpp/src/c/mama/mama.h 8 Jan 2012 03:48:20 -0000 @@ -220,6 +220,40 @@ extern mama_status mama_openWithProperties (const char* path, const char* filename); + /** + * Initialize MAMA. + * + * Allows users of the API to override the default behavior of mama_open() + * where a file mama.properties is required to be located in the directory + * specified by \$WOMBAT_PATH. + * + * The properties file must have the same structure as a standard + * mama.properties file. + * + * If null is passed as the path the API will look for the properties file on + * the \$WOMBAT_PATH. + * + * If null is passed as the filename the API will look for the default + * filename of mama.properties. + * + * The count value on return will be the number of times that mama_openXxx() + * has ben invoked successfully. Applicatiins can use this to perform + * one-time initialization when the value is 1 and the return is + * MAMA_STATUS_OK + * + * @param path Fully qualified path to the directory containing the properties + * file + * @param filename The name of the file containing MAMA properties. + * @param count The number of times mama_OpenXXX() has been called + * successfully. + * + * @return mama_status Whether the call was successful or not. + */ + MAMAExpDLL + extern mama_status + mama_openWithPropertiesCount (const char* path, + const char* filename, + unsigned int* count);
/** * Set a specific property for the API. @@ -291,6 +325,17 @@ MAMAExpDLL extern mama_status mama_close (void); + + /** + * Close MAMA and free all associated resource. + * + * @param count Filled with the number of times mama has been opened + * successfully. Applications can perform global one-time cleanup when this + * value is 0 and the return value is MAMA_STATUS_OK. + */ + MAMAExpDLL + extern mama_status + mama_closeCount (unsigned int* count);
/** * Return the version information for the library.
Signed-off-by: John Gray <jgray@...>
|
|