Skip to content

Commit

Permalink
manual merge
Browse files Browse the repository at this point in the history
  • Loading branch information
massand committed Feb 1, 2019
2 parents 36b6b26 + d5382e3 commit a43a968
Show file tree
Hide file tree
Showing 27 changed files with 1,164 additions and 73 deletions.
4 changes: 1 addition & 3 deletions iothub_client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,7 @@ endif()
set(IOTHUB_CLIENT_INC_FOLDER ${CMAKE_CURRENT_LIST_DIR}/inc CACHE INTERNAL "this is what needs to be included if using iothub_client lib" FORCE)


if(NOT ${dont_use_uploadtoblob} OR ${use_edge_modules})
include_directories(../deps/parson)
endif()
include_directories(../deps/parson)

include_directories(${DEV_AUTH_MODULES_CLIENT_INC_FOLDER})
include_directories(${AZURE_C_SHARED_UTILITY_INCLUDES})
Expand Down
69 changes: 58 additions & 11 deletions iothub_client/inc/internal/iothub_client_diagnostic.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,72 @@ extern "C" {
#include <stddef.h>
#endif

/* Deprecated: Use IOTHUB_DISTRIBUTED_TRACING_SETTING_DATA_TAG instead with IoTHubClient_DistributedTracing_AddToMessageHeadersIfNecessary API */
/** @brief diagnostic related setting */
typedef struct IOTHUB_DIAGNOSTIC_SETTING_DATA_TAG
{
uint32_t diagSamplingPercentage;
uint32_t currentMessageNumber;
} IOTHUB_DIAGNOSTIC_SETTING_DATA;

#define IOTHUB_DISTRIBUTED_TRACING_SAMPLING_MODE_VALUE \
IOTHUB_DISTRIBUTED_TRACING_SAMPLING_MODE_NOT_SET, \
IOTHUB_DISTRIBUTED_TRACING_SAMPLING_MODE_ON, \
IOTHUB_DISTRIBUTED_TRACING_SAMPLING_MODE_OFF, \
IOTHUB_DISTRIBUTED_TRACING_SAMPLING_MODE_INHERIT
DEFINE_ENUM(IOTHUB_DISTRIBUTED_TRACING_SAMPLING_MODE, IOTHUB_DISTRIBUTED_TRACING_SAMPLING_MODE_VALUE);

/** @brief distributed tracing settings */
typedef struct IOTHUB_DISTRIBUTED_TRACING_SETTING_DATA_TAG
{
bool policyEnabled;

/* Distributed Tracing sampling enabled flag.
Possible options from server - On (1), Off (2), Inherit (3) */
IOTHUB_DISTRIBUTED_TRACING_SAMPLING_MODE samplingMode;

/* Distributed tracing fixed-rate sampling percentage.
Set to 100/N where N is an integer. E.g. 50 (=100/2), 33.33 (=100/3), 25 (=100/4), 20, 1 (=100/100), 0.1 (=100/1000) */
uint8_t samplingRate;

/* Distributed tracing message sequence number */
uint32_t currentMessageNumber;
} IOTHUB_DISTRIBUTED_TRACING_SETTING_DATA;

/**
* @brief Adds diagnostic information to message if:
* a. diagSetting->diagSamplingPercentage > 0 and
* b. the number of current message matches sample rule specified by diagSetting->diagSamplingPercentage
*
* @param diagSetting Pointer to an @c IOTHUB_DIAGNOSTIC_SETTING_DATA structure
*
* @param messageHandle message handle
*
* @return 0 upon success
*/
MOCKABLE_FUNCTION(, int, IoTHubClient_Diagnostic_AddIfNecessary, IOTHUB_DIAGNOSTIC_SETTING_DATA *, diagSetting, IOTHUB_MESSAGE_HANDLE, messageHandle);
* @brief Adds diagnostic information to message if:
** DEPRECATED: Use IoTHubClient_DistributedTracing_AddToMessageHeadersIfNecessary instead. **
* a. diagSetting->diagSamplingPercentage > 0 and
* b. the number of current message matches sample rule specified by diagSetting->diagSamplingPercentage
*
* @param diagSetting Pointer to an @c IOTHUB_DIAGNOSTIC_SETTING_DATA structure
* @param messageHandle message handle
* @return 0 upon success, non-zero otherwise
*/
MOCKABLE_FUNCTION(, int, IoTHubClient_Diagnostic_AddIfNecessary, IOTHUB_DIAGNOSTIC_SETTING_DATA*, diagSetting, IOTHUB_MESSAGE_HANDLE, messageHandle);

/**
* @brief Adds tracestate information to message if:
* a. distributedTracingSetting->sampingMode = true
* b. distributedTracingSetting->samplingRate > 0 and
* c. the number of current message matches sample rule specified by distributedTracingSetting->samplingRate
*
* @param distributedTracingSetting Pointer to an @c IOTHUB_DISTRIBUTED_TRACING_SETTING_DATA structure
* @param messageHandle message handle
* @return 0 upon success, non-zero otherwise
*/
MOCKABLE_FUNCTION(, int, IoTHubClient_DistributedTracing_AddToMessageHeadersIfNecessary, IOTHUB_DISTRIBUTED_TRACING_SETTING_DATA*, distributedTracingSetting, IOTHUB_MESSAGE_HANDLE, messageHandle);

/**
* @brief Update distributed tracing settings from device twin
*
* @param distributedTracingSetting Pointer to an @c IOTHUB_DISTRIBUTED_TRACING_SETTING_DATA structure
* @param isPartialUpdate Whether device twin is complete or partial update
* @param payLoad Received device twin
* @param reportedStatePayload Reported state payload for distributed tracing setting
* @return 0 upon success, non-zero otherwise
*/
MOCKABLE_FUNCTION(, int, IoTHubClient_DistributedTracing_UpdateFromTwin, IOTHUB_DISTRIBUTED_TRACING_SETTING_DATA*, distributedTracingSetting, bool, isPartialUpdate, const unsigned char*, payLoad, STRING_HANDLE*, reportedStatePayload);

#ifdef __cplusplus
}
Expand Down
1 change: 1 addition & 0 deletions iothub_client/inc/iothub_client_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ extern "C"

MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClientCore_SendEventToOutputAsync, IOTHUB_CLIENT_CORE_HANDLE, iotHubClientHandle, IOTHUB_MESSAGE_HANDLE, eventMessageHandle, const char*, outputName, IOTHUB_CLIENT_EVENT_CONFIRMATION_CALLBACK, eventConfirmationCallback, void*, userContextCallback);
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClientCore_SetInputMessageCallback, IOTHUB_CLIENT_CORE_HANDLE, iotHubClientHandle, const char*, inputName, IOTHUB_CLIENT_MESSAGE_CALLBACK_ASYNC, eventHandlerCallback, void*, userContextCallback);
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClientCore_EnablePolicyConfiguration, IOTHUB_CLIENT_CORE_HANDLE, iotHubClientHandle, POLICY_CONFIGURATION_TYPE, policyType, bool, enablePolicyConfiguration);

#ifdef USE_EDGE_MODULES
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_CORE_HANDLE, IoTHubClientCore_CreateFromEnvironment, IOTHUB_CLIENT_TRANSPORT_PROVIDER, protocol);
Expand Down
5 changes: 5 additions & 0 deletions iothub_client/inc/iothub_client_core_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ extern "C"
const char* deviceSasToken;
} IOTHUB_CLIENT_DEVICE_CONFIG;

#define POLICY_CONFIGURATION_TYPE_VALUES \
POLICY_CONFIGURATION_DISTRIBUTED_TRACING

DEFINE_ENUM(POLICY_CONFIGURATION_TYPE, POLICY_CONFIGURATION_TYPE_VALUES);

