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