1 /*
2 * Copyright (c) 2020 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 "dmslite_devmgr.h"
17
18 #include "dmslite_session.h"
19 #include "securec.h"
20 #include "softbus_bus_center.h"
21
22 #define DMSLITE_BUNDLE_NAME "dmslite"
23
24 static char g_peerDevId[NETWORK_ID_BUF_LEN] = {0};
25
26 static void onNodeOnline(NodeBasicInfo *info);
27 static void onNodeOffline(NodeBasicInfo *info);
28 static void onNodeBasicInfoChanged(NodeBasicInfoType type, NodeBasicInfo *info);
29
30 static INodeStateCb g_networkListener = {
31 .events = EVENT_NODE_STATE_ONLINE | EVENT_NODE_STATE_OFFLINE,
32 .onNodeOnline = onNodeOnline,
33 .onNodeOffline = onNodeOffline,
34 .onNodeBasicInfoChanged = onNodeBasicInfoChanged
35 };
36
onNodeOnline(NodeBasicInfo * info)37 void onNodeOnline(NodeBasicInfo *info)
38 {
39 if (info == NULL) {
40 return;
41 }
42 (void)strncpy_s(g_peerDevId, NETWORK_ID_BUF_LEN, info->networkId, sizeof(info->networkId));
43 CreateDMSSessionServer();
44 }
45
onNodeOffline(NodeBasicInfo * info)46 void onNodeOffline(NodeBasicInfo *info)
47 {
48 if (info == NULL) {
49 return;
50 }
51 (void)memset_s(g_peerDevId, NETWORK_ID_BUF_LEN, 0x00, NETWORK_ID_BUF_LEN);
52 CloseDMSSessionServer();
53 }
54
onNodeBasicInfoChanged(NodeBasicInfoType type,NodeBasicInfo * info)55 void onNodeBasicInfoChanged(NodeBasicInfoType type, NodeBasicInfo *info)
56 {
57 return;
58 }
59
AddDevMgrListener()60 int32_t AddDevMgrListener()
61 {
62 return RegNodeDeviceStateCb(DMSLITE_BUNDLE_NAME, &g_networkListener);
63 }
64
UnRegisterDevMgrListener()65 int32_t UnRegisterDevMgrListener()
66 {
67 return UnregNodeDeviceStateCb(&g_networkListener);
68 }
69
GetPeerId()70 char* GetPeerId()
71 {
72 return g_peerDevId;
73 }
74