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