• 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 
26 #include <set>
27 #include <mutex>
28 #include <unordered_set>
29 
30 namespace OHOS {
31 namespace Notification {
32 using namespace DistributedHardware;
33 
34 class DistributedDeviceInfo {
35 public:
DistributedDeviceInfo()36     DistributedDeviceInfo() {}
DistributedDeviceInfo(std::string deviceId,std::string deviceName,std::string networkId,uint16_t deviceType)37     DistributedDeviceInfo(std::string deviceId, std::string deviceName,
38         std::string networkId, uint16_t deviceType) : deviceId_(deviceId),
39         deviceName_(deviceName), networkId_(networkId), deviceType_(deviceType) { }
40     ~DistributedDeviceInfo() = default;
41     std::string deviceId_;
42     std::string deviceName_;
43     std::string networkId_;
44     uint16_t deviceType_;
45 };
46 
47 class DistributedExtensionService {
48 public:
49     bool initConfig();
50     int32_t InitDans();
51     int32_t ReleaseLocalDevice();
52     void OnDeviceOnline(const DmDeviceInfo &deviceInfo);
53     void OnDeviceOffline(const DmDeviceInfo &deviceInfo);
54     void OnDeviceChanged(const DmDeviceInfo &deviceInfo);
55     static DistributedExtensionService& GetInstance();
56     void HADotCallback(int32_t code, int32_t ErrCode, uint32_t branchId, std::string reason);
57     void SendReportCallback(int32_t messageType, int32_t errCode, std::string reason);
58     int32_t GetOperationReplyTimeout();
59 
60 private:
61     DistributedExtensionService();
62     ~DistributedExtensionService();
63     void SetMaxContentLength(nlohmann::json &configJson);
64     void SetOperationReplyTimeout(nlohmann::json &configJson);
65     std::string AnonymousProcessing(std::string data);
66 
67     std::mutex mapLock_;
68     std::atomic<bool> dansRunning_ = false;
69     std::shared_ptr<ffrt::queue> distributedQueue_ = nullptr;
70     std::shared_ptr<NotificationLoadUtils> dansHandler_;
71     std::map<std::string, DistributedDeviceInfo> deviceMap_;
72     DistributedDeviceConfig deviceConfig_;
73 };
74 }
75 }
76 #endif // NOTIFICATION_DISTRIBUTED_EXTENSION_SERVICE_H
77