• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
34 class DevicesFactoryHalHidl : public DevicesFactoryHalInterface
35 {
36   public:
37     explicit DevicesFactoryHalHidl(sp<IDevicesFactory> devicesFactory);
38     void onFirstRef() override;
39 
40     // Opens a device with the specified name. To close the device, it is
41     // necessary to release references to the returned object.
42     status_t openDevice(const char *name, sp<DeviceHalInterface> *device) override;
43 
44     status_t getHalPids(std::vector<pid_t> *pids) override;
45 
46     status_t setCallbackOnce(sp<DevicesFactoryHalCallback> callback) override;
47 
getHalVersion()48     float getHalVersion() const override { return MAJOR_VERSION + (float)MINOR_VERSION / 10; }
49 
50   private:
51     friend class ServiceNotificationListener;
52     void addDeviceFactory(sp<IDevicesFactory> factory, bool needToNotify);
53     std::vector<sp<IDevicesFactory>> copyDeviceFactories();
54 
55     std::mutex mLock;
56     std::vector<sp<IDevicesFactory>> mDeviceFactories;  // GUARDED_BY(mLock)
57     wp<DevicesFactoryHalCallback> mCallback;  // GUARDED_BY(mLock)
58     bool mHaveUndeliveredNotifications = false;  // GUARDED_BY(mLock)
59 
60     virtual ~DevicesFactoryHalHidl() = default;
61 };
62 
63 } // namespace android
64 
65 #endif // ANDROID_HARDWARE_DEVICES_FACTORY_HAL_HIDL_H
66