# Session Management

## ISession

ISession offers simple and easy interface to the clients to (1) Facilitate interaction with Qualcomm Sensing Hub (2) Abstracts the underlying transport layer mechanism.

- class ISession

    - ISession interface class provides methods to interact with QSH framework.

Public Types

- enum error

    - Error codes if any from ISession.

*Values:*

- enumerator RESET

    - indicates restart / resetting of QSH subsystem due to fatal events

- using respCallBack = std::function&lt;void(const uint32\_t respValue, uint64\_t clientConnectID)&gt;

    - Type alias for ISession respCallBack, errorCallBack and eventCallBack respectively.

- using errorCallBack = std::function&lt;void(error errorValue)&gt;

    - 

- using eventCallBack = std::function&lt;void(const uint8\_t \*sensorData, size\_t sensorDataSize, uint64\_t sensorDataTimeStamp)&gt;

    -

Public Functions

- virtual int open() = 0

    - Initiates the client session created using getSession(). Sets up and establishes communication between the client and the QSH framework. The client should call this function only once per session.

- Returns:

    - - 0 Success.
- -1 Failure.

- virtual void close() = 0

    - Closes the session for this instance, terminates the communication between the client and the QSH framework. The client must call this function at the end of the session to release resources and avoid memory leaks.

- virtual int setCallBacks(suid suid, respCallBack respCB, errorCallBack errorCB, eventCallBack eventCB) = 0

    - Set the callbacks for the given suid. Client needs to call only once per given suid.

Note

All parameters are mandatory.

- Incase SUID is already registered, callbacks are updated with new ones.
- The client may pass nullptr, incase any callback function is not defined / required.
- To unset the callbacks for already registered SUID, the client may pass nullptr for all the three callback functions.
- For any unregistered SUID, passing nullptr for all callback functions is considered as an error.

- Parameters:

    - - **suid** – **[in]** SUID for which callbacks are to be registered.
- **respCB** – **[in]** Response callback pointer.
- **errorCB** – **[in]** Error callback pointer.
- **eventCB** – **[in]** Event callback pointer.

- Returns:

    - - 0 Success.
- -1 Failure, if all callback functions are nullptr for an unregistered SUID.

- virtual int sendRequest(suid suid, std::string message) = 0

    - Asynchronously sends a protocol buffer (proto) encoded message to the QSH framework.

- Parameters:

    - - **suid** – **[in]** Unique SUID of the sensor for which request will be sent.
- **message** – **[in]** Proto encoded request message, formulated with client API for the given sensor.

- Returns:

    - - 0 Success
- -1 Failure

    - if client tries to send request over a closed session
    - if encoded message size exceeds the permissible size
    - if sending message fails due to channel related issue

- inline virtual ~ISession()

    - Destructor for ISession. Once the usecase is done, to avoid the memory leaks, clients are expected to delete the ISession instance.

## Session Factory

SessionFactory provides simple and flexible way for creating ISession instances.

- class sessionFactory

    - SessionFactory is a runtime interface that provides simple and flexible way for creating instances of ISession, functioning as factory class. Users can create an ISession only through sessionFactory instance.

Private Types

- typedef ISession \*(\*getSession\_t)(int)

    - Pointer to ISession object.

- typedef void \*(\*getSensingHubIds\_t)()

    - Pointer to vector containing Sensing Hub IDs.

Public Functions

- inline sessionFactory()

    - Constructor for sessionFactory, creates singleton object.

- inline ~sessionFactory()

    - Destructor for sessionFactory. Once the usecase is done, to avoid the memory leaks, clients are expected to delete the sessionFactory instance.

- ISession \*getSession(int hub\_id = -1)

    - Creates ISession instance for the specified sensing-hub ID.

- Parameters:

    - **hub\_id** – **[in]** Hub ID of the desired sensing-hub Default value = -1.

- Returns:

    - - Pointer to ISession object Success.
- Nullptr Failure.

- std::vector&lt;int&gt; getSensingHubIds()

    - Retrieve Hub IDs of the supported Sensing Hubs.

- Returns:

    - vector containing all supported Hub IDs.

Last Published: Jul 14, 2025

Previous Topic
 
sns\_client\_qsocket\_msg::msg