# Sensor API

## Common

### Data Stream

Data stream represents a unique connection between a client sensor and a source sensor. The client sensor is responsible for creating, maintaining and removing the data stream. After successful creation of the data stream, it can be used by the client sensor to send requests to and receive events from the source sensor.

- struct sns\_data\_stream

    - Data Stream Manager.

Public Members

- const struct [sns\_data\_stream\_api](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv419sns_data_stream_api) \*api

    - Data Stream APIs.

- struct sns\_data\_stream\_api

    - Data Stream APIs.

Public Members

- uint32\_t struct\_len

    - Length of [sns\_data\_stream\_api](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#structsns__data__stream__api) structure.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) (\*send\_request)([sns\_data\_stream](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv415sns_data_stream) \*data\_stream, [sns\_request](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv411sns_request) \*request)

    - Sends a request to the source Sensor. This request may update or replace the existing request, depending on the Sensor specification.

- Param data\_stream:

    - **[inout]** Data stream on which to send the request.

- Param request:

    - **[in]** Request to be sent; Framework will copy request.

- Return:

    - - SNS\_RC\_SUCCESS Success.
- SNS\_RC\_INVALID\_STATE Stream is no longer available; create again.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) (\*initiate\_flush)([sns\_data\_stream](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv415sns_data_stream) \*data\_stream)

    - Send a flush request to the source Sensor. This is a helper function; clients may also initiate a flush by generating a flush request message, and sending it via send\_request.

- Param data\_stream:

    - **[inout]** Data stream on which to initiate the flush.

- Return:

    - - SNS\_RC\_SUCCESS Success.
- SNS\_RC\_INVALID\_STATE Stream is no longer available; create again.

- [sns\_sensor\_event](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv416sns_sensor_event) \*(\*peek\_input)([sns\_data\_stream](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv415sns_data_stream) \*data\_stream)

    - Retrieve a pointer to the oldest unprocessed event associated with this data stream from the event queue.

Note

Multiple sequential calls to this function will return the same event pointer.

- Param data\_stream:

    - **[inout]** Data stream from which to get an event

- Return:

    - - sns\_sensor\_event\* Oldest unprocessed event on the queue.
- NULL if no events remain.

- [sns\_sensor\_event](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv416sns_sensor_event) \*(\*get\_next\_input)([sns\_data\_stream](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv415sns_data_stream) \*data\_stream)

    - Remove the current event from the event queue (the event that would be returned via peek\_input). Return the next unprocessed event from the event queue. Once this function returns, there is no means to retrieve the removed Event again; the data has been freed, and its memory should not be accessed.

- Param data\_stream:

    - **[inout]** Data stream from which to get an event

- Return:

    - - sns\_sensor\_event\* The next oldest unprocessed event on the queue (after the removal occurs).
- NULL if no further events remain.

- uint32\_t (\*get\_input\_cnt)([sns\_data\_stream](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv415sns_data_stream) \*data\_stream)

    - Lookup the current number of unprocessed events on this data stream. This value may change at any time, and should not be treated as precise.

Note

Do no rely on this value to assume valid input from peek\_input.

- Param data\_stream:

    - **[inout]** Data stream from which to get the input count.

- Return:

    - - uint32\_t Number of unprocessed events on this data stream.

### Error Codes

Common return codes used by the Sensor Framework.

Enums

- enum sns\_rc

    - Enumeration for common return codes used by the sensor framework.

*Values:*

- enumerator SNS\_RC\_SUCCESS

    - No error occurred; success.

- enumerator SNS\_RC\_FAILED

    - Unfixable or internal error occurred.

- enumerator SNS\_RC\_NOT\_SUPPORTED

    - This API is not supported or is not implemented.

- enumerator SNS\_RC\_INVALID\_TYPE

    - Function argument contains invalid data type, e.g., unknown message ID, unknown registry group, or unexpected. Sensor UID.

- enumerator SNS\_RC\_INVALID\_STATE

    - Sensor[Instance] in bad or invalid state; is unable to recover.

- enumerator SNS\_RC\_INVALID\_VALUE

    - One or more argument values were outside of the valid range.

- enumerator SNS\_RC\_NOT\_AVAILABLE

    - This operation is not available at this time.

