1 /*
2  * Copyright 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 #include "CameraProvider_2_4.h"
18 #include "LegacyCameraProviderImpl_2_4.h"
19 #include "ExternalCameraProviderImpl_2_4.h"
20 
21 const char *kLegacyProviderName = "legacy/0";
22 const char *kExternalProviderName = "external/0";
23 
24 namespace android {
25 namespace hardware {
26 namespace camera {
27 namespace provider {
28 namespace V2_4 {
29 namespace implementation {
30 
31 using android::hardware::camera::provider::V2_4::ICameraProvider;
32 
33 extern "C" ICameraProvider* HIDL_FETCH_ICameraProvider(const char* name);
34 
35 template<typename IMPL>
getProviderImpl()36 CameraProvider<IMPL>* getProviderImpl() {
37     CameraProvider<IMPL> *provider = new CameraProvider<IMPL>();
38     if (provider == nullptr) {
39         ALOGE("%s: cannot allocate camera provider!", __FUNCTION__);
40         return nullptr;
41     }
42     if (provider->isInitFailed()) {
43         ALOGE("%s: camera provider init failed!", __FUNCTION__);
44         delete provider;
45         return nullptr;
46     }
47     return provider;
48 }
49 
HIDL_FETCH_ICameraProvider(const char * name)50 ICameraProvider* HIDL_FETCH_ICameraProvider(const char* name) {
51     using namespace android::hardware::camera::provider::V2_4::implementation;
52     ICameraProvider* provider = nullptr;
53     if (strcmp(name, kLegacyProviderName) == 0) {
54         provider = getProviderImpl<LegacyCameraProviderImpl_2_4>();
55     } else if (strcmp(name, kExternalProviderName) == 0) {
56         provider = getProviderImpl<ExternalCameraProviderImpl_2_4>();
57     } else {
58         ALOGE("%s: unknown instance name: %s", __FUNCTION__, name);
59     }
60 
61     return provider;
62 }
63 
64 }  // namespace implementation
65 }  // namespace V2_4
66 }  // namespace provider
67 }  // namespace camera
68 }  // namespace hardware
69 }  // namespace android
70