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 ANDROID_HARDWARE_DEVICES_FACTORY_HAL_HIDL_H 18 #define ANDROID_HARDWARE_DEVICES_FACTORY_HAL_HIDL_H 19 20 #include <mutex> 21 #include <vector> 22 23 #include PATH(android/hardware/audio/FILE_VERSION/IDevicesFactory.h) 24 #include <media/audiohal/DevicesFactoryHalInterface.h> 25 #include <utils/Errors.h> 26 #include <utils/RefBase.h> 27 28 #include "DeviceHalHidl.h" 29 30 using ::android::hardware::audio::CPP_VERSION::IDevicesFactory; 31 32 namespace android { 33 namespace CPP_VERSION { 34 35 class DevicesFactoryHalHidl : public DevicesFactoryHalInterface 36 { 37 public: 38 explicit DevicesFactoryHalHidl(sp<IDevicesFactory> devicesFactory); 39 void onFirstRef() override; 40 41 // Opens a device with the specified name. To close the device, it is 42 // necessary to release references to the returned object. 43 status_t openDevice(const char *name, sp<DeviceHalInterface> *device) override; 44 45 status_t getHalPids(std::vector<pid_t> *pids) override; 46 47 status_t setCallbackOnce(sp<DevicesFactoryHalCallback> callback) override; 48 49 private: 50 friend class ServiceNotificationListener; 51 void addDeviceFactory(sp<IDevicesFactory> factory, bool needToNotify); 52 std::vector<sp<IDevicesFactory>> copyDeviceFactories(); 53 54 std::mutex mLock; 55 std::vector<sp<IDevicesFactory>> mDeviceFactories; // GUARDED_BY(mLock) 56 wp<DevicesFactoryHalCallback> mCallback; // GUARDED_BY(mLock) 57 bool mHaveUndeliveredNotifications = false; // GUARDED_BY(mLock) 58 59 virtual ~DevicesFactoryHalHidl() = default; 60 }; 61 62 } // namespace CPP_VERSION 63 } // namespace android 64 65 #endif // ANDROID_HARDWARE_DEVICES_FACTORY_HAL_HIDL_H 66