sensord: replace usleep() code with sleep()
[platform/core/system/sensord.git] / src / server / sensor_manager.h
1 /*
2  * sensord
3  *
4  * Copyright (c) 2017 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_MANAGER_H__
21 #define __SENSOR_MANAGER_H__
22
23 #include <string>
24 #include <vector>
25 #include <unordered_map>
26
27 #include "event_loop.h"
28
29 #include "sensor_handler.h"
30 #include "sensor_observer.h"
31 #include "sensor_loader.h"
32
33 #include "physical_sensor_handler.h"
34 #include "fusion_sensor_handler.h"
35 #include "external_sensor_handler.h"
36
37 namespace sensor {
38
39 class sensor_manager {
40 public:
41         sensor_manager(ipc::event_loop *loop);
42         ~sensor_manager();
43
44         bool init(void);
45         bool deinit(void);
46
47         bool is_supported(const std::string uri);
48
49         bool register_sensor(sensor_handler *sensor);
50         void deregister_sensor(const std::string uri);
51
52         sensor_handler *get_sensor_by_type(const std::string uri);
53         sensor_handler *get_sensor(const std::string uri);
54         std::vector<sensor_handler *> get_sensors(void);
55
56         size_t serialize(int sock_fd, char **bytes);
57
58 private:
59         typedef std::map<std::string, sensor_handler *> sensor_map_t;
60
61         void create_physical_sensors(
62                         device_sensor_registry_t &devices,
63                         physical_sensor_registry_t &psensors);
64         void create_fusion_sensors(fusion_sensor_registry_t &vsensors);
65         void create_external_sensors(external_sensor_registry_t &vsensors);
66
67         void init_sensors(void);
68         void register_handler(physical_sensor_handler *sensor);
69
70         void show(void);
71
72         ipc::event_loop *m_loop;
73         sensor_loader m_loader;
74         sensor_map_t m_sensors;
75 };
76
77 }
78
79 #endif /* __SENSOR_MANAGER_H__ */