*
*/
+#include "sensor_handler.h"
+
#include <message.h>
#include <sensor_log.h>
-#include "sensor_handler.h"
+#include <sensor_utils.h>
+#include <sensor_types_private.h>
using namespace sensor;
+sensor_handler::sensor_handler(const sensor_info &info)
+: m_info(info)
+, m_last_data(NULL)
+, m_last_data_size(0)
+{
+ const char *priv = sensor::utils::get_privilege(m_info.get_uri());
+ m_info.set_privilege(priv);
+
+ sensor_type_t type = sensor::utils::get_type(m_info.get_uri());
+ m_info.set_type(type);
+
+ /* TODO: temporary walkaround for sensors that require multiple privileges */
+ switch (m_info.get_type()) {
+ case EXTERNAL_EXERCISE_SENSOR:
+ case EXERCISE_STANDALONE_SENSOR:
+ m_info.add_privilege(PRIVILEGE_LOCATION_URI);
+ break;
+ default:
+ break;
+ }
+}
+
bool sensor_handler::has_observer(sensor_observer *ob)
{
for (auto it = m_observers.begin(); it != m_observers.end(); ++it) {
if (msg->ref_count() == 0)
msg->unref();
+ set_cache(data, len);
+
return OP_SUCCESS;
}
{
return m_observers.size();
}
+
+void sensor_handler::set_cache(sensor_data_t *data, int size)
+{
+ if (m_last_data == NULL) {
+ m_last_data = (sensor_data_t*)malloc(size);
+ retm_if(m_last_data == NULL, "Memory allocation failed");
+ }
+
+ m_last_data_size = size;
+ memcpy(m_last_data, data, size);
+}
+
+int sensor_handler::get_cache(sensor_data_t **data, int *len)
+{
+ retv_if(m_last_data == NULL, -ENODATA);
+
+ *data = (sensor_data_t *)malloc(m_last_data_size);
+ retvm_if(*data == NULL, -ENOMEM, "Memory allocation failed");
+
+ memcpy(*data, m_last_data, m_last_data_size);
+ *len = m_last_data_size;
+
+ return 0;
+}