1 /* 2 * Copyright (c) 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 I_STANDARD_CAMERA_LISTENER_H 17 #define I_STANDARD_CAMERA_LISTENER_H 18 19 #include "ipc_types.h" 20 #include "iremote_broker.h" 21 #include "iremote_proxy.h" 22 #include "iremote_stub.h" 23 #include "input/camera_death_recipient.h" 24 #include <mutex> 25 26 27 namespace OHOS { 28 namespace CameraStandard { 29 class IStandardCameraListener : public IRemoteBroker { 30 public: 31 virtual ~IStandardCameraListener() = default; 32 DECLARE_INTERFACE_DESCRIPTOR(u"IStandardCameraListener"); 33 AddCameraDeathRecipient(sptr<CameraDeathRecipient> & deathRecipient)34 void AddCameraDeathRecipient(sptr<CameraDeathRecipient> &deathRecipient) 35 { 36 std::lock_guard<std::mutex> lock(deathRecipientLock_); 37 if (this->AsObject() != nullptr) { 38 (void)this->AsObject()->AddDeathRecipient(deathRecipient); 39 } 40 deathRecipient_ = deathRecipient; 41 } 42 RemoveCameraDeathRecipient()43 void RemoveCameraDeathRecipient() 44 { 45 std::lock_guard<std::mutex> lock(deathRecipientLock_); 46 (void)this->AsObject()->RemoveDeathRecipient(deathRecipient_.promote()); 47 } 48 private: 49 std::mutex deathRecipientLock_; 50 wptr<CameraDeathRecipient> deathRecipient_ = nullptr; 51 }; 52 } // namespace CameraStandard 53 } // namespace OHOS 54 #endif // I_STANDARD_CAMERA_LISTENER_H 55