static void IoTHubDeviceTwin_CreatebasicModel_WithData15_inertPath(void) { STRICT_EXPECTED_CALL(Schema_GetSchemaForModel("basicModel_WithData15")); STRICT_EXPECTED_CALL(Schema_GetMetadata(TEST_SCHEMA_HANDLE)); STRICT_EXPECTED_CALL(Schema_GetModelByName(TEST_SCHEMA_HANDLE, "basicModel_WithData15")); STRICT_EXPECTED_CALL(CodeFirst_CreateDevice(TEST_SCHEMA_MODEL_TYPE_HANDLE, &ALL_REFLECTED(basic15), sizeof(basicModel_WithData15), true)); STRICT_EXPECTED_CALL(IoTHubClient_SetDeviceTwinCallback(TEST_IOTHUB_CLIENT_HANDLE, serializer_ingest, TEST_DEVICE_HANDLE)); STRICT_EXPECTED_CALL(IoTHubClient_SetDeviceMethodCallback(TEST_IOTHUB_CLIENT_HANDLE, deviceMethodCallback, TEST_DEVICE_HANDLE)); STRICT_EXPECTED_CALL(VECTOR_create(sizeof(SERIALIZER_DEVICETWIN_PROTOHANDLE))); STRICT_EXPECTED_CALL(VECTOR_push_back(IGNORED_PTR_ARG, IGNORED_PTR_ARG, 1)) .IgnoreArgument_handle() .IgnoreArgument_elements(); }
static int iothub_client_sample_mqtt_dm_run(const char *connectionString, bool traceOn) { LogInfo("Initialize Platform"); int retValue; if (platform_init() != 0) { LogError("Failed to initialize the platform."); retValue = -4; } else { if (serializer_init(NULL) != SERIALIZER_OK) { LogError("Failed in serializer_init."); retValue = -5; } else { LogInfo("Instantiate the device."); thingie_t *iot_device = CREATE_MODEL_INSTANCE(Contoso, thingie_t); if (iot_device == NULL) { LogError("Failed on CREATE_MODEL_INSTANCE."); retValue = -6; } else { LogInfo("Initialize From Connection String."); IOTHUB_CLIENT_HANDLE iotHubClientHandle = IoTHubClient_CreateFromConnectionString(connectionString, MQTT_Protocol); if (iotHubClientHandle == NULL) { LogError("iotHubClientHandle is NULL!"); retValue = -7; } else { LogInfo("Device successfully connected."); if (IoTHubClient_SetOption(iotHubClientHandle, "logtrace", &traceOn) != IOTHUB_CLIENT_OK) { LogError("failed to set logtrace option"); } PHYSICAL_DEVICE *physical_device = physical_device_new(iot_device); if (physical_device == NULL) { LogError("failed to make an iot device callback structure"); retValue = -8; } else { if (IoTHubClient_SetDeviceMethodCallback(iotHubClientHandle, DeviceMethodCallback, physical_device) != IOTHUB_CLIENT_OK) { LogError("failed to associate a callback for device methods"); retValue = -9; } else { bool keepRunning = send_reported(physical_device, iotHubClientHandle); if (!keepRunning) { LogError("Failed to send initia device reported"); retValue = -10; } else { FIRMWARE_UPDATE_STATUS oldStatus = get_physical_device_fwupdate_status(physical_device); while (keepRunning) { FIRMWARE_UPDATE_STATUS newStatus = get_physical_device_fwupdate_status(physical_device); /* send reported only if the status changes */ if (newStatus != oldStatus) { oldStatus = newStatus; keepRunning = send_reported(physical_device, iotHubClientHandle); } ThreadAPI_Sleep(1000); } retValue = 0; } } physical_device_delete(physical_device); } IoTHubClient_Destroy(iotHubClientHandle); } DESTROY_MODEL_INSTANCE(iot_device); } serializer_deinit(); } platform_deinit(); } return retValue; }