1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "nuitrack/Nuitrack.h"
#include "nuitrack_bridge/device.h"
#include <stdexcept>
#include <string>
namespace nuitrack_bridge::device {
std::shared_ptr<Device> unwrapSharedPtrDevice(const SharedPtrDevice& spd) {
return spd;
}
std::unique_ptr<std::vector<std::shared_ptr<Device>>> getDevices() {
return std::make_unique<std::vector<std::shared_ptr<tdv::nuitrack::device::NuitrackDevice>>>(
tdv::nuitrack::Nuitrack::getDeviceList()
);
}
rust::String getDeviceInfo(
const std::shared_ptr<Device>& device_shared_ptr, // This is const std::shared_ptr<Device>&
tdv::nuitrack::device::DeviceInfoType info_type
) {
if (!device_shared_ptr) {
throw std::runtime_error("Device (SharedPtrDevice) is null in get_device_info_from_shared");
}
std::string result_std_string; // Temporary std::string
try {
// WARNING: Assuming getInfo is logically const despite missing C++ const qualifier.
result_std_string = const_cast<tdv::nuitrack::device::NuitrackDevice&>(*device_shared_ptr).getInfo(info_type);
} catch (const tdv::nuitrack::Exception& e) {
// Propagate exceptions for Rust's Result handling
throw std::runtime_error(std::string("Nuitrack getInfo failed: ") + e.what());
} catch (const std::exception& e) {
throw; // Rethrow other std exceptions
} catch (...) {
throw std::runtime_error("Unknown exception during Nuitrack getInfo");
}
// *** Convert std::string to rust::String before returning ***
return rust::String(result_std_string);
}
void setDevice(
const std::shared_ptr<Device>& device_shared_ptr // This is const std::shared_ptr<Device>&
) {
if (!device_shared_ptr) {
// Or handle as Nuitrack::setDevice would (it might accept null to unset).
// For safety, let's assume we don't want to pass a null pointer if it's not explicitly supported.
throw std::runtime_error("Device (SharedPtrDevice) is null in set_device_from_shared. Cannot set null device unless Nuitrack::setDevice explicitly supports it.");
}
try {
// Call the static Nuitrack::setDevice method, passing the shared_ptr
tdv::nuitrack::Nuitrack::setDevice(device_shared_ptr);
} catch (const tdv::nuitrack::Exception& e) {
// Propagate exceptions for Rust Result handling
throw std::runtime_error(std::string("Nuitrack setDevice failed: ") + e.what());
} catch (const std::exception& e) {
throw; // Rethrow other standard exceptions
} catch (...) {
throw std::runtime_error("Unknown exception during Nuitrack setDevice");
}
}
}