#ifdef __cplusplus
}
#endif
Expand Down
3 changes: 2 additions & 1 deletion iothub_client/inc/iothub_client_core_ll.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ extern "C"
#ifdef USE_EDGE_MODULES
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_CORE_LL_HANDLE, IoTHubClientCore_LL_CreateFromEnvironment, IOTHUB_CLIENT_TRANSPORT_PROVIDER, protocol);
#endif


MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClientCore_LL_EnablePolicyConfiguration, IOTHUB_CLIENT_CORE_LL_HANDLE, iotHubClientHandle, POLICY_CONFIGURATION_TYPE, policyType, bool, enablePolicyConfiguration);
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClientCore_LL_SetStreamRequestCallback, IOTHUB_CLIENT_CORE_LL_HANDLE, iotHubClientHandle, DEVICE_STREAM_C2D_REQUEST_CALLBACK, streamRequestCallback, void*, context);
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClientCore_LL_SendStreamResponse, IOTHUB_CLIENT_CORE_LL_HANDLE, iotHubClientHandle, DEVICE_STREAM_C2D_RESPONSE*, response);

Expand Down
12 changes: 12 additions & 0 deletions iothub_client/inc/iothub_device_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,18 @@ extern "C"

#endif /* DONT_USE_UPLOADTOBLOB */

/**
* @brief This API enables the device to use specific IoTHub features that are configured via device twins.
*
* @param iotHubClientHandle The handle created by a call to the create function.
* @param policyType The policy type that will be accepted from Azure IoT Hub.
* @param enablePolicyConfiguration True to enable parsing device twin for specific feature configuration.
Default is false.
*
* @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
*/
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubDeviceClient_EnablePolicyConfiguration, IOTHUB_DEVICE_CLIENT_HANDLE, iotHubClientHandle, POLICY_CONFIGURATION_TYPE, policyType, bool, enablePolicyConfiguration);

/**
* @brief Subscribes/unsubscribes for cloud-to-device stream requests.
*
Expand Down
12 changes: 12 additions & 0 deletions iothub_client/inc/iothub_device_client_ll.h
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,18 @@ typedef struct IOTHUB_CLIENT_CORE_LL_HANDLE_DATA_TAG* IOTHUB_DEVICE_CLIENT_LL_HA

#endif /*DONT_USE_UPLOADTOBLOB*/

/**
* @brief This API enables the device to use specific IoTHub features that are configured via device twins.
*
* @param iotHubClientHandle The handle created by a call to the create function.
* @param policyType The policy type that will be accepted from Azure IoT Hub.
* @param enablePolicyConfiguration True to enable parsing device twin for specific feature configuration.
Default is false.
*
* @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
*/
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubDeviceClient_LL_EnablePolicyConfiguration, IOTHUB_DEVICE_CLIENT_LL_HANDLE, iotHubClientHandle, POLICY_CONFIGURATION_TYPE, policyType, bool, enablePolicyConfiguration);

/**
* @brief Subscribes/unsubscribes for cloud-to-device stream requests.
*
Expand Down
23 changes: 22 additions & 1 deletion iothub_client/inc/iothub_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ typedef struct IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA_TAG
char* diagnosticCreationTimeUtc;
}IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA, *IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA_HANDLE;

static const char DIAG_CREATION_TIME_UTC_PROPERTY_NAME[] = "diag_creation_time_utc";

/**
* @brief Creates a new IoT hub message from a byte array. The type of the
Expand Down Expand Up @@ -246,6 +245,7 @@ MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_RESULT, IoTHubMessage_SetCorrelationId, IOTHU

/**
* @brief Gets the DiagnosticData from the IOTHUB_MESSAGE_HANDLE. CAUTION: SDK user should not call it directly, it is for internal use only.
** DEPRECATED: Use IoTHubMessage_GetDistributedTracingSystemProperty instead. **
*
* @param iotHubMessageHandle Handle to the message.
*
Expand All @@ -255,6 +255,7 @@ MOCKABLE_FUNCTION(, const IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA*, IoTHubMessag

/**
* @brief Sets the DiagnosticData for the IOTHUB_MESSAGE_HANDLE. CAUTION: SDK user should not call it directly, it is for internal use only.
** DEPRECATED: Use IoTHubMessage_SetDistributedTracingSystemProperty instead. **
*
* @param iotHubMessageHandle Handle to the message.
* @param diagnosticData Pointer to the memory location of the diagnosticData
Expand All @@ -264,6 +265,26 @@ MOCKABLE_FUNCTION(, const IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA*, IoTHubMessag
*/
MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_RESULT, IoTHubMessage_SetDiagnosticPropertyData, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle, const IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA*, diagnosticData);

