1 /* 2 * Copyright (c) 2023 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 OHOS_DP_SUBSCRIBER_INFO_H 17 #define OHOS_DP_SUBSCRIBER_INFO_H 18 19 #include <string> 20 #include <memory> 21 #include "dp_parcel.h" 22 #include "macro_utils.h" 23 #include "iremote_broker.h" 24 #include "i_profile_change_listener.h" 25 #include "distributed_device_profile_constants.h" 26 27 namespace OHOS { 28 namespace DistributedDeviceProfile { 29 class SubscribeInfo : public DpParcel { 30 public: 31 SubscribeInfo(int32_t saId, const std::string& subscribeKey, 32 std::unordered_set<ProfileChangeType> subscribeChangeTypes, sptr<IProfileChangeListener> profileChangeListener); 33 SubscribeInfo(); 34 ~SubscribeInfo(); 35 36 int32_t GetSaId() const; 37 void SetSaId(int32_t saId); 38 std::string GetSubscribeKey() const; 39 void SetSubscribeKey(const std::string& deviceId, const std::string& deviceAttribute); 40 void SetSubscribeKey(const std::string& deviceId, const std::string& serviceName, 41 const std::string& serviceAttribute); 42 void SetSubscribeKey(const std::string& deviceId, const std::string& serviceName, 43 const std::string& characteristicKey, const std::string& characteristicAttribute); 44 // subscribeTrustDeviceProfile 45 void SetSubscribeKey(const std::string& subscribeKey); 46 sptr<IRemoteObject> GetListener() const; 47 void SetListener(sptr<IProfileChangeListener> listener); 48 std::unordered_set<ProfileChangeType> GetProfileChangeTypes() const; 49 void AddProfileChangeType(ProfileChangeType profileChangeType); 50 bool Marshalling(MessageParcel& parcel) const override; 51 bool UnMarshalling(MessageParcel& parcel) override; 52 std::string dump() const override; 53 54 private: 55 int32_t saId_ = -1; 56 std::string subscribeKey_ = ""; 57 std::unordered_set<ProfileChangeType> subscribeChangeTypes_; 58 sptr<IRemoteObject> listener_ = nullptr; 59 }; 60 61 class SubscribeCompare { 62 public: 63 SubscribeCompare() = default; 64 ~SubscribeCompare() = default; 65 operator()66 int operator()(const SubscribeInfo& one, const SubscribeInfo& other) const 67 { 68 return (one.GetSaId() == other.GetSaId()) && (one.GetSubscribeKey() == other.GetSubscribeKey()); 69 } 70 }; 71 72 class SubscribeHash { 73 public: 74 SubscribeHash() = default; 75 ~SubscribeHash() = default; operator()76 int operator()(const SubscribeInfo& subscriberInfo) const 77 { 78 return subscriberInfo.GetSaId(); 79 } 80 }; 81 } // namespace DistributedDeviceProfile 82 } // namespace OHOS 83 #endif // OHOS_DP_SUBSCRIBER_INFO_H 84