Tizen Native API
9.0
|
The Sensor Provider API provides functions to define a new sensor instance and provide its data.
Required Header
#include <sensor.h>
Overview
This Sensor API provides functions to define a new sensor instance from an application. Other applications are able to be notified whenever a new sensor instance is registered and listen to the new sensor.
Functions | |
int | sensor_create_provider (const char *uri, sensor_provider_h *provider) |
Create a sensor provider for a given valid URI string. | |
int | sensor_add_provider (sensor_provider_h provider) |
Register the sensor provider created by sensor_create_provider(). | |
int | sensor_remove_provider (sensor_provider_h provider) |
Unregisters the given sensor provider registered by sensor_add_provider(). | |
int | sensor_destroy_provider (sensor_provider_h provider) |
Destroy resources of the given sensor provider. | |
int | sensor_provider_set_name (sensor_provider_h provider, const char *name) |
Set the name of the given sensor provider as name. | |
int | sensor_provider_set_vendor (sensor_provider_h provider, const char *vendor) |
Set the vendor name of the given sensor provider as vendor. | |
int | sensor_provider_set_range (sensor_provider_h provider, float min_range, float max_range) |
Set the range of sensor values to the sensor provider. | |
int | sensor_provider_set_resolution (sensor_provider_h provider, float resolution) |
Set the resolution of sensor values of the sensor provider. | |
int | sensor_provider_set_start_cb (sensor_provider_h provider, sensor_provider_start_cb callback, void *user_data) |
Register the callback to be called when a listener starts the sensor provider. | |
int | sensor_provider_set_stop_cb (sensor_provider_h provider, sensor_provider_stop_cb callback, void *user_data) |
Register the callback to be called when a sensor listener stops the sensor provider. | |
int | sensor_provider_set_interval_changed_cb (sensor_provider_h provider, sensor_provider_interval_changed_cb callback, void *user_data) |
Register the callback to be invoked when the interval is changed. | |
int | sensor_provider_publish (sensor_provider_h provider, sensor_event_s event) TIZEN_DEPRECATED_API |
Publishes a sensor event through the declared sensor. | |
int | sensor_provider_publish_events (sensor_provider_h provider, sensor_event_s events[], int count) |
Publishes sensor events through the declared sensor. | |
Typedefs | |
typedef struct _sensor_provider_s * | sensor_provider_h |
Sensor provider handle. | |
typedef void(* | sensor_provider_start_cb )(sensor_provider_h provider, void *user_data) |
Callback function type to be called when a sensor listener starts the sensor provider. | |
typedef void(* | sensor_provider_stop_cb )(sensor_provider_h provider, void *user_data) |
Callback function type to be called when a sensor listener stops the sensor provider. | |
typedef void(* | sensor_provider_interval_changed_cb )(sensor_provider_h provider, unsigned int interval_ms, void *user_data) |
Callback function type to be called when the interval of the sensor provider is changed. |
Typedef Documentation
typedef struct _sensor_provider_s* sensor_provider_h |
Sensor provider handle.
One or more sensor providers can be created by using sensor_create_provider(). The sensor's data can be published to listeners, via the provider.
- Since :
- 4.0
typedef void(* sensor_provider_interval_changed_cb)(sensor_provider_h provider, unsigned int interval_ms, void *user_data) |
Callback function type to be called when the interval of the sensor provider is changed.
Will be called when the interval of the sensor provider is changed. Callback function can be added using function sensor_provider_set_interval_changed_cb().
- Since :
- 4.0
- Remarks:
- provider is the object created with sensor_create_provider() and is the object for which the callback was triggered.
- Parameters:
-
[in] provider The sensor provider handle [in] interval_ms The interval [in] user_data The user data to be passed to the callback function
- Precondition:
- A callback function needs to be set using sensor_provider_set_interval_changed_cb().
- See also:
- sensor_provider_set_interval_changed_cb()
void sensor_provider_interval_change_callback(sensor_provider_h provider, void *user_data) { ... } ... sensor_provider_set_interval_changed_cb(provider, sensor_provider_interval_change_callback, NULL);
typedef void(* sensor_provider_start_cb)(sensor_provider_h provider, void *user_data) |
Callback function type to be called when a sensor listener starts the sensor provider.
Will be called when a sensor listener starts the sensor provider. Callback function can be added using function sensor_provider_set_start_cb().
- Since :
- 4.0
- Remarks:
- provider is the object created with sensor_create_provider() and is the object for which the callback was triggered.
- Parameters:
-
[in] provider The sensor provider handle [in] user_data The user data to be passed to the callback function
- Precondition:
- A callback function needs to be set using sensor_provider_set_start_cb().
- See also:
- sensor_provider_set_start_cb()
void sensor_provider_start_callback(sensor_provider_h provider, void *user_data) { ... } ... sensor_provider_set_start_cb(provider, sensor_provider_start_callback, NULL);
typedef void(* sensor_provider_stop_cb)(sensor_provider_h provider, void *user_data) |
Callback function type to be called when a sensor listener stops the sensor provider.
Will be called when a sensor listener stops the sensor provider. Callback function can be added using function sensor_provider_set_stop_cb().
- Since :
- 4.0
- Remarks:
- provider is the object created with sensor_create_provider() and is the object for which the callback was triggered.
- Parameters:
-
[in] provider The sensor provider handle [in] user_data The user data to be passed to the callback function
- Precondition:
- A callback function needs to be set using sensor_provider_set_stop_cb().
- See also:
- sensor_provider_set_stop_cb()
void sensor_provider_stop_callback(sensor_provider_h provider, void *user_data) { ... } ... sensor_provider_set_stop_cb(provider, sensor_provider_start_callback, NULL);
Function Documentation
int sensor_add_provider | ( | sensor_provider_h | provider | ) |
Register the sensor provider created by sensor_create_provider().
A sensor provider is created via sensor_create_provider(), and the three callback functions sensor_provider_start_cb(), sensor_provider_stop_cb(), and sensor_provider_set_interval_changed_cb() should be set in advance.
- Since :
- 4.0
- Parameters:
-
[in] provider The sensor provider handle
- Returns:
- SENSOR_ERROR_NONE on success, otherwise a negative error value
- Return values:
-
SENSOR_ERROR_NONE Successful SENSOR_ERROR_INVALID_PARAMETER Invalid parameter SENSOR_ERROR_PERMISSION_DENIED Permission denied SENSOR_ERROR_OPERATION_FAILED Operation failed
- See also:
- sensor_remove_provider()
const char *provider_uri = "http://appsensor/sensor/general/providersensor/heartbeat"; sensor_provider_h sensor_provider; sensor_create_provider(provider_uri, &sensor_provider); ... sensor_add_provider(sensor_provider);
int sensor_create_provider | ( | const char * | uri, |
sensor_provider_h * | provider | ||
) |
Create a sensor provider for a given valid URI string.
This function creates a sensor provider handle with a given URI. The URI should be in the valid form described in Sensor URIs. In addition, it is not allowed to set the vendor in the URI to "tizen.org", as it is pre-assigned to the platform-defined sensors.
- Since :
- 4.0
- Remarks:
- If your application needs to publish health-related sensor data, the URI category should be "healthinfo". Then the applications without the privilege http://tizen.org/privilege/healthinfo are not allowed to listen your application's health-related sensor.
- The provider must be released using sensor_destroy_provider().
- Parameters:
-
[in] uri The URI of sensor to be created [out] provider The sensor provider handle
- Returns:
- SENSOR_ERROR_NONE on success, otherwise a negative error value
- Return values:
-
SENSOR_ERROR_NONE Successful SENSOR_ERROR_INVALID_PARAMETER Invalid parameter SENSOR_ERROR_OUT_OF_MEMORY Out of memory SENSOR_ERROR_OPERATION_FAILED Operation failed
- See also:
- sensor_destroy_provider()
const char *provider_uri = "http://appsensor/sensor/general/providersensor/heartbeat"; sensor_provider_h sensor_provider; sensor_create_provider(provider_uri, &sensor_provider);
int sensor_destroy_provider | ( | sensor_provider_h | provider | ) |
Destroy resources of the given sensor provider.
Release all the resources allocated for the sensor provider by the function sensor_create_provider().
- Since :
- 4.0
- Remarks:
- If this function is called before sensor_remove_provider() is called, then the sensor provider will be implicitly unregistered.
- Parameters:
-
[in] provider The sensor provider handle
- Returns:
- SENSOR_ERROR_NONE on success, otherwise a negative error value
- Return values:
-
SENSOR_ERROR_NONE Successful SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
- See also:
- sensor_create_provider()
const char *provider_uri = "http://appsensor/sensor/general/providersensor/heartbeat"; sensor_provider_h sensor_provider; sensor_create_provider(provider_uri, &sensor_provider); ... sensor_add_provider(sensor_provider); ... sensor_remove_provider(sensor_provider); sensor_destroy_provider(sensor_provider);
int sensor_provider_publish | ( | sensor_provider_h | provider, |
sensor_event_s | event | ||
) |
Publishes a sensor event through the declared sensor.
- Deprecated:
- Deprecated since 5.5. Use sensor_provider_publish_events() instead.
This function publishes a sensor's data to its listeners.
- Since :
- 4.0
- Parameters:
-
[in] provider The sensor provider handle [in] event The sensor event
- Returns:
- SENSOR_ERROR_NONE on success, otherwise a negative error value
- Return values:
-
SENSOR_ERROR_NONE Successful SENSOR_ERROR_INVALID_PARAMETER Invalid parameter SENSOR_ERROR_OPERATION_FAILED Operation failed
int sensor_provider_publish_events | ( | sensor_provider_h | provider, |
sensor_event_s | events[], | ||
int | count | ||
) |
Publishes sensor events through the declared sensor.
This function publishes a sensor's data to its listeners.
- Since :
- 5.5
- Remarks:
- Both callbacks sensor_event_cb() (set with sensor_listener_set_event_cb()) and sensor_events_cb() (set with sensor_listener_set_events_cb()) are available. Only one of the callbacks can be used at any given time. A call to sensor_listener_set_event_cb() or sensor_listener_set_events_cb() sets the new callback in place of the callback previously set by any of the callback setters. If sensor_events_cb() is set and a single event is published with sensor_provider_publish(), then the event will be delivered through this callback with events_count set to 1. If sensor_event_cb() is set and multiple events are published with sensor_provider_publish_events(), then only the first element of events will be delivered. This behavior is not guaranteed, it's strongly recommended not to use sensor_provider_publish_events() with sensor_event_cb().
- Parameters:
-
[in] provider The sensor provider handle [in] events The sensor events [in] count The number of events
- Returns:
- SENSOR_ERROR_NONE on success, otherwise a negative error value
- Return values:
-
SENSOR_ERROR_NONE Successful SENSOR_ERROR_INVALID_PARAMETER Invalid parameter SENSOR_ERROR_OPERATION_FAILED Operation failed ... sensor_event_s events[10]; ... for (int i = 0; i < 10; ++i) { events[i].accuracy = 3; events[i].timestamp = timestamp; events[i].value_count = 3; events[i].values[0] = i; events[i].values[1] = i + 2; events[i].values[2] = i + 4; } ... sensor_provider_publish_events(provider, events, 10);
int sensor_provider_set_interval_changed_cb | ( | sensor_provider_h | provider, |
sensor_provider_interval_changed_cb | callback, | ||
void * | user_data | ||
) |
Register the callback to be invoked when the interval is changed.
Register the callback function(sensor_provider_interval_changed_cb) to be invoked when the interval is changed.
- Since :
- 4.0
- Parameters:
-
[in] provider The sensor provider handle [in] callback The callback function to attach to the provider handle [in] user_data The user data to be passed to the callback function
- Returns:
- SENSOR_ERROR_NONE on success, otherwise a negative error value
- Return values:
-
SENSOR_ERROR_NONE Successful SENSOR_ERROR_INVALID_PARAMETER Invalid parameter SENSOR_ERROR_OPERATION_FAILED Operation failed void sensor_provider_interval_change_callback(sensor_provider_h provider, void *user_data) { ... } ... sensor_provider_set_interval_changed_cb(provider, sensor_provider_interval_change_callback, NULL);
int sensor_provider_set_name | ( | sensor_provider_h | provider, |
const char * | name | ||
) |
Set the name of the given sensor provider as name.
The name of the given sensor provider will be name if success.
- Since :
- 4.0
- Parameters:
-
[in] provider The sensor provider handle [in] name The name of the sensor
- Returns:
- SENSOR_ERROR_NONE on success, otherwise a negative error value
- Return values:
-
SENSOR_ERROR_NONE Successful SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
- Precondition:
- sensor_create_provider()
- See also:
- sensor_provider_set_vendor() sensor_provider_set_range() sensor_provider_set_resolution()
const char *provider_uri = "http://appsensor/sensor/general/providersensor/heartbeat"; sensor_provider_h sensor_provider; sensor_create_provider(provider_uri, &sensor_provider); ... sensor_provider_set_name(sensor_provider, "heartbeat");
int sensor_provider_set_range | ( | sensor_provider_h | provider, |
float | min_range, | ||
float | max_range | ||
) |
Set the range of sensor values to the sensor provider.
Set the range of possible sensor values to the sensor provider handle.
- Since :
- 4.0
- Remarks:
- If the application does not set the range, the default values are 0 and 1.
- Parameters:
-
[in] provider The sensor provider handle [in] min_range The lower bound [in] max_range The upper bound
- Returns:
- SENSOR_ERROR_NONE on success, otherwise a negative error value
- Return values:
-
SENSOR_ERROR_NONE Successful SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
- Precondition:
- sensor_create_provider()
- See also:
- sensor_provider_set_name() sensor_provider_set_vendor() sensor_provider_set_resolution()
const char *provider_uri = "http://appsensor/sensor/general/providersensor/heartbeat"; sensor_provider_h sensor_provider; sensor_create_provider(provider_uri, &sensor_provider); ... sensor_provider_set_range(sensor_provider, 0.0f, 1.0f);
int sensor_provider_set_resolution | ( | sensor_provider_h | provider, |
float | resolution | ||
) |
Set the resolution of sensor values of the sensor provider.
Set the resolution of sensor values as a float value of the given sensor provider.
- Since :
- 4.0
- Remarks:
- If the application does not set the resolution, the default value is 1.
- Parameters:
-
[in] provider The sensor provider handle [in] resolution The resolution
- Returns:
- SENSOR_ERROR_NONE on success, otherwise a negative error value
- Return values:
-
SENSOR_ERROR_NONE Successful SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
- Precondition:
- sensor_create_provider()
- See also:
- sensor_provider_set_name() sensor_provider_set_vendor() sensor_provider_set_range()
const char *provider_uri = "http://appsensor/sensor/general/providersensor/heartbeat"; sensor_provider_h sensor_provider; sensor_create_provider(provider_uri, &sensor_provider); ... sensor_provider_set_resolution(sensor_provider, 0.1f);
int sensor_provider_set_start_cb | ( | sensor_provider_h | provider, |
sensor_provider_start_cb | callback, | ||
void * | user_data | ||
) |
Register the callback to be called when a listener starts the sensor provider.
Register the callback function(sensor_provider_start_cb) to be invoked when a listener starts the sensor provider.
- Since :
- 4.0
- Parameters:
-
[in] provider The provider handle [in] callback The callback function to attach to the provider handle [in] user_data The user data to be passed to the callback function
- Returns:
- SENSOR_ERROR_NONE on success, otherwise a negative error value
- Return values:
-
SENSOR_ERROR_NONE Successful SENSOR_ERROR_INVALID_PARAMETER Invalid parameter SENSOR_ERROR_OPERATION_FAILED Operation failed
void sensor_provider_start_callback(sensor_provider_h provider, void *user_data) { ... } ... sensor_provider_set_start_cb(provider, sensor_provider_start_callback, NULL);
int sensor_provider_set_stop_cb | ( | sensor_provider_h | provider, |
sensor_provider_stop_cb | callback, | ||
void * | user_data | ||
) |
Register the callback to be called when a sensor listener stops the sensor provider.
Register the callback function(sensor_provider_stop_cb) to be invoked when a sensor listener stops the sensor provider.
- Since :
- 4.0
- Parameters:
-
[in] provider The sensor provider handle [in] callback The callback function to attach to the provider handle [in] user_data The user data to be passed to the callback function
- Returns:
- SENSOR_ERROR_NONE on success, otherwise a negative error value
- Return values:
-
SENSOR_ERROR_NONE Successful SENSOR_ERROR_INVALID_PARAMETER Invalid parameter SENSOR_ERROR_OPERATION_FAILED Operation failed void sensor_provider_stop_callback(sensor_provider_h provider, void *user_data) { ... } ... sensor_provider_set_stop_cb(provider, sensor_provider_start_callback, NULL);
int sensor_provider_set_vendor | ( | sensor_provider_h | provider, |
const char * | vendor | ||
) |
Set the vendor name of the given sensor provider as vendor.
The vendor name of the given sensor provider will be vendor if success.
- Since :
- 4.0
- Parameters:
-
[in] provider The sensor provider handle [in] vendor The vendor of the sensor
- Returns:
- SENSOR_ERROR_NONE on success, otherwise a negative error value
- Return values:
-
SENSOR_ERROR_NONE Successful SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
- Precondition:
- sensor_create_provider()
- See also:
- sensor_provider_set_name() sensor_provider_set_range() sensor_provider_set_resolution()
const char *provider_uri = "http://appsensor/sensor/general/providersensor/heartbeat"; sensor_provider_h sensor_provider; sensor_create_provider(provider_uri, &sensor_provider); ... sensor_provider_set_vendor(sensor_provider, "appsensor");
int sensor_remove_provider | ( | sensor_provider_h | provider | ) |
Unregisters the given sensor provider registered by sensor_add_provider().
A sensor provider that registered by sensor_add_provider() function call previously, can be unregistered by sensor_removed_provider().
- Since :
- 4.0
- Parameters:
-
[in] provider The sensor provider handle
- Returns:
- SENSOR_ERROR_NONE on success, otherwise a negative error value
- Return values:
-
SENSOR_ERROR_NONE Successful SENSOR_ERROR_INVALID_PARAMETER Invalid parameter SENSOR_ERROR_OPERATION_FAILED Operation failed
- See also:
- sensor_add_provider()
const char *provider_uri = "http://appsensor/sensor/general/providersensor/heartbeat"; sensor_provider_h sensor_provider; sensor_create_provider(provider_uri, &sensor_provider); ... sensor_add_provider(sensor_provider); ... sensor_remove_provider(sensor_provider);