• 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 #include "distributed_manager.h"
17 
18 #include "distributed_server.h"
19 #include "distributed_client.h"
20 #include "distributed_service.h"
21 #include "distributed_local_config.h"
22 #include "ans_log_wrapper.h"
23 #include "distributed_liveview_all_scenarios_extension_wrapper.h"
24 
25 namespace OHOS {
26 namespace Notification {
DistributedManager()27 DistributedManager::DistributedManager()
28 {
29     DistributedClient::GetInstance();
30     DistributedServer::GetInstance();
31 }
32 
GetInstance()33 DistributedManager& DistributedManager::GetInstance()
34 {
35     static DistributedManager distributedManager;
36     return distributedManager;
37 }
38 
ReleaseLocalDevice()39 void DistributedManager::ReleaseLocalDevice()
40 {
41     DistributedService::GetInstance().DestoryService();
42 }
43 
InitLocalDevice(const std::string & deviceId,uint16_t deviceType,const DistributedDeviceConfig config)44 int32_t DistributedManager::InitLocalDevice(const std::string &deviceId, uint16_t deviceType,
45     const DistributedDeviceConfig config)
46 {
47     ANS_LOGI("InitLocalDevice %{public}s %{public}d.", StringAnonymous(deviceId).c_str(), (int32_t)(deviceType));
48     DISTRIBUTED_LIVEVIEW_ALL_SCENARIOS_EXTENTION_WRAPPER->InitExtentionWrapper();
49     DistributedLocalConfig::GetInstance().SetLocalDevice(config);
50     return DistributedService::GetInstance().InitService(deviceId, deviceType);
51 }
52 
AddDevice(const std::string & deviceId,uint16_t deviceType,const std::string & networkId)53 void DistributedManager::AddDevice(const std::string &deviceId, uint16_t deviceType,
54     const std::string &networkId)
55 {
56     ANS_LOGI("InitLocalDevice %{public}s %{public}d %{public}s.", StringAnonymous(deviceId).c_str(),
57         (int32_t)(deviceType), StringAnonymous(networkId).c_str());
58     DistributedDeviceInfo peerDevice = DistributedDeviceInfo(deviceType, deviceId, networkId);
59     DistributedClient::GetInstance().AddDevice(peerDevice);
60     DistributedService::GetInstance().AddDevice(peerDevice);
61 }
62 
ReleaseDevice(const std::string & deviceId,uint16_t deviceType)63 void DistributedManager::ReleaseDevice(const std::string &deviceId, uint16_t deviceType)
64 {
65     ANS_LOGI("ReleaseDevice %{public}s %{public}d.", StringAnonymous(deviceId).c_str(), (int32_t)(deviceType));
66     DISTRIBUTED_LIVEVIEW_ALL_SCENARIOS_EXTENTION_WRAPPER->CloseExtentionWrapper();
67     DistributedClient::GetInstance().ReleaseDevice(deviceId, deviceType);
68     DistributedService::GetInstance().UnSubscribeNotifictaion(deviceId, deviceType);
69 }
70 
RefreshDevice(const std::string & deviceId,uint16_t deviceType,const std::string & networkId)71 void DistributedManager::RefreshDevice(const std::string &deviceId, uint16_t deviceType,
72     const std::string &networkId)
73 {
74     ANS_LOGI("RefreshDevice %{public}s %{public}d %{public}s.", StringAnonymous(deviceId).c_str(),
75         (int32_t)(deviceType), StringAnonymous(networkId).c_str());
76     DistributedClient::GetInstance().RefreshDevice(deviceId, deviceType, networkId);
77 }
78 
InitHACallBack(std::function<void (int32_t,int32_t,uint32_t,std::string)> callback)79 void DistributedManager::InitHACallBack(std::function<void(int32_t, int32_t, uint32_t, std::string)> callback)
80 {
81     DistributedService::GetInstance().InitHACallBack(callback);
82 }
83 
InitSendReportCallBack(std::function<void (int32_t,int32_t,std::string)> callback)84 void DistributedManager::InitSendReportCallBack(std::function<void(int32_t, int32_t, std::string)> callback)
85 {
86     DistributedService::GetInstance().InitSendReportCallBack(callback);
87 }
88 
89 }
90 }
91