Azure IoT common library

Dependents:   STM32F746_iothub_client_sample_mqtt f767zi_mqtt iothub_client_sample_amqp iothub_client_sample_http ... more

Committer:
AzureIoTClient
Date:
Sat Jan 28 09:35:22 2017 -0800
Revision:
19:2e0811512ceb
Parent:
6:c55b013dfc2a
Child:
22:10640b226104
1.1.6

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Azure.IoT Build 0:fa2de1b79154 1 // Copyright (c) Microsoft. All rights reserved.
Azure.IoT Build 0:fa2de1b79154 2 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
Azure.IoT Build 0:fa2de1b79154 3
Azure.IoT Build 0:fa2de1b79154 4 #include "azure_c_shared_utility/lock.h"
Azure.IoT Build 6:c55b013dfc2a 5 #include "azure_c_shared_utility/xlogging.h"
Azure.IoT Build 0:fa2de1b79154 6 #include "rtos.h"
Azure.IoT Build 0:fa2de1b79154 7
Azure.IoT Build 0:fa2de1b79154 8 DEFINE_ENUM_STRINGS(LOCK_RESULT, LOCK_RESULT_VALUES);
Azure.IoT Build 0:fa2de1b79154 9
Azure.IoT Build 0:fa2de1b79154 10 /*Tests_SRS_LOCK_99_002:[ This API on success will return a valid lock handle which should be a non NULL value]*/
Azure.IoT Build 0:fa2de1b79154 11 LOCK_HANDLE Lock_Init(void)
Azure.IoT Build 0:fa2de1b79154 12 {
Azure.IoT Build 0:fa2de1b79154 13 Mutex* lock_mtx = new Mutex();
Azure.IoT Build 0:fa2de1b79154 14
Azure.IoT Build 0:fa2de1b79154 15 return (LOCK_HANDLE)lock_mtx;
Azure.IoT Build 0:fa2de1b79154 16 }
Azure.IoT Build 0:fa2de1b79154 17
Azure.IoT Build 0:fa2de1b79154 18
Azure.IoT Build 0:fa2de1b79154 19 LOCK_RESULT Lock(LOCK_HANDLE handle)
Azure.IoT Build 0:fa2de1b79154 20 {
Azure.IoT Build 0:fa2de1b79154 21 LOCK_RESULT result;
Azure.IoT Build 0:fa2de1b79154 22 if (handle == NULL)
Azure.IoT Build 0:fa2de1b79154 23 {
Azure.IoT Build 0:fa2de1b79154 24 /*Tests_SRS_LOCK_99_007:[ This API on NULL handle passed returns LOCK_ERROR]*/
Azure.IoT Build 0:fa2de1b79154 25 result = LOCK_ERROR;
AzureIoTClient 1:9190c0f4d23a 26 LogError("(result = %s)", ENUM_TO_STRING(LOCK_RESULT, result));
Azure.IoT Build 0:fa2de1b79154 27 }
Azure.IoT Build 0:fa2de1b79154 28 else
Azure.IoT Build 0:fa2de1b79154 29 {
Azure.IoT Build 0:fa2de1b79154 30 Mutex* lock_mtx = (Mutex*)handle;
Azure.IoT Build 0:fa2de1b79154 31 if (lock_mtx->lock() == osOK)
Azure.IoT Build 0:fa2de1b79154 32 {
Azure.IoT Build 0:fa2de1b79154 33 /*Tests_SRS_LOCK_99_005:[ This API on success should return LOCK_OK]*/
Azure.IoT Build 0:fa2de1b79154 34 result = LOCK_OK;
Azure.IoT Build 0:fa2de1b79154 35 }
Azure.IoT Build 0:fa2de1b79154 36 else
Azure.IoT Build 0:fa2de1b79154 37 {
Azure.IoT Build 0:fa2de1b79154 38 /*Tests_SRS_LOCK_99_006:[ This API on error should return LOCK_ERROR]*/
Azure.IoT Build 0:fa2de1b79154 39 result = LOCK_ERROR;
AzureIoTClient 1:9190c0f4d23a 40 LogError("(result = %s)", ENUM_TO_STRING(LOCK_RESULT, result));
Azure.IoT Build 0:fa2de1b79154 41 }
Azure.IoT Build 0:fa2de1b79154 42 }
Azure.IoT Build 0:fa2de1b79154 43 return result;
Azure.IoT Build 0:fa2de1b79154 44 }
Azure.IoT Build 0:fa2de1b79154 45 LOCK_RESULT Unlock(LOCK_HANDLE handle)
Azure.IoT Build 0:fa2de1b79154 46 {
Azure.IoT Build 0:fa2de1b79154 47 LOCK_RESULT result;
Azure.IoT Build 0:fa2de1b79154 48 if (handle == NULL)
Azure.IoT Build 0:fa2de1b79154 49 {
Azure.IoT Build 0:fa2de1b79154 50 /*Tests_SRS_LOCK_99_011:[ This API on NULL handle passed returns LOCK_ERROR]*/
Azure.IoT Build 0:fa2de1b79154 51 result = LOCK_ERROR;
AzureIoTClient 1:9190c0f4d23a 52 LogError("(result = %s)", ENUM_TO_STRING(LOCK_RESULT, result));
Azure.IoT Build 0:fa2de1b79154 53 }
Azure.IoT Build 0:fa2de1b79154 54 else
Azure.IoT Build 0:fa2de1b79154 55 {
Azure.IoT Build 0:fa2de1b79154 56 Mutex* lock_mtx = (Mutex*)handle;
Azure.IoT Build 0:fa2de1b79154 57 if (lock_mtx->unlock() == osOK)
Azure.IoT Build 0:fa2de1b79154 58 {
Azure.IoT Build 0:fa2de1b79154 59 /*Tests_SRS_LOCK_99_009:[ This API on success should return LOCK_OK]*/
Azure.IoT Build 0:fa2de1b79154 60 result = LOCK_OK;
Azure.IoT Build 0:fa2de1b79154 61 }
Azure.IoT Build 0:fa2de1b79154 62 else
Azure.IoT Build 0:fa2de1b79154 63 {
Azure.IoT Build 0:fa2de1b79154 64 /*Tests_SRS_LOCK_99_010:[ This API on error should return LOCK_ERROR]*/
Azure.IoT Build 0:fa2de1b79154 65 result = LOCK_ERROR;
AzureIoTClient 1:9190c0f4d23a 66 LogError("(result = %s)", ENUM_TO_STRING(LOCK_RESULT, result));
Azure.IoT Build 0:fa2de1b79154 67 }
Azure.IoT Build 0:fa2de1b79154 68 }
Azure.IoT Build 0:fa2de1b79154 69 return result;
Azure.IoT Build 0:fa2de1b79154 70 }
Azure.IoT Build 0:fa2de1b79154 71
Azure.IoT Build 0:fa2de1b79154 72 LOCK_RESULT Lock_Deinit(LOCK_HANDLE handle)
Azure.IoT Build 0:fa2de1b79154 73 {
Azure.IoT Build 0:fa2de1b79154 74 LOCK_RESULT result=LOCK_OK ;
Azure.IoT Build 0:fa2de1b79154 75 if (NULL == handle)
Azure.IoT Build 0:fa2de1b79154 76 {
Azure.IoT Build 0:fa2de1b79154 77 /*Tests_SRS_LOCK_99_013:[ This API on NULL handle passed returns LOCK_ERROR]*/
Azure.IoT Build 0:fa2de1b79154 78 result = LOCK_ERROR;
AzureIoTClient 1:9190c0f4d23a 79 LogError("(result = %s)", ENUM_TO_STRING(LOCK_RESULT, result));
Azure.IoT Build 0:fa2de1b79154 80 }
Azure.IoT Build 0:fa2de1b79154 81 else
Azure.IoT Build 0:fa2de1b79154 82 {
Azure.IoT Build 0:fa2de1b79154 83 /*Tests_SRS_LOCK_99_012:[ This API frees the memory pointed by handle]*/
Azure.IoT Build 0:fa2de1b79154 84 Mutex* lock_mtx = (Mutex*)handle;
Azure.IoT Build 0:fa2de1b79154 85 delete lock_mtx;
Azure.IoT Build 0:fa2de1b79154 86 }
Azure.IoT Build 0:fa2de1b79154 87
Azure.IoT Build 0:fa2de1b79154 88 return result;
Azure.IoT Build 0:fa2de1b79154 89 }