• 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 #ifndef NOTIFICATION_DISTRIBUTED_EXTENSION_SERVICE_H
17 #define NOTIFICATION_DISTRIBUTED_EXTENSION_SERVICE_H
18 
19 #include "device_manager.h"
20 
21 #include "notifictaion_load_utils.h"
22 #include "ffrt.h"
23 #include "notification_config_parse.h"
24 #include "distributed_data_define.h"
25 #include "ffrt.h"
26 
27 #include <set>
28 #include <mutex>
29 #include <unordered_set>
30 
31 namespace OHOS {
32 namespace Notification {
33 using namespace DistributedHardware;
34 
35 class DistributedDeviceInfo {
36 public:
DistributedDeviceInfo()37     DistributedDeviceInfo() {}
DistributedDeviceInfo(std::string deviceId,std::string deviceName,std::string networkId,uint16_t deviceType)38     DistributedDeviceInfo(std::string deviceId, std::string deviceName,
39         std::string networkId, uint16_t deviceType) : deviceId_(deviceId),
40         deviceName_(deviceName), networkId_(networkId), deviceType_(deviceType) { }
41     ~DistributedDeviceInfo() = default;
42     std::string deviceId_;
43     std::string deviceName_;
44     std::string networkId_;
45     uint16_t deviceType_;
46 };
47 
48 class DistributedExtensionService {
49 public:
50     bool initConfig();
51     int32_t InitDans();
52     int32_t ReleaseLocalDevice();
53     void OnAllConnectOnline();
54     void OnDeviceOnline(const DmDeviceInfo &deviceInfo);
55     void OnDeviceOffline(const DmDeviceInfo &deviceInfo);
56     void OnDeviceChanged(const DmDeviceInfo &deviceInfo);
57     void DeviceStatusChange(const DeviceStatueChangeInfo& changeInfo);
58     static DistributedExtensionService& GetInstance();
59     static std::string TransDeviceTypeToName(uint16_t deviceType_);
60     static std::string DeviceTypeToTypeString(uint16_t deviceType_);
61     void HADotCallback(int32_t code, int32_t ErrCode, uint32_t branchId, std::string reason);
62     void SendReportCallback(int32_t messageType, int32_t errCode, std::string reason);
63     int32_t GetOperationReplyTimeout();
64     int32_t TransDeviceIdToUdid(const std::string& networkId, std::string& udid);
65     void HaOperationCallback(const std::string& deviceType, int32_t sceneType, int32_t slotType, std::string reason);
66 
67 private:
68     DistributedExtensionService();
69     ~DistributedExtensionService();
70     void SetMaxContentLength(nlohmann::json &configJson);
71     void SetOperationReplyTimeout(nlohmann::json &configJson);
72     bool SetLocalType(nlohmann::json &configJson);
73     bool SetSupportPeerDevice(nlohmann::json &configJson);
74     bool SetMaxTitleLength(nlohmann::json &configJson);
75 
76     ffrt::mutex mapLock_;
77     std::atomic<bool> dansRunning_ = false;
78     std::shared_ptr<ffrt::queue> distributedQueue_ = nullptr;
79     std::shared_ptr<NotificationLoadUtils> dansHandler_;
80     std::map<std::string, DistributedDeviceInfo> deviceMap_;
81     DistributedDeviceConfig deviceConfig_;
82 };
83 }
84 }
85 #endif // NOTIFICATION_DISTRIBUTED_EXTENSION_SERVICE_H
86