/**
* @brief Gets the tracestate (current timestamp) from the IOTHUB_MESSAGE_HANDLE.
*
* @param iotHubMessageHandle Handle to the message.
*
* @return A const char* pointing to the distributed tracing tracestate value.
*/
MOCKABLE_FUNCTION(, const char*, IoTHubMessage_GetDistributedTracingSystemProperty, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);

/**
* @brief Sets the distributed tracing system property for the IOTHUB_MESSAGE_HANDLE.
*
* @param iotHubMessageHandle Handle to the message.
* @param distributedTracingTracestate Pointer to the memory location of the Distributed Tracing tracestate.
*
* @return Returns IOTHUB_MESSAGE_OK if the Distributed Tracing tracestate was set successfully
* or an error code otherwise.
*/
MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_RESULT, IoTHubMessage_SetDistributedTracingSystemProperty, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle, const char*, distributedTracingTracestate);

/**
* @brief Gets the output name from the IOTHUB_MESSAGE_HANDLE.
*
Expand Down
29 changes: 29 additions & 0 deletions iothub_client/src/iothub_client_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -2689,6 +2689,35 @@ IOTHUB_CLIENT_RESULT IoTHubClientCore_GenericMethodInvoke(IOTHUB_CLIENT_CORE_HAN
}
#endif /* USE_EDGE_MODULES */

IOTHUB_CLIENT_RESULT IoTHubClientCore_EnablePolicyConfiguration(IOTHUB_CLIENT_CORE_HANDLE iotHubClientHandle, POLICY_CONFIGURATION_TYPE policyType, bool enablePolicyConfiguration)
{
IOTHUB_CLIENT_RESULT result;
if (iotHubClientHandle == NULL)
{
LogError("Invalid argument (iotHubClientHandle=%p)", iotHubClientHandle);
result = IOTHUB_CLIENT_INVALID_ARG;
}
else
{
IOTHUB_CLIENT_CORE_INSTANCE* iotHubClientInstance = (IOTHUB_CLIENT_CORE_INSTANCE*)iotHubClientHandle;

/*Codes_SRS_IOTHUBCLIENT_38_001: [ IoTHubClientCore_EnablePolicyConfiguration shall be made thread-safe by using the lock created in IoTHubClient_Create. ]*/
if (Lock(iotHubClientInstance->LockHandle) != LOCK_OK)
{
/*Codes_SRS_IOTHUBCLIENT_38_002: [ If acquiring the lock fails, IoTHubClientCore_EnablePolicyConfiguration shall return IOTHUB_CLIENT_ERROR. ]*/
result = IOTHUB_CLIENT_ERROR;
LogError("Could not acquire lock");
}
else
{
result = IoTHubClientCore_LL_EnablePolicyConfiguration(iotHubClientHandle->IoTHubClientLLHandle, policyType, enablePolicyConfiguration);
(void)Unlock(iotHubClientInstance->LockHandle);
}
}

return result;
}

static DEVICE_STREAM_C2D_RESPONSE* iothub_ll_device_stream_request_callback(DEVICE_STREAM_C2D_REQUEST* request, void* context)
{
DEVICE_STREAM_C2D_RESPONSE* result;
Expand Down
Loading

0 comments on commit a43a968

Please sign in to comment.