Microsoft Azure IoTHub client libraries
Dependents: sht15_remote_monitoring RobotArmDemo iothub_client_sample_amqp f767zi_mqtt ... more
This library implements the Microsoft Azure IoTHub client library. The code is replicated from https://github.com/Azure/azure-iot-sdks
Diff: iothub_client.c
- Revision:
- 67:ecebc2a41159
- Parent:
- 66:a419827cb051
- Child:
- 71:0d498da5ece1
--- a/iothub_client.c Mon May 08 10:50:31 2017 -0700 +++ b/iothub_client.c Mon May 22 10:35:09 2017 -0700 @@ -414,15 +414,31 @@ switch (queued_cb->type) { case CALLBACK_TYPE_DEVICE_TWIN: - if (iotHubClientInstance->desired_state_callback) + { + IOTHUB_CLIENT_DEVICE_TWIN_CALLBACK desired_state_callback; + + if (Lock(iotHubClientInstance->LockHandle) != LOCK_OK) + { + LogError("failed locking for dispatch_user_callbacks"); + desired_state_callback = NULL; + } + else { - iotHubClientInstance->desired_state_callback(queued_cb->iothub_callback.dev_twin_cb_info.update_state, queued_cb->iothub_callback.dev_twin_cb_info.payLoad, queued_cb->iothub_callback.dev_twin_cb_info.size, queued_cb->userContextCallback); + desired_state_callback = iotHubClientInstance->desired_state_callback; + (void)Unlock(iotHubClientInstance->LockHandle); } + + if (desired_state_callback) + { + desired_state_callback(queued_cb->iothub_callback.dev_twin_cb_info.update_state, queued_cb->iothub_callback.dev_twin_cb_info.payLoad, queued_cb->iothub_callback.dev_twin_cb_info.size, queued_cb->userContextCallback); + } + if (queued_cb->iothub_callback.dev_twin_cb_info.payLoad) { free(queued_cb->iothub_callback.dev_twin_cb_info.payLoad); } break; + } case CALLBACK_TYPE_EVENT_CONFIRM: if (iotHubClientInstance->event_confirm_callback) { @@ -1406,11 +1422,6 @@ } else { - if (iotHubClientInstance->created_with_transport_handle == 0) - { - iotHubClientInstance->desired_state_callback = deviceTwinCallback; - } - /*Codes_SRS_IOTHUBCLIENT_10_020: [** `IoTHubClient_SetDeviceTwinCallback` shall be made thread - safe by using the lock created in IoTHubClient_Create. ]*/ if (Lock(iotHubClientInstance->LockHandle) != LOCK_OK) { @@ -1420,6 +1431,11 @@ } else { + if (iotHubClientInstance->created_with_transport_handle == 0) + { + iotHubClientInstance->desired_state_callback = deviceTwinCallback; + } + if (iotHubClientInstance->created_with_transport_handle != 0 || deviceTwinCallback == NULL) { /*Codes_SRS_IOTHUBCLIENT_10_005: [** `IoTHubClient_LL_SetDeviceTwinCallback` shall call `IoTHubClient_LL_SetDeviceTwinCallback`, while passing the `IoTHubClient_LL handle` created by `IoTHubClient_LL_Create` along with the parameters `reportedStateCallback` and `userContextCallback`. ]*/