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