Home | History | Annotate | Download | only in libsensorndkbridge
      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 A_SENSOR_MANAGER_H_
     18 
     19 #define A_SENSOR_MANAGER_H_
     20 
     21 #include <android/frameworks/sensorservice/1.0/ISensorManager.h>
     22 #include <android/sensor.h>
     23 #include <utils/Mutex.h>
     24 #include <utils/RefBase.h>
     25 
     26 struct ALooper;
     27 
     28 struct ASensorManager {
     29     static ASensorManager *getInstance();
     30 
     31     ASensorManager();
     32     android::status_t initCheck() const;
     33 
     34     // Returns error or number of sensors returned.
     35     int getSensorList(ASensorList *list);
     36 
     37     ASensorRef getDefaultSensor(int type);
     38     ASensorRef getDefaultSensorEx(int type, bool wakeup);
     39 
     40     ASensorEventQueue *createEventQueue(
     41             ALooper *looper,
     42             int ident,
     43             ALooper_callbackFunc callback,
     44             void *data);
     45 
     46     void destroyEventQueue(ASensorEventQueue *queue);
     47 
     48 private:
     49 
     50     struct SensorDeathRecipient : public android::hardware::hidl_death_recipient
     51     {
     52         // hidl_death_recipient interface
     53         virtual void serviceDied(uint64_t cookie,
     54                 const ::android::wp<::android::hidl::base::V1_0::IBase>& who) override;
     55     };
     56 
     57     using ISensorManager = android::frameworks::sensorservice::V1_0::ISensorManager;
     58     using SensorInfo = android::hardware::sensors::V1_0::SensorInfo;
     59 
     60     static ASensorManager *sInstance;
     61     android::sp<SensorDeathRecipient> mDeathRecipient = nullptr;
     62 
     63     android::status_t mInitCheck;
     64     android::sp<ISensorManager> mManager;
     65 
     66     mutable android::Mutex mLock;
     67     android::hardware::hidl_vec<SensorInfo> mSensors;
     68     std::unique_ptr<ASensorRef[]> mSensorList;
     69 
     70     DISALLOW_COPY_AND_ASSIGN(ASensorManager);
     71 };
     72 
     73 #endif  // A_SENSOR_MANAGER_H_
     74