Azure IoT common library

Dependents:   STM32F746_iothub_client_sample_mqtt f767zi_mqtt iothub_client_sample_amqp iothub_client_sample_http ... more

Committer:
Azure.IoT Build
Date:
Fri Jul 01 10:43:23 2016 -0700
Revision:
6:c55b013dfc2a
Parent:
1:9190c0f4d23a
Child:
19:2e0811512ceb
1.0.10

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 <cstdlib>
Azure.IoT Build 0:fa2de1b79154 5 #ifdef _CRTDBG_MAP_ALLOC
Azure.IoT Build 0:fa2de1b79154 6 #include <crtdbg.h>
Azure.IoT Build 0:fa2de1b79154 7 #endif
Azure.IoT Build 0:fa2de1b79154 8
Azure.IoT Build 0:fa2de1b79154 9 #include "azure_c_shared_utility/lock.h"
Azure.IoT Build 6:c55b013dfc2a 10 #include "azure_c_shared_utility/xlogging.h"
Azure.IoT Build 0:fa2de1b79154 11 #include "rtos.h"
Azure.IoT Build 0:fa2de1b79154 12
Azure.IoT Build 0:fa2de1b79154 13 DEFINE_ENUM_STRINGS(LOCK_RESULT, LOCK_RESULT_VALUES);
Azure.IoT Build 0:fa2de1b79154 14
Azure.IoT Build 0:fa2de1b79154 15 /*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 16 LOCK_HANDLE Lock_Init(void)
Azure.IoT Build 0:fa2de1b79154 17 {
Azure.IoT Build 0:fa2de1b79154 18 Mutex* lock_mtx = new Mutex();
Azure.IoT Build 0:fa2de1b79154 19
Azure.IoT Build 0:fa2de1b79154 20 return (LOCK_HANDLE)lock_mtx;
Azure.IoT Build 0:fa2de1b79154 21 }
Azure.IoT Build 0:fa2de1b79154 22
Azure.IoT Build 0:fa2de1b79154 23
Azure.IoT Build 0:fa2de1b79154 24 LOCK_RESULT Lock(LOCK_HANDLE handle)
Azure.IoT Build 0:fa2de1b79154 25 {
Azure.IoT Build 0:fa2de1b79154 26 LOCK_RESULT result;
Azure.IoT Build 0:fa2de1b79154 27 if (handle == NULL)
Azure.IoT Build 0:fa2de1b79154 28 {
Azure.IoT Build 0:fa2de1b79154 29 /*Tests_SRS_LOCK_99_007:[ This API on NULL handle passed returns LOCK_ERROR]*/
Azure.IoT Build 0:fa2de1b79154 30 result = LOCK_ERROR;
AzureIoTClient 1:9190c0f4d23a 31 LogError("(result = %s)", ENUM_TO_STRING(LOCK_RESULT, result));
Azure.IoT Build 0:fa2de1b79154 32 }
Azure.IoT Build 0:fa2de1b79154 33 else
Azure.IoT Build 0:fa2de1b79154 34 {
Azure.IoT Build 0:fa2de1b79154 35 Mutex* lock_mtx = (Mutex*)handle;
Azure.IoT Build 0:fa2de1b79154 36 if (lock_mtx->lock() == osOK)
Azure.IoT Build 0:fa2de1b79154 37 {
Azure.IoT Build 0:fa2de1b79154 38 /*Tests_SRS_LOCK_99_005:[ This API on success should return LOCK_OK]*/
Azure.IoT Build 0:fa2de1b79154 39 result = LOCK_OK;
Azure.IoT Build 0:fa2de1b79154 40 }
Azure.IoT Build 0:fa2de1b79154 41 else
Azure.IoT Build 0:fa2de1b79154 42 {
Azure.IoT Build 0:fa2de1b79154 43 /*Tests_SRS_LOCK_99_006:[ This API on error should return LOCK_ERROR]*/
Azure.IoT Build 0:fa2de1b79154 44 result = LOCK_ERROR;
AzureIoTClient 1:9190c0f4d23a 45 LogError("(result = %s)", ENUM_TO_STRING(LOCK_RESULT, result));
Azure.IoT Build 0:fa2de1b79154 46 }
Azure.IoT Build 0:fa2de1b79154 47 }
Azure.IoT Build 0:fa2de1b79154 48 return result;
Azure.IoT Build 0:fa2de1b79154 49 }
Azure.IoT Build 0:fa2de1b79154 50 LOCK_RESULT Unlock(LOCK_HANDLE handle)
Azure.IoT Build 0:fa2de1b79154 51 {
Azure.IoT Build 0:fa2de1b79154 52 LOCK_RESULT result;
Azure.IoT Build 0:fa2de1b79154 53 if (handle == NULL)
Azure.IoT Build 0:fa2de1b79154 54 {
Azure.IoT Build 0:fa2de1b79154 55 /*Tests_SRS_LOCK_99_011:[ This API on NULL handle passed returns LOCK_ERROR]*/
Azure.IoT Build 0:fa2de1b79154 56 result = LOCK_ERROR;
AzureIoTClient 1:9190c0f4d23a 57 LogError("(result = %s)", ENUM_TO_STRING(LOCK_RESULT, result));
Azure.IoT Build 0:fa2de1b79154 58 }
Azure.IoT Build 0:fa2de1b79154 59 else
Azure.IoT Build 0:fa2de1b79154 60 {
Azure.IoT Build 0:fa2de1b79154 61 Mutex* lock_mtx = (Mutex*)handle;
Azure.IoT Build 0:fa2de1b79154 62 if (lock_mtx->unlock() == osOK)
Azure.IoT Build 0:fa2de1b79154 63 {
Azure.IoT Build 0:fa2de1b79154 64 /*Tests_SRS_LOCK_99_009:[ This API on success should return LOCK_OK]*/
Azure.IoT Build 0:fa2de1b79154 65 result = LOCK_OK;
Azure.IoT Build 0:fa2de1b79154 66 }
Azure.IoT Build 0:fa2de1b79154 67 else
Azure.IoT Build 0:fa2de1b79154 68 {
Azure.IoT Build 0:fa2de1b79154 69 /*Tests_SRS_LOCK_99_010:[ This API on error should return LOCK_ERROR]*/
Azure.IoT Build 0:fa2de1b79154 70 result = LOCK_ERROR;
AzureIoTClient 1:9190c0f4d23a 71 LogError("(result = %s)", ENUM_TO_STRING(LOCK_RESULT, result));
Azure.IoT Build 0:fa2de1b79154 72 }
Azure.IoT Build 0:fa2de1b79154 73 }
Azure.IoT Build 0:fa2de1b79154 74 return result;
Azure.IoT Build 0:fa2de1b79154 75 }
Azure.IoT Build 0:fa2de1b79154 76
Azure.IoT Build 0:fa2de1b79154 77 LOCK_RESULT Lock_Deinit(LOCK_HANDLE handle)
Azure.IoT Build 0:fa2de1b79154 78 {
Azure.IoT Build 0:fa2de1b79154 79 LOCK_RESULT result=LOCK_OK ;
Azure.IoT Build 0:fa2de1b79154 80 if (NULL == handle)
Azure.IoT Build 0:fa2de1b79154 81 {
Azure.IoT Build 0:fa2de1b79154 82 /*Tests_SRS_LOCK_99_013:[ This API on NULL handle passed returns LOCK_ERROR]*/
Azure.IoT Build 0:fa2de1b79154 83 result = LOCK_ERROR;
AzureIoTClient 1:9190c0f4d23a 84 LogError("(result = %s)", ENUM_TO_STRING(LOCK_RESULT, result));
Azure.IoT Build 0:fa2de1b79154 85 }
Azure.IoT Build 0:fa2de1b79154 86 else
Azure.IoT Build 0:fa2de1b79154 87 {
Azure.IoT Build 0:fa2de1b79154 88 /*Tests_SRS_LOCK_99_012:[ This API frees the memory pointed by handle]*/
Azure.IoT Build 0:fa2de1b79154 89 Mutex* lock_mtx = (Mutex*)handle;
Azure.IoT Build 0:fa2de1b79154 90 delete lock_mtx;
Azure.IoT Build 0:fa2de1b79154 91 }
Azure.IoT Build 0:fa2de1b79154 92
Azure.IoT Build 0:fa2de1b79154 93 return result;
Azure.IoT Build 0:fa2de1b79154 94 }