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 <physical_sensor.h>
21 #include <sensor_event_queue.h>
23 #define UNKNOWN_NAME "UNKNOWN_SENSOR"
25 cmutex physical_sensor::m_mutex;
27 physical_sensor::physical_sensor()
28 : m_sensor_device(NULL)
32 physical_sensor::~physical_sensor()
36 void physical_sensor::set_sensor_handle(sensor_handle_t handle)
38 m_handle.id = handle.id;
39 m_handle.name = handle.name;
40 m_handle.type = handle.type;
41 m_handle.event_type = handle.event_type;
42 m_handle.model_name = handle.model_name;
43 m_handle.vendor = handle.vendor;
44 m_handle.min_range = handle.min_range;
45 m_handle.max_range = handle.max_range;
46 m_handle.resolution = handle.resolution;
47 m_handle.min_interval = handle.min_interval;
48 m_handle.max_batch_count = handle.max_batch_count;
49 m_handle.wakeup_supported = handle.wakeup_supported;
52 void physical_sensor::set_sensor_device(sensor_device *device)
54 m_sensor_device = device;
57 sensor_type_t physical_sensor::get_type(void)
59 return static_cast<sensor_type_t>(m_handle.type);
62 unsigned int physical_sensor::get_event_type(void)
64 return m_handle.event_type;
67 const char* physical_sensor::get_name(void)
75 int physical_sensor::get_poll_fd()
82 return m_sensor_device->get_poll_fd();
85 bool physical_sensor::read_fd(std::vector<uint16_t> &ids)
94 size = m_sensor_device->read_fd(&_ids);
96 for (int i = 0; i < size; ++i)
97 ids.push_back(_ids[i]);
102 int physical_sensor::get_data(sensor_data_t **data, int *length)
106 if (!m_sensor_device)
110 remains = m_sensor_device->get_data(m_handle.id, data, length);
113 ERR("Failed to get sensor event");
120 bool physical_sensor::flush(void)
124 if (!m_sensor_device)
127 return m_sensor_device->flush(m_handle.id);
130 bool physical_sensor::set_interval(unsigned long interval)
134 if (!m_sensor_device)
137 INFO("Polling interval is set to %dms", interval);
139 return m_sensor_device->set_interval(m_handle.id, interval);
142 bool physical_sensor::set_batch_latency(unsigned long latency)
146 if (!m_sensor_device)
149 INFO("Polling interval is set to %dms", latency);
151 return m_sensor_device->set_batch_latency(m_handle.id, latency);
154 int physical_sensor::set_attribute(int32_t attribute, int32_t value)
158 if (!m_sensor_device)
161 return m_sensor_device->set_attribute(m_handle.id, attribute, value);
164 int physical_sensor::set_attribute(char *attribute, char *value, int value_len)
168 if (!m_sensor_device)
171 return m_sensor_device->set_attribute_str(m_handle.id, attribute, value, value_len);
174 bool physical_sensor::set_wakeup(int wakeup)
179 bool physical_sensor::on_start()
183 if (!m_sensor_device)
186 return m_sensor_device->enable(m_handle.id);
189 bool physical_sensor::on_stop()
193 if (!m_sensor_device)
196 return m_sensor_device->disable(m_handle.id);
199 bool physical_sensor::get_sensor_info(sensor_info &info)
201 info.set_type(get_type());
202 info.set_id(get_id());
203 info.set_privilege(SENSOR_PRIVILEGE_PUBLIC); // FIXME
204 info.set_name(m_handle.model_name);
205 info.set_vendor(m_handle.vendor);
206 info.set_min_range(m_handle.min_range);
207 info.set_max_range(m_handle.max_range);
208 info.set_resolution(m_handle.resolution);
209 info.set_min_interval(m_handle.min_interval);
210 info.set_fifo_count(0); // FIXME
211 info.set_max_batch_count(m_handle.max_batch_count);
212 info.set_supported_event(get_event_type());
213 info.set_wakeup_supported(m_handle.wakeup_supported);