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 #ifndef HCE_SESSION_STUB_H
16 #define HCE_SESSION_STUB_H
17 
18 #include "access_token.h"
19 #include "ihce_cmd_callback.h"
20 #include "iremote_stub.h"
21 #include "ihce_session.h"
22 #include "message_parcel.h"
23 #include "start_hce_info_parcelable.h"
24 
25 namespace OHOS {
26 namespace NFC {
27 namespace HCE {
28 class HceSessionStub : public OHOS::IRemoteStub<OHOS::NFC::HCE::IHceSession> {
29 public:
30     int OnRemoteRequest(uint32_t code,                         /* [in] */
31                         OHOS::MessageParcel& data,             /* [in] */
32                         OHOS::MessageParcel& reply,            /* [out] */
33                         OHOS::MessageOption& option) override; /* [in] */
HceSessionStub()34     HceSessionStub() {}
~HceSessionStub()35     virtual ~HceSessionStub() {}
36 
37     virtual KITS::ErrorCode RegHceCmdCallbackByToken(const sptr<KITS::IHceCmdCallback>& callback,
38                                                      const std::string& type,
39                                                      Security::AccessToken::AccessTokenID callerToken) = 0;
40 
41     virtual KITS::ErrorCode UnRegHceCmdCallback(const std::string& type,
42                                                 Security::AccessToken::AccessTokenID callerToken) = 0;
43     virtual KITS::ErrorCode UnRegAllCallback(Security::AccessToken::AccessTokenID callerToken) = 0;
44     virtual KITS::ErrorCode HandleWhenRemoteDie(Security::AccessToken::AccessTokenID callerToken) = 0;
45 
46     virtual KITS::ErrorCode StopHce(const ElementName& element,
47                                     Security::AccessToken::AccessTokenID callerToken) = 0;
48 
49     virtual int SendRawFrameByToken(std::string hexCmdData, bool raw, std::string& hexRespData,
50                                     Security::AccessToken::AccessTokenID callerToken) = 0;
51 
52     void RemoveHceDeathRecipient(const wptr<IRemoteObject>& remote);
53 
54 private:
55     int HandleRegHceCmdCallback(MessageParcel& data, MessageParcel& reply);
56 
57     int HandleSendRawFrame(OHOS::MessageParcel& data, OHOS::MessageParcel& reply);
58 
59     int HandleGetPaymentServices(MessageParcel& data, MessageParcel& reply);
60 
61     int HandleStopHce(MessageParcel& data, MessageParcel& reply);
62 
63     int HandleStartHce(MessageParcel& data, MessageParcel& reply);
64 
65     KITS::ErrorCode StartHceInner(std::shared_ptr<KITS::StartHceInfoParcelable> startHceInfo);
66 
67     int HandleIsDefaultService(MessageParcel& data, MessageParcel& reply);
68 
69     KITS::ErrorCode RegHceCmdCallback(const sptr<KITS::IHceCmdCallback>& callback,
70                                       const std::string& type) override;
71 
72     int SendRawFrame(std::string hexCmdData, bool raw, std::string& hexRespData) override;
73     KITS::ErrorCode StopHce(ElementName &element) override;
74 
75 private:
76     std::mutex mutex_{};
77     sptr<KITS::IHceCmdCallback> hceCmdCallback_;
78     sptr<IRemoteObject::DeathRecipient> deathRecipient_{nullptr};
79 };
80 } // namespace HCE
81 } // namespace NFC
82 } // namespace OHOS
83 #endif // HCE_SESSION_STUB_H
84