• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "config_manager.h"
17 
18 extern "C"
19 {
20 #include "camera_host_config.h"
21 }
22 
23 extern "C"
24 {
25 const struct HdfConfigHostRoot* HdfGetHostModuleConfigRoot(void);
26 }
27 
28 namespace OHOS::Camera {
29 std::map<std::string, CameraId> ConfigManager::enumCameraIdMap_ = {
30     { "CAMERA_FIRST", CAMERA_FIRST },
31     { "CAMERA_SECOND", CAMERA_SECOND },
32     { "CAMERA_THIRD", CAMERA_THIRD },
33 };
34 
ConfigManager()35 ConfigManager::ConfigManager()
36 {
37 }
38 
~ConfigManager()39 ConfigManager::~ConfigManager()
40 {
41 }
42 
ReadConfigFile()43 CamRetCode ConfigManager::ReadConfigFile()
44 {
45     const struct HdfConfigHostRoot *hcsRoot = HdfGetHostModuleConfigRoot();
46     uint16_t lcameraIdCount = hcsRoot->camera_host_config.cameraHostCfgSize;
47     for (uint16_t i = 0; i < lcameraIdCount; i++) {
48         const char *lcameraId = hcsRoot->camera_host_config.cameraHostCfg[i].logicCameraId;
49         std::shared_ptr<CameraAbility> ability = std::make_shared<CameraAbility>(0, 0);
50         cameraAbilityMap_.insert(std::make_pair(std::string(lcameraId), ability));
51 
52         std::vector<std::string> pCameraIds;
53         uint16_t pcameraIdCount = hcsRoot->camera_host_config.cameraHostCfg[i].physicsCameraIdSize;
54         for (uint16_t j = 0; j < pcameraIdCount; j++) {
55             const char *pcameraId = hcsRoot->camera_host_config.cameraHostCfg[i].physicsCameraId[j].cameraId;
56             pCameraIds.push_back(std::string(pcameraId));
57             CAMERA_LOGE("phy cameraID = %{public}s.", pcameraId);
58         }
59 
60         if (!pCameraIds.empty()) {
61             cameraIdMap_.insert(std::make_pair(std::string(lcameraId), pCameraIds));
62         }
63     }
64 
65     return NO_ERROR;
66 }
67 
GetCameraIds(std::vector<std::string> & cameraIds)68 CamRetCode ConfigManager::GetCameraIds(std::vector<std::string> &cameraIds)
69 {
70     auto itr = cameraAbilityMap_.begin();
71     for (; itr != cameraAbilityMap_.end(); itr++) {
72         cameraIds.push_back(itr->first);
73     }
74 
75     return NO_ERROR;
76 }
77 
GetPhysicCameraIds(const std::string & lCameraId,std::vector<std::string> & pCameraIds)78 CamRetCode ConfigManager::GetPhysicCameraIds(const std::string &lCameraId, std::vector<std::string> &pCameraIds)
79 {
80     auto itr = cameraIdMap_.find(lCameraId);
81     if (itr != cameraIdMap_.end()) {
82         pCameraIds = itr->second;
83         return NO_ERROR;
84     }
85     return INSUFFICIENT_RESOURCES;
86 }
87 
GetCameraAbility(const std::string & cameraId,std::shared_ptr<CameraAbility> & ability)88 CamRetCode ConfigManager::GetCameraAbility(
89     const std::string &cameraId, std::shared_ptr<CameraAbility> &ability)
90 {
91     if (ability == nullptr) {
92         CAMERA_LOGE("ability is null.");
93         return INVALID_ARGUMENT;
94     }
95 
96     auto itr = cameraAbilityMap_.find(cameraId);
97     if (itr != cameraAbilityMap_.end()) {
98         ability = itr->second;
99         return NO_ERROR;
100     }
101 
102     return INSUFFICIENT_RESOURCES;
103 }
104 } // end namespace OHOS::Camera
105