- enumerator SNS\_RC\_POLICY

    - This action was rejected due to the current policy settings.

- enumerator SNS\_RC\_INVALID\_LIBRARY\_STATE

    - All sensors of the library are in an invalid state and cannot recover from it. No error occurred; success.

- enumerator SNS\_RC\_DYNAMIC\_OBJECT\_LOAD\_FAILED

    - Loading of a dynamic object failed.

- enumerator SNS\_RC\_DYNAMIC\_OBJECT\_SYMBOL\_NOT\_FOUND

    - A symbol look up in a dynamically loaded library failed.

- enumerator SNS\_RC\_DYNAMIC\_OBJECT\_UNLOAD\_FAILED

    - Unloading of a dynamic object failed.

### Event

An output generated by a Sensor. The Event may contain multiple logical sensor samples. The Framework will ensure samples can be fed into the client individually.

- struct sns\_sensor\_event

    - Structure for an event generated by a sensor.

Public Members

- sns\_time timestamp

    - Timestamp of the event.

- uint32\_t message\_id

    - Sensor event Message ID.

- uint32\_t event\_len

    - Length of the event.

- uint64\_t event[1]

    - Sensor event data.

### Request

Client-generated configuration request. Buffer contains a published, backward-compatible structure. Requests may have a version number, but Sensors must appropriately handle older or newer versions.

- struct sns\_request

    - Structure for a Client-generated configuration request.

Public Members

- uint32\_t message\_id

    - Message ID of the sns\_std\_request::payload.

- uint32\_t request\_len

    - Length of the request payload.

- void \*request

    - Request payload; is an encoded message of type sns\_std\_request.

### Unique Identifier (UID)

A SUID uniquely identifies a specific Sensor. E.g. Different Accel drivers will use different and unique SUIDs. Each Sensor (driver or algorithm) has hard-coded SUIDs. A driver loaded multiple times, may need to advertise different SUIDs for each. Query message for clients. Clients specify a particular attribute they want to match against. I.e. “Datatype” = “Accelerometer” Framework determines the list of Sensors that have this matching attribute. And returns this list of SUIDs in the response message. All communication from the client &lt;-&gt; Sensor will use this SUID Send individual query to each SUID for additional attributes.

Defines

- PRIsuid

    - PRINTF type specifier used in confjunction with SNS\_PRI\_SUID.

- SNS\_PRI\_SUID(suid)

    - PRINTF argument used in junction with PRIsuid type specifier.

- struct sns\_sensor\_uid

    - A sensor’s unique identifier.

Public Members

- uint8\_t sensor\_uid[16]

    -

Functions

- bool sns\_sensor\_uid\_compare(struct [sns\_sensor\_uid](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv414sns_sensor_uid) const \*uid1, struct [sns\_sensor\_uid](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv414sns_sensor_uid) const \*uid2)

    - Determine whether the two SUIDs are equivalent.

- Parameters:

    - - **uid1** – **[in]** First SUID to be compare.
- **uid2** – **[in]** Second SUID to be compare.

- Returns:

    - - True If equivalent
- False Otherwise

## Sensor

Represents a source of data within the Sensors Framework; Sensors may optionally and additionally be data consumers. Sensors must manage their list of Sensor Instances. The Framework will not explicitly create or destroy any Sensor Instance; although it may relocate it in memory as needed, so pointers should not be saved.

- struct sns\_sensor

    - A physical, virtual, or utility Sensor residing on the system.

Public Members

- struct [sns\_sensor\_cb](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv413sns_sensor_cb) const \*cb

    - Functions which call back into the framework; provided by the Framework.

- struct [sns\_sensor\_api](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv414sns_sensor_api) const \*sensor\_api

    - API implementation provided for and by this Sensor.

- struct [sns\_sensor\_instance\_api](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv423sns_sensor_instance_api) const \*instance\_api

    - The associated API for Sensor Instances created for and by this Sensor.

- struct [sns\_sensor\_state](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv416sns_sensor_state) \*state

    - State space allocated by the Framework for the sole use of the Sensor developer.

- struct sns\_sensor\_cb

    - Sensor functions available for use by the Sensor developer.

Public Members

