1 /* 2 * Copyright (C) 2016 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 CHRE_PLATFORM_SLPI_SMGR_PLATFORM_SENSOR_BASE_H_ 18 #define CHRE_PLATFORM_SLPI_SMGR_PLATFORM_SENSOR_BASE_H_ 19 20 extern "C" { 21 22 #include "sns_smgr_api_v01.h" 23 24 } // extern "C" 25 26 #include "chre/core/sensor_request.h" 27 #include "chre/core/timer_pool.h" 28 #include "chre/platform/atomic.h" 29 30 namespace chre { 31 32 /** 33 * Storage for the SLPI implementation of the PlatformSensor class. 34 */ 35 class PlatformSensorBase { 36 public: PlatformSensorBase()37 PlatformSensorBase() : timerHandle(CHRE_TIMER_INVALID) {} 38 39 /** 40 * Copies the supplied event to the sensor's last event and marks last event 41 * valid. 42 * 43 * @param event The pointer to the event to copy from. 44 */ 45 void setLastEvent(const ChreSensorData *event); 46 47 //! The handle to uniquely identify this sensor. 48 uint8_t sensorId; 49 50 //! The type of data that this sensor uses. SMGR overloads sensor IDs and 51 //! allows them to behave as two sensors. The data type differentiates which 52 //! sensor this object refers to. 53 uint8_t dataType; 54 55 //! The calibration type of this sensor. SMGR overloads sensorId and dataType 56 //! and allows them to represent both uncalibrated and calibrated sensors. 57 uint8_t calType; 58 59 //! The name (type and model) of this sensor. 60 char sensorName[SNS_SMGR_MAX_SENSOR_NAME_SIZE_V01]; 61 62 //! The minimum interval of this sensor. 63 uint64_t minInterval; 64 65 //! Pointer to dynamically allocated memory to store the last event. Only 66 //! non-null if this is an on-change sensor. 67 ChreSensorData *lastEvent = nullptr; 68 69 //! The timer that is used to determine whether CHRE should issue passive 70 //! requests or not to avoid checking for every sensor status callback. 71 AtomicUint32 timerHandle; 72 73 //! The amount of memory we've allocated in lastEvent (this varies depending 74 //! on the sensor type) 75 size_t lastEventSize = 0; 76 77 //! Set to true only when this is an on-change sensor that is currently active 78 //! and we have a copy of the most recent event in lastEvent. 79 bool lastEventValid = false; 80 81 //! Whether the sensor is turned off. This can be different from what's been 82 //! requested through Sensor::setRequest() as a passive request may not 83 //! always be honored by PlatformSensor and the sensor can stay off. 84 bool isSensorOff = true; 85 86 //! Stores the sampling status for all CHRE clients of this sensor. 87 struct chreSensorSamplingStatus samplingStatus; 88 }; 89 90 } // namespace chre 91 92 #endif // CHRE_PLATFORM_SLPI_SMGR_PLATFORM_SENSOR_BASE_H_ 93