coverity issues fix
[platform/core/system/sensord.git] / include / fusion_sensor.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_H__
21 #define __FUSION_SENSOR_H__
22
23 #include <stdint.h>
24 #include <stdbool.h>
25 #include <sensor_types.h>
26 #include <vector>
27 #include <string>
28
29 #ifndef FUSION_SENSOR_VERSION
30 #define FUSION_SENSOR_VERSION(maj, min) \
31                 ((((maj) & 0xFFFF) << 24) | ((min) & 0xFFFF))
32 #endif
33
34 #ifndef OP_SUCCESS
35 #define OP_SUCCESS 0
36 #endif
37 #ifndef OP_ERROR
38 #define OP_ERROR   -1
39 #endif
40 #ifndef OP_DEFAULT
41 #define OP_DEFAULT 1
42 #endif
43
44 /*
45  * Create sensor
46  */
47 typedef void *fusion_sensor_t;
48 typedef int (*create_fusion_t)(fusion_sensor_t **sensors);
49
50 typedef void *observer_h;
51
52 typedef struct required_sensor_s {
53         uint32_t id;
54         const char *uri;
55 } required_sensor_s;
56
57 /*
58  * Sensor interface
59  */
60 class fusion_sensor {
61 public:
62         virtual ~fusion_sensor() {}
63
64         inline uint32_t get_version(void) { return FUSION_SENSOR_VERSION(1, 0); }
65
66         virtual int get_sensor_info(const sensor_info2_t **info) = 0;
67         virtual int get_required_sensors(const required_sensor_s **info) = 0;
68
69         /* if update() returns positive value, then get_data() is called */
70         virtual int update(uint32_t id, sensor_data_t *data, int len) = 0;
71         virtual int get_data(sensor_data_t **data, int *len) = 0;
72
73         virtual int start(observer_h ob)
74         {
75                 return OP_DEFAULT;
76         }
77 ;
78         virtual int stop(observer_h ob)
79         {
80                 return OP_DEFAULT;
81         }
82
83         virtual int set_interval(observer_h ob, int32_t &interval)
84         {
85                 return OP_DEFAULT;
86         }
87
88         virtual int set_batch_latency(observer_h ob, int32_t &latency)
89         {
90                 return OP_DEFAULT;
91         }
92
93         virtual int set_attribute(observer_h ob, int32_t attr, int32_t value)
94         {
95                 return OP_DEFAULT;
96         }
97
98         virtual int set_attribute(observer_h ob, int32_t attr, const char *value, int len)
99         {
100                 return OP_DEFAULT;
101         }
102
103         virtual int flush(observer_h ob)
104         {
105                 return OP_DEFAULT;
106         }
107 };
108
109 #endif /* __FUSION_SENSOR_H__ */