/**
+ * @brief Called when a sensor event occurs.
+ * @since_tizen 5.5
+ *
+ * @param[in] sensor The corresponding sensor handle
+ * @param[in] event A sensor event
+ * @param[in] data The user data had passed to sensor_listener_set_event_cb()
+ *
+ * @pre The sensor needs to be started regarding a listener handle, using sensor_listener_start().
+ */
+typedef void (*sensor_events_cb)(sensor_h sensor, sensor_event_s* events[], int events_count, void *data);
+
+/**
* @brief Called when the accuracy of a sensor changes.
* @details Sensors can be affected by the environment.
* For example, #SENSOR_MAGNETIC is sensitive to any surrounding objects that can influence
/**
+ * @brief Registers the callback function to be invoked when sensor events are delivered via a sensor listener.
+ * @since_tizen 5.5
+ *
+ * @param[in] listener A listener handle
+ * @param[in] callback A callback function to attach with the @a listener handle
+ * @param[in] data A user data to be passed to the callback function
+ *
+ * @return #SENSOR_ERROR_NONE on success, otherwise a negative error value
+ * @retval #SENSOR_ERROR_NONE Successful
+ * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed
+ *
+ * @see sensor_listener_unset_events_cb()
+ */
+int sensor_listener_set_events_cb(sensor_listener_h listener, sensor_events_cb callback, void *data);
+
+/**
+ * @brief Unregisters the sensor events callback function attached to a given sensor listener.
+ * @since_tizen 5.5
+ *
+ * @param[in] listener A listener handle
+ *
+ * @return #SENSOR_ERROR_NONE on success, otherwise a negative error value
+ * @retval #SENSOR_ERROR_NONE Successful
+ * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed
+ *
+ * @see sensor_listener_set_events_cb()
+ */
+int sensor_listener_unset_events_cb(sensor_listener_h listener);
+
+/**
* @brief Registers the callback function to be invoked when the accuracy of a sensor changes.
* @details In addition to sensor_event_cb(), sensor_accuracy_changed_cb() also can be attached
* to sensor listeners. With this accuracy callback function, applications can be notified
* @since_tizen 4.0
*
* @param[in] provider The sensor provider handle
- * @param[out] event The sensor event
+ * @param[in] event The sensor event
*
* @return #SENSOR_ERROR_NONE on success, otherwise a negative error value
* @retval #SENSOR_ERROR_NONE Successful
int sensor_provider_publish(sensor_provider_h provider, sensor_event_s event);
/**
+ * @brief Publishes a sensor event through the declared sensor.
+ * @details This function publishes a sensor's data to its listeners.
+ * @since_tizen 5.5
+ *
+ * @param[in] provider The sensor provider handle
+ * @param[in] events The sensor events
+ * @param[in] count The number of event
+ *
+ * @return #SENSOR_ERROR_NONE on success, otherwise a negative error value
+ * @retval #SENSOR_ERROR_NONE Successful
+ * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed
+ */
+int sensor_provider_publish_events(sensor_provider_h provider, sensor_event_s events[], int count);
+
+/**
* @}
*/
return id;
}
+static void sensor_callback(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data)
+{
+ sensor_event_s *event;
+ sensor_listener_h listener;
+ listener = (sensor_listener_h)user_data;
+
+ if (!sensor || !listener->callback)
+ return;
+
+ event = (sensor_event_s *)data;
+
+ ((sensor_event_cb) listener->callback)(sensor, event, listener->user_data);
+ return;
+}
+
+static void sensor_events_callback(sensor_t sensor, unsigned int event_type, sensor_data_t* datas[], int events_count, void *user_data)
+{
+ sensor_event_s **events;
+ sensor_listener_h listener;
+ listener = (sensor_listener_h)user_data;
+
+ if (!sensor || !listener->callback)
+ return;
+
+ events = (sensor_event_s **)datas;
+
+ ((sensor_events_cb) listener->callback)(sensor, events, events_count, listener->user_data);
+ return;
+}
+
+static inline int sensor_listener_unset_event_cb_impl(sensor_listener_h listener, bool is_events_callback)
+{
+ int id;
+ int type;
+ unsigned int event_id;
+
+ _D("called sensor_listener_unset_event_cb_impl : listener[%p]", listener);
+
+ if (!listener)
+ return SENSOR_ERROR_INVALID_PARAMETER;
+
+ if (listener->magic != SENSOR_LISTENER_MAGIC)
+ return SENSOR_ERROR_INVALID_PARAMETER;
+
+ id = listener->id;
+ type = (int)listener->type;
+ event_id = type << SENSOR_SHIFT_TYPE | 0x1;
+
+ int ret = false;
+ if (is_events_callback) {
+ ret = sensord_unregister_events(id, event_id);
+ } else {
+ ret = sensord_unregister_event(id, event_id);
+ }
+
+ if (!ret)
+ return SENSOR_ERROR_OPERATION_FAILED;
+
+ listener->callback = NULL;
+ listener->user_data = NULL;
+
+ _D("success sensor_unregister_event");
+
+ return SENSOR_ERROR_NONE;
+}
+
+static inline int sensor_listener_set_event_cb_impl(sensor_listener_h listener,
+ unsigned int interval, void* callback, bool is_events_callback, void *user_data)
+{
+ int id;
+ unsigned int event_id;
+ unsigned int batch_latency;
+
+ if (!listener || !callback)
+ return SENSOR_ERROR_INVALID_PARAMETER;
+
+ if (listener->magic != SENSOR_LISTENER_MAGIC)
+ return SENSOR_ERROR_INVALID_PARAMETER;
+
+ _D("called sensor_listener_set_event_cb_impl : listener[%p], interval[%u], callback[%p], user_data[%p], id[%d]",
+ listener, interval, callback, user_data, listener->id);
+
+ id = listener->id;
+ event_id = (listener->type) << SENSOR_SHIFT_TYPE | 0x1;
+ batch_latency = listener->batch_latency;
+
+ listener->callback = (void *)callback;
+ listener->user_data = user_data;
+
+ int ret = false;
+ if (is_events_callback) {
+ ret = sensord_register_events(id, event_id, batch_latency, sensor_events_callback, listener);
+ } else {
+ ret = sensord_register_event(id, event_id, interval, batch_latency, sensor_callback, listener);
+ }
+
+ if (!ret) {
+ listener->callback = NULL;
+ listener->user_data = NULL;
+ return SENSOR_ERROR_OPERATION_FAILED;
+ }
+
+ _D("success sensor_listener_set_event");
+
+ return SENSOR_ERROR_NONE;
+}
+
int sensor_is_supported(sensor_type_e type, bool *supported)
{
int result;
return SENSOR_ERROR_NONE;
}
-static void sensor_callback(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data)
-{
- sensor_event_s *event;
- sensor_listener_h listener;
- listener = (sensor_listener_h)user_data;
-
- if (!sensor || !listener->callback)
- return;
-
- event = (sensor_event_s *)data;
-
- ((sensor_event_cb) listener->callback)(sensor, event, listener->user_data);
- return;
-}
-
int sensor_listener_set_event_cb(sensor_listener_h listener,
unsigned int interval, sensor_event_cb callback, void *user_data)
{
- int id;
- unsigned int event_id;
- unsigned int batch_latency;
-
- if (!listener || !callback)
- return SENSOR_ERROR_INVALID_PARAMETER;
-
- if (listener->magic != SENSOR_LISTENER_MAGIC)
- return SENSOR_ERROR_INVALID_PARAMETER;
-
- _D("called sensor_listener_set_event : listener[%p], interval[%u], callback[%p], user_data[%p], id[%d]",
- listener, interval, callback, user_data, listener->id);
-
- id = listener->id;
- event_id = (listener->type) << SENSOR_SHIFT_TYPE | 0x1;
- batch_latency = listener->batch_latency;
-
- listener->callback = (void *)callback;
- listener->user_data = user_data;
-
- if (!sensord_register_event(id, event_id, interval, batch_latency,
- sensor_callback, listener)) {
- listener->callback = NULL;
- listener->user_data = NULL;
-
- return SENSOR_ERROR_OPERATION_FAILED;
- }
-
- _D("success sensor_listener_set_event");
-
- return SENSOR_ERROR_NONE;
+ _D("called sensor_listener_set_event_cb : listener[%p]", listener);
+ return sensor_listener_set_event_cb_impl(listener, interval, (void*) callback, false, user_data);
}
int sensor_listener_unset_event_cb(sensor_listener_h listener)
{
- int id;
- int type;
- unsigned int event_id;
-
- _D("called sensor_unregister_event : listener[%p]", listener);
-
- if (!listener)
- return SENSOR_ERROR_INVALID_PARAMETER;
-
- if (listener->magic != SENSOR_LISTENER_MAGIC)
- return SENSOR_ERROR_INVALID_PARAMETER;
-
- id = listener->id;
- type = (int)listener->type;
- event_id = type << SENSOR_SHIFT_TYPE | 0x1;
-
- if (!sensord_unregister_event(id, event_id))
- return SENSOR_ERROR_OPERATION_FAILED;
-
- listener->callback = NULL;
- listener->user_data = NULL;
+ _D("called sensor_listener_unset_event_cb : listener[%p]", listener);
+ return sensor_listener_unset_event_cb_impl(listener, false);
+}
- _D("success sensor_unregister_event");
+int sensor_listener_set_events_cb(sensor_listener_h listener, sensor_events_cb callback, void *user_data)
+{
+ _D("called sensor_listener_set_events_cb : listener[%p]", listener);
+ return sensor_listener_set_event_cb_impl(listener, 0, (void*) callback, true, user_data);
+}
- return SENSOR_ERROR_NONE;
+int sensor_listener_unset_events_cb(sensor_listener_h listener)
+{
+ _D("called sensor_listener_unset_events_cb : listener[%p]", listener);
+ return sensor_listener_unset_event_cb_impl(listener, true);
}
static void accuracy_changed_callback(sensor_t sensor,