263a2b8a60e28913d897e72cddb24aadfe4016d2
[platform/adaptation/tw3/sensor-hal-tw3.git] / src / create.cpp
1 /*
2  * Copyright (c) 2017 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/sensor_hal.h>
19 #include <sensor_log.h>
20 #include <vector>
21
22 #include "accel/accel_device.h"
23 #include "gyro/gyro_device.h"
24 #include "pressure/pressure_device.h"
25 #include "light/light_device.h"
26 #include "hrm_raw/hrm_raw_device.h"
27 #include "hrm/hrm_device.h"
28
29 static std::vector<sensor_device_t> devs;
30
31 template<typename _sensor>
32 void create_sensor(const char *name)
33 {
34         sensor_device *instance = NULL;
35         try {
36                 instance = new _sensor;
37         } catch (std::exception &e) {
38                 ERR("Failed to create %s sensor device, exception: %s", name, e.what());
39                 return;
40         } catch (int err) {
41                 _ERRNO(err, _E, "Failed to create %s sensor device", name);
42                 return;
43         }
44
45         devs.push_back(instance);
46 }
47
48 extern "C" int create(sensor_device_t **devices)
49 {
50         create_sensor<accel_device>("Accelerometer");
51         create_sensor<gyro_device>("Gyroscope");
52         create_sensor<pressure_device>("Pressure");
53         create_sensor<light_device>("Light");
54         create_sensor<hrm_raw_device>("HRM Raw");
55         create_sensor<hrm_device>("HRM");
56
57         *devices = &devs[0];
58         return devs.size();
59 }