1 /* 2 * Copyright (c) 2023 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_VDI_CAMERA_V1_0_ICAMERAHOSTVDI_H 17 #define OHOS_VDI_CAMERA_V1_0_ICAMERAHOSTVDI_H 18 19 #include <stdint.h> 20 #include <string> 21 #include <vector> 22 #include <hdf_base.h> 23 #include <hdi_base.h> 24 #include "v1_0/icamera_device_vdi.h" 25 #include "v1_0/icamera_device_vdi_callback.h" 26 #include "v1_0/icamera_host_vdi_callback.h" 27 #include "hdf_load_vdi.h" 28 #include "camera.h" 29 30 31 namespace OHOS { 32 namespace VDI { 33 namespace Camera { 34 namespace V1_0 { 35 using namespace OHOS; 36 using namespace OHOS::HDI; 37 38 class ICameraHostVdi : public HdiBase { 39 public: 40 class CameraHostCallBackDeathRecipient : public IRemoteObject::DeathRecipient { 41 public: CameraHostCallBackDeathRecipient(const sptr<ICameraHostVdi> & cameraHostVdi)42 explicit CameraHostCallBackDeathRecipient(const sptr<ICameraHostVdi> &cameraHostVdi) 43 : cameraHostVdi_(cameraHostVdi) {} 44 45 virtual ~CameraHostCallBackDeathRecipient() = default; 46 OnRemoteDied(const wptr<IRemoteObject> & object)47 void OnRemoteDied(const wptr<IRemoteObject> &object) override 48 { 49 CAMERA_LOGE("Remote died, do clean works."); 50 51 if (cameraHostVdi_ == nullptr) { 52 return; 53 } 54 55 (void) cameraHostVdi_->CloseAllCameras(); 56 } 57 58 private: 59 sptr<ICameraHostVdi> cameraHostVdi_; 60 }; 61 62 virtual ~ICameraHostVdi() = default; 63 64 static ICameraHostVdi* Get(bool isStub = false); 65 static ICameraHostVdi* Get(const std::string &serviceName, bool isStub = false); 66 SetCallback(const sptr<ICameraHostVdiCallback> & callbackObj)67 virtual int32_t SetCallback(const sptr<ICameraHostVdiCallback> &callbackObj) 68 { 69 sptr<CameraHostCallBackDeathRecipient> callBackDeathRecipient = 70 new CameraHostCallBackDeathRecipient(this); 71 72 const sptr<IRemoteObject> remote = callbackObj->Remote(); 73 if (nullptr == remote) { 74 CAMERA_LOGE("No remote of hostcallback, set deathcallback fail."); 75 76 return VDI::Camera::V1_0::INVALID_ARGUMENT; 77 } 78 79 bool res = remote->AddDeathRecipient(callBackDeathRecipient); 80 if (!res) { 81 return VDI::Camera::V1_0::INVALID_ARGUMENT; 82 } 83 return VDI::Camera::V1_0::NO_ERROR; 84 } 85 86 virtual int32_t GetCameraIds(std::vector<std::string> &cameraIds) = 0; 87 88 virtual int32_t GetCameraAbility(const std::string &cameraId, std::vector<uint8_t> &cameraAbility) = 0; 89 90 virtual int32_t OpenCamera(const std::string &cameraId, const sptr<ICameraDeviceVdiCallback> &callbackObj, 91 sptr<ICameraDeviceVdi> &device) = 0; 92 93 virtual int32_t SetFlashlight(const std::string &cameraId, bool isEnable) = 0; 94 95 virtual int32_t CloseAllCameras() = 0; 96 }; 97 98 struct VdiWrapperCameraHost { 99 struct HdfVdiBase base; 100 ICameraHostVdi *module; 101 }; 102 } // V1_0 103 } // Camera 104 } // VDI 105 } // OHOS 106 #endif // OHOS_VDI_CAMERA_V1_0_ICAMERAHOSTVDI_H 107