# Session Management ## ISession Interface to interact with Sensing Hub. - class ISession - [ISession](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#classISession) is transport-neutral, OS-agnostic, extensible interface for communicating to Sensing Hub. It exposes APIs for clients to: (1) Establish a session to Sensing Hub. (2) Register callbacks per sensor SUID. (3) Send proto-encoded requests and receive responses/events asynchronously. 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 a reset of the Sensing Hub subsystem. - No further events will be recieved on this session - The session remains in open state - Client may resend the sensor requests to resume event reception - enumerator SERVICE\_DOWN - Indicates unavailability of the Sensing Hub subsystem. - No further events will be recieved on this session - The session remains in closed state - The Client is expected to call [open()](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#classISession_1aa0f845777df1e9d332c1c2fe7652c247) again to attempt reconnection - using respCallBack = std::function<void(const uint32\_t respValue, uint64\_t clientConnectID)> - This callback is invoked when a response is received for the registered sensor SUID. Response is an acknowledgement that the client request was sent successfully by the underlying transport layer. - Param respValue: - **[in]** Response status associated with the request. 0 - Success non-zero - Failure - Param clientConnectID: - **[in]** Connection identifier assigned by Sensing Hub for this client session. - using errorCallBack = std::function<void([error](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#_CPPv4N8ISession5errorE) errorValue)> - This callback is invoked when an error occurs in Sensing Hub. - Param errorValue: - **[in]** [ISession](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#classISession) error detected - using eventCallBack = std::function<void(const uint8\_t \*sensorData, size\_t sensorDataSize, uint64\_t sensorDataTimeStamp)> - This callback is invoked when an event is received for the registered sensor SUID. Event is the sensor data requested by the client. - Param sensorData: - **[in]** pointer to protocol-buffer-encoded data stream - Param sensorDataSize: - **[in]** size of the sensorData - Param sensorDataTimeStamp: - **[in]** timestamp at which sensorData is generated Public Functions - virtual int open() = 0 - Open the session and establish a connection to Sensing Hub. Initiates the client session created using getSession(). Sets up and establishes communication channel between the client and the Sensing Hub framework. This should be called exactly once per [ISession](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#classISession) instance before any other operations such as [setCallBacks()](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#classISession_1af15518b49a9a665be06b22e9939f3152) or [sendRequest()](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#classISession_1abccb97cb2abdc84f050a2cbca3404418). - Returns: - - 0 Success (session is now open and ready for use). - -1 Failure (session remains closed). - virtual void close() = 0 - Closes the session for this instance and release associated resources. Terminates the communication channel between the client and the Sensing Hub framework and frees any resources held by this session. After [close()](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#classISession_1a1d830d97269f9e891ed61704ecc5e58f) is called: - No further requests should be sent using this [ISession](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#classISession) instance. - Registered callbacks will no longer receive events. The client is expected to call [close()](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#classISession_1a1d830d97269f9e891ed61704ecc5e58f) once it is done with the session to avoid leaks and dangling resources. - 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 specified sensor SUID. Client needs to call only once per given suid. Associates response, error, and event callbacks with the given SUID for this session. These callbacks are invoked for messages received from Sensing Hub that correspond to the specified 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. - For an already registered SUID, passing nullptr for all callbacks effectively unregisters that SUID. - For a new/unregistered SUID, passing nullptr for all callback functions is considered as an error. - Parameters: - - **suid** – **[in]** Unique SUID of the sensor for which callbacks are set. - **respCB** – **[in]** respCallBack pointer (may be nullptr). - **errorCB** – **[in]** errorCallBack pointer (may be nullptr) - **eventCB** – **[in]** eventCallBack pointer (may be nullptr). - 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 - Send an asynchronous request for a given sensor. Sends a protocol-buffer-encoded request message to the Sensing Hub for the specified SUID. - Parameters: - - **suid** – **[in]** Unique SUID of the target sensor. - **message** – **[in]** Proto encoded request message, formulated with client API for the given sensor. - Returns: - - 0 Success - -1 Failure - Session is not open or already closed. - Encoded message size exceeds the allowed limit. - Underlying transport/channel error while sending. - inline virtual ~ISession() - Destructor for [ISession](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#classISession). Clients are expected to delete the [ISession](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#classISession) instance once the use case is complete to avoid memory leaks. ## Session Factory SessionFactory provides a simple and flexible way to create [ISession](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#classISession) instances for communicating with Sensing Hub. - class sessionFactory - Runtime factory for creating [ISession](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#classISession) instances. Private Types - typedef [ISession](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#_CPPv48ISession) \*(\*getSession\_t)(int) - Function pointer type for the [ISession](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#classISession) creation symbol. - typedef void \*(\*getSensingHubIds\_t)() - Function pointer type for the Sensing Hub ID retrieval symbol. Public Functions - inline sessionFactory() - Construct a [sessionFactory](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#classsessionFactory) instance. Creates a factory object that can be used to obtain [ISession](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#classISession) instances and query supported Sensing Hub IDs. Multiple [sessionFactory](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#classsessionFactory) instances are allowed; they may share the same underlying runtime resources. - inline ~sessionFactory() - Destroy the [sessionFactory](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#classsessionFactory) instance. Once the client no longer needs to create sessions or query hub IDs, it should destroy the [sessionFactory](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#classsessionFactory) instance to release any associated resources. Note Destroying the factory does not automatically destroy [ISession](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#classISession) instances created from it. Clients remain responsible for cleaning up their session objects. - [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. This API loads the [ISession](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#classISession) implementation at runtime and constructs a [ISession](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#classISession) object that can be used to communicate with the Sensing Hub. Note The returned [ISession](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#classISession) instance is initially not in open state. The client must call open() before sending any requests. - 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<int> getSensingHubIds() - Retrieve the IDs of supported Sensing Hubs. Queries the underlying implementation for all available Sensing Hub IDs on the system. These IDs can be used as input to [getSession()](https://docs.qualcomm.com/doc/80-P9361-100/topic/isession.html#classsessionFactory_1a4b367958764b84ac6cc2957173cfb640). - Returns: - A std::vector<int> containing the hub IDs supported by the current platform. An empty vector indicates that no Sensing Hubs were discovered or that discovery is not supported. Last Published: Jul 25, 2026 [Previous Topic sns\_client\_qsocket\_msg::msg](https://docs.qualcomm.com/bundle/publicresource/80-P9361-100/topics/standard.md)