added icsneo_device_type_from_type

David Rebbe 2024-11-25 21:07:48 -05:00
parent 79293216af
commit 64f038f781
2 changed files with 25 additions and 0 deletions

View File

@ -53,6 +53,21 @@ ICSNEO_API icsneo_error_t icsneo_error_code(icsneo_error_t error_code, const cha
return icsneo_error_success;
}
ICSNEO_API icsneo_error_t icsneo_device_type_from_type(icsneo_devicetype_t device_type, const char* value, uint32_t* value_length) {
if (!value || !value_length) {
return icsneo_error_invalid_parameters;
}
auto device_type_str = DeviceType::getGenericProductName(device_type);
// Find the minimum length of the device type string and set value_length
auto min_length = std::minmax(static_cast<uint32_t>(device_type_str.length()), *value_length).first;
*value_length = min_length;
// Copy the string into value
strncpy(const_cast<char *>(value), device_type_str.c_str(), min_length);
return icsneo_error_success;
}
ICSNEO_API icsneo_error_t icsneo_find(icsneo_device_t** devices, uint32_t* devices_count, void* reserved) {
if (!devices || !devices_count) {
return icsneo_error_invalid_parameters;

View File

@ -75,6 +75,16 @@ typedef uint32_t icsneo_error_t;
*/
ICSNEO_API icsneo_error_t icsneo_error_code(icsneo_error_t error_code, const char* value, uint32_t* value_length);
/** @brief Get the device type string for a icsneo_devicetype_t.
*
* @param[in] icsneo_devicetype_t device_type The device type to get the description of.
* @param[out] const char* value Pointer to a buffer to copy the description into. Null terminated.
* @param[in,out] uint32_t* value_length Size of the value buffer. Modified with the length of the description.
*
* @return icsneo_error_t icsneo_error_success if successful, icsneo_error_invalid_parameters otherwise.
*/
ICSNEO_API icsneo_error_t icsneo_device_type_from_type(icsneo_devicetype_t device_type, const char* value, uint32_t* value_length);
/** @brief Find all hardware attached to the system.
*
* @param[out] icsneo_device_t array of devices to be filled with found devices.