From: Hongkuk, Son Date: Wed, 21 Oct 2015 05:26:47 +0000 (+0900) Subject: sensord: batch mode support X-Git-Tag: submit/tizen/20151218.070016~25 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f479a00df3d02d8616a607c52c4e8064cde618d1;p=platform%2Fcore%2Fsystem%2Fsensord.git sensord: batch mode support Signed-off-by: Hongkuk, Son Change-Id: Id5f72577237caeb9dd814796a7b059f53e68015d --- diff --git a/src/server/command_worker.cpp b/src/server/command_worker.cpp index 22c30fe..f8148de 100644 --- a/src/server/command_worker.cpp +++ b/src/server/command_worker.cpp @@ -640,6 +640,13 @@ bool command_worker::cmd_set_batch(void *payload) 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: @@ -673,6 +680,12 @@ bool command_worker::cmd_unset_batch(void *payload) 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: diff --git a/src/shared/CMakeLists.txt b/src/shared/CMakeLists.txt index d869101..b5d589c 100644 --- a/src/shared/CMakeLists.txt +++ b/src/shared/CMakeLists.txt @@ -30,7 +30,7 @@ add_library(sensord-server SHARED 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 @@ -66,7 +66,7 @@ install(FILES 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 diff --git a/src/shared/cbatch_info_list.cpp b/src/shared/cbatch_info_list.cpp new file mode 100644 index 0000000..3c2681c --- /dev/null +++ b/src/shared/cbatch_info_list.cpp @@ -0,0 +1,91 @@ +/* + * 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 +#include + +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; +} + diff --git a/src/shared/cbatch_info_list.h b/src/shared/cbatch_info_list.h new file mode 100644 index 0000000..390c39d --- /dev/null +++ b/src/shared/cbatch_info_list.h @@ -0,0 +1,49 @@ +/* + * 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 + +class cbatch_info +{ +public: + cbatch_info(int client_id, unsigned int latency); + int client_id; + unsigned int latency; +}; + +typedef std::list::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 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 diff --git a/src/shared/sensor_base.cpp b/src/shared/sensor_base.cpp index 52915e7..83815a9 100644 --- a/src/shared/sensor_base.cpp +++ b/src/shared/sensor_base.cpp @@ -314,6 +314,62 @@ int sensor_base::get_wakeup(int client_id) 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; @@ -376,6 +432,11 @@ bool sensor_base::set_wakeup(int client_id, int wakeup) 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; diff --git a/src/shared/sensor_base.h b/src/shared/sensor_base.h index c4c4600..2f726f9 100644 --- a/src/shared/sensor_base.h +++ b/src/shared/sensor_base.h @@ -30,6 +30,7 @@ #include #include +#include #include #include @@ -71,6 +72,10 @@ public: 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); @@ -79,6 +84,7 @@ public: 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); @@ -96,8 +102,10 @@ protected: 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;