4 * Copyright (c) 2017 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_adapter.h"
22 #include <sensor_internal.h>
26 #include "test_bench.h"
28 #define SENSOR_EVENT(type) ((type) << 16 | 0x1)
30 bool sensor_adapter::is_supported(sensor_type_t type)
34 int ret = sensord_get_default_sensor(type, &sensor);
41 int sensor_adapter::get_count(sensor_type_t type)
46 if (sensord_get_sensors(type, &sensors, &count) == 0)
52 bool sensor_adapter::get_handle(sensor_info info, int &handle)
56 sensor_t *sensors = NULL;
58 err = sensord_get_sensors(info.type, &sensors, &count);
61 handle = sensord_connect(sensors[info.index]);
62 ASSERT_FREE((handle < 0), sensors);
71 bool sensor_adapter::start(sensor_info info, int &handle)
73 sensor_t *sensors = NULL;
78 err = sensord_get_sensors(info.type, &sensors, &count);
81 ASSERT_FREE((info.index >= count), sensors);
82 ASSERT_LT(info.index, count);
84 ASSERT_FREE((info.index < 0), sensors);
85 ASSERT_GE(info.index, 0);
87 handle = sensord_connect(sensors[info.index]);
88 ASSERT_FREE((handle < 0), sensors);
91 ret = sensord_register_event(handle, SENSOR_EVENT(info.type), info.interval, info.batch_latency, info.cb, NULL);
92 ASSERT_FREE((ret != true), sensors);
95 ret = sensord_start(handle, info.powersave);
96 ASSERT_FREE((ret != true), sensors);
105 bool sensor_adapter::stop(sensor_info info, int handle)
109 ret = sensord_stop(handle);
112 ret = sensord_unregister_event(handle, SENSOR_EVENT(info.type));
115 ret = sensord_disconnect(handle);
121 bool sensor_adapter::change_interval(int handle, int interval)
126 bool sensor_adapter::change_batch_latency(int handle, int batch_latency)
131 bool sensor_adapter::change_powersave(int handle, int powersave)
136 bool sensor_adapter::set_attribute(int handle, int attribute, int value)
140 ret = sensord_set_attribute_int(handle, attribute, value);
146 bool sensor_adapter::set_attribute(int handle, int attribute, char *value, int size)
150 ret = sensord_set_attribute_str(handle, attribute, value, size);
152 return ((ret == 0) ? true : false);
155 bool sensor_adapter::get_data(int handle, sensor_type_t type, sensor_data_t &data)
159 ret = sensord_get_data(handle, SENSOR_EVENT(type), &data);
165 bool sensor_adapter::flush(int handle)
169 ret = sensord_flush(handle);