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 #include <dlfcn.h>
16 #include <cstdint>
17 #include <utility>
18
19 #include "distributed_server.h"
20 #include "distributed_client.h"
21 #include "distributed_service.h"
22 #include "distributed_local_config.h"
23 #include "ans_log_wrapper.h"
24 #include "analytics_util.h"
25
26 #define SYMBOL_EXPORT __attribute__ ((visibility("default")))
27 namespace OHOS {
28 namespace Notification {
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
InitLocalDevice(const std::string & deviceId,uint16_t deviceType,DistributedDeviceConfig config,DistributedHaCallbacks callbacks)33 SYMBOL_EXPORT int32_t InitLocalDevice(const std::string &deviceId, uint16_t deviceType,
34 DistributedDeviceConfig config, DistributedHaCallbacks callbacks)
35 {
36 ANS_LOGI("InitLocalDevice %{public}s %{public}d.", StringAnonymous(deviceId).c_str(), (int32_t)(deviceType));
37 AnalyticsUtil::GetInstance().InitOperationCallback(callbacks.haOperationCallback);
38 AnalyticsUtil::GetInstance().InitHACallBack(callbacks.haMaintenanceCallback);
39 AnalyticsUtil::GetInstance().InitSendReportCallBack(callbacks.hiSysEventCallback);
40 DistributedLocalConfig::GetInstance().SetLocalDevice(config);
41 return DistributedService::GetInstance().InitService(deviceId, deviceType);
42 }
43
AddDevice(const std::string & deviceId,const std::string & udid,uint16_t deviceType,const std::string & networkId)44 SYMBOL_EXPORT void AddDevice(const std::string &deviceId, const std::string &udid, uint16_t deviceType,
45 const std::string &networkId)
46 {
47 ANS_LOGI("AddDevice %{public}s %{public}d %{public}s.", StringAnonymous(deviceId).c_str(),
48 (int32_t)(deviceType), StringAnonymous(networkId).c_str());
49 DistributedDeviceInfo peerDevice = DistributedDeviceInfo(deviceType, deviceId, networkId);
50 peerDevice.udid_ = udid;
51 DistributedClient::GetInstance().AddDevice(peerDevice);
52 DistributedService::GetInstance().AddDevice(peerDevice);
53 }
54
DeviceStatusChange(const DeviceStatueChangeInfo & changeInfo)55 SYMBOL_EXPORT void DeviceStatusChange(const DeviceStatueChangeInfo& changeInfo)
56 {
57 ANS_LOGI("Device StatusChange %{public}s %{public}d.", StringAnonymous(changeInfo.deviceId).c_str(),
58 changeInfo.changeType);
59 DistributedService::GetInstance().DeviceStatusChange(changeInfo);
60 }
61
ReleaseDevice(const std::string & deviceId,uint16_t deviceType)62 SYMBOL_EXPORT void ReleaseDevice(const std::string &deviceId, uint16_t deviceType)
63 {
64 ANS_LOGI("ReleaseDevice %{public}s %{public}d.", StringAnonymous(deviceId).c_str(), (int32_t)(deviceType));
65 DistributedClient::GetInstance().ReleaseDevice(deviceId, deviceType);
66 DistributedService::GetInstance().ReleaseDevice(deviceId, deviceType);
67 }
68
RefreshDevice(const std::string & deviceId,uint16_t deviceType,const std::string & networkId)69 SYMBOL_EXPORT void RefreshDevice(const std::string &deviceId, uint16_t deviceType,
70 const std::string &networkId)
71 {
72 ANS_LOGI("RefreshDevice %{public}s %{public}d %{public}s.", StringAnonymous(deviceId).c_str(),
73 (int32_t)(deviceType), StringAnonymous(networkId).c_str());
74 DistributedClient::GetInstance().RefreshDevice(deviceId, deviceType, networkId);
75 }
76
ReleaseLocalDevice()77 SYMBOL_EXPORT void ReleaseLocalDevice()
78 {
79 DistributedService::GetInstance().DestroyService();
80 }
81
82 #ifdef __cplusplus
83 }
84 #endif
85 } // namespace Notification
86 } // namespace OHOS
87