Update for attribute changed callback and attribute getter
[platform/core/system/sensord.git] / src / server / sensor_listener_proxy.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_LISTENER_PROXY_H__
21 #define __SENSOR_LISTENER_PROXY_H__
22
23 #include <channel.h>
24 #include <message.h>
25
26 #include "sensor_manager.h"
27 #include "sensor_observer.h"
28 #include "sensor_policy_listener.h"
29
30 namespace sensor {
31
32 class sensor_listener_proxy : public sensor_observer, sensor_policy_listener {
33 public:
34         sensor_listener_proxy(uint32_t id,
35                         std::string uri, sensor_manager *manager, ipc::channel *ch);
36         ~sensor_listener_proxy();
37
38         uint32_t get_id(void);
39
40         /* sensor observer */
41         int update(const char *uri, std::shared_ptr<ipc::message> msg);
42         int on_attribute_changed(std::shared_ptr<ipc::message> msg);
43
44         int start(bool policy = false);
45         int stop(bool policy = false);
46
47         int set_interval(int32_t interval);
48         int get_interval(int32_t& interval);
49         int set_max_batch_latency(int32_t max_batch_latency);
50         int get_max_batch_latency(int32_t& max_batch_latency);
51         int delete_batch_latency(void);
52         int set_passive_mode(bool passive);
53         int set_attribute(int32_t attribute, int32_t value);
54         int get_attribute(int32_t attribute, int32_t *value);
55         int set_attribute(int32_t attribute, const char *value, int len);
56         int get_attribute(int32_t attribute, char **value, int *len);
57         int flush(void);
58         int get_data(sensor_data_t **data, int *len);
59         std::string get_required_privileges(void);
60
61         /* sensor_policy_listener interface */
62         void on_policy_changed(int policy, int value);
63         bool notify_attribute_changed(int32_t attribute, int32_t value);
64         bool notify_attribute_changed(int32_t attribute, const char *value, int len);
65         bool need_to_notify_attribute_changed();
66         void set_need_to_notify_attribute_changed(bool value);
67
68 private:
69         void update_event(std::shared_ptr<ipc::message> msg);
70         void update_accuracy(std::shared_ptr<ipc::message> msg);
71         void apply_sensor_handler_need_to_notify_attribute_changed(sensor_handler* handler);
72
73         uint32_t m_id;
74         std::string m_uri;
75
76         sensor_manager *m_manager;
77         ipc::channel *m_ch;
78
79         bool m_started;
80         bool m_passive;
81         int32_t m_pause_policy;
82         int32_t m_axis_orientation;
83         int32_t m_last_accuracy;
84         bool m_need_to_notify_attribute_changed;
85 };
86
87 }
88
89 #endif /* __SENSOR_LISTENER_PROXY_H__ */