DLAPI 4.1.1.0
An API for controlling Aluma branded cameras
dl::IPromise Class Referenceabstract

Promise interface class. More...

#include <dlapi.h>

Public Types

enum  Status {
  Idle , Executing , Complete , Error ,
  InvalidFuture = 0xff
}
 

Public Member Functions

virtual void getLastError (char *buffer, size_t &bufferSize) const =0
 Puts a human readable string into the supplied buffer containing the last known error for command the IPromise is tracking.
 
virtual EStatusCode getAPIStatusCode () const =0
 Returns the API status code reported by the execution of the command.
 
virtual Status getStatus () const =0
 Retrieve the status of the command the IPromise is tracking.
 
virtual Status wait ()=0
 Wait (blocking) until the IPromise either completes, or returns an error (timing out at 10 seconds since the last known update).
 
virtual void release ()=0
 Flags the promise for release within DLAPI.
 

Detailed Description

Promise interface class.

Device/Peripheral interface calls which complete asynchronously (e.g. query and set methods) will return a pointer to an IPromise object. Users are responsible for releasing IPromise pointers when they are done with them so that the API can manage their memory internally. A failure to release promises will result in memory leakage.

An example of how to use a promise in a blocking fashion:

++
ICamera::Info getInfo(ICameraPtr pCamera)
{
IPromisePtr pPromise = pCamera->queryInfo();
IPromise::Status result = pPromise->wait();
if (result != IPromise::Complete)
{
char buf[512] = {0};
size_t lng = 512;
pPromise->getLastError(&(buf[0]), lng);
pPromise->release(); // Mandatory!
throw std::logic_error(&(buf[0]), lng);
}
pPromise->release(); // Mandatory!
return pCamera->getInfo();
}
Camera interface class.
Definition dlapi.h:1632
virtual ICamera::Info getInfo() const =0
Returns the buffered ICamera::Info structure.
virtual IPromisePtr queryInfo()=0
Queries the camera's unit information structure (ICamera::Info)
Promise interface class.
Definition dlapi.h:537
Status
Definition dlapi.h:545
@ Complete
Promise completed successfully.
Definition dlapi.h:548
virtual Status wait()=0
Wait (blocking) until the IPromise either completes, or returns an error (timing out at 10 seconds si...
virtual void release()=0
Flags the promise for release within DLAPI.
virtual void getLastError(char *buffer, size_t &bufferSize) const =0
Puts a human readable string into the supplied buffer containing the last known error for command the...
Definition dlapi.h:1748

An example of how to use a promise in a non-blocking fashion, executing a callback function while we wait:

++
bool isPromiseDone(IPromisePtr pPromise)
{
IPromise::Status result = pProimse->getStatus();
if ( result == IPromise::Error )
{
char buf[512] = {0};
size_t lng = 512;
pPromise->getLastError(&(buf[0]), lng);
pPromise->release();
throw std::logic_error(&(buf[0]), lng);
}
else if ( result == IPromise::Complete )
{
pPromise->release();
}
return result == IPromise::Complete;
}
ICamera::Info getInfo(ICameraPtr pCamera, std::function<void()> fCallback)
{
IPromisePtr pPromise = pCamera->queryInfo();
try
{
while (!isPromiseDone())
{
// Execute fCallback while we wait
fCallback();
}
}
catch (std::exception &ex)
{
// Log any error messages
}
return pCamera->getInfo();
}
@ Error
Promise completed with an error.
Definition dlapi.h:549
IPromise * IPromisePtr
Convenience typedef for IPromise pointers.
Definition dlapi.h:605
ICamera * ICameraPtr
Convenience typedef for ICamera pointers.
Definition dlapi.h:2042
Camera info structure.

IPromise is also thread-safe, and thus could be monitored on a worker thread. You should try to avoid making multiple calls before promises have the chance to return, as the internal queuing system can get overloaded, and bog-down IO to the camera.

Member Enumeration Documentation

◆ Status

Enumerator
Idle 

Promise has not yet begun execution.

Executing 

Promise is currently being executed.

Complete 

Promise completed successfully.

Error 

Promise completed with an error.

InvalidFuture 

Promise is uninstantiated.

545 {
546 Idle,
547 Executing,
548 Complete,
549 Error,
550
551 InvalidFuture = 0xff
552 };
@ Idle
Promise has not yet begun execution.
Definition dlapi.h:546
@ InvalidFuture
Promise is uninstantiated.
Definition dlapi.h:551
@ Executing
Promise is currently being executed.
Definition dlapi.h:547

Member Function Documentation

◆ getAPIStatusCode()

virtual EStatusCode dl::IPromise::getAPIStatusCode ( ) const
pure virtual

Returns the API status code reported by the execution of the command.

Returns
API status code reported by the camera
See also
EStatusCode

This function returns a more fine-grained error code from the API when a failure is encountered. Some error codes are recoverable (such as the feature not supported), and we need to

◆ getLastError()

virtual void dl::IPromise::getLastError ( char * buffer,
size_t & bufferSize ) const
pure virtual

Puts a human readable string into the supplied buffer containing the last known error for command the IPromise is tracking.

Parameters
buffera pointer to an array of characters that will receive the last error.
size_ta reference to a variable which passes in the size of the supplied buffer, and updates with the length of the string returned.

This function retrieves the last error stored in this promise object. It is best to call this function only when getStatus(), or wait() returns IPromise::Error. All error strings are English text only. No localization is done within DLAPI.

◆ getStatus()

virtual Status dl::IPromise::getStatus ( ) const
pure virtual

Retrieve the status of the command the IPromise is tracking.

Returns
IPromise::Status
See also
IPromise::Status

A non-blocking call to obtain the status of the promise's operation.

◆ release()

virtual void dl::IPromise::release ( )
pure virtual

Flags the promise for release within DLAPI.

Signals to the API that the user is done using the promise, and it can be handled by garbage collection. This function must be called on all promises returned from the API, no exceptions. The IPromise object is no longer valid after calling this.

◆ wait()

virtual Status dl::IPromise::wait ( )
pure virtual

Wait (blocking) until the IPromise either completes, or returns an error (timing out at 10 seconds since the last known update).

Returns
IPromise::Status

Blocking function waits for the operation to complete with a result (Success, or Error), and returns that result.


The documentation for this class was generated from the following file: