Registering Callbacks

In this section there is a short introdcuction of the callback methods and the way how the callback methods will be registered.

Callback Methods

In Access.h, Stream.h and OnboardService.h there are some methods that takes function pointers (callback methods). Using those callback methods you can receive any response asynchoronously. Below are some callback methods which are defined in Access.h.


....................

///
/// Asynchronous callback for Endpoint pairing keys.
///
/// \param[in] apiStatus - OK on success, other values on failure.
/// \param[in] pairingToken - Endpoint pairing token.
///
typedef std::function<void(const int apiStatus, const PairingToken &pairingToken)> PairingTokenCallback;

///
/// Asynchronous callback function for retrieving Endpoint info.
///
/// \param[in] apiStatus - OK on success, other values on failure.
/// \param[in] endpointInfo - EndpointInfo instance containing endpoint information.
///
typedef std::function<void(const int apiStatus, const std::shared_ptr<types::EndpointInfo> endpointInfo)> EndpointInfoCallback;

.........................

Registration API

The callback methods are passed as function pointers as parameters to some registraion-API. Using this registration API you can make a call to access sdk and get the notified asynchronously. Below are some registration APIs which are present in Access.h.


...........................

///
/// Fetch the pairing token. Device will use this token to pair with this endpoint.
/// This API can be invoked from App only.
///
/// \param[in] callback - Asynchronous callback function that shall return the token.
///
/// \return - AccessRet::OK if successful, other values on failure.
///
virtual AccessRet getPairingToken(PairingTokenCallback callback) = 0;

///
/// Retrieves the endpoint information for an specified endpoint.
///
/// \param[in] endpointId - Id of the endpoint to fetch info. Possible value may be self Id
///                         or Id of some endpoint with association.
/// \param[in] callback   - Asynchronous callback function that shall return endpoint info.
///
/// \return - AccessRet::OK if successful, other values on failure.
///
virtual AccessRet getEndpointInfo(const Endpoint endpointId, EndpointInfoCallback callback) = 0;

...............

AccessRet

When the registration methods are called it returns immediatedly an object of AccessRet. It is an enum and it holds the status codes like below.

enum AccessRet : std::int32_t {
    OK                                  =  0, ///< Successful invocation.
    FAIL                                = -1, ///< Generic failure.
    SERVICE_UNAVAILABLE                 = -2, ///< Smarter AI REST service is temporarily unavailable.
    NOT_RUNNING                         = -3, ///< Access is not yet started. Invoke Access::start() before calling this API.
    EXCEPTION_UNKNOWN_API               = -4, ///< Unknown API invoked
    EXCEPTION_INVALID_QUERY             = -5, ///< Invalid query
    INVALID_PARAMETERS                  = -6, ///< One or more parameters provided during API invocation are invalid.
    EXCEPTION_ID_INVALID                = -7, ///< Provided Endpoint Id is invalid (may be reset).
    EXCEPTION_SECRET_INVALID            = -9, ///< Provided Endpoint secret is invalid (tampered, for example).
    EXCEPTION_SECRET_EXPIRED            = -11, ///< Provided Endpoint secret is expired.
    EXCEPTION_CONSTRAINT_VIOLATION      = -13, ///< Provided data on API invocation violated some constraint.
    EXCEPTION_NO_CONNECTIVITY           = -15, ///< Access failed to reach Smarter AI REST server (may be no internet).
    EXCEPTION_BAD_CALLBACK              = -17, ///< Provided asynchronous callback function is bad
    EXCEPTION_INSUFFICIENT_PRIVILEGES   = -18, ///< INSUFFICIENT_PRIVILEGES
    EXCEPTION_GENERIC                   = -21,  ///< Generic failure.
    EXCEPTION_GENERIC_CLIENT_ERROR      = -22,  ///< HTTP 400 series errors
    EXCEPTION_GENERIC_SERVER_ERROR      = -23  // < HTTP 500 series errors
};

StreamRet

Like AccessRet the StreamRet is an enum it also holds some status. The stream registration APIs and the callback methods which are present Stream.h

enum class StreamRet {
    OK,                  ///< Successful invocation.
    NOT_STARTED,         ///< Call start() before calling APIs.
    INVALID_PARAMETERS,  ///< Invalid parameters.
    FAIL,                ///< Generic failure.
};

ReportType

ReportType is used to send report to Smarter AI Cloud through access library.

enum class ReportType {
    Init,
    Release,
    Account,
    Logging,
    Pairing,
    .....

    /// Connect specific enum
    General,
    Session,
    Networking,
    Connectivity,
    DataTransfer,
    /// Connect enum ends

    /// Stream specific enum
    ABT,
    ALSA,
    G711,
    G722,
    G729,
    H264,
    ......    

    /// Vision specific en enums
    VideoClassifier,
    AudioClassifier,
    Sensor,
    IoTGateway,

    /// Vision enum ends
    Unknown //Only for internal use
};

Below is a Sample Code that shows how to send report to Smarter AI cloud

access->registerEndpointResetCallback([this](const types::Endpoint endpointId) {
    ..........................
    access->postReports(props, types::ReportType::Release, types::ReportSeverity::Warning, types::ReportModule::App, "[STREAMAPP] Reset event received");
});