diff options
author | Ballista Milsim <ballista.milsim@gmail.com> | 2020-03-21 12:39:57 +0100 |
---|---|---|
committer | Ballista Milsim <ballista.milsim@gmail.com> | 2020-03-21 12:39:57 +0100 |
commit | cf89cd0ee392a73c7b92d0220b3963f1901908ae (patch) | |
tree | cf27da201041b870f1668b24b3c88506c9e80523 /tracker-tobii/thread.cpp | |
parent | 77885b4d65f49fd220d2426c01cd336402b86c60 (diff) |
Fixes according to code review.
Diffstat (limited to 'tracker-tobii/thread.cpp')
-rw-r--r-- | tracker-tobii/thread.cpp | 73 |
1 files changed, 32 insertions, 41 deletions
diff --git a/tracker-tobii/thread.cpp b/tracker-tobii/thread.cpp index f9fd2c01..bdd48125 100644 --- a/tracker-tobii/thread.cpp +++ b/tracker-tobii/thread.cpp @@ -1,20 +1,15 @@ #include "thread.hpp" #include "compat/sleep.hpp" -tobii_thread::tobii_thread() -{ - head_pose = new tobii_head_pose_t(); - connect(this, &tobii_thread::tobii_ready_signal, this, &tobii_thread::tobii_ready_signal_impl, Qt::QueuedConnection); - connect(this, &tobii_thread::tobii_error_signal, this, &tobii_thread::tobii_error_signal_impl, Qt::QueuedConnection); -} - tobii_thread::~tobii_thread() { - if (device) tobii_device_destroy(device); - if (api) tobii_api_destroy(api); exit_thread = true; - terminate(); wait(); + + if (device) tobii_device_destroy(device); + if (api) tobii_api_destroy(api); + + quit(); } void tobii_thread::run() @@ -22,7 +17,8 @@ void tobii_thread::run() /* See https://developer.tobii.com/consumer-eye-trackers/stream-engine/ */ if (tobii_api_create(&api, nullptr, nullptr) != TOBII_ERROR_NO_ERROR) { - emit tobii_error_signal("Failed to initialize the Tobii Stream Engine API."); + error_last = "Failed to initialize the Tobii Stream Engine API."; + exit_thread = true; } std::vector<std::string> devices; @@ -33,13 +29,15 @@ void tobii_thread::run() list->push_back(url); }, &devices) != TOBII_ERROR_NO_ERROR) { - emit tobii_error_signal("Failed to enumerate devices."); + error_last = "Failed to enumerate devices."; + exit_thread = true; } if (devices.size() == 0) { tobii_api_destroy(api); - emit tobii_error_signal("No stream engine compatible device(s) found."); + error_last = "No stream engine compatible device(s) found."; + exit_thread = true; } std::string selected_device = devices[0]; @@ -54,10 +52,25 @@ void tobii_thread::run() } while (retry < retries); if (tobii_error != TOBII_ERROR_NO_ERROR) { tobii_api_destroy(api); - emit tobii_error_signal("Failed to connect to device."); + error_last = "Failed to connect to device."; + exit_thread = true; } - emit tobii_ready_signal(); + if (tobii_head_pose_subscribe(device, [](tobii_head_pose_t const* head_pose, void* user_data) { + + if ((*head_pose).position_validity != TOBII_VALIDITY_VALID + || (*head_pose).rotation_validity_xyz[0] != TOBII_VALIDITY_VALID + || (*head_pose).rotation_validity_xyz[1] != TOBII_VALIDITY_VALID + || (*head_pose).rotation_validity_xyz[2] != TOBII_VALIDITY_VALID) return; + + tobii_head_pose_t* tobii_head_pose_storage = (tobii_head_pose_t*)user_data; + *tobii_head_pose_storage = *head_pose; + + }, head_pose) != TOBII_ERROR_NO_ERROR) + { + error_last = "Failed to subscribe to head pose stream."; + exit_thread = true; + } tobii_error = TOBII_ERROR_NO_ERROR; while (!exit_thread) @@ -66,7 +79,7 @@ void tobii_thread::run() if (tobii_error == TOBII_ERROR_TIMED_OUT) continue; else if (tobii_error != TOBII_ERROR_NO_ERROR) { - emit tobii_error_signal("tobii_wait_for_callbacks failed."); + error_last = "tobii_wait_for_callbacks failed."; } tobii_error = tobii_device_process_callbacks(device); @@ -83,36 +96,14 @@ void tobii_thread::run() } while (retry < retries); if (tobii_error != TOBII_ERROR_NO_ERROR) { - emit tobii_error_signal("Connection was lost and reconnection failed."); + error_last = "Connection was lost and reconnection failed."; + exit_thread = true; } continue; } else if (tobii_error != TOBII_ERROR_NO_ERROR) { - emit tobii_error_signal("tobii_device_process_callbacks failed."); + error_last = "tobii_device_process_callbacks failed."; } } } - -void tobii_thread::tobii_error_signal_impl(QString error_message) -{ - //TODO: log? terminate? -} - -void tobii_thread::tobii_ready_signal_impl() -{ - if (tobii_head_pose_subscribe(device, [](tobii_head_pose_t const* head_pose, void* user_data) { - - if ((*head_pose).position_validity != TOBII_VALIDITY_VALID - || (*head_pose).rotation_validity_xyz[0] != TOBII_VALIDITY_VALID - || (*head_pose).rotation_validity_xyz[1] != TOBII_VALIDITY_VALID - || (*head_pose).rotation_validity_xyz[2] != TOBII_VALIDITY_VALID) return; - - tobii_head_pose_t* tobii_head_pose_storage = (tobii_head_pose_t*)user_data; - *tobii_head_pose_storage = *head_pose; - - }, head_pose) != TOBII_ERROR_NO_ERROR) - { - emit tobii_error_signal("Failed to subscribe to head pose stream."); - } -} |