goto out;
}
+ if (!m_module->add_batch(m_client_id, cmd->latency)) {
+ ERR("Failed to set latency for client [%d], for sensor [0x%x] with latency [%d]",
+ m_client_id, m_sensor_id, cmd->latency);
+ ret_value = OP_ERROR;
+ goto out;
+ }
+
ret_value = OP_SUCCESS;
out:
goto out;
}
+ if (!m_module->delete_batch(m_client_id)) {
+ ERR("Failed to delete latency for client [%d]", m_client_id);
+ ret_value = OP_ERROR;
+ goto out;
+ }
+
ret_value = OP_SUCCESS;
out:
cclient_sensor_record.cpp
cinterval_info_list.cpp
cwakeup_info_list.cpp
- batch_info_list.cpp
+ cbatch_info_list.cpp
sensor_plugin_loader.cpp
sensor_hal.cpp
sensor_base.cpp
csensor_event_queue.h
cinterval_info_list.h
cwakeup_info_list.h
- batch_info_list.h
+ cbatch_info_list.h
sensor_plugin_loader.h
sensor_hal.h
sensor_base.h
--- /dev/null
+/*
+ * libsensord-share
+ *
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <cbatch_info_list.h>
+#include <algorithm>
+
+cbatch_info::cbatch_info(int client_id, unsigned int latency)
+{
+ this->client_id = client_id;
+ this->latency = latency;
+}
+
+bool cbatch_info_list::comp_batch_info(cbatch_info a, cbatch_info b)
+{
+ return a.latency < b.latency;
+}
+
+cbatch_info_iterator cbatch_info_list::find_if(int client_id)
+{
+ auto iter = m_list.begin();
+
+ while (iter != m_list.end()) {
+ if ((iter->client_id == client_id))
+ break;
+
+ ++iter;
+ }
+
+ return iter;
+}
+
+bool cbatch_info_list::add_batch(int client_id, unsigned int latency)
+{
+ auto iter = find_if(client_id);
+
+ if (iter != m_list.end())
+ *iter = cbatch_info(client_id, latency);
+ else
+ m_list.push_back(cbatch_info(client_id, latency));
+
+ return true;
+}
+
+bool cbatch_info_list::delete_batch(int client_id)
+{
+ auto iter = find_if(client_id);
+
+ if (iter == m_list.end())
+ return false;
+
+ m_list.erase(iter);
+
+ return true;
+}
+
+unsigned int cbatch_info_list::get_batch(int client_id)
+{
+ auto iter = find_if(client_id);
+
+ if (iter == m_list.end())
+ return 0;
+
+ return iter->latency;
+}
+
+unsigned int cbatch_info_list::get_max(void)
+{
+ if (m_list.empty())
+ return 0;
+
+ auto iter = max_element(m_list.begin(), m_list.end(), comp_batch_info);
+
+ return iter->latency;
+}
+
--- /dev/null
+/*
+ * libsensord-share
+ *
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef _CBATCH_INFO_LIST_CLASS_H_
+#define _CBATCH_INFO_LIST_CLASS_H_
+
+#include <list>
+
+class cbatch_info
+{
+public:
+ cbatch_info(int client_id, unsigned int latency);
+ int client_id;
+ unsigned int latency;
+};
+
+typedef std::list<cbatch_info>::iterator cbatch_info_iterator;
+
+class cbatch_info_list
+{
+private:
+ static bool comp_batch_info(cbatch_info a, cbatch_info b);
+ cbatch_info_iterator find_if(int client_id);
+
+ std::list<cbatch_info> m_list;
+
+public:
+ bool add_batch(int client_id, unsigned int latency);
+ bool delete_batch(int client_id);
+ unsigned int get_batch(int client_id);
+ unsigned int get_max(void);
+};
+#endif
return m_wakeup_info_list.is_wakeup_on();
}
+bool sensor_base::add_batch(int client_id, unsigned int latency)
+{
+ unsigned int prev_max, cur_max;
+
+ AUTOLOCK(m_batch_info_list_mutex);
+
+ prev_max = m_batch_info_list.get_max();
+
+ if (!m_batch_info_list.add_batch(client_id, latency))
+ return false;
+
+ cur_max = m_batch_info_list.get_max();
+
+ if (cur_max != prev_max) {
+ INFO("Max latency for sensor[0x%x] is changed from %dms to %dms by client[%d] adding latency",
+ get_id(), prev_max, cur_max, client_id);
+ set_batch(client_id, cur_max);
+ }
+
+ return true;
+}
+
+bool sensor_base::delete_batch(int client_id)
+{
+ unsigned int prev_max, cur_max;
+ AUTOLOCK(m_batch_info_list_mutex);
+
+ prev_max = m_batch_info_list.get_max();
+
+ if (!m_batch_info_list.delete_batch(client_id))
+ return false;
+
+ cur_max = m_batch_info_list.get_max();
+
+ if (!cur_max) {
+ INFO("No latency for sensor[0x%x] by client[%d] deleting latency, so set to default 0 ms",
+ get_id(), client_id);
+
+ set_batch(client_id, 0);
+ } else if (cur_max != prev_max) {
+ INFO("Max latency for sensor[0x%x] is changed from %dms to %dms by client[%d] deleting latency",
+ get_id(), prev_max, cur_max, client_id);
+
+ set_batch(client_id, cur_max);
+ }
+
+ return true;
+}
+
+unsigned int sensor_base::get_batch(int client_id)
+{
+ AUTOLOCK(m_batch_info_list_mutex);
+
+ return m_batch_info_list.get_batch(client_id);
+}
+
void sensor_base::get_sensor_info(sensor_type_t sensor_type, sensor_info &info)
{
sensor_properties_s properties;
return false;
}
+bool sensor_base::set_batch(int client_id, unsigned int latency)
+{
+ return false;
+}
+
int sensor_base::send_sensorhub_data(const char* data, int data_len)
{
return -1;
#include <cinterval_info_list.h>
#include <cwakeup_info_list.h>
+#include <cbatch_info_list.h>
#include <cmutex.h>
#include <common.h>
virtual bool delete_wakeup(int client_id);
int get_wakeup(int client_id);
+ virtual bool add_batch(int client_id, unsigned int latency);
+ virtual bool delete_batch(int client_id);
+ unsigned int get_batch(int client_id);
+
void get_sensor_info(sensor_type_t sensor_type, sensor_info &info);
virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties);
virtual long set_command(unsigned int cmd, long value);
virtual bool set_wakeup(int client_id, int wakeup);
+ virtual bool set_batch(int client_id, unsigned int latency);
virtual int send_sensorhub_data(const char* data, int data_len);
virtual int get_sensor_data(unsigned int type, sensor_data_t &data);
cinterval_info_list m_interval_info_list;
cwakeup_info_list m_wakeup_info_list;
+ cbatch_info_list m_batch_info_list;
cmutex m_interval_info_list_mutex;
cmutex m_wakeup_info_list_mutex;
+ cmutex m_batch_info_list_mutex;
cmutex m_mutex;