Mark Radbourne / Mbed 2 deprecated iothub_client_sample_amqp

Dependencies:   EthernetInterface NTPClient iothub_amqp_transport iothub_client mbed-rtos mbed

Fork of iothub_client_sample_amqp by Azure IoT

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers lock_rtx_mbed.cpp Source File

lock_rtx_mbed.cpp

00001 // Copyright (c) Microsoft. All rights reserved.
00002 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
00003 
00004 #include <cstdlib>
00005 #ifdef _CRTDBG_MAP_ALLOC
00006 #include <crtdbg.h>
00007 #endif
00008 
00009 #include "azure_c_shared_utility/lock.h"
00010 #include "azure_c_shared_utility/xlogging.h"
00011 #include "rtos.h"
00012 
00013 DEFINE_ENUM_STRINGS(LOCK_RESULT, LOCK_RESULT_VALUES);
00014 
00015 /*Tests_SRS_LOCK_99_002:[ This API on success will return a valid lock handle which should be a non NULL value]*/
00016 LOCK_HANDLE Lock_Init(void)
00017 {
00018     Mutex* lock_mtx = new Mutex();
00019   
00020     return (LOCK_HANDLE)lock_mtx;
00021 }
00022 
00023 
00024 LOCK_RESULT Lock(LOCK_HANDLE handle)
00025 {
00026     LOCK_RESULT result;
00027     if (handle == NULL)
00028     {
00029         /*Tests_SRS_LOCK_99_007:[ This API on NULL handle passed returns LOCK_ERROR]*/
00030         result = LOCK_ERROR;
00031         LogError("(result = %s)", ENUM_TO_STRING(LOCK_RESULT, result));
00032     }
00033     else
00034     {
00035         Mutex* lock_mtx = (Mutex*)handle;
00036         if (lock_mtx->lock() == osOK)
00037         {
00038             /*Tests_SRS_LOCK_99_005:[ This API on success should return LOCK_OK]*/
00039             result = LOCK_OK;
00040         }
00041         else
00042         {
00043             /*Tests_SRS_LOCK_99_006:[ This API on error should return LOCK_ERROR]*/
00044             result = LOCK_ERROR;
00045             LogError("(result = %s)", ENUM_TO_STRING(LOCK_RESULT, result));
00046         }
00047     }
00048     return result;
00049 }
00050 LOCK_RESULT Unlock(LOCK_HANDLE handle)
00051 {
00052     LOCK_RESULT result;
00053     if (handle == NULL)
00054     {
00055         /*Tests_SRS_LOCK_99_011:[ This API on NULL handle passed returns LOCK_ERROR]*/
00056         result = LOCK_ERROR;
00057         LogError("(result = %s)", ENUM_TO_STRING(LOCK_RESULT, result));
00058     }
00059     else
00060     {
00061         Mutex* lock_mtx = (Mutex*)handle;
00062         if (lock_mtx->unlock() == osOK)
00063         {
00064             /*Tests_SRS_LOCK_99_009:[ This API on success should return LOCK_OK]*/
00065             result = LOCK_OK;
00066         }
00067         else
00068         {
00069             /*Tests_SRS_LOCK_99_010:[ This API on error should return LOCK_ERROR]*/
00070             result = LOCK_ERROR;
00071             LogError("(result = %s)", ENUM_TO_STRING(LOCK_RESULT, result));
00072         }
00073     }
00074     return result;
00075 }
00076 
00077 LOCK_RESULT Lock_Deinit(LOCK_HANDLE handle)
00078 {
00079     LOCK_RESULT result=LOCK_OK ;
00080     if (NULL == handle)
00081     {
00082         /*Tests_SRS_LOCK_99_013:[ This API on NULL handle passed returns LOCK_ERROR]*/
00083         result = LOCK_ERROR;
00084         LogError("(result = %s)", ENUM_TO_STRING(LOCK_RESULT, result));
00085     }
00086     else
00087     {
00088         /*Tests_SRS_LOCK_99_012:[ This API frees the memory pointed by handle]*/
00089         Mutex* lock_mtx = (Mutex*)handle;
00090         delete lock_mtx;
00091     }
00092     
00093     return result;
00094 }