orbbec-sdk-sys 0.1.2+2.5.5

Low-level Rust bindings for https://github.com/orbbec/OrbbecSDK_v2
Documentation
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
// Copyright (c) Orbbec Inc. All Rights Reserved.
// Licensed under the MIT License.

#include "libobsensor/h/Device.h"

#include "ImplTypes.hpp"
#include "exception/ObException.hpp"
#include "firmwareupdater/FirmwareUpdater.hpp"
#include "shared/utils/Utils.hpp"

#include "IDeviceManager.hpp"
#include "IProperty.hpp"
#include "IDevice.hpp"
#include "IDeviceMonitor.hpp"
#include "IAlgParamManager.hpp"
#include "IFrameTimestamp.hpp"

#ifdef __cplusplus
extern "C" {
#endif

void ob_delete_device_list(ob_device_list *list, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(list);
    delete list;
}
HANDLE_EXCEPTIONS_NO_RETURN(list)

uint32_t ob_device_list_get_count(const ob_device_list *list, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(list);
    return static_cast<uint32_t>(list->list.size());
}
HANDLE_EXCEPTIONS_AND_RETURN(0, list)

const char *ob_device_list_get_device_name(const ob_device_list *list, uint32_t index, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(list);
    VALIDATE_UNSIGNED_INDEX(index, list->list.size());
    auto &info = list->list[index];
    return info->getFullName().c_str();
}
HANDLE_EXCEPTIONS_AND_RETURN(nullptr, list, index)

int ob_device_list_get_device_pid(const ob_device_list *list, uint32_t index, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(list);
    VALIDATE_UNSIGNED_INDEX(index, list->list.size());
    auto &info = list->list[index];
    return info->getPid();
}
HANDLE_EXCEPTIONS_AND_RETURN(0, list, index)

int ob_device_list_get_device_vid(const ob_device_list *list, uint32_t index, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(list);
    VALIDATE_UNSIGNED_INDEX(index, list->list.size());
    auto &info = list->list[index];
    return info->getVid();
}
HANDLE_EXCEPTIONS_AND_RETURN(0, list, index)

const char *ob_device_list_get_device_uid(const ob_device_list *list, uint32_t index, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(list);
    VALIDATE_UNSIGNED_INDEX(index, list->list.size());
    auto &info = list->list[index];
    return info->getUid().c_str();
}
HANDLE_EXCEPTIONS_AND_RETURN(nullptr, list, index)

const char *ob_device_list_get_device_serial_number(const ob_device_list *list, uint32_t index, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(list);
    VALIDATE_UNSIGNED_INDEX(index, list->list.size());
    auto &info = list->list[index];
    return info->getDeviceSn().c_str();
}
HANDLE_EXCEPTIONS_AND_RETURN(nullptr, list, index)

const char *ob_device_list_get_device_connection_type(const ob_device_list *list, uint32_t index, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(list);
    VALIDATE_UNSIGNED_INDEX(index, list->list.size());
    auto &info = list->list[index];
    return info->getConnectionType().c_str();
}
HANDLE_EXCEPTIONS_AND_RETURN(nullptr, list, index)

const char *ob_device_list_get_device_ip_address(const ob_device_list *list, uint32_t index, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(list);
    VALIDATE_UNSIGNED_INDEX(index, list->list.size());
    auto &info = list->list[index];
    if(std::string(info->getConnectionType()) != "Ethernet") {
        LOG_WARN("Failed to get device IP address: valid only for Ethernet devices.");
        return "0.0.0.0";
    }

    auto sourcePort    = info->getSourcePortInfoList().front();
    auto netSourcePort = std::dynamic_pointer_cast<const libobsensor::NetSourcePortInfo>(sourcePort);
    return netSourcePort->address.c_str();
}
HANDLE_EXCEPTIONS_AND_RETURN(nullptr, list, index)

const char *ob_device_list_get_device_subnet_mask(const ob_device_list *list, uint32_t index, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(list);
    VALIDATE_UNSIGNED_INDEX(index, list->list.size());
    auto &info = list->list[index];
    if(std::string(info->getConnectionType()) != "Ethernet") {
        LOG_WARN("Failed to get subnet mask: valid only for Ethernet devices.");
        return "0.0.0.0";
    }

    auto sourcePort    = info->getSourcePortInfoList().front();
    auto netSourcePort = std::dynamic_pointer_cast<const libobsensor::NetSourcePortInfo>(sourcePort);
    return netSourcePort->mask.c_str();
}
HANDLE_EXCEPTIONS_AND_RETURN(nullptr, list, index)

const char *ob_device_list_get_device_gateway(const ob_device_list *list, uint32_t index, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(list);
    VALIDATE_UNSIGNED_INDEX(index, list->list.size());
    auto &info = list->list[index];
    if(std::string(info->getConnectionType()) != "Ethernet") {
        LOG_WARN("Failed to get gateway: valid only for Ethernet devices.");
        return "0.0.0.0";
    }

    auto sourcePort    = info->getSourcePortInfoList().front();
    auto netSourcePort = std::dynamic_pointer_cast<const libobsensor::NetSourcePortInfo>(sourcePort);
    return netSourcePort->gateway.c_str();
}
HANDLE_EXCEPTIONS_AND_RETURN(nullptr, list, index)

const char *ob_device_list_get_device_local_mac(const ob_device_list *list, uint32_t index, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(list);
    VALIDATE_UNSIGNED_INDEX(index, list->list.size());
    auto &info = list->list[index];
    if(std::string(info->getConnectionType()) != "Ethernet") {
        LOG_WARN("Failed to get local net iface mac address: valid only for Ethernet devices.");
        return "0:0:0:0:0:0";
    }

    auto sourcePort    = info->getSourcePortInfoList().front();
    auto netSourcePort = std::dynamic_pointer_cast<const libobsensor::NetSourcePortInfo>(sourcePort);
    return netSourcePort->localMac.c_str();
}
HANDLE_EXCEPTIONS_AND_RETURN(nullptr, list, index)

const char *ob_device_list_get_device_local_ip(const ob_device_list *list, uint32_t index, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(list);
    VALIDATE_UNSIGNED_INDEX(index, list->list.size());
    auto &info = list->list[index];
    if(std::string(info->getConnectionType()) != "Ethernet") {
        LOG_WARN("Failed to get local net iface IP address: valid only for Ethernet devices.");
        return "0:0:0:0";
    }

    auto sourcePort    = info->getSourcePortInfoList().front();
    auto netSourcePort = std::dynamic_pointer_cast<const libobsensor::NetSourcePortInfo>(sourcePort);
    return netSourcePort->localAddress.c_str();
}
HANDLE_EXCEPTIONS_AND_RETURN(nullptr, list, index)

uint8_t ob_device_list_get_device_local_subnet_length(const ob_device_list *list, uint32_t index, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(list);
    VALIDATE_UNSIGNED_INDEX(index, list->list.size());
    auto &info = list->list[index];
    if(std::string(info->getConnectionType()) != "Ethernet") {
        LOG_WARN("Failed to get local net iface subnet length: valid only for Ethernet devices.");
        return 0;
    }

    auto sourcePort    = info->getSourcePortInfoList().front();
    auto netSourcePort = std::dynamic_pointer_cast<const libobsensor::NetSourcePortInfo>(sourcePort);
    return netSourcePort->localSubnetLength;
}
HANDLE_EXCEPTIONS_AND_RETURN(uint8_t(0), list, index)

const char *ob_device_list_get_device_local_gateway(const ob_device_list *list, uint32_t index, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(list);
    VALIDATE_UNSIGNED_INDEX(index, list->list.size());
    auto &info = list->list[index];
    if(std::string(info->getConnectionType()) != "Ethernet") {
        LOG_WARN("get localGateway() failed! Only valid for Ethernet devices.");
        return "0:0:0:0";
    }

    auto sourcePort    = info->getSourcePortInfoList().front();
    auto netSourcePort = std::dynamic_pointer_cast<const libobsensor::NetSourcePortInfo>(sourcePort);
    return (netSourcePort->localGateway.empty() || netSourcePort->localGateway == "unknown") ? "0.0.0.0" : netSourcePort->localGateway.c_str();
}
HANDLE_EXCEPTIONS_AND_RETURN(nullptr, list, index)

ob_device *ob_device_list_get_device(const ob_device_list *list, uint32_t index, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(list);
    VALIDATE_UNSIGNED_INDEX(index, list->list.size());
    auto &info      = list->list[index];
    auto  deviceMgr = info->getDeviceManager();
    VALIDATE_NOT_NULL(deviceMgr);

    auto device  = deviceMgr->createDevice(info);
    auto impl    = new ob_device();
    impl->device = device;
    return impl;
}
HANDLE_EXCEPTIONS_AND_RETURN(nullptr, list, index)

ob_device *ob_device_list_get_device_by_serial_number(const ob_device_list *list, const char *serial_number, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(list);
    VALIDATE_NOT_NULL(serial_number);
    for(auto &info: list->list) {
        if(info->getDeviceSn() == serial_number) {
            auto deviceMgr = info->getDeviceManager();
            VALIDATE_NOT_NULL(deviceMgr);

            auto device  = deviceMgr->createDevice(info);
            auto impl    = new ob_device();
            impl->device = device;
            return impl;
        }
    }
    throw libobsensor::invalid_value_exception("Device not found by serial number: " + std::string(serial_number));
}
HANDLE_EXCEPTIONS_AND_RETURN(nullptr, list, serial_number)

ob_device *ob_device_list_get_device_by_uid(const ob_device_list *list, const char *uid, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(list);
    VALIDATE_NOT_NULL(uid);
    for(auto &info: list->list) {
        auto deviceUid = info->getUid();
        if(deviceUid == uid
#if defined(__linux__)
           // For linux platform, the usb device uid is like "bus-port-dev", try to rm the dev part to match the uid
           || deviceUid.substr(0, deviceUid.find_last_of('-')) == uid
#endif
        ) {
            auto deviceMgr = info->getDeviceManager();
            VALIDATE_NOT_NULL(deviceMgr);

            auto device  = deviceMgr->createDevice(info);
            auto impl    = new ob_device();
            impl->device = device;
            return impl;
        }
    }
    throw libobsensor::invalid_value_exception("Device not found by UID: " + std::string(uid));
}
HANDLE_EXCEPTIONS_AND_RETURN(nullptr, list, uid)

void ob_delete_device(ob_device *device, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(device);
    delete device;
}
HANDLE_EXCEPTIONS_NO_RETURN(device)

ob_sensor_list *ob_device_get_sensor_list(const ob_device *device, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(device);
    auto impl         = new ob_sensor_list();
    impl->device      = device->device;
    impl->sensorTypes = device->device->getSensorTypeList();
    return impl;
}
HANDLE_EXCEPTIONS_AND_RETURN(nullptr, device)

ob_sensor *ob_device_get_sensor(ob_device *device, ob_sensor_type type, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(device);
    auto sensorTypelist = device->device->getSensorTypeList();
    auto iter           = std::find(sensorTypelist.begin(), sensorTypelist.end(), type);
    if(iter == sensorTypelist.end()) {
        throw libobsensor::invalid_value_exception("Sensor not found by type: " + std::to_string(type));
    }
    auto impl    = new ob_sensor();
    impl->device = device->device;
    impl->type   = type;
    return impl;
}
HANDLE_EXCEPTIONS_AND_RETURN(nullptr, device, type)

void ob_device_set_int_property(ob_device *device, ob_property_id property_id, int32_t value, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(device);
    auto propServer = device->device->getPropertyServer();
    propServer->setPropertyValueT(property_id, value, libobsensor::PROP_ACCESS_USER);
}
HANDLE_EXCEPTIONS_NO_RETURN(device, property_id, value)

int32_t ob_device_get_int_property(ob_device *device, ob_property_id property_id, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(device);
    auto propServer = device->device->getPropertyServer();
    return propServer->getPropertyValueT<int32_t>(property_id, libobsensor::PROP_ACCESS_USER);
}
HANDLE_EXCEPTIONS_AND_RETURN(0, device, property_id)

ob_int_property_range ob_device_get_int_property_range(ob_device *device, ob_property_id property_id, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(device);
    auto propServer = device->device->getPropertyServer();
    auto range      = propServer->getPropertyRangeT<int32_t>(property_id, libobsensor::PROP_ACCESS_USER);
    return { range.cur, range.max, range.min, range.step, range.def };
}
HANDLE_EXCEPTIONS_AND_RETURN(ob_int_property_range(), device, property_id)

void ob_device_set_float_property(ob_device *device, ob_property_id property_id, float value, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(device);
    auto propServer = device->device->getPropertyServer();
    propServer->setPropertyValueT(property_id, value, libobsensor::PROP_ACCESS_USER);
}
HANDLE_EXCEPTIONS_NO_RETURN(device, property_id, value)

float ob_device_get_float_property(ob_device *device, ob_property_id property_id, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(device);
    auto propServer = device->device->getPropertyServer();
    return propServer->getPropertyValueT<float>(property_id, libobsensor::PROP_ACCESS_USER);
}
HANDLE_EXCEPTIONS_AND_RETURN(0.0f, device, property_id)

ob_float_property_range ob_device_get_float_property_range(ob_device *device, ob_property_id property_id, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(device);
    auto propServer = device->device->getPropertyServer();
    auto range      = propServer->getPropertyRangeT<float>(property_id, libobsensor::PROP_ACCESS_USER);
    return { range.cur, range.max, range.min, range.step, range.def };
}
HANDLE_EXCEPTIONS_AND_RETURN(ob_float_property_range(), device, property_id)

void ob_device_set_bool_property(ob_device *device, ob_property_id property_id, bool value, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(device);
    auto propServer = device->device->getPropertyServer();
    propServer->setPropertyValueT(property_id, value, libobsensor::PROP_ACCESS_USER);
}
HANDLE_EXCEPTIONS_NO_RETURN(device, property_id, value)

bool ob_device_get_bool_property(ob_device *device, ob_property_id property_id, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(device);
    auto propServer = device->device->getPropertyServer();
    return propServer->getPropertyValueT<bool>(property_id, libobsensor::PROP_ACCESS_USER);
}
HANDLE_EXCEPTIONS_AND_RETURN(false, device, property_id)

ob_bool_property_range ob_device_get_bool_property_range(ob_device *device, ob_property_id property_id, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(device);
    auto propServer = device->device->getPropertyServer();
    auto range      = propServer->getPropertyRangeT<bool>(property_id, libobsensor::PROP_ACCESS_USER);
    return { range.cur, range.max, range.min, range.step, range.def };
}
HANDLE_EXCEPTIONS_AND_RETURN(ob_bool_property_range(), device, property_id)

void ob_device_set_structured_data(ob_device *device, ob_property_id property_id, const uint8_t *data, uint32_t data_size, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(device);
    if(property_id == OB_STRUCT_DEVICE_IP_ADDR_CONFIG) {
        VALIDATE_NOT_NULL(data);
        VALIDATE_EQUAL(data_size, sizeof(ob_net_ip_config));
        auto config = reinterpret_cast<const ob_net_ip_config *>(data);
        if(!libobsensor::utils::checkIpConfig(*config)) {
            throw libobsensor::invalid_value_exception("Invalid IP configuration");
            return;
        }
    }
    auto                 propServer = device->device->getPropertyServer();
    std::vector<uint8_t> dataVec(data, data + data_size);
    propServer->setStructureData(property_id, dataVec, libobsensor::PROP_ACCESS_USER);
}
HANDLE_EXCEPTIONS_NO_RETURN(device, property_id, data, data_size)

void ob_device_get_structured_data(ob_device *device, ob_property_id property_id, uint8_t *data, uint32_t *data_size, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(device);
    auto  propServer   = device->device->getPropertyServer();
    auto &firmwareData = propServer->getStructureData(property_id, libobsensor::PROP_ACCESS_USER);

    memcpy(data, firmwareData.data(), firmwareData.size());
    *data_size = static_cast<uint32_t>(firmwareData.size());
}
HANDLE_EXCEPTIONS_NO_RETURN(device, property_id, data, data_size)

void ob_device_get_raw_data(ob_device *device, ob_property_id property_id, ob_get_data_callback cb, void *user_data, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(device);
    auto propServer = device->device->getPropertyServer();
    propServer->getRawData(
        property_id,
        [=](OBDataTranState state, OBDataChunk *dataChunk) {
            if(cb) {
                cb(state, dataChunk, user_data);
            }
        },
        libobsensor::PROP_ACCESS_USER);
}
HANDLE_EXCEPTIONS_NO_RETURN(device, property_id, user_data)

void ob_device_write_customer_data(ob_device *device, const void *data, uint32_t data_size, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(device);
    VALIDATE_NOT_NULL(data);
    auto updater = device->device->getComponentT<libobsensor::FirmwareUpdater>(libobsensor::OB_DEV_COMPONENT_FIRMWARE_UPDATER, true);
    updater->writeCustomerDataExt(reinterpret_cast<const uint8_t *>(data), data_size, error);
}
HANDLE_EXCEPTIONS_NO_RETURN(device)

void ob_device_read_customer_data(ob_device *device, void *data, uint32_t *data_size, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(device);
    VALIDATE_NOT_NULL(data);
    auto updater = device->device->getComponentT<libobsensor::FirmwareUpdater>(libobsensor::OB_DEV_COMPONENT_FIRMWARE_UPDATER, true);
    updater->readCustomerDataExt(reinterpret_cast<uint8_t *>(data), data_size, error);
}
HANDLE_EXCEPTIONS_NO_RETURN(device)

uint32_t ob_device_get_supported_property_count(const ob_device *device, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(device);
    auto propServer = device->device->getPropertyServer();
    return static_cast<int>(propServer->getAvailableProperties(libobsensor::PROP_ACCESS_USER).size());
}
HANDLE_EXCEPTIONS_AND_RETURN(0, device)

ob_property_item ob_device_get_supported_property_item(const ob_device *device, uint32_t index, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(device);
    auto propServer = device->device->getPropertyServer();
    auto properties = propServer->getAvailableProperties(libobsensor::PROP_ACCESS_USER);
    VALIDATE_UNSIGNED_INDEX(index, properties.size());
    return properties.at(index);
}
HANDLE_EXCEPTIONS_AND_RETURN(ob_property_item(), device, index)

bool ob_device_is_property_supported(const ob_device *device, ob_property_id property_id, ob_permission_type permission, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(device);
    auto operationType = libobsensor::PROP_OP_READ_WRITE;
    if(permission == OB_PERMISSION_READ) {
        operationType = libobsensor::PROP_OP_READ;
    }
    else if(permission == OB_PERMISSION_WRITE) {
        operationType = libobsensor::PROP_OP_WRITE;
    }

    auto propServer = device->device->getPropertyServer();
    return propServer->isPropertySupported(property_id, operationType, libobsensor::PROP_ACCESS_USER);
}
HANDLE_EXCEPTIONS_AND_RETURN(false, device, property_id, permission)

bool ob_device_is_global_timestamp_supported(const ob_device *device, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(device);
    return device->device->isComponentExists(libobsensor::OB_DEV_COMPONENT_GLOBAL_TIMESTAMP_FILTER);
}
HANDLE_EXCEPTIONS_AND_RETURN(false, device)

void ob_device_enable_global_timestamp(ob_device *device, bool enable, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(device);
    auto globalTimestampFilter = device->device->getComponentT<libobsensor::IGlobalTimestampFitter>(libobsensor::OB_DEV_COMPONENT_GLOBAL_TIMESTAMP_FILTER);
    globalTimestampFilter->enable(enable);
}
HANDLE_EXCEPTIONS_NO_RETURN(device, enable)

void ob_device_update_firmware(ob_device *device, const char *path, ob_device_fw_update_callback callback, bool async, void *user_data,
                               ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(device);
    VALIDATE_NOT_NULL(path);
    VALIDATE_NOT_NULL(callback);
    auto data = libobsensor::utils::readFile(path);

    device->device->updateFirmware(
        data,
        [callback, user_data](ob_fw_update_state status, const char *message, uint8_t percent) {  //
            callback(status, message, percent, user_data);
        },
        async);
}
HANDLE_EXCEPTIONS_NO_RETURN(device, path, callback, async, user_data)

void ob_device_update_firmware_from_data(ob_device *device, const uint8_t *data, uint32_t data_size, ob_device_fw_update_callback callback, bool async,
                                         void *user_data, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(device);
    VALIDATE_NOT_NULL(data);
    VALIDATE_NOT_NULL(callback);
    auto dataVec = std::vector<uint8_t>(data, data + data_size);
    device->device->updateFirmware(
        dataVec,
        [callback, user_data](ob_fw_update_state status, const char *message, uint8_t percent) {  //
            callback(status, message, percent, user_data);
        },
        async);
}
HANDLE_EXCEPTIONS_NO_RETURN(device, data, data_size, callback, async, user_data)

void ob_device_update_optional_depth_presets(ob_device *device, const char file_path_list[][OB_PATH_MAX], uint8_t path_count,
                                             ob_device_fw_update_callback callback, void *user_data, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(device);
    VALIDATE_NOT_NULL(file_path_list);
    VALIDATE_GE(path_count, 0);
    VALIDATE_NOT_NULL(callback);
    
    device->device->updateOptionalDepthPresets(
        file_path_list, path_count,
        [callback, user_data](ob_fw_update_state status, const char *message, uint8_t percent) {
            callback(status, message, percent, user_data);
        });
}
HANDLE_EXCEPTIONS_NO_RETURN(device, file_path_list, path_count, callback, user_data)

void ob_device_reboot(ob_device *device, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(device);
    device->device->reboot();
}
HANDLE_EXCEPTIONS_NO_RETURN(device)

ob_device_state ob_device_get_device_state(const ob_device *device, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(device);

    auto devMonitor = device->device->getComponentT<libobsensor::IDeviceMonitor>(libobsensor::OB_DEV_COMPONENT_DEVICE_MONITOR);
    return devMonitor->getCurrentDeviceState();
}
HANDLE_EXCEPTIONS_AND_RETURN(0, device)

void ob_device_set_state_changed_callback(ob_device *device, ob_device_state_callback callback, void *user_data, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(device);
    VALIDATE_NOT_NULL(callback);
    auto devMonitor = device->device->getComponentT<libobsensor::IDeviceMonitor>(libobsensor::OB_DEV_COMPONENT_DEVICE_MONITOR);
    devMonitor->registerStateChangedCallback([callback, user_data](OBDeviceState state, const std::string &message) {  //
        callback(state, message.c_str(), user_data);
    });
}
HANDLE_EXCEPTIONS_NO_RETURN(device, callback, user_data)

void ob_device_enable_heartbeat(ob_device *device, bool enable, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(device);
    auto devMonitor = device->device->getComponentT<libobsensor::IDeviceMonitor>(libobsensor::OB_DEV_COMPONENT_DEVICE_MONITOR);

    if(enable) {
        devMonitor->enableHeartbeat();
    }
    else {
        devMonitor->disableHeartbeat();
    }
}
HANDLE_EXCEPTIONS_NO_RETURN(device, enable)

void ob_device_send_and_receive_data(ob_device *device, const uint8_t *send_data, uint32_t send_data_size, uint8_t *receive_data, uint32_t *receive_data_size,
                                     ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(device);
    VALIDATE_NOT_NULL(send_data);
    VALIDATE_NOT_NULL(receive_data);
    VALIDATE_NOT_NULL(receive_data_size);

    auto devMonitor = device->device->getComponentT<libobsensor::IDeviceMonitor>(libobsensor::OB_DEV_COMPONENT_DEVICE_MONITOR);
    devMonitor->sendAndReceiveData(send_data, send_data_size, receive_data, receive_data_size);
}
HANDLE_EXCEPTIONS_NO_RETURN(device, send_data, send_data_size, receive_data, receive_data_size)

ob_device_info *ob_device_get_device_info(const ob_device *device, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(device);
    auto info  = device->device->getInfo();
    auto impl  = new ob_device_info();
    impl->info = info;
    return impl;
}
HANDLE_EXCEPTIONS_AND_RETURN(nullptr, device)

void ob_delete_device_info(ob_device_info *info, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(info);
    delete info;
}
HANDLE_EXCEPTIONS_NO_RETURN(info)

const char *ob_device_info_get_name(const ob_device_info *info, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(info);
    return info->info->fullName_.c_str();
}
HANDLE_EXCEPTIONS_AND_RETURN(nullptr, info)

int ob_device_info_get_pid(const ob_device_info *info, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(info);
    return info->info->pid_;
}
HANDLE_EXCEPTIONS_AND_RETURN(0, info)

int ob_device_info_get_vid(const ob_device_info *info, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(info);
    return info->info->vid_;
}
HANDLE_EXCEPTIONS_AND_RETURN(0, info)

const char *ob_device_info_get_uid(const ob_device_info *info, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(info);
    return info->info->uid_.c_str();
}
HANDLE_EXCEPTIONS_AND_RETURN(nullptr, info)

const char *ob_device_info_get_serial_number(const ob_device_info *info, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(info);
    return info->info->deviceSn_.c_str();
}
HANDLE_EXCEPTIONS_AND_RETURN(nullptr, info)

const char *ob_device_info_get_firmware_version(const ob_device_info *info, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(info);
    return info->info->fwVersion_.c_str();
}
HANDLE_EXCEPTIONS_AND_RETURN(nullptr, info)

const char *ob_device_info_get_hardware_version(const ob_device_info *info, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(info);
    return info->info->hwVersion_.c_str();
}
HANDLE_EXCEPTIONS_AND_RETURN(nullptr, info)

const char *ob_device_info_get_connection_type(const ob_device_info *info, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(info);
    return info->info->connectionType_.c_str();
}
HANDLE_EXCEPTIONS_AND_RETURN(nullptr, info)

const char *ob_device_info_get_ip_address(const ob_device_info *info, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(info);
    auto netDeviceInfo = std::static_pointer_cast<const libobsensor::NetDeviceInfo>(info->info);
    if(!netDeviceInfo) {
        throw libobsensor::invalid_value_exception("Not a network device");
    }
    return netDeviceInfo->ipAddress_.c_str();
}
HANDLE_EXCEPTIONS_AND_RETURN(nullptr, info)

const char *ob_device_info_get_supported_min_sdk_version(const ob_device_info *info, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(info);
    return info->info->supportedSdkVersion_.c_str();
}
HANDLE_EXCEPTIONS_AND_RETURN(nullptr, info)

const char *ob_device_info_get_asicName(const ob_device_info *info, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(info);
    return info->info->asicName_.c_str();
}
HANDLE_EXCEPTIONS_AND_RETURN(nullptr, info)

ob_device_type ob_device_info_get_device_type(const ob_device_info *info, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(info);
    return static_cast<ob_device_type>(info->info->type_);
}
HANDLE_EXCEPTIONS_AND_RETURN(OB_DEVICE_TYPE_UNKNOWN, info)

const char *ob_device_info_get_subnet_mask(const ob_device_info *info, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(info);
    auto netDeviceInfo = std::static_pointer_cast<const libobsensor::NetDeviceInfo>(info->info);
    if(!netDeviceInfo) {
        throw libobsensor::invalid_value_exception("Not a network device");
    }
    return netDeviceInfo->subnetMask_.c_str();
}
HANDLE_EXCEPTIONS_AND_RETURN(nullptr, info)

const char *ob_device_info_get_gateway(const ob_device_info *info, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(info);
    auto netDeviceInfo = std::static_pointer_cast<const libobsensor::NetDeviceInfo>(info->info);
    if(!netDeviceInfo) {
        throw libobsensor::invalid_value_exception("Not a network device");
    }
    return netDeviceInfo->gateway_.c_str();
}
HANDLE_EXCEPTIONS_AND_RETURN(nullptr, info)

bool ob_device_is_extension_info_exist(const ob_device *device, const char *info_key, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(device);
    VALIDATE_NOT_NULL(info_key);
    return device->device->isExtensionInfoExists(info_key);
}
HANDLE_EXCEPTIONS_AND_RETURN(false, device, info_key)

const char *ob_device_get_extension_info(const ob_device *device, const char *info_key, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(device);
    VALIDATE_NOT_NULL(info_key);
    const auto &extensionInfo = device->device->getExtensionInfo(info_key);
    if(extensionInfo.empty()) {
        return nullptr;
    }
    return extensionInfo.c_str();
}
HANDLE_EXCEPTIONS_AND_RETURN("", device, info_key)

ob_camera_param_list *ob_device_get_calibration_camera_param_list(ob_device *device, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(device);
    auto algParamManager         = device->device->getComponentT<libobsensor::IAlgParamManager>(libobsensor::OB_DEV_COMPONENT_ALG_PARAM_MANAGER, false);
    auto calibrationCameraParams = algParamManager->getCalibrationCameraParamList();
    auto impl                    = new ob_camera_param_list();
    impl->paramList              = calibrationCameraParams;
    return impl;
}
HANDLE_EXCEPTIONS_AND_RETURN(nullptr, device)

uint32_t ob_camera_param_list_get_count(ob_camera_param_list *list, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(list);
    return static_cast<uint32_t>(list->paramList.size());
}
HANDLE_EXCEPTIONS_AND_RETURN(0, list)

ob_camera_param ob_camera_param_list_get_param(ob_camera_param_list *list, uint32_t index, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(list);
    VALIDATE_UNSIGNED_INDEX(index, list->paramList.size());

    return list->paramList.at(index);
}
HANDLE_EXCEPTIONS_AND_RETURN(ob_camera_param(), list, index)

void ob_delete_camera_param_list(ob_camera_param_list *list, ob_error **error) BEGIN_API_CALL {
    VALIDATE_NOT_NULL(list);
    delete list;
}
HANDLE_EXCEPTIONS_NO_RETURN(list)

#ifdef __cplusplus
}
#endif