Add sensor handle attribute
[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         int set_attribute(sensor_t sensor, int attribute, int value);
51         int get_attribute(sensor_t sensor, int attribute, int *value);
52
53         /* sensor provider */
54         int add_sensor(sensor_info &info);
55         int add_sensor(sensor_provider *provider);
56         int remove_sensor(const char *uri);
57         int remove_sensor(sensor_provider *provider);
58
59         void add_sensor_added_cb(sensord_added_cb cb, void *user_data);
60         void remove_sensor_added_cb(sensord_added_cb cb);
61
62         void add_sensor_removed_cb(sensord_removed_cb cb, void *user_data);
63         void remove_sensor_removed_cb(sensord_removed_cb cb);
64
65 private:
66         class channel_handler;
67
68         bool init(void);
69         void deinit(void);
70
71         bool connect_channel(void);
72         bool is_connected(void);
73
74         void decode_sensors(const char *buf, std::list<sensor_info> &infos);
75         bool get_sensors_internal(void);
76
77         bool has_privilege(std::string &uri);
78         sensor_info *get_info(const char *uri);
79         std::vector<sensor_info *> get_infos(const char *uri);
80
81         ipc::ipc_client *m_client;
82         ipc::channel *m_cmd_channel;     /* get sensor information */
83         ipc::channel *m_mon_channel;     /* monitor sensors dinamically added/removed */
84         ipc::event_loop m_loop;
85         std::atomic<bool> m_connected;
86         channel_handler *m_handler;
87
88         std::list<sensor_info> m_sensors;
89 };
90
91 }
92
93 #endif /* __SENSOR_MANAGER_H__ */