1 /*
2  * Copyright (C) 2019 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__MANAGER_BASE_H_
18 #define CHRE_PLATFORM_SLPI_SEE_PLATFORM_SENSOR__MANAGER_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 /**
26  * Contains additional methods needed by the SLPI SEE implementation of
27  * PlatformSensorManager. Specifically, implements the
28  * SeeHelperCallbackInterface to allow the manager to receive callbacks from
29  * SEE.
30  */
31 class PlatformSensorManagerBase : public SeeHelperCallbackInterface {
32  public:
33 #ifdef CHRE_SLPI_UIMG_ENABLED
PlatformSensorManagerBase()34   PlatformSensorManagerBase() : mBigImageSeeHelper(mSeeHelper.getCalHelper()) {}
35 #endif  // CHRE_SLPI_UIMG_ENABLED
36 
37   /**
38    * Helper function to retrieve the SeeHelper for a given sensor.
39    * @param sensor The sensor
40    * @return A reference to the appropriate (bimg or uimg) SeeHelper
41    */
42   SeeHelper &getSeeHelperForSensor(const Sensor &sensor);
43 
getSeeHelperForSensor(const Sensor & sensor)44   const SeeHelper &getSeeHelperForSensor(const Sensor &sensor) const {
45     // The following cast is done to share code between this method and
46     // getSeeHelperForSensor so we can expose either a const or non-const
47     // SeeHelper depending on the requirements of the caller. The non-const
48     // version of getSeeHelperForSensor will not modify
49     // PlatformSensorManagerBase so this should be safe.
50     return const_cast<PlatformSensorManagerBase *>(this)->getSeeHelperForSensor(
51         sensor);
52   }
53 
54 #ifdef CHRE_SLPI_UIMG_ENABLED
55   /**
56    * Registers alternate sensor(s) to be used separately by big image nanoapps.
57    */
58   void getBigImageSensors(DynamicVector<Sensor> *sensors);
59 #endif  // CHRE_SLPI_UIMG_ENABLED
60 
61   void onSamplingStatusUpdate(
62       UniquePtr<SeeHelperCallbackInterface::SamplingStatusData> &&status)
63       override;
64 
65   void onSensorDataEvent(uint8_t sensorType,
66                          UniquePtr<uint8_t> &&eventData) override;
67 
68   void onHostWakeSuspendEvent(bool awake) override;
69 
70   void onSensorBiasEvent(
71       uint8_t sensorHandle,
72       UniquePtr<struct chreSensorThreeAxisData> &&biasData) override;
73 
74   void onFlushCompleteEvent(uint8_t sensorType) override;
75 
76  protected:
77   SeeHelper mSeeHelper;
78 
79 #ifdef CHRE_SLPI_UIMG_ENABLED
80   BigImageSeeHelper mBigImageSeeHelper;
81 #endif  // CHRE_SLPI_UIMG_ENABLED
82 };
83 
84 }  // namespace chre
85 
86 #endif  // CHRE_PLATFORM_SLPI_SEE_PLATFORM_SENSOR__MANAGER_BASE_H_
87