sensor-hal: re-organize build procedure
[platform/adaptation/tm1/sensor-hal-tm1.git] / src / create.cpp
1 /*
2  * sensor-plugins-tm1
3  *
4  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
5  *
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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  */
19
20 #include <sensor_common.h>
21
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"
32
33 static sensor_devices *devices = NULL;
34
35 template<typename _sensor>
36 void create_sensor(const char *name)
37 {
38         sensor_device *instance = NULL;
39         try {
40                 instance = new _sensor;
41         } catch (std::exception &e) {
42                 ERR("Failed to create %s sensor device, exception: %s", name, e.what());
43                 return;
44         } catch (int err) {
45                 ERR("Failed to create %s sensor device, err: %d, cause: %s", name, err, strerror(err));
46                 return;
47         }
48
49         devices->devices.push_back(instance);
50 }
51
52 extern "C" sensor_devices* create(void)
53 {
54         devices = new(std::nothrow) sensor_devices;
55         retvm_if(!devices, NULL, "Failed to allocate memory");
56
57 #ifdef ENABLE_ACCEL
58         create_sensor<accel_sensor_device>("Accel");
59 #endif
60
61 #ifdef ENABLE_GYRO
62         create_sensor<gyro_sensor_device>("Gyro");
63 #endif
64
65 #ifdef ENABLE_MAGNETIC
66         create_sensor<geo_sensor_device>("Magnetic");
67 #endif
68
69 #ifdef ENABLE_PROXIMITY
70         create_sensor<proxi_sensor_device>("Proximity");
71 #endif
72
73 #ifdef ENABLE_LIGHT
74         create_sensor<light_sensor_device>("Light");
75 #endif
76
77 #ifdef ENABLE_ROTATION_VECTOR
78         create_sensor<rv_raw_sensor_device>("Rotation Vector");
79 #endif
80
81 #ifdef ENABLE_PRESSURE
82         create_sensor<pressure_sensor_device>("Pressure");
83 #endif
84
85 #ifdef ENABLE_TEMPERATURE
86         create_sensor<temperature_sensor_device>("Temperature");
87 #endif
88
89 #ifdef ENABLE_ULTRAVIOLET
90         create_sensor<ultraviolet_sensor_device>("Ultraviolet");
91 #endif
92
93 #ifdef ENABLE_HRM_LED_RED
94         create_sensor<bio_led_red_sensor_device>("HRM Led Red");
95 #endif
96
97         return devices;
98 }