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_SERVICE_H
17 #define CAMERA_HOST_SERVICE_H
18 
19 #include <map>
20 #include "camera.h"
21 #include "hcs_dm_parser.h"
22 #include "v1_0/icamera_device.h"
23 #include "v1_0/icamera_host.h"
24 #include "v1_0/icamera_host_vdi.h"
25 
26 namespace OHOS::Camera {
27 #ifdef CHIP_PROD_CAMERA_HOST_CONFIG
28 #define CONFIG_PATH_NAME HDF_CHIP_PROD_CONFIG_DIR"/camera_host_config.hcb"
29 #else
30 #define CONFIG_PATH_NAME HDF_CONFIG_DIR"/camera_host_config.hcb"
31 #endif
32 
33 using namespace OHOS::HDI::Camera::V1_0;
34 using namespace OHOS::VDI::Camera::V1_0;
35 
36 struct CameraIdInfo {
37     std::string currentCameraId;
38     ICameraHostVdi* cameraHostVdi;
39     std::string vendorCameraId;
40     bool isDeleted;
41 };
42 
43 class CameraHostService : public ICameraHost {
44 public:
45     static OHOS::sptr<CameraHostService> GetInstance();
46     int32_t SetCallback(const sptr<ICameraHostCallback> &callbackObj) override;
47     int32_t GetCameraIds(std::vector<std::string> &cameraIds) override;
48     int32_t GetCameraAbility(const std::string &cameraId,
49         std::vector<uint8_t> &cameraAbility) override;
50     int32_t OpenCamera(const std::string &cameraId, const sptr<ICameraDeviceCallback> &callbackObj,
51         sptr<ICameraDevice> &device) override;
52     int32_t SetFlashlight(const std::string &cameraId, bool isEnable) override;
53 
54 private:
55     CameraHostService(std::vector<ICameraHostVdi*> cameraHostVdiList,
56         std::vector<struct HdfVdiObject *> cameraHostVdiLoaderList);
57     virtual ~CameraHostService();
58     CameraHostService(const CameraHostService &other) = delete;
59     CameraHostService(CameraHostService &&other) = delete;
60     CameraHostService &operator=(const CameraHostService &other) = delete;
61     CameraHostService &operator=(CameraHostService &&other) = delete;
62 
63     static int32_t GetVdiLibList(std::vector<std::string> &vdiLibList);
64     static void HdfCloseVdiLoaderList(std::vector<struct HdfVdiObject *> &cameraHostVdiLoaderList);
65     ICameraHostVdi* GetCameraHostVdi(const std::string &currentCameraId);
66     const std::string GetVendorCameraId(const std::string &currentCameraId);
67     int32_t UpdateCameraIdMapList();
68 
69     std::vector<ICameraHostVdi*> cameraHostVdiList_;
70     std::vector<CameraIdInfo> cameraIdInfoList_;
71     std::vector<struct HdfVdiObject *> cameraHostVdiLoaderList_;
72     static OHOS::sptr<CameraHostService> cameraHostService_;
73 };
74 } // end namespace OHOS::Camera
75 #endif // CAMERA_HOST_SERVICE_H
76