4 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
20 #include <sensor_info_list.h>
23 interval_info::interval_info(int client_id, bool is_processor, unsigned int interval)
25 this->client_id = client_id;
26 this->is_processor = is_processor;
27 this->interval = interval;
30 batch_info::batch_info(int client_id, unsigned int latency)
32 this->client_id = client_id;
33 this->latency = latency;
36 bool sensor_info_list::comp_interval_info(interval_info a, interval_info b)
38 return a.interval < b.interval;
41 bool sensor_info_list::comp_batch_info(batch_info a, batch_info b)
43 return a.latency < b.latency;
46 interval_info_iterator sensor_info_list::find_if_interval_info(int client_id, bool is_processor)
48 auto iter = m_interval_info_list.begin();
50 while (iter != m_interval_info_list.end()) {
51 if ((iter->client_id == client_id) && (iter->is_processor == is_processor))
60 batch_info_iterator sensor_info_list::find_if_batch_info(int client_id)
62 auto iter = m_batch_info_list.begin();
64 while (iter != m_batch_info_list.end()) {
65 if ((iter->client_id == client_id))
74 bool sensor_info_list::add_interval(int client_id, unsigned int interval, bool is_processor)
76 auto iter = find_if_interval_info(client_id, is_processor);
78 if (iter != m_interval_info_list.end())
79 *iter = interval_info(client_id, is_processor, interval);
81 m_interval_info_list.push_back(interval_info(client_id, is_processor, interval));
86 bool sensor_info_list::delete_interval(int client_id, bool is_processor)
88 auto iter = find_if_interval_info(client_id, is_processor);
90 if (iter == m_interval_info_list.end())
93 m_interval_info_list.erase(iter);
98 unsigned int sensor_info_list::get_interval(int client_id, bool is_processor)
100 auto iter = find_if_interval_info(client_id, is_processor);
102 if (iter == m_interval_info_list.end())
105 return iter->interval;
108 unsigned int sensor_info_list::get_min_interval(void)
110 if (m_interval_info_list.empty())
113 auto iter = min_element(m_interval_info_list.begin(), m_interval_info_list.end(), comp_interval_info);
115 return iter->interval;
118 bool sensor_info_list::add_batch(int client_id, unsigned int latency)
120 auto iter = find_if_batch_info(client_id);
122 if (iter != m_batch_info_list.end())
123 *iter = batch_info(client_id, latency);
125 m_batch_info_list.push_back(batch_info(client_id, latency));
130 bool sensor_info_list::delete_batch(int client_id)
132 auto iter = find_if_batch_info(client_id);
134 if (iter == m_batch_info_list.end())
137 m_batch_info_list.erase(iter);
142 unsigned int sensor_info_list::get_batch(int client_id)
144 auto iter = find_if_batch_info(client_id);
146 if (iter == m_batch_info_list.end())
149 return iter->latency;
152 unsigned int sensor_info_list::get_max_batch(void)
154 if (m_batch_info_list.empty())
157 auto iter = max_element(m_batch_info_list.begin(), m_batch_info_list.end(), comp_batch_info);
159 return iter->latency;