sensord: add testcase for sensor-provider APIs
[platform/core/system/sensord.git] / src / sensor / create.cpp
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <sensor_log.h>
19 #include <fusion_sensor.h>
20 #include <vector>
21
22 #ifdef ENABLE_AUTO_ROTATION
23 #include "auto_rotation/auto_rotation_sensor.h"
24 #endif
25 #ifdef ENABLE_GRAVITY
26 #include "gravity/gravity_lowpass_sensor.h"
27 #include "gravity/gravity_comp_sensor.h"
28 #endif
29 #ifdef ENABLE_LINEAR_ACCEL
30 #include "linear_accel/linear_accel_sensor.h"
31 #endif
32 #ifdef ENABLE_ROTATION_VECTOR
33 #include "rotation_vector/rv_sensor.h"
34 #include "rotation_vector/magnetic_rv_sensor.h"
35 #include "rotation_vector/gyro_rv_sensor.h"
36 #endif
37 #ifdef ENABLE_ORIENTATION
38 #include "orientation/orientation_sensor.h"
39 #endif
40
41 static std::vector<fusion_sensor_t> sensors;
42
43 template<typename _sensor>
44 void create_sensor(const char *name)
45 {
46         fusion_sensor *instance = NULL;
47         try {
48                 instance = new _sensor;
49         } catch (std::exception &e) {
50                 _E("Failed to create %s sensor, exception: %s", name, e.what());
51                 return;
52         } catch (int err) {
53                 _ERRNO(err, _E, "Failed to create %s sensor device", name);
54                 return;
55         }
56
57         sensors.push_back(instance);
58 }
59
60 extern "C" int create(fusion_sensor_t **fsensors)
61 {
62 #ifdef ENABLE_AUTO_ROTATION
63         create_sensor<auto_rotation_sensor>("Accelerometer");
64 #endif
65
66 #ifdef ENABLE_GRAVITY
67         create_sensor<gravity_lowpass_sensor>("Gravity(Lowpass)");
68         create_sensor<gravity_comp_sensor>("Gravity(Complementary)");
69 #endif
70
71 #ifdef ENABLE_LINEAR_ACCEL
72         create_sensor<linear_accel_sensor>("Linear Acceleration Sensor");
73 #endif
74
75 #ifdef ENABLE_ROTATION_VECTOR
76         create_sensor<rv_sensor>("Rotation Vector Sensor");
77         create_sensor<magnetic_rv_sensor>("Magnetic Rotation Vector Sensor");
78         create_sensor<gyro_rv_sensor>("Gyroscope Rotation Vector Sensor");
79 #endif
80
81 #ifdef ENABLE_ORIENTATION
82         create_sensor<orientation_sensor>("Orientation Sensor");
83 #endif
84
85         *fsensors = &sensors[0];
86         return sensors.size();
87 }