sensord: replace usleep() code with sleep()
[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, 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 set_batch_latency(sensor_observer *ob, int32_t latency);
63         int set_attribute(sensor_observer *ob, int32_t attr, int32_t value);
64         int set_attribute(sensor_observer *ob, int32_t attr, const char *value, int len);
65         int flush(sensor_observer *ob);
66         int get_data(sensor_data_t **data, int *len);
67
68 private:
69         int start_internal(void);
70         int stop_internal(void);
71         int set_interval_internal(int32_t interval);
72         int set_batch_latency_internal(int32_t latency);
73         int set_attribute_internal(int32_t attr, int32_t value);
74         int set_attribute_internal(int32_t attr, const char *value, int len);
75
76         int get_min_interval(void);
77         int get_min_batch_latency(void);
78
79         sensor_info m_info;
80         fusion_sensor *m_sensor;
81         std::unordered_map<std::string, required_sensor> m_required_sensors;
82
83         std::unordered_map<sensor_observer *, int> m_interval_map;
84         std::unordered_map<sensor_observer *, int> m_batch_latency_map;
85 };
86
87 }
88
89 #endif /* __FUSION_SENSOR_HANDLER_H__ */