Update for attribute changed callback and attribute getter
[platform/core/system/sensord.git] / src / server / fusion_sensor_handler.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 __FUSION_SENSOR_HANDLER_H__
21 #define __FUSION_SENSOR_HANDLER_H__
22
23 #include <message.h>
24 #include <sensor_types.h>
25 #include <fusion_sensor.h>
26 #include <unordered_map>
27
28 #include "sensor_handler.h"
29 #include "sensor_observer.h"
30
31 namespace sensor {
32
33 class required_sensor {
34 public:
35         required_sensor(uint32_t _id, sensor_handler *_sensor)
36         : id(_id)
37         , sensor(_sensor)
38         {}
39
40         uint32_t id;
41         sensor_handler *sensor;
42 };
43
44 class fusion_sensor_handler : public sensor_handler, public sensor_observer {
45 public:
46         fusion_sensor_handler(const sensor_info &info,
47                         fusion_sensor *sensor);
48         ~fusion_sensor_handler();
49
50         void add_required_sensor(uint32_t id, sensor_handler *sensor);
51
52         /* subscriber */
53         int update(const char *uri, std::shared_ptr<ipc::message> msg);
54
55         /* sensor interface */
56         const sensor_info &get_sensor_info(void);
57
58         int start(sensor_observer *ob);
59         int stop(sensor_observer *ob);
60
61         int set_interval(sensor_observer *ob, int32_t interval);
62         int get_interval(sensor_observer *ob, int32_t& interval);
63
64         int set_batch_latency(sensor_observer *ob, int32_t latency);
65         int get_batch_latency(sensor_observer *ob, int32_t &latency);
66
67         int set_attribute(sensor_observer *ob, int32_t attr, int32_t value);
68         int set_attribute(sensor_observer *ob, int32_t attr, const char *value, int len);
69         int flush(sensor_observer *ob);
70         int get_data(sensor_data_t **data, int *len);
71
72 private:
73         int start_internal(void);
74         int stop_internal(void);
75         int set_interval_internal(int32_t interval);
76         int set_batch_latency_internal(int32_t latency);
77         int set_attribute_internal(int32_t attr, int32_t value);
78         int set_attribute_internal(int32_t attr, const char *value, int len);
79
80         int get_min_interval(void);
81         int get_min_batch_latency(void);
82
83         fusion_sensor *m_sensor;
84         std::unordered_map<std::string, required_sensor> m_required_sensors;
85
86         std::unordered_map<sensor_observer *, int> m_interval_map;
87         std::unordered_map<sensor_observer *, int> m_batch_latency_map;
88 };
89
90 }
91
92 #endif /* __FUSION_SENSOR_HANDLER_H__ */