• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 #ifndef CAMERA_HOST_CONFIG_MANAGER_H
17 #define CAMERA_HOST_CONFIG_MANAGER_H
18 
19 #include <vector>
20 #include <map>
21 #include <list>
22 #include "utils.h"
23 #include "camera.h"
24 
25 namespace OHOS::Camera {
26 class HcsDeal;
27 class CameraHostConfig {
28 public:
29     static CameraHostConfig *GetInstance();
30     RetCode ReadConfigFile();
31     RetCode GetCameraIds(std::vector<std::string> &cameraIds);
32     RetCode GetPhysicCameraIds(const std::string &lCameraId, std::vector<std::string> &pCameraIds);
33     RetCode GetCameraAbility(const std::string &cameraId, std::shared_ptr<CameraAbility> &ability);
34     RetCode AddCameraId(const std::string &logicalCameraId,
35         const std::vector<std::string> &physicalCameraIds, const std::shared_ptr<CameraAbility> ability);
36     std::string SubtractCameraId(const std::vector<std::string> &physicalCameraIds);
37     std::string ReturnEnableLogicalCameraId();
38     std::string GenerateNewLogicalCameraId();
39     std::string ReturnPhysicalCameraIdToString(const CameraId &physicalCameraId);
40     std::string ReturnLogicalCameraIdToString(const std::string &physicalCameraId);
41     void AddUsbCameraId(std::string cameraId);
42     bool SearchUsbCameraId(std::string cameraId);
43 
44 public:
45     virtual ~CameraHostConfig();
46     CameraHostConfig(const CameraHostConfig &other) = delete;
47     CameraHostConfig(CameraHostConfig &&other) = delete;
48     CameraHostConfig& operator=(const CameraHostConfig &other) = delete;
49     CameraHostConfig& operator=(CameraHostConfig &&other) = delete;
50 
51 public:
52     // key: config cameraId; value: DeviceManager cameraId enum
53     static std::map<std::string, CameraId> enumCameraIdMap_;
54 
55 private:
56     CameraHostConfig();
57     class AutoRelease {
58     public:
AutoRelease()59         AutoRelease() {}
~AutoRelease()60         ~AutoRelease()
61         {
62             if (CameraHostConfig::instance_ != nullptr) {
63                 delete CameraHostConfig::instance_;
64                 CameraHostConfig::instance_ = nullptr;
65             }
66         }
67     };
68     static CameraHostConfig *instance_;
69     static AutoRelease autoRelease_;
70 
71 private:
72     // key: cameraId, value: CameraAbility
73     using CameraAbilityMap = std::map<std::string, std::shared_ptr<CameraAbility>>;
74     CameraAbilityMap cameraAbilityMap_;
75     // key: logicCameraId, value: physicsCameraIds
76     using CameraIdMap = std::map<std::string, std::vector<std::string>>;
77     CameraIdMap cameraIdMap_;
78     std::vector<std::string> usbCameraIdVector_;
79 };
80 } // end namespace OHOS::Camera
81 #endif // CAMERA_HOST_CONFIG_MANAGER_H
82