sensord: notify that the sensor is registered or unregistered
[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 <channel.h>
28 #include <event_loop.h>
29
30 #include "sensor_handler.h"
31 #include "sensor_observer.h"
32 #include "sensor_loader.h"
33
34 #include "physical_sensor_handler.h"
35 #include "fusion_sensor_handler.h"
36 #include "external_sensor_handler.h"
37
38 namespace sensor {
39
40 class sensor_manager {
41 public:
42         sensor_manager(ipc::event_loop *loop);
43         ~sensor_manager();
44
45         bool init(void);
46         bool deinit(void);
47
48         bool is_supported(const std::string uri);
49
50         bool register_sensor(sensor_handler *sensor);
51         void deregister_sensor(const std::string uri);
52
53         void register_channel(ipc::channel *ch);
54         void deregister_channel(ipc::channel *ch);
55
56         sensor_handler *get_sensor_by_type(const std::string uri);
57         sensor_handler *get_sensor(const std::string uri);
58         std::vector<sensor_handler *> get_sensors(void);
59
60         size_t serialize(int sock_fd, char **bytes);
61
62 private:
63         typedef std::map<std::string, sensor_handler *> sensor_map_t;
64
65         void create_physical_sensors(
66                         device_sensor_registry_t &devices,
67                         physical_sensor_registry_t &psensors);
68         void create_fusion_sensors(fusion_sensor_registry_t &vsensors);
69         void create_external_sensors(external_sensor_registry_t &vsensors);
70
71         void init_sensors(void);
72         void register_handler(physical_sensor_handler *sensor);
73
74         int serialize(sensor_info *info, char **bytes);
75
76         void send(ipc::message &msg);
77         void send_added_msg(sensor_info *info);
78         void send_removed_msg(const std::string &uri);
79
80         void show(void);
81
82         ipc::event_loop *m_loop;
83         sensor_loader m_loader;
84         sensor_map_t m_sensors;
85
86         std::vector<ipc::channel *> m_channels;
87 };
88
89 }
90
91 #endif /* __SENSOR_MANAGER_H__ */