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 #include "securec.h"
17 
18 #include "remote_connect_manager.h"
19 #include "remote_connect_listener.h"
20 #include "remote_connect_listener_manager.h"
21 #include "soft_bus_manager.h"
22 #include "device_manager.h"
23 
24 #define LOG_TAG "USER_AUTH_SA"
25 namespace OHOS {
26 namespace UserIam {
27 namespace UserAuth {
28 using namespace OHOS::DistributedHardware;
GetInstance()29 RemoteConnectionManager &RemoteConnectionManager::GetInstance()
30 {
31     IAM_LOGD("start.");
32     static RemoteConnectionManager instance;
33     return instance;
34 }
35 
OpenConnection(const std::string & connectionName,std::string remoteNetworkId,uint32_t tokenId)36 ResultCode RemoteConnectionManager::OpenConnection(const std::string &connectionName,
37     std::string remoteNetworkId, uint32_t tokenId)
38 {
39     IAM_LOGD("start.");
40     return SoftBusManager::GetInstance().OpenConnection(connectionName, tokenId, remoteNetworkId);
41 }
42 
CloseConnection(const std::string & connectionName)43 ResultCode RemoteConnectionManager::CloseConnection(const std::string &connectionName)
44 {
45     IAM_LOGD("start.");
46     return SoftBusManager::GetInstance().CloseConnection(connectionName);
47 }
48 
RegisterConnectionListener(const std::string & connectionName,const std::string & endPointName,const std::shared_ptr<ConnectionListener> & listener)49 ResultCode RemoteConnectionManager::RegisterConnectionListener(const std::string &connectionName,
50     const std::string &endPointName, const std::shared_ptr<ConnectionListener> &listener)
51 {
52     IAM_LOGD("start.");
53     return RemoteConnectListenerManager::GetInstance().RegisterListener(connectionName, endPointName, listener);
54 }
55 
RegisterConnectionListener(const std::string & endPointName,const std::shared_ptr<ConnectionListener> & listener)56 ResultCode RemoteConnectionManager::RegisterConnectionListener(const std::string &endPointName,
57     const std::shared_ptr<ConnectionListener> &listener)
58 {
59     IAM_LOGD("start.");
60     return RemoteConnectListenerManager::GetInstance().RegisterListener(endPointName, listener);
61 }
62 
UnregisterConnectionListener(const std::string & connectionName,const std::string & endPointName)63 ResultCode RemoteConnectionManager::UnregisterConnectionListener(const std::string &connectionName,
64     const std::string &endPointName)
65 {
66     IAM_LOGD("start.");
67     return RemoteConnectListenerManager::GetInstance().UnregisterListener(connectionName, endPointName);
68 }
69 
UnregisterConnectionListener(const std::string & endPointName)70 ResultCode RemoteConnectionManager::UnregisterConnectionListener(const std::string &endPointName)
71 {
72     IAM_LOGD("start.");
73     return RemoteConnectListenerManager::GetInstance().UnregisterListener(endPointName);
74 }
75 
SendMessage(const std::string & connectionName,const std::string & srcEndPoint,const std::string & destEndPoint,const std::shared_ptr<Attributes> & attributes,MsgCallback & callback)76 ResultCode RemoteConnectionManager::SendMessage(const std::string &connectionName,
77     const std::string &srcEndPoint, const std::string &destEndPoint,
78     const std::shared_ptr<Attributes> &attributes, MsgCallback &callback)
79 {
80     IAM_LOGD("start.");
81     return SoftBusManager::GetInstance().SendMessage(connectionName,
82         srcEndPoint, destEndPoint, attributes, callback);
83 }
84 } // namespace UserAuth
85 } // namespace UserIam
86 } // namespace OHOS
87