OptrisOptrisDocumentation

Documentation/OTC SDK/optris_sdk — Rust API referencev12.0

metadata — functions and constants

What this machine records about a camera, keyed by its serial.

A camera reports a model and a serial, and neither is what an operator calls it. Plug two identical cameras into one machine and a device list is two lines differing by a number nobody has memorised.

These functions attach a host-side name (and anything else worth recording) to a serial number. Nothing here opens a camera, so naming one does not take it away from whatever is streaming from it, and the store is on disk, so the next process reads it back.

The serial is the key, deliberately

It is the only stable identity a camera has: move the plug and the USB path changes while the camera does not. It also means the metadata is not carried with the camera; move it to another machine and the name stays behind.

Concurrency

Last writer wins. Every setter reads the store, changes one entry and writes it back whole, atomically, so a reader never sees a partial store. Two processes changing different keys on the same camera at the same instant will still lose one of the two changes.

pub const DEVICE_NAME_KEY: &str = "name";

The key the host-side name is stored under.

device_name and set_device_name are this key through metadata_get and metadata_set, and are there because naming a camera is the one thing every application does. Knowing the key is what lets a listing skip the name when printing the rest.

pub fn device_name(serial: &str) -> Result<String>

Read the host-side name of a camera.

A camera nobody has named reports an empty string. It never invents one, and an unnamed camera is not an error.

Errors

Returns crate::Status::InvalidArgument if serial contains an interior NUL, and crate::Status::Io if the store cannot be read.

Examples

# fn main() -> optris_sdk::Result<()> {
let name = optris_sdk::device_name("21074191")?;
println!("{}", if name.is_empty() { "(unnamed)" } else { &name });
# Ok(())
# }

pub fn metadata_clear(serial: &str) -> Result<()>

Forget everything recorded about a camera, name included.

Doing this to a camera with no metadata is not an error.

Errors

As set_device_name.

pub fn metadata_get(serial: &str, key: &str) -> Result<String>

Read one metadata value.

An absent key reports an empty string rather than an error, so reading an optional field needs no special case.

Errors

As device_name.

pub fn metadata_keys(serial: &str) -> Result<Vec<String>>

Every key recorded for a camera, in sorted order.

Empty for a camera nobody has described. The name is one of these keys, see DEVICE_NAME_KEY.

A note on the two-call shape underneath

The C reads the count and then each key with a separate call, and re-reads the store every time, so a key written in between shifts the indices. This function takes the count and the keys in one go and returns what it found; a key that vanished mid-read is skipped rather than reported as an error, because a name being changed by another process is not a failure of this call.

Errors

As device_name.

pub fn metadata_set(serial: &str, key: &str, value: &str) -> Result<()>

Write one metadata value, keeping the other entries.

An empty value removes the key. key must be non-empty and free of control characters.

Errors

As set_device_name.

pub fn set_device_name(serial: &str, name: &str) -> Result<()>

Name a camera, keeping anything else recorded about it.

An empty name forgets the name and leaves the other entries alone.

Takes effect immediately and is on disk when this returns, so the next enumeration, in this process or the next one, reports it.

Errors

Returns crate::Status::InvalidArgument for a name longer than the SDK's limit, and crate::Status::Io if the store cannot be written.