private static bool CreateDeviceContext(IStreamEngineInterop interop, string url, Interop.tobii_field_of_use_t fieldOfUse, IntPtr apiContext, string[] licenseKeys, out IntPtr deviceContext)
        {
            if (licenseKeys == null || licenseKeys.Length == 0)
            {
                return(interop.tobii_device_create(apiContext, url, fieldOfUse, out deviceContext) == tobii_error_t.TOBII_ERROR_NO_ERROR);
            }

            var licenseResults = new List <tobii_license_validation_result_t>();
            var result         = interop.tobii_device_create_ex(apiContext, url, fieldOfUse, licenseKeys, licenseResults, out deviceContext);

            if (result != tobii_error_t.TOBII_ERROR_NO_ERROR)
            {
                UnityEngine.Debug.LogError(string.Format("Failed to create device context for {0}. {1}", url, result));
                return(false);
            }

            for (int i = 0; i < licenseKeys.Length; i++)
            {
                var licenseResult = licenseResults[i];
                if (licenseResult == tobii_license_validation_result_t.TOBII_LICENSE_VALIDATION_RESULT_OK)
                {
                    continue;
                }

                UnityEngine.Debug.LogError("License " + licenseKeys[i] + " failed. Return code " + licenseResult);
            }

            return(true);
        }
 public tobii_error_t tobii_device_create(IntPtr api, string url, Interop.tobii_field_of_use_t field_of_use, out IntPtr device)
 {
     return(Interop.tobii_device_create(api, url, field_of_use, out device));
 }
 public tobii_error_t tobii_device_create_ex(IntPtr api, string url, Interop.tobii_field_of_use_t field_of_use, string[] license_keys, List <tobii_license_validation_result_t> license_results, out IntPtr device)
 {
     return(Interop.tobii_device_create_ex(api, url, field_of_use, license_keys, license_results, out device));
 }
        private static bool GetFirstSupportedTracker(IStreamEngineInterop interop, IntPtr apiContext, Interop.tobii_field_of_use_t fieldOfUse, IList <string> connectedDevices, StreamEngineTracker_Description description, out IntPtr deviceContext, out string deviceUrl)
        {
            deviceContext = IntPtr.Zero;
            deviceUrl     = "";

            for (var i = 0; i < connectedDevices.Count; i++)
            {
                var connectedDeviceUrl = connectedDevices[i];
                if (CreateDeviceContext(interop, connectedDeviceUrl, fieldOfUse, apiContext, description.License, out deviceContext) == false)
                {
                    continue;
                }

                tobii_device_info_t info;
                var result = interop.tobii_get_device_info(deviceContext, out info);
                if (result != tobii_error_t.TOBII_ERROR_NO_ERROR)
                {
                    DestroyDeviceContext(interop, deviceContext);
                    UnityEngine.Debug.LogWarning("Failed to get device info. " + result);
                    continue;
                }

                var integrationType = info.integration_type.ToLowerInvariant();
                if (integrationType != description.SupportedIntegrationType)
                {
                    DestroyDeviceContext(interop, deviceContext);
                    continue;
                }

                deviceUrl = connectedDeviceUrl;
                return(true);
            }

            UnityEngine.Debug.LogWarning(string.Format("Failed to find Tobii eye trackers of integration type {0}", description.SupportedIntegrationType));
            return(false);
        }