4 * Copyright (c) 2014 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_common.h>
21 #include <physical_sensor.h>
22 #include <sensor_event_queue.h>
24 #define UNKNOWN_NAME "UNKNOWN_SENSOR"
26 cmutex physical_sensor::m_mutex;
28 physical_sensor::physical_sensor()
29 : m_sensor_device(NULL)
33 physical_sensor::~physical_sensor()
35 _I("physical sensor is destroyed");
38 void physical_sensor::set_sensor_info(const sensor_info_t *info)
43 void physical_sensor::set_sensor_device(sensor_device *device)
45 m_sensor_device = device;
48 sensor_type_t physical_sensor::get_type(void)
50 return static_cast<sensor_type_t>(m_info->type);
53 unsigned int physical_sensor::get_event_type(void)
55 return m_info->event_type;
58 const char* physical_sensor::get_name(void)
60 retv_if(!m_info, UNKNOWN_NAME);
61 retv_if(!m_info->name, UNKNOWN_NAME);
66 uint32_t physical_sensor::get_hal_id(void)
71 int physical_sensor::get_poll_fd(void)
78 return m_sensor_device->get_poll_fd();
81 bool physical_sensor::on_event(const sensor_data_t *data, int data_len, int remains)
86 bool physical_sensor::read_fd(std::vector<uint32_t> &ids)
95 size = m_sensor_device->read_fd(&_ids);
97 for (int i = 0; i < size; ++i)
98 ids.push_back(_ids[i]);
103 int physical_sensor::get_data(sensor_data_t **data, int *length)
107 if (!m_sensor_device)
111 remains = m_sensor_device->get_data(m_info->id, data, length);
114 _E("Failed to get sensor event");
121 bool physical_sensor::flush(void)
125 if (!m_sensor_device)
128 return m_sensor_device->flush(m_info->id);
131 bool physical_sensor::set_interval(unsigned long interval)
135 if (!m_sensor_device)
138 _I("Polling interval is set to %dms", interval);
140 return m_sensor_device->set_interval(m_info->id, interval);
143 bool physical_sensor::set_batch_latency(unsigned long latency)
147 if (!m_sensor_device)
150 _I("Batch latency is set to %dms", latency);
152 return m_sensor_device->set_batch_latency(m_info->id, latency);
155 int physical_sensor::set_attribute(int32_t attribute, int32_t value)
159 if (!m_sensor_device)
162 if (!m_sensor_device->set_attribute_int(m_info->id, attribute, value))
168 int physical_sensor::set_attribute(int32_t attribute, char *value, int value_len)
172 if (!m_sensor_device)
175 if (!m_sensor_device->set_attribute_str(m_info->id, attribute, value, value_len))
181 bool physical_sensor::on_start(void)
185 if (!m_sensor_device)
188 return m_sensor_device->enable(m_info->id);
191 bool physical_sensor::on_stop(void)
195 if (!m_sensor_device)
198 return m_sensor_device->disable(m_info->id);
201 bool physical_sensor::get_sensor_info(sensor_info &info)
203 info.set_type(get_type());
204 info.set_id(get_id());
205 info.set_privilege(SENSOR_PRIVILEGE_PUBLIC); // FIXME
206 info.set_name(m_info->model_name);
207 info.set_vendor(m_info->vendor);
208 info.set_min_range(m_info->min_range);
209 info.set_max_range(m_info->max_range);
210 info.set_resolution(m_info->resolution);
211 info.set_min_interval(m_info->min_interval);
212 info.set_fifo_count(0);
213 info.set_max_batch_count(m_info->max_batch_count);
214 info.set_supported_event(get_event_type());
215 info.set_wakeup_supported(m_info->wakeup_supported);