1 /*
2  * Copyright (c) 2024 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_PIN_HOLDER_SESSION_H
17 #define OHOS_PIN_HOLDER_SESSION_H
18 
19 #include "dm_device_info.h"
20 #include "pinholder_session_callback.h"
21 
22 #include "inner_session.h"
23 #include "session.h"
24 #include "softbus_bus_center.h"
25 
26 namespace OHOS {
27 namespace DistributedHardware {
28 class PinHolderSession {
29 public:
30     static int OnSessionOpened(int sessionId, int result);
31     static void OnSessionClosed(int sessionId);
32     static void OnBytesReceived(int sessionId, const void *data, unsigned int dataLen);
33 
34 public:
35     PinHolderSession();
36     ~PinHolderSession();
37 
38     /**
39      * @tc.name: PinHolderSession::RegisterSessionCallback
40      * @tc.desc: RegisterSessionCallback of the Softbus Session
41      * @tc.type: FUNC
42      */
43     int32_t RegisterSessionCallback(std::shared_ptr<IPinholderSessionCallback> callback);
44 
45     /**
46      * @tc.name: PinHolderSession::UnRegisterSessionCallback
47      * @tc.desc: UnRegister SessionCallback of the Softbus Session
48      * @tc.type: FUNC
49      */
50     int32_t UnRegisterSessionCallback();
51 
52     /**
53      * @tc.name: PinHolderSession::OpenAuthSession
54      * @tc.desc: Open AuthSession of the Softbus Session
55      * @tc.type: FUNC
56      */
57     int32_t OpenSessionServer(const PeerTargetId &targetId);
58 
59     /**
60      * @tc.name: PinHolderSession::CloseAuthSession
61      * @tc.desc: Close AuthSession of the Softbus Session
62      * @tc.type: FUNC
63      */
64     int32_t CloseSessionServer(int32_t sessionId);
65 
66     /**
67      * @tc.name: PinHolderSession::SendData
68      * @tc.desc: Send Data of the Softbus Session
69      * @tc.type: FUNC
70      */
71     int32_t SendData(int32_t sessionId, const std::string &message);
72 
73 private:
74     int32_t GetAddrByTargetId(const PeerTargetId &targetId, ConnectionAddr &addrInfo);
75 
76 private:
77     static std::shared_ptr<IPinholderSessionCallback> pinholderSessionCallback_;
78 };
79 }
80 }
81 #endif // OHOS_PIN_HOLDER_SESSION_H