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