• 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 #ifndef CAMERA_HOST_CAMERA_HOST_IMPL_H
17 #define CAMERA_HOST_CAMERA_HOST_IMPL_H
18 
19 #include <map>
20 #include "v1_0/icamera_device.h"
21 #include "v1_0/icamera_host.h"
22 #include "utils.h"
23 #include "camera_device_impl.h"
24 
25 namespace OHOS::Camera {
26 using namespace OHOS::HDI::Camera::V1_0;
27 
28 class CameraHostImpl : public ICameraHost {
29 public:
30     CamRetCode Init();
31     int32_t SetCallback(const sptr<ICameraHostCallback>& callbackObj) override;
32     int32_t GetCameraIds(std::vector<std::string> &cameraIds) override;
33     int32_t GetCameraAbility(const std::string &cameraId,
34         std::vector<uint8_t>& cameraAbility) override;
35     int32_t OpenCamera(const std::string& cameraId, const sptr<ICameraDeviceCallback>& callbackObj,
36         sptr<ICameraDevice>& device) override;
37     int32_t SetFlashlight(const std::string &cameraId, bool isEnable) override;
38 
39 public:
40     CameraHostImpl();
41     virtual ~CameraHostImpl();
42     CameraHostImpl(const CameraHostImpl &other) = delete;
43     CameraHostImpl(CameraHostImpl &&other) = delete;
44     CameraHostImpl& operator=(const CameraHostImpl &other) = delete;
45     CameraHostImpl& operator=(CameraHostImpl &&other) = delete;
46 
47 private:
48     RetCode CameraPowerUp(const std::string &cameraId,
49         const std::vector<std::string> &phyCameraIds);
50     void CameraPowerDown(const std::vector<std::string> &phyCameraIds);
51     RetCode CameraIdInvalid(const std::string &cameraId);
52     RetCode SetFlashlight(const std::vector<std::string> &phyCameraIds,
53         bool isEnable, FlashlightStatus &flashlightStatus);
54     void OnCameraStatus(CameraId cameraId, CameraStatus status, const std::shared_ptr<CameraAbility> ability);
55 
56 private:
57     // key: cameraId, value: CameraDevice
58     using CameraDeviceMap = std::map<std::string, std::shared_ptr<CameraDeviceImpl>>;
59     CameraDeviceMap cameraDeviceMap_;
60     OHOS::sptr<ICameraHostCallback> cameraHostCallback_;
61     // to keep remote object OHOS::sptr<ICameraDevice> alive
62     std::map<std::string, OHOS::sptr<ICameraDevice>> deviceBackup_ = {};
63 };
64 } // end namespace OHOS::Camera
65 #endif // CAMERA_HOST_CAMERA_HOST_IMPL_H
66