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 DISTRIBUTED_CAMERA_HOST_H 17 #define DISTRIBUTED_CAMERA_HOST_H 18 19 #include "dcamera.h" 20 #include "dcamera_device.h" 21 #include "icamera_device.h" 22 #include "icamera_host_callback.h" 23 #include "icamera_device_callback.h" 24 25 #include <foundation/distributedhardware/distributedcamera/camera_hdf/interfaces/include/types.h> 26 #ifdef BALTIMORE_CAMERA 27 #include <drivers/peripheral/adapter/camera/interfaces/include/types.h> 28 #else 29 #include <drivers/peripheral/camera/interfaces/include/types.h> 30 #endif 31 32 namespace OHOS { 33 namespace DistributedHardware { 34 class DCameraHost { 35 public: 36 DCameraHost() = default; 37 virtual ~DCameraHost() = default; 38 DCameraHost(const DCameraHost &other) = delete; 39 DCameraHost(DCameraHost &&other) = delete; 40 DCameraHost& operator=(const DCameraHost &other) = delete; 41 DCameraHost& operator=(DCameraHost &&other) = delete; 42 43 public: 44 static std::shared_ptr<DCameraHost> GetInstance(); 45 CamRetCode SetCallback(const OHOS::sptr<ICameraHostCallback> &callback); 46 CamRetCode GetCameraIds(std::vector<std::string> &cameraIds); 47 CamRetCode GetCameraAbility(const std::string &cameraId, std::shared_ptr<CameraAbility> &ability); 48 CamRetCode OpenCamera(const std::string &cameraId, const OHOS::sptr<ICameraDeviceCallback> &callback, 49 OHOS::sptr<ICameraDevice> &pDevice); 50 CamRetCode SetFlashlight(const std::string &cameraId, bool &isEnable); 51 52 DCamRetCode AddDCameraDevice(const std::shared_ptr<DHBase> &dhBase, const std::string &abilityInfo, 53 const sptr<IDCameraProviderCallback> &callback); 54 DCamRetCode RemoveDCameraDevice(const std::shared_ptr<DHBase> &dhBase); 55 OHOS::sptr<DCameraDevice> GetDCameraDeviceByDHBase(const std::shared_ptr<DHBase> &dhBase); 56 void NotifyDCameraStatus(const std::shared_ptr<DHBase> &dhBase, int32_t result); 57 58 private: 59 bool IsCameraIdInvalid(const std::string &cameraId); 60 std::string GetCameraIdByDHBase(const std::shared_ptr<DHBase> &dhBase); 61 62 private: 63 class AutoRelease { 64 public: AutoRelease()65 AutoRelease() {}; ~AutoRelease()66 ~AutoRelease() 67 { 68 if (DCameraHost::instance_ != nullptr) { 69 DCameraHost::instance_ = nullptr; 70 } 71 }; 72 }; 73 static AutoRelease autoRelease_; 74 static std::shared_ptr<DCameraHost> instance_; 75 76 OHOS::sptr<ICameraHostCallback> dCameraHostCallback_; 77 std::map<DHBase, std::string> dhBaseHashDCamIdMap_; 78 std::map<std::string, OHOS::sptr<DCameraDevice>> dCameraDeviceMap_; 79 }; 80 } // end namespace DistributedHardware 81 } // end namespace OHOS 82 #endif // DISTRIBUTED_CAMERA_HOST_H