optris::sdk::faults
Breaking a simulated camera on purpose, or having another program hold it, so that an application can test what it does when that happens to a real one.
Nothing here is a feature of a camera, and nothing here works on one. Every call refuses a real camera with FeatureNotSupportedException, so a call that reached a production build fails the first time it meets hardware instead of doing anything to it. That is also why this is a namespace and a header of its own, outside the single-include header: a test has to include optris/sdk/faults.h and write faults:: on purpose. The same name as the Python and Rust modules; in C# it is Optris.Sdk.Testing.FaultInjection.
Enumerations
LinkChange
enum LinkChange
What SimulateLinkChange() does to a simulated camera.
The values are the C ABI's optris_sdk_testing_link_change.
| Value | Initialiser | Description |
|---|---|---|
kLost |
= 0 | |
kStalled |
= 1 | |
kResumed |
= 2 | |
kUnplugged |
= 3 | |
kReplugged |
= 4 |
Functions
SimulateLinkChange
OTC_SDK_API void SimulateLinkChange(Imager &imager, LinkChange change, const std::string &message={})
Make a simulated camera's link change, for real: frames stop or start, the connection status moves, and a re-open genuinely brings the camera back.
Everything downstream behaves as it does for a real camera: the handler given to Imager::SetConnectionStatusCallback() runs, and with Imager::EnableAutoReconnect() in force the SDK's recovery starts and reports its phases to Imager::SetReconnectCallback(). A re-open is what a real one is to the application: a recording in progress is stopped, a process interface handle taken before it is refused afterwards, and everything set through the imager (palette, regions, alarm rules and the rest) is kept.
Parameters
| Name | Description |
|---|---|
imager |
The camera. Must be simulated. |
change |
What happens to it. |
message |
Detail carried to the connection status handler, as a real event's is. Empty for a description of change. |
Exceptions
| Name | Description |
|---|---|
FeatureNotSupportedException |
if imager is not a simulated camera. |
InvalidStateException |
for kStalled when the link is not up, and for kResumed when it is not stalled. A lost link does not heal on its own; only a re-open brings it back. |
InvalidArgumentException |
for a value that is not a LinkChange. |
HoldByAnotherProcess
OTC_SDK_API void HoldByAnotherProcess(const std::string &serial, const std::string &holder)
Make another program hold a simulated camera, so that an application can test what it does when a real camera is in use elsewhere.
Everything that meets the hold meets it through the SDK's own claim refusal, the one a real camera held by another program produces:
- Opening the camera, by DeviceInfo or by its SimulatedConfig, throws DeviceBusyException with
DeviceBusyReason::kClaimedByAnotherProcessandholderinDeviceBusyDetail::holder. Imager::Reconnect()of a camera whose link is down (SimulateLinkChange()) throws the same and publishesConnectionStatus::Failed.- Automatic recovery reports
ReconnectPhase::kWaitingForDevice, saying another program holds the camera, and spends no attempt. A holder that cannot be named (an emptyholder) is attempted instead, and each attempt fails on the claim, as for a real camera whose holder the platform cannot identify. EnumerateDevices()lists the camera withDeviceInfo::is_claimedset andDeviceInfo::claimed_bynamingholder.
A camera this process already has open keeps running: as with a real camera, another program cannot take a claim this process holds, so the hold is met at the camera's next open or re-open. ReleaseHold() ends it, and the next attempt succeeds.
DeviceBusyDetail::claim_path reads simulated:<serial>: a simulated hold writes no claim file. The hold is kept in this process only, and goes with the camera when it is unregistered.
Parameters
| Name | Description |
|---|---|
serial |
A simulated camera registered with RegisterSimulatedDevice(). |
holder |
How the holder is named, as a real claim names it, for example optris-connect (pid 4711). Empty for a holder that cannot be named. |
Exceptions
| Name | Description |
|---|---|
FeatureNotSupportedException |
if no simulated camera is registered under serial, which is also what a real camera's serial gets. |
ReleaseHold
OTC_SDK_API void ReleaseHold(const std::string &serial)
End the hold HoldByAnotherProcess() placed: the other program lets the camera go. The next open, Imager::Reconnect() or automatic recovery attempt succeeds. A camera that is not held is left as it is.
Parameters
| Name | Description |
|---|---|
serial |
A simulated camera registered with RegisterSimulatedDevice(). |
Exceptions
| Name | Description |
|---|---|
FeatureNotSupportedException |
if no simulated camera is registered under serial. |