• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #include "softbus_adapter.h"
17 
18 #include <securec.h>
19 #include <unistd.h>
20 #include "dm_log.h"
21 #include "softbus_bus_center.h"
22 #include "softbus_common.h"
23 #include "device_manager_service.h"
24 namespace OHOS {
25 namespace DistributedHardware {
26 IMPLEMENT_SINGLE_INSTANCE(SoftbusAdapter);
DmOnSoftbusSessionOpened(int32_t sessionId,int32_t result)27 static int32_t DmOnSoftbusSessionOpened(int32_t sessionId, int32_t result)
28 {
29     SoftbusAdapter::GetInstance().OnSoftbusSessionOpened(sessionId, result);
30     return DM_OK;
31 }
32 
DmOnSoftbusSessionClosed(int32_t sessionId)33 static void DmOnSoftbusSessionClosed(int32_t sessionId)
34 {
35     SoftbusAdapter::GetInstance().OnSoftbusSessionClosed(sessionId);
36 }
37 
DmOnBytesReceived(int32_t sessionId,const void * data,uint32_t dataLen)38 static void DmOnBytesReceived(int32_t sessionId, const void *data, uint32_t dataLen)
39 {
40     SoftbusAdapter::GetInstance().OnBytesReceived(sessionId, data, dataLen);
41 }
42 
DmOnStreamReceived(int32_t sessionId,const StreamData * data,const StreamData * ext,const StreamFrameInfo * frameInfo)43 static void DmOnStreamReceived(int32_t sessionId, const StreamData *data, const StreamData *ext,
44     const StreamFrameInfo *frameInfo)
45 {
46     SoftbusAdapter::GetInstance().OnStreamReceived(sessionId, data, ext, frameInfo);
47 }
48 
DmOnMessageReceived(int sessionId,const void * data,unsigned int dataLen)49 static void DmOnMessageReceived(int sessionId, const void *data, unsigned int dataLen)
50 {
51     SoftbusAdapter::GetInstance().OnMessageReceived(sessionId, data, dataLen);
52 }
53 
DmOnQosEvent(int sessionId,int eventId,int tvCount,const QosTv * tvList)54 static void DmOnQosEvent(int sessionId, int eventId, int tvCount, const QosTv *tvList)
55 {
56     SoftbusAdapter::GetInstance().OnQosEvent(sessionId, eventId, tvCount, tvList);
57 }
58 
SoftbusAdapter()59 SoftbusAdapter::SoftbusAdapter()
60 {
61     LOGI("SoftbusAdapter");
62     sessListener_.OnSessionOpened = DmOnSoftbusSessionOpened;
63     sessListener_.OnSessionClosed = DmOnSoftbusSessionClosed;
64     sessListener_.OnBytesReceived = DmOnBytesReceived;
65     sessListener_.OnStreamReceived = DmOnStreamReceived;
66     sessListener_.OnMessageReceived = DmOnMessageReceived;
67     sessListener_.OnQosEvent = DmOnQosEvent;
68 }
69 
~SoftbusAdapter()70 SoftbusAdapter::~SoftbusAdapter()
71 {
72     LOGI("~SoftbusAdapter");
73 }
74 
CreateSoftbusSessionServer(const std::string & pkgname,const std::string & sessionName)75 int32_t SoftbusAdapter::CreateSoftbusSessionServer(const std::string &pkgname, const std::string &sessionName)
76 {
77     LOGI("SoftbusAdapter::CreateSoftbusSessionServer.");
78     if (CreateSessionServer(pkgname.c_str(), sessionName.c_str(), &sessListener_) != DM_OK) {
79         LOGE("CreateSoftbusSessionServer failed.");
80         return ERR_DM_FAILED;
81     }
82     LOGI("SoftbusAdapter::CreateSoftbusSessionServer success.");
83     return DM_OK;
84 }
85 
RemoveSoftbusSessionServer(const std::string & pkgname,const std::string & sessionName)86 int32_t SoftbusAdapter::RemoveSoftbusSessionServer(const std::string &pkgname, const std::string &sessionName)
87 {
88     LOGI("SoftbusAdapter::RemoveSoftbusSessionServer");
89     if (RemoveSessionServer(pkgname.c_str(), sessionName.c_str()) != DM_OK) {
90         LOGE("RemoveSoftbusSessionServer failed.");
91         return ERR_DM_FAILED;
92     }
93     LOGI("SoftbusAdapter::RemoveSoftbusSessionServer success.");
94     return DM_OK;
95 }
96 
OnSoftbusSessionOpened(int32_t sessionId,int32_t result)97 void SoftbusAdapter::OnSoftbusSessionOpened(int32_t sessionId, int32_t result)
98 {
99     LOGI("SoftbusAdapter::OnSoftbusSessionOpened");
100     DeviceManagerService::GetInstance().OnUnbindSessionOpened(sessionId, result);
101 }
102 
OnSoftbusSessionClosed(int32_t sessionId)103 void SoftbusAdapter::OnSoftbusSessionClosed(int32_t sessionId)
104 {
105     LOGI("SoftbusAdapter::OnSoftbusSessionClosed");
106     DeviceManagerService::GetInstance().OnUnbindSessionCloseed(sessionId);
107 }
108 
OnBytesReceived(int32_t sessionId,const void * data,uint32_t dataLen)109 void SoftbusAdapter::OnBytesReceived(int32_t sessionId, const void *data, uint32_t dataLen)
110 {
111     LOGI("SoftbusAdapter::OnBytesReceived");
112     DeviceManagerService::GetInstance().OnUnbindBytesReceived(sessionId, data, dataLen);
113 }
114 
OnStreamReceived(int32_t sessionId,const StreamData * data,const StreamData * ext,const StreamFrameInfo * frameInfo)115 void SoftbusAdapter::OnStreamReceived(int32_t sessionId, const StreamData *data, const StreamData *ext,
116     const StreamFrameInfo *frameInfo)
117 {
118     (void)data;
119     (void)ext;
120     (void)frameInfo;
121     LOGI("SoftbusAdapter::OnStreamReceived, sessionId:%d", sessionId);
122 }
123 
OnMessageReceived(int sessionId,const void * data,unsigned int dataLen) const124 void SoftbusAdapter::OnMessageReceived(int sessionId, const void *data, unsigned int dataLen) const
125 {
126     (void)data;
127     (void)dataLen;
128     LOGI("SoftbusAdapter::OnMessageReceived, sessionId:%d", sessionId);
129 }
130 
OnQosEvent(int sessionId,int eventId,int tvCount,const QosTv * tvList) const131 void SoftbusAdapter::OnQosEvent(int sessionId, int eventId, int tvCount, const QosTv *tvList) const
132 {
133     (void)eventId;
134     (void)tvCount;
135     (void)tvList;
136     LOGI("SoftbusAdapter::OnQosEvent, sessionId:%d", sessionId);
137 }
138 } // namespace DistributedHardware
139 } // namespace OHOS