1 /* 2 * Copyright (c) 2021-2022 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 OHOS_CAMERA_H_CAMERA_HOST_MANAGER_H 17 #define OHOS_CAMERA_H_CAMERA_HOST_MANAGER_H 18 19 #include <refbase.h> 20 #include <iostream> 21 #include <memory> 22 #include <mutex> 23 #include <string> 24 #include <vector> 25 #include "camera_metadata_info.h" 26 #include "icamera_device.h" 27 #include "icamera_host.h" 28 #include "icamera_service_callback.h" 29 #include "iservstat_listener_hdi.h" 30 31 namespace OHOS { 32 namespace CameraStandard { 33 class HCameraHostManager : public virtual RefBase, public HDI::ServiceManager::V1_0::ServStatListenerStub { 34 public: 35 class StatusCallback { 36 public: 37 virtual ~StatusCallback() = default; 38 virtual void OnCameraStatus(const std::string& cameraId, CameraStatus status) = 0; 39 virtual void OnFlashlightStatus(const std::string& cameraId, FlashStatus status) = 0; 40 }; 41 42 explicit HCameraHostManager(StatusCallback* statusCallback); 43 ~HCameraHostManager() override; 44 45 int32_t Init(void); 46 void DeInit(void); 47 virtual int32_t GetCameras(std::vector<std::string> &cameraIds); 48 virtual int32_t GetCameraAbility(std::string &cameraId, std::shared_ptr<Camera::CameraMetadata> &ability); 49 virtual int32_t OpenCameraDevice(std::string &cameraId, 50 const sptr<Camera::ICameraDeviceCallback> &callback, 51 sptr<Camera::ICameraDevice> &pDevice); 52 virtual int32_t SetFlashlight(const std::string& cameraId, bool isEnable); 53 54 // HDI::ServiceManager::V1_0::IServStatListener 55 void OnReceive(const HDI::ServiceManager::V1_0::ServiceStatus& status) override; 56 57 private: 58 struct CameraDeviceInfo; 59 class CameraHostInfo; 60 61 void AddCameraHost(const std::string& svcName); 62 void RemoveCameraHost(const std::string& svcName); 63 sptr<CameraHostInfo> FindCameraHostInfo(const std::string& cameraId); 64 65 std::mutex mutex_; 66 StatusCallback* statusCallback_; 67 std::vector<sptr<CameraHostInfo>> cameraHostInfos_; 68 }; 69 } // namespace CameraStandard 70 } // namespace OHOS 71 #endif // OHOS_CAMERA_H_CAMERA_HOST_MANAGER_H 72