Merge "sensord: delete batch latency/attribute when client is terminated unexpectedly...
[platform/core/system/sensord.git] / src / server / sensor_loader.h
1 /*
2  * sensord
3  *
4  * Copyright (c) 2013 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 #ifndef _SENSOR_LOADER_H_
21 #define _SENSOR_LOADER_H_
22
23 #include <sensor_common.h>
24 #include <sensor_types.h>
25 #include <sensor_hal.h>
26
27 #include <cmutex.h>
28 #include <sstream>
29
30 #include <string>
31 #include <vector>
32 #include <map>
33 #include <set>
34 #include <memory>
35
36 class sensor_base;
37
38 typedef std::multimap<sensor_type_t, std::shared_ptr<sensor_base>> sensor_map_t;
39 typedef std::map<const sensor_info_t *, std::shared_ptr<sensor_device>> sensor_device_map_t;
40
41 class sensor_loader {
42 private:
43         sensor_loader();
44         virtual ~sensor_loader();
45
46         bool load_sensor_devices(const std::string &path, void* &handle);
47
48         void create_sensors(void);
49         template <typename _sensor> void create_physical_sensors(sensor_type_t type);
50         template <typename _sensor> void create_virtual_sensors(const char *name);
51         template <typename _sensor> void create_external_sensors(const char *name);
52         template <typename _sensor> sensor_base* create_sensor(void);
53
54         void show_sensor_info(void);
55         bool get_paths_from_dir(const std::string &dir_path, std::vector<std::string> &hal_paths);
56
57         sensor_map_t m_sensors;
58         sensor_device_map_t m_devices;
59         sensor_device_map_t m_active_devices;
60         std::vector<void *> m_handles;
61 public:
62         static sensor_loader& get_instance(void);
63         bool load(void);
64
65         sensor_base* get_sensor(sensor_type_t type);
66         sensor_base* get_sensor(sensor_id_t id);
67
68         std::vector<sensor_type_t> get_sensor_types(void);
69         std::vector<sensor_base *> get_sensors(sensor_type_t type);
70         std::vector<sensor_base *> get_virtual_sensors(void);
71 };
72
73 #endif  /* _SENSOR_LOADER_H_ */