/// <summary> /// Create an instance of the IoTConnection_LL object /// </summary> /// <param name="connectionString">Azure IoT device connection string</param> /// <param name="protocol">Required communicaton protocol</param> /// <param name="userContextCallback">User data</param> public IoTConnection_LL(string connectionString, Protocols protocol, UIntPtr userContextCallback) { _connectionString = connectionString; _protocol = protocol; _iotHandle = UIntPtr.Zero; _messageConfirmationCallback = new MessageConfirmationCallback(confirmationCallback); _messageCallback = new MessageCallback(messageReceived); _reportedStateCallback = new ReportedStateCallback(reportedStateCallback); _deviceMethodCallback = new DeviceMethodCallback(deviceMethodReceived); _deviceTwinCallback = new DeviceTwinCallback(deviceTwinCallback); _clientConnectionStatusCallback = new ClientConnectionStatusCallback(clientConnectionStatusCallback); int ret; ret = IoTWrapper.platform_init(); if (ret != 0) { throw new InvalidOperationException("Failed to intialize the platform: " + ret); } _iotHandle = IoTHubClient_LL_CreateFromConnectionString(_connectionString, getProtocolFunction(protocol)); if (_iotHandle == UIntPtr.Zero) { throw new InvalidOperationException("Failed to create IoT handle"); } ret = IoTHubClient_LL_SetMessageCallback(_iotHandle, _messageCallback, userContextCallback); if (ret != 0) { throw new IoTHubException("Failed to set message callback", ret); } ret = IoTHubClient_LL_SetDeviceMethodCallback(_iotHandle, _deviceMethodCallback, userContextCallback); if (ret != 0) { throw new IoTHubException("Failed to set device method callback", ret); } ret = IoTHubClient_LL_SetDeviceTwinCallback(_iotHandle, _deviceTwinCallback, userContextCallback); if (ret != 0) { throw new IoTHubException("Failed to set device twin callback", ret); } ret = IoTHubClient_LL_SetConnectionStatusCallback(_iotHandle, clientConnectionStatusCallback, UIntPtr.Zero); if (ret != 0) { throw new IoTHubException("Failed to set client connection status callback", ret); } }
public static extern int IoTHubClient_LL_SetDeviceMethodCallback( UIntPtr iotHubClientHandle, DeviceMethodCallback deviceMethodCallback, UIntPtr userContextCallback);