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 CHRE_PLATFORM_SLPI_SEE_PLATFORM_SENSOR_BASE_H_ 18 #define CHRE_PLATFORM_SLPI_SEE_PLATFORM_SENSOR_BASE_H_ 19 20 #include "chre/core/sensor_request.h" 21 #include "chre/platform/slpi/see/see_helper.h" 22 23 namespace chre { 24 25 //! The max length of sensorName 26 constexpr size_t kSensorNameMaxLen = 64; 27 28 /** 29 * Storage for the SLPI SEE implementation of the PlatformSensor class. 30 */ 31 class PlatformSensorBase { 32 public: 33 /** 34 * Initializes the members of PlatformSensorBase. 35 */ 36 void initBase( 37 SensorType sensorType, uint64_t mMinInterval, const char *sensorName, 38 ChreSensorData *lastEvent, size_t lastEventSize, bool passiveSupported); 39 40 /** 41 * Copies the supplied event to the sensor's last event and marks last event 42 * valid. 43 * 44 * @param event The pointer to the event to copy from. 45 */ 46 void setLastEvent(const ChreSensorData *event); 47 48 /** 49 * Sets the current status of this sensor in the CHRE API format. 50 * 51 * @param status The current sampling status. 52 */ 53 void setSamplingStatus(const struct chreSensorSamplingStatus& status); 54 55 //! Stores the last received sampling status from SEE for this sensor making 56 //! it easier to dedup updates that come in later from SEE. 57 SeeHelperCallbackInterface::SamplingStatusData mLastReceivedSamplingStatus {}; 58 59 protected: 60 //! The sensor type of this sensor. 61 SensorType mSensorType; 62 63 //! The minimum interval of this sensor. 64 uint64_t mMinInterval; 65 66 //! The name (type and model) of this sensor. 67 char mSensorName[kSensorNameMaxLen]; 68 69 //! Pointer to dynamically allocated memory to store the last event. Only 70 //! non-null if this is an on-change sensor. 71 ChreSensorData *mLastEvent = nullptr; 72 73 //! The amount of memory we've allocated in lastEvent (this varies depending 74 //! on the sensor type) 75 size_t mLastEventSize = 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 mLastEventValid = false; 80 81 //! Whether this sensor supports passive sensor requests. 82 bool mPassiveSupported = false; 83 84 //! Stores the sampling status for all CHRE clients of this sensor. 85 struct chreSensorSamplingStatus mSamplingStatus; 86 }; 87 88 } // namespace chre 89 90 #endif // CHRE_PLATFORM_SLPI_SEE_PLATFORM_SENSOR_BASE_H_ 91