• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ANDROID_SENSORHAL_BASE_SENSOR_OBJECT_H
18 #define ANDROID_SENSORHAL_BASE_SENSOR_OBJECT_H
19 
20 #include "Utils.h"
21 #include <cstdint>
22 
23 struct sensor_t;
24 struct sensors_event_t;
25 
26 namespace android {
27 namespace SensorHalExt {
28 
29 class SensorEventCallback;
30 
REF_BASE(BaseSensorObject)31 class BaseSensorObject : virtual public REF_BASE(BaseSensorObject) {
32 public:
33     BaseSensorObject();
34     virtual ~BaseSensorObject() = default;
35 
36     // always called by DynamicSensorManager, callback must point to
37     // valid object throughout life cycle of BaseSensorObject
38     bool setEventCallback(SensorEventCallback* callback);
39 
40     // virtual functions to get sensor information and operate sensor
41     virtual const sensor_t* getSensor() const = 0;
42 
43     // get uuid of sensor, default implementation set it to all zero, means does not have a uuid.
44     virtual void getUuid(uint8_t* uuid) const;
45 
46     // enable sensor
47     virtual int enable(bool enable) = 0;
48 
49     // set sample period and batching period of sensor.
50     // both sample period and batch period are in nano-seconds.
51     virtual int batch(int64_t samplePeriod, int64_t batchPeriod) = 0;
52 
53     // flush sensor, default implementation will send a flush complete event back.
54     virtual int flush();
55 
56 protected:
57     // utility function for sub-class
58     void generateEvent(const sensors_event_t &e);
59 private:
60     SensorEventCallback* mCallback;
61 };
62 
63 } // namespace SensorHalExt
64 } // namespace android
65 
66 #endif // ANDROID_SENSORHAL_BASE_SENSOR_OBJECT_H
67 
68