Integrate internal fixes
[platform/core/system/sensord.git] / src / client / 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 <channel.h>
24 #include <sensor_info.h>
25 #include <ipc_client.h>
26 #include <event_loop.h>
27 #include <list>
28 #include <atomic>
29
30 #include "sensor_internal.h"
31 #include "sensor_provider.h"
32
33 namespace sensor {
34
35 class sensor_manager {
36 public:
37         sensor_manager();
38         virtual ~sensor_manager();
39
40         bool connect(void);
41         void disconnect(void);
42         void restore(void);
43
44         int get_sensor(const char *uri, sensor_t *sensor);
45         int get_sensors(const char *uri, sensor_t **list, int *count);
46
47         bool is_supported(sensor_t sensor);
48         bool is_supported(const char *uri);
49
50         /* sensor provider */
51         int add_sensor(sensor_info &info);
52         int add_sensor(sensor_provider *provider);
53         int remove_sensor(const char *uri);
54         int remove_sensor(sensor_provider *provider);
55
56         void add_sensor_added_cb(sensord_added_cb cb, void *user_data);
57         void remove_sensor_added_cb(sensord_added_cb cb);
58
59         void add_sensor_removed_cb(sensord_removed_cb cb, void *user_data);
60         void remove_sensor_removed_cb(sensord_removed_cb cb);
61
62 private:
63         class channel_handler;
64
65         bool init(void);
66         void deinit(void);
67
68         bool connect_channel(void);
69         bool is_connected(void);
70
71         void decode_sensors(const char *buf, std::list<sensor_info> &infos);
72         bool get_sensors_internal(void);
73
74         bool has_privilege(std::string &uri);
75         sensor_info *get_info(const char *uri);
76         std::vector<sensor_info *> get_infos(const char *uri);
77
78         ipc::ipc_client *m_client;
79         ipc::channel *m_cmd_channel;     /* get sensor information */
80         ipc::channel *m_mon_channel;     /* monitor sensors dinamically added/removed */
81         ipc::event_loop m_loop;
82         std::atomic<bool> m_connected;
83         channel_handler *m_handler;
84
85         std::list<sensor_info> m_sensors;
86 };
87
88 }
89
90 #endif /* __SENSOR_MANAGER_H__ */