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_common.h>
22 #include "accel/accel_sensor_device.h"
23 //#include "gyro/gyro_sensor_device.h"
24 //#include "magnetic/geo_sensor_device.h"
25 #include "proximity/proxi_sensor_device.h"
26 //#include "light/light_sensor_device.h"
27 //#include "rotation_vector/rv_raw_sensor_device.h"
28 //#include "pressure/pressure_sensor_device.h"
29 //#include "temperature/temperature_sensor_device.h"
30 //#include "ultraviolet/ultraviolet_sensor_device.h"
31 //#include "hrm_led_red/bio_led_red_sensor_device.h"
33 static sensor_devices *devices = NULL;
35 template<typename _sensor>
36 void create_sensor(const char *name)
38 sensor_device *instance = NULL;
40 instance = new _sensor;
41 } catch (std::exception &e) {
42 ERR("Failed to create %s sensor device, exception: %s", name, e.what());
45 ERR("Failed to create %s sensor device, err: %d, cause: %s", name, err, strerror(err));
49 devices->devices.push_back(instance);
52 extern "C" sensor_devices* create(void)
54 devices = new(std::nothrow) sensor_devices;
55 retvm_if(!devices, NULL, "Failed to allocate memory");
58 create_sensor<accel_sensor_device>("Accel");
62 create_sensor<gyro_sensor_device>("Gyro");
65 #ifdef ENABLE_MAGNETIC
66 create_sensor<geo_sensor_device>("Magnetic");
69 #ifdef ENABLE_PROXIMITY
70 create_sensor<proxi_sensor_device>("Proximity");
74 create_sensor<light_sensor_device>("Light");
77 #ifdef ENABLE_ROTATION_VECTOR
78 create_sensor<rv_raw_sensor_device>("Rotation Vector");
81 #ifdef ENABLE_PRESSURE
82 create_sensor<pressure_sensor_device>("Pressure");
85 #ifdef ENABLE_TEMPERATURE
86 create_sensor<temperature_sensor_device>("Temperature");
89 #ifdef ENABLE_ULTRAVIOLET
90 create_sensor<ultraviolet_sensor_device>("Ultraviolet");
93 #ifdef ENABLE_HRM_LED_RED
94 create_sensor<bio_led_red_sensor_device>("HRM Led Red");