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 #include "nfc_controller_death_recipient.h"
17 #include "loghelper.h"
18 #include "nfc_sdk_common.h"
19
20 namespace OHOS {
21 namespace NFC {
NfcControllerDeathRecipient(sptr<NfcControllerStub> nfcConctrolService,Security::AccessToken::AccessTokenID callerToken)22 NfcControllerDeathRecipient::NfcControllerDeathRecipient(
23 sptr<NfcControllerStub> nfcConctrolService, Security::AccessToken::AccessTokenID callerToken)
24 {
25 InfoLog("NfcControllerDeathRecipient, ##callerToken=%{public}d\n", callerToken);
26 nfcConctrolService_ = nfcConctrolService;
27 callerToken_ = callerToken;
28 }
29
OnRemoteDied(const wptr<IRemoteObject> & remote)30 void NfcControllerDeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
31 {
32 ErrorLog("NfcControllerDeathRecipient::OnRemoteDied.");
33 if (nfcConctrolService_ == nullptr) {
34 ErrorLog("NfcControllerDeathRecipient nfcConctrolService_ is nullptr!");
35 return;
36 }
37 std::lock_guard<std::mutex> lock(mutex_);
38 InfoLog("OnRemoteDied, ##callerToken=%{public}d\n", callerToken_);
39 KITS::ErrorCode ret = nfcConctrolService_->UnRegisterAllCallBack(callerToken_);
40 InfoLog("OnRemoteDied, UnRegisterAllCallBack##ret=%{public}d\n", ret);
41 nfcConctrolService_->RemoveNfcDeathRecipient(remote);
42 }
43 } // namespace NFC
44 } // namespace OHOS