coverity issues fix
[platform/core/system/sensord.git] / include / physical_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 __PHYSICAL_SENSOR_H__
21 #define __PHYSICAL_SENSOR_H__
22
23 #include <stdint.h>
24 #include <stdbool.h>
25 #include <string>
26 #include <sensor_types.h>
27
28 #ifndef SENSOR_VERSION
29 #define PHYSICAL_SENSOR_VERSION(maj, min) \
30                 ((((maj) & 0xFFFF) << 24) | ((min) & 0xFFFF))
31 #endif
32
33 #ifndef OP_SUCCESS
34 #define OP_SUCCESS 1
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 *physical_sensor_t;
47 typedef int (*create_physical_t)(physical_sensor_t **sensors);
48
49 typedef void *observer_h;
50
51 /*
52  * Sensor interface
53  */
54 class physical_sensor {
55 public:
56         virtual ~physical_sensor() {}
57
58         inline uint32_t get_version(void) { return PHYSICAL_SENSOR_VERSION(1, 0); }
59
60         /* TODO */
61         virtual std::string get_privilege(void) { return ""; }
62
63         virtual int start(observer_h ob) = 0;
64         virtual int stop(observer_h ob) = 0;
65         virtual int set_interval(observer_h ob, uint32_t interval)
66         {
67                 return OP_DEFAULT;
68         }
69
70         virtual int set_batch_latency(observer_h ob, uint32_t latency)
71         {
72                 return OP_DEFAULT;
73         }
74
75         virtual int set_attribute(observer_h ob, int32_t attr, int32_t value)
76         {
77                 return OP_DEFAULT;
78         }
79
80         virtual int set_attribute(observer_h ob, int32_t attr, const char *value, int len)
81         {
82                 return OP_DEFAULT;
83         }
84
85         virtual int flush(observer_h ob)
86         {
87                 return OP_DEFAULT;
88         }
89
90         virtual int on_event(sensor_data_t *data, int32_t len, int32_t remains)
91         {
92                 return OP_DEFAULT;
93         }
94 };
95
96 #endif /* __PHYSICAL_SENSOR_H__ */