1 /*
2  * Copyright (C) 2020 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 #include "device_factory.h"
18 #include "primary_device.h"
19 #include <system/audio.h>
20 #include <log/log.h>
21 
22 namespace android {
23 namespace hardware {
24 namespace audio {
25 namespace V6_0 {
26 namespace implementation {
27 
28 using ::android::hardware::Void;
29 
openDevice(const hidl_string & device,openDevice_cb _hidl_cb)30 Return<void> DevicesFactory::openDevice(const hidl_string& device,
31                                         openDevice_cb _hidl_cb) {
32     Result result = Result::OK;
33     std::unique_ptr<IDevice> dev;
34 
35     if (device == AUDIO_HARDWARE_MODULE_ID_PRIMARY) {
36         dev = std::make_unique<PrimaryDevice>();
37     } else {
38         result = Result::INVALID_ARGUMENTS;
39     }
40 
41     if (!dev) {
42         ALOGE("DevicesFactory::%s:%d: failed, device='%s' result='%s'",
43               __func__, __LINE__, device.c_str(), toString(result).c_str());
44     }
45 
46     _hidl_cb(result, dev.release());
47     return Void();
48 }
49 
openPrimaryDevice(openPrimaryDevice_cb _hidl_cb)50 Return<void> DevicesFactory::openPrimaryDevice(openPrimaryDevice_cb _hidl_cb) {
51     _hidl_cb(Result::OK, new PrimaryDevice);
52     return Void();
53 }
54 
55 }  // namespace implementation
56 }  // namespace V6_0
57 }  // namespace audio
58 }  // namespace hardware
59 }  // namespace android
60