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 RetCode CameraPowerUp(const std::string &cameraId, 48 const std::vector<std::string> &phyCameraIds); 49 void CameraPowerDown(const std::vector<std::string> &phyCameraIds); 50 RetCode CameraIdInvalid(const std::string &cameraId); 51 RetCode SetFlashlight(const std::vector<std::string> &phyCameraIds, 52 bool isEnable, FlashlightStatus &flashlightStatus); 53 void OnCameraStatus(CameraId cameraId, CameraStatus status, const std::shared_ptr<CameraAbility> ability); 54 55 private: 56 // key: cameraId, value: CameraDevice 57 using CameraDeviceMap = std::map<std::string, std::shared_ptr<CameraDevice>>; 58 CameraDeviceMap cameraDeviceMap_; 59 OHOS::sptr<ICameraHostCallback> cameraHostCallback_; 60 // to keep remote object OHOS::sptr<ICameraDevice> alive 61 std::map<std::string, OHOS::sptr<ICameraDevice>> deviceBackup_ = {}; 62 }; 63 } // end namespace OHOS::Camera 64 #endif // CAMERA_HOST_CAMERA_HOST_IMPL_H 65