Azure IoT common library
Dependents: STM32F746_iothub_client_sample_mqtt f767zi_mqtt iothub_client_sample_amqp iothub_client_sample_http ... more
Diff: lock_rtx_mbed.cpp
- Revision:
- 22:10640b226104
- Parent:
- 19:2e0811512ceb
--- a/lock_rtx_mbed.cpp Fri Feb 24 14:01:41 2017 -0800 +++ b/lock_rtx_mbed.cpp Fri Mar 10 11:48:28 2017 -0800 @@ -5,84 +5,91 @@ #include "azure_c_shared_utility/xlogging.h" #include "rtos.h" -DEFINE_ENUM_STRINGS(LOCK_RESULT, LOCK_RESULT_VALUES); -/*Tests_SRS_LOCK_99_002:[ This API on success will return a valid lock handle which should be a non NULL value]*/ LOCK_HANDLE Lock_Init(void) { - Mutex* lock_mtx = new Mutex(); - - return (LOCK_HANDLE)lock_mtx; + /* Codes_SRS_LOCK_10_002: [Lock_Init on success shall return a valid lock handle which should be a non NULL value] */ + /* Codes_SRS_LOCK_10_003: [Lock_Init on error shall return NULL] */ + Mutex* result = new Mutex(); + if (result == NULL) + { + LogError("Failed to instantiate a new Mutex object."); + } + + return (LOCK_HANDLE)result; } - LOCK_RESULT Lock(LOCK_HANDLE handle) { LOCK_RESULT result; if (handle == NULL) { - /*Tests_SRS_LOCK_99_007:[ This API on NULL handle passed returns LOCK_ERROR]*/ + /* Codes_SRS_LOCK_10_007: [Lock on NULL handle passed returns LOCK_ERROR] */ + LogError("Invalid argument; handle is NULL."); result = LOCK_ERROR; - LogError("(result = %s)", ENUM_TO_STRING(LOCK_RESULT, result)); } else { Mutex* lock_mtx = (Mutex*)handle; if (lock_mtx->lock() == osOK) { - /*Tests_SRS_LOCK_99_005:[ This API on success should return LOCK_OK]*/ + /* Codes_SRS_LOCK_10_005: [Lock on success shall return LOCK_OK] */ result = LOCK_OK; } else { - /*Tests_SRS_LOCK_99_006:[ This API on error should return LOCK_ERROR]*/ + /* Codes_SRS_LOCK_10_006: [Lock on error shall return LOCK_ERROR] */ + LogError("Mutex(%p)->lock() failed.", handle); result = LOCK_ERROR; - LogError("(result = %s)", ENUM_TO_STRING(LOCK_RESULT, result)); } } + return result; } + LOCK_RESULT Unlock(LOCK_HANDLE handle) { LOCK_RESULT result; if (handle == NULL) { - /*Tests_SRS_LOCK_99_011:[ This API on NULL handle passed returns LOCK_ERROR]*/ + /* Codes_SRS_LOCK_10_007: [Unlock on NULL handle passed returns LOCK_ERROR] */ + LogError("Invalid argument; handle is NULL."); result = LOCK_ERROR; - LogError("(result = %s)", ENUM_TO_STRING(LOCK_RESULT, result)); } else { Mutex* lock_mtx = (Mutex*)handle; if (lock_mtx->unlock() == osOK) { - /*Tests_SRS_LOCK_99_009:[ This API on success should return LOCK_OK]*/ + /* Codes_SRS_LOCK_10_009: [Unlock on success shall return LOCK_OK] */ result = LOCK_OK; } else { - /*Tests_SRS_LOCK_99_010:[ This API on error should return LOCK_ERROR]*/ + /* Codes_SRS_LOCK_10_010: [Unlock on error shall return LOCK_ERROR] */ + LogError("Mutex(%p)->unlock() failed.", handle); result = LOCK_ERROR; - LogError("(result = %s)", ENUM_TO_STRING(LOCK_RESULT, result)); } } + return result; } LOCK_RESULT Lock_Deinit(LOCK_HANDLE handle) { - LOCK_RESULT result=LOCK_OK ; + LOCK_RESULT result; if (NULL == handle) { - /*Tests_SRS_LOCK_99_013:[ This API on NULL handle passed returns LOCK_ERROR]*/ + /* Codes_SRS_LOCK_10_007: [Lock_Deinit on NULL handle passed returns LOCK_ERROR] */ + LogError("Invalid argument; handle is NULL."); result = LOCK_ERROR; - LogError("(result = %s)", ENUM_TO_STRING(LOCK_RESULT, result)); } else { - /*Tests_SRS_LOCK_99_012:[ This API frees the memory pointed by handle]*/ + /* Codes_SRS_LOCK_10_012: [Lock_Deinit frees the memory pointed by handle] */ Mutex* lock_mtx = (Mutex*)handle; delete lock_mtx; + result = LOCK_OK; } return result;