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 BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_H 17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_H 18 19 #include <string> 20 #include "ffrt.h" 21 #include "socket.h" 22 #include "distributed_subscriber.h" 23 #include "distributed_device_data.h" 24 #include "request_box.h" 25 #include "match_box.h" 26 #include <functional> 27 #include "bundle_icon_box.h" 28 #include <unordered_set> 29 #include "distributed_data_define.h" 30 #include "response_box.h" 31 32 namespace OHOS { 33 namespace Notification { 34 35 class DistributedService { 36 public: 37 DistributedService(); 38 static DistributedService& GetInstance(); 39 void DestroyService(); 40 int32_t InitService(const std::string &deviceId, uint16_t deviceType); 41 void AddDevice(DistributedDeviceInfo device); 42 void ReleaseDevice(const std::string &deviceId, uint16_t deviceType); 43 void DeviceStatusChange(const DeviceStatueChangeInfo& changeInfo); 44 void OnConsumed(const std::shared_ptr<Notification> &request, 45 const DistributedDeviceInfo& device); 46 void OnApplicationInfnChanged(const std::string& bundleName); 47 int32_t OnOperationResponse(const std::shared_ptr<NotificationOperationInfo>& operationInfo, 48 const DistributedDeviceInfo& device); 49 void OnCanceled(const std::shared_ptr<Notification>& notification, const DistributedDeviceInfo& peerDevice); 50 void OnBatchCanceled(const std::vector<std::shared_ptr<Notification>>& notifications, 51 const DistributedDeviceInfo& peerDevice); 52 void OnReceiveMsg(const void *data, uint32_t dataLen); 53 #ifdef DISTRIBUTED_FEATURE_MASTER 54 void HandleBundlesEvent(const std::string& bundleName, const std::string& action); 55 void HandleDeviceUsingChange(const DeviceStatueChangeInfo& changeInfo); 56 #else 57 void SyncDeviceStatus(int32_t status); 58 void SyncInstalledBundle(const std::string& bundleName, bool isAdd); 59 #endif 60 std::string GetNotificationKey(const std::shared_ptr<Notification>& notification); 61 constexpr static const char* WEARABLE_DEVICE_TYPE = "wearable"; 62 constexpr static const char* LITEWEARABLE_DEVICE_TYPE = "liteWearable"; 63 constexpr static const char* PAD_DEVICE_TYPE = "tablet"; 64 constexpr static const char* PC_DEVICE_TYPE = "2in1"; 65 constexpr static const char* PHONE_DEVICE_TYPE = "phone"; 66 private: 67 void OnHandleMsg(std::shared_ptr<TlvBox>& box); 68 void ConnectPeerDevice(DistributedDeviceInfo device); 69 void HandleMatchSync(const std::shared_ptr<TlvBox>& boxMessage); 70 bool OnConsumedSetFlags(const std::shared_ptr<Notification> &request, 71 const DistributedDeviceInfo& peerDevice); 72 73 private: 74 std::shared_ptr<ffrt::queue> serviceQueue_ = nullptr; 75 }; 76 } 77 } 78 #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_H 79