# Session Management

## ISession

[ISession](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#classISession) 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](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#classISession) interface class provides methods to interact with QSH framework.

Public Types

- enum error

    - Error codes if any from [ISession](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#classISession).

*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](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#classISession) respCallBack, errorCallBack and eventCallBack respectively.

- using errorCallBack = std::function&lt;void([error](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#_CPPv4N8ISession5errorE) 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](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#_CPPv4N8ISession12setCallBacksE4suid12respCallBack13errorCallBack13eventCallBack) suid, [respCallBack](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#_CPPv4N8ISession12respCallBackE) respCB, [errorCallBack](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#_CPPv4N8ISession13errorCallBackE) errorCB, [eventCallBack](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#_CPPv4N8ISession13eventCallBackE) 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](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#_CPPv4N8ISession11sendRequestE4suidNSt6stringE) 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](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#classISession). Once the usecase is done, to avoid the memory leaks, clients are expected to delete the [ISession](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#classISession) instance.

## Session Factory

SessionFactory provides simple and flexible way for creating [ISession](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#classISession) instances.

- class sessionFactory

    - SessionFactory is a runtime interface that provides simple and flexible way for creating instances of [ISession](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#classISession), functioning as factory class. Users can create an [ISession](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#classISession) only through [sessionFactory](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#classsessionFactory) instance.

Private Types

- typedef [ISession](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#_CPPv48ISession) \*(\*getSession\_t)(int)

    - Pointer to [ISession](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#classISession) object.

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

    - Pointer to vector containing Sensing Hub IDs.

Public Functions

- inline sessionFactory()

    - Constructor for [sessionFactory](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#classsessionFactory), creates singleton object.

- inline ~sessionFactory()

    - Destructor for [sessionFactory](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#classsessionFactory). Once the usecase is done, to avoid the memory leaks, clients are expected to delete the [sessionFactory](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#classsessionFactory) instance.

- [ISession](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#_CPPv48ISession) \*getSession(int hub\_id = -1)

    - Creates [ISession](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#classISession) 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](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#classISession) 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](https://docs.qualcomm.com/bundle/publicresource/80-P9361-100/topics/standard.md)