- uint32\_t struct\_len

    - Length of [sns\_sensor\_cb](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#structsns__sensor__cb) structure.

- struct [sns\_service\_manager](https://docs.qualcomm.com/doc/80-P9361-100/topic/service.html#_CPPv419sns_service_manager) \*(\*get\_service\_manager)([sns\_sensor](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv410sns_sensor) const \*sensor)

    - Get a reference to the Service Manager. With this object, a reference to any other utility service can be obtained.

- Param sensor:

    - **[in]** Sensor reference.

- Return:

    - - sns\_service\_manager\* Service Manager reference.

- struct [sns\_sensor\_instance](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv419sns_sensor_instance) \*(\*get\_sensor\_instance)([sns\_sensor](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv410sns_sensor) const \*sensor, bool first)

    - Return the next Sensor Instance associated with this Sensor. Each Sensor has a list of associated Sensor Instances; entries are added to that list within calls to ‘create\_instance’, and removed from the list when it services no client requests.

- Param sensor:

    - **[in]** Sensor reference.

- Param first:

    - **[in]** Return the first instance; reset the internal iterator Must be called first to initialize iteration.

- Return:

    - - sns\_sensor\_instance\* Next Sensor Instance associated with this Sensor.
- NULL At the end of the list, or if the list is empty.

- struct [sns\_sensor\_instance](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv419sns_sensor_instance) \*(\*create\_instance)([sns\_sensor](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv410sns_sensor) \*sensor, uint32\_t state\_len)

    - Allocate and initialize a new Sensor Instance to be associated with this Sensor. Will call sns\_sensor\_instance::init.

Note

Direct pointers to the returned value should not be saved.

- Param sensor:

    - **[in]** Sensor reference.

- Param state\_len:

    - **[in]** Allocation size for [sns\_sensor\_instance::state](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#structsns__sensor__instance_1a2c24c1868d6446a44dcc6bf21720ca3a).

- Return:

    - - sns\_sensor\_instance\* Newly created Sensor Instance.

- void (\*remove\_instance)(struct [sns\_sensor\_instance](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv419sns_sensor_instance) \*instance)

    - Remove and deallocate a Sensor Instance. Will call sns\_sensor\_instance::deinit.

- Param instance:

    - **[in]** Instance received within set\_client\_request.

- Return:

    - - None.

- struct [sns\_sensor](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv410sns_sensor) \*(\*get\_library\_sensor)([sns\_sensor](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv410sns_sensor) const \*sensor, bool first)

    - Return the next Sensor associated with this library. Each Sensor is a member of a library; each library may contain several Sensors. Sensors may be removed from a library upon errors. This function is intended to be used by Sensors which share physical hardware with another sensor, and hence must share state/instances.

- Param sensor:

    - **[in]** Sensor reference.

- Param first:

    - **[in]** Return the first sensor; reset the internal iterator; Must be called first to initialize iteration.

- Return:

    - - sns\_sensor\* Each call to this function iterates over the list, and returns the next Sensor associated with this library.
- NULL At the end of the list, or if the list is empty.

- uint32\_t (\*get\_registration\_index)([sns\_sensor](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv410sns_sensor) const \*sensor)

    - If multiple copies of this Sensor Library have been registered with the sensors framework, this returns the index (starting at ‘0’) of this particular copy. See parameter registration\_cnt of env.AddSSCSU.

- Param sensor:

    - **[in]** Sensor reference.

- Return:

    - - uint32\_t Library registration index.

- struct [sns\_sensor\_instance](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv419sns_sensor_instance) \*(\*create\_instance\_v2)([sns\_sensor](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv410sns_sensor) \*sensor, uint32\_t state\_len, uint32\_t state\_len\_ni)

    - Allocate and initialize a new Sensor Instance to be associated with this Sensor. Will call sns\_sensor\_instance::init. Direct references to/within the returned value may not be saved.

- Param sensor:

    - **[in]** Sensor reference.

- Param state\_len:

    - **[in]** Allocation size for [sns\_sensor\_instance::state](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#structsns__sensor__instance_1a2c24c1868d6446a44dcc6bf21720ca3a).

- Param state\_len\_ni:

    - **[in]** Allocation size for [sns\_sensor\_instance::state\_ni](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#structsns__sensor__instance_1a38e1c9c9a197e5ffe445b28dc82bebc8).

- Return:

    - - sns\_sensor\_instance\* Newly created Sensor Instance.

- struct sns\_sensor\_api

    - Functions every Sensor developer must implement. These functions are exclusively used by the Sensor Framework.

Public Members

- uint32\_t struct\_len

    - Length of [sns\_sensor\_api](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#structsns__sensor__api) structure.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) (\*init)([sns\_sensor](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv410sns_sensor) \*const sensor)

    - Initialize a Sensor to its hard-coded/default state. Generate requests for any other necessary data (e.g. Registry data). A call to [sns\_sensor\_api::deinit](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#structsns__sensor__api_1a7d0d5caf4bb43b54cc7c89f8147a767d) will precede any subsequent calls to this function.

- Param sensor:

    - **[in]** Sensor reference.

- Return:

    - - SNS\_RC\_SUCCESS Success.
- Any other value Failure.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) (\*deinit)([sns\_sensor](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv410sns_sensor) \*const sensor)

    - Release all hardware and software resources associated with this Sensor.

- Param sensor:

    - **[in]** Sensor reference.

- Return:

    - - SNS\_RC\_SUCCESS Success.
- Any other value Failure.

- [sns\_sensor\_uid](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv414sns_sensor_uid) const \*(\*get\_sensor\_uid)([sns\_sensor](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv410sns_sensor) const \*const sensor)

    - Each Sensor must have a globally unique identifier; each algorithm and driver will define their own. If a Sensor may be loaded twice on the system, it is responsible for returning two unique values. These must not change across device reboots.

- Param sensor:

    - **[in]** Sensor reference.

- Return:

    - - [sns\_sensor\_uid](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#structsns__sensor__uid) const\* The unique identifier for this Sensor.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) (\*notify\_event)([sns\_sensor](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv410sns_sensor) \*const sensor)

    - Notification to the client that some data has been received.

Note

The client must use the [sns\_event\_service](https://docs.qualcomm.com/doc/80-P9361-100/topic/service.html#structsns__event__service) to obtain this data for processing.

- Param sensor:

    - **[in]** Sensor reference.

- Return:

    - - SNS\_RC\_SUCCESS Success.
- SNS\_RC\_INVALID\_LIBRARY\_STATE - A sensor should return this error when all sensors in this library are in invalid state and unable to recover. When this error is received by framework, Framework will start library removal process. This removes all the sensors associated with this library and removes library after that.
- SNS\_RC\_NOT\_AVAILABLE - Sensors should return this error if certain operation cann’t be completed at this time. Upon receiving this error type, framework will drop all the events from all data streams except most recent SNS\_STREAM\_REMAINDER number of events.
- All other errors will deinit this sensor

- struct [sns\_sensor\_instance](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv419sns_sensor_instance) \*(\*set\_client\_request)([sns\_sensor](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv410sns_sensor) \*const sensor, struct [sns\_request](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv411sns_request) const \*exist\_request, struct [sns\_request](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv411sns_request) const \*new\_request, bool remove)

    - Add, remove, or update a client’s request to this Sensor.

For each new request sent by a client, the Sensor (via this function) will receive the new\_request. If the client has an active request (which is to be replaced), it will be specified in exist\_request. If ‘remove’ is false: A client has sent a new request to this Sensor. Determine if any active Sensor Instance in [sns\_sensor\_cb::get\_sensor\_instance()](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#structsns__sensor__cb_1a5a768be0986305c26b1fa1bbb6001d50) will handle this request. If yes, use add\_client\_request to associate this new request with that existing Instance. If not, instantiate and initialize a new Sensor Instance with the appropriate configuration, and similarly use add\_client\_request. In either case, if exist\_request is provided and new\_request provides a superceding configuration, exist\_request must be removed via remove\_client\_request. If the new\_request received by the sensor is invalid and cannot be serviced, it is expected to retain the exist\_request on the data stream If ‘remove’ is true: Remove this client request by [sns\_sensor\_instance\_cb::remove\_client\_request](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#structsns__sensor__instance__cb_1ab026ec98f116d5ce47313d1b3c4dc664); re-arrange any remaining client requests/sensor instances. In all cases, if the result of the operation is a Sensor Instance with zero clients, [sns\_sensor\_cb::remove\_instance](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#structsns__sensor__cb_1af7c9c7f667084b7d9e3f99b2b86aaef5) must be called.

- Param sensor:

    - **[in]** Sensor reference.

- Param exist\_request:

    - **[in]** If this request comes-in over an existing stream, this is the existing request.

- Param new\_request:

    - **[in]** New request just received.

- Param remove:

    - **[in]** If the client no longer requires this data.

- Return:

    - - sns\_sensor\_instance\* The Sensor Instance chosen to handle this new client.
- NULL if an error occurred during processing; or if “remove” was true. Or sns\_instance\_no\_error (see above).

- struct sns\_sensor\_state

    - State specifically allocated for the Sensor, to be used by the Sensor developer as needed. May be moved; no pointers into this buffer may be saved.

Public Members

- uint32\_t state\_len

    - Length of [sns\_sensor\_state](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#structsns__sensor__state) structure.

- uint64\_t state[1]

    - Sensor State data.

## Sensor Instance

Represents a specific instance of a Sensor. Each Sensor may have 0 or more instances active at any given time. The Sensor determines when multiple client requests may be shared; it is expected to share aggressively.

- struct sns\_sensor\_instance

    - Structure for the instance created by a sensor.

Public Members

- struct [sns\_sensor\_instance\_cb](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv422sns_sensor_instance_cb) const \*cb

    - Functions which call back into the framework; provided by the framework.

- struct [sns\_sensor\_instance\_state](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv425sns_sensor_instance_state) \*state

    - Fixed-size memory allocation made by the framework from the power efficient heap appropriate for this Sensor. Memory is for the sole use of the Sensor Instance. Memory may be moved between Sensor registered function calls. Therefore direct references should not be maintained.

- struct [sns\_sensor\_instance\_state](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv425sns_sensor_instance_state) \*state\_ni

    - Fixed-sized memory allocation made by the framework from the Non-Island, high power memory heap. May not be dereferenced unless Instance created via [sns\_sensor\_cb::create\_instance\_v2](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#structsns__sensor__cb_1a4adc75b796a17974fa5a3cdf6a21a72e). Developer is responsible for invoking sns\_island\_service::sensor\_instance\_island\_exit before accessing.

- struct sns\_sensor\_instance\_cb

    - Accessor functions for Sensor Instance state managed by the Framework.

Public Members

- uint32\_t struct\_len

    - 

- struct [sns\_service\_manager](https://docs.qualcomm.com/doc/80-P9361-100/topic/service.html#_CPPv419sns_service_manager) \*(\*get\_service\_manager)([sns\_sensor\_instance](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv419sns_sensor_instance) \*instance)

    - Get a reference to the Service Manager. With this object, a reference to any other utility service can be obtained.

- Param instance:

    - **[in]** Sensor Instance reference.

- Return:

    - - sns\_service\_manager\* Service Manager reference.

- struct [sns\_request](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv411sns_request) const \*(\*get\_client\_request)([sns\_sensor\_instance](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv419sns_sensor_instance) \*instance, [sns\_sensor\_uid](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv414sns_sensor_uid) const \*suid, bool first)

    - Return the next client request associated with this Sensor Instance and SUID.

Each Sensor Instance has a list of client requests per SUID which it is servicing. Entries are added via calls to add\_client\_request; removed via remove\_client\_request. An Instance may be handling client requests for multiple (related) Sensors; must use SUID parameter to filter.

- Param instance:

    - **[in]** Sensor Instance reference.

- Param suid:

    - **[in]** Suid of the sensor associated with this instance.

- Param first:

    - **[in]** Return the first request; reset the internal iterator Must be called first to initialize iteration.

- Return:

    - - [sns\_request](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#structsns__request) const\* Each call to this function iterates over the list, and returns the next entry.
- NULL At the end of the list, or if the list is empty.

- void (\*remove\_client\_request)([sns\_sensor\_instance](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv419sns_sensor_instance) \*instance, struct [sns\_request](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv411sns_request) const \*request)

    - Remove a client request from this Sensor Instance.

- Param instance:

    - **[in]** Sensor Instance reference.

- Param request:

    - **[in]** Client request to be removed.

- Return:

    - - None.

- void (\*add\_client\_request)([sns\_sensor\_instance](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv419sns_sensor_instance) \*instance, struct [sns\_request](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv411sns_request) const \*request)

    - Assign this Sensor Instance to service the client request. Replaces any existing request from the same client.

Note

The SUID of the recepient Sensor will be noted upon addition; this SUID must be used within get\_client\_request.

- Param instance:

    - **[in]** Sensor Instance reference.

- Param request:

    - **[in]** Client request to be added.

- Return:

    - - None.

- struct sns\_sensor\_instance\_api

    - Sensor Instance API; to be implemented by the Sensor developer.

Public Members

- uint32\_t struct\_len

    - Length of [sns\_sensor\_instance\_api](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#structsns__sensor__instance__api) structure.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) (\*init)([sns\_sensor\_instance](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv419sns_sensor_instance) \*const instance, [sns\_sensor\_state](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv416sns_sensor_state) const \*sensor\_state)

    - Initialize a Sensor Instance to its default state. A call to [sns\_sensor\_instance\_api::deinit](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#structsns__sensor__instance__api_1a1c94d91ba8ffe5944514d5817b358281) will precede any subsequent calls to this function.

Note

Persistent configuration can be made available using the sensor\_state.

- Param instance:

    - **[in]** Sensor Instance reference.

- Param sensor\_state:

    - **[in]** State of the Sensor which created this Instance.

- Return:

    - - SNS\_RC\_SUCCESS Success.
- Any other value Failure.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) (\*deinit)([sns\_sensor\_instance](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv419sns_sensor_instance) \*const instance)

    - Release all hardware and software resources associated with this Sensor Instance.

- Param instance:

    - **[in]** Sensor Instance reference.

- Return:

    - - SNS\_RC\_SUCCESS Success
- Any other value Failure

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) (\*set\_client\_config)([sns\_sensor\_instance](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv419sns_sensor_instance) \*const instance, struct [sns\_request](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv411sns_request) const \*client\_request)

    - Update a Sensor Instance configuration to this client request. The Sensor Instance is expected to start all dependent streams, timers, etc..

Note

A Sensor may define any number of unique request types they support. However, a client may only have a single active stream; an enable request can inherently serve as a “reconfiguration” request.

- Param instance:

    - **[in]** Sensor Instance reference.

- Param client\_request:

    - **[in]** Client request reference.

- Return:

    - - SNS\_RC\_SUCCESS Success.
- Any other value Failure.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) (\*notify\_event)([sns\_sensor\_instance](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv419sns_sensor_instance) \*const instance)

    - Notification to the client that some data has been received. The client must use the [sns\_event\_service](https://docs.qualcomm.com/doc/80-P9361-100/topic/service.html#structsns__event__service) to obtain this data for processing.

- Param instance:

    - **[in]** Sensor Instance reference.

- Return:

    - - SNS\_RC\_SUCCESS The sensor instance handled the event(s), and is in an operational state. This return code should be used if a recoverable error occurs (such as recoverable message decode errors, etc).
- SNS\_RC\_INVALID\_STATE Sensor instance is in bad or invalid state and is unable to recover. Framework will start removing this instance upon receiving this error.
- SNS\_RC\_NOT\_AVAILABLE - Sensors should return this error if certain operation cann’t be completed at this time. Upon receiving this error type, framework will drop all the events from all data streams except most recent SNS\_STREAM\_REMAINDER number of events.
- For all other errors, Framework will deinit the sensor which created this instance.

- struct sns\_sensor\_instance\_state

    - State specifically allocated for the Sensor Instance, to be used by the Sensor developer as needed. May be relocated; no pointers into this buffer may be saved.

Public Members

- uint32\_t state\_len

    - Length of sensor instance state.

- uint64\_t state[1]

    - Sensor instance state.

Last Published: Jul 14, 2025

[Previous Topic
sns\_timer\_init()](https://docs.qualcomm.com/bundle/publicresource/80-P9361-100/topics/pal.md)