• 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 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 
22 namespace chre {
23 
24 //! The max length of sensorName
25 constexpr size_t kSensorNameMaxLen = 64;
26 
27 /**
28  * Storage for the SLPI SEE implementation of the PlatformSensor class.
29  */
30 class PlatformSensorBase {
31  public:
32   /**
33    * Initializes the members of PlatformSensorBase.
34    */
35   void initBase(
36       SensorType sensorType, uint64_t mMinInterval, const char *sensorName,
37       ChreSensorData *lastEvent, size_t lastEventSize, bool passiveSupported);
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   /**
48    * Sets the current status of this sensor in the CHRE API format.
49    *
50    * @param status The current sampling status.
51    */
52   void setSamplingStatus(const struct chreSensorSamplingStatus& status);
53 
54  protected:
55   //! The sensor type of this sensor.
56   SensorType mSensorType;
57 
58   //! The minimum interval of this sensor.
59   uint64_t mMinInterval;
60 
61   //! The name (type and model) of this sensor.
62   char mSensorName[kSensorNameMaxLen];
63 
64   //! Pointer to dynamically allocated memory to store the last event. Only
65   //! non-null if this is an on-change sensor.
66   ChreSensorData *mLastEvent = nullptr;
67 
68   //! The amount of memory we've allocated in lastEvent (this varies depending
69   //! on the sensor type)
70   size_t mLastEventSize = 0;
71 
72   //! Set to true only when this is an on-change sensor that is currently active
73   //! and we have a copy of the most recent event in lastEvent.
74   bool mLastEventValid = false;
75 
76   //! Whether this sensor supports passive sensor requests.
77   bool mPassiveSupported = false;
78 
79   //! Stores the sampling status for all CHRE clients of this sensor.
80   struct chreSensorSamplingStatus mSamplingStatus;
81 };
82 
83 }  // namespace chre
84 
85 #endif  // CHRE_PLATFORM_SLPI_SEE_PLATFORM_SENSOR_BASE_H_
86