• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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         int32_t userId = DEFAULT_USER_ID);
34     SubscribeInfo();
35     ~SubscribeInfo();
36 
37     int32_t GetSaId() const;
38     void SetSaId(int32_t saId);
39     std::string GetSubscribeKey() const;
40     void SetSubscribeKey(const std::string& deviceId, const std::string& deviceAttribute,
41         int32_t userId = DEFAULT_USER_ID);
42     void SetSubscribeKey(const std::string& deviceId, const std::string& serviceName,
43         const std::string& serviceAttribute, int32_t userId = DEFAULT_USER_ID);
44     void SetSubscribeKey(const std::string& deviceId, const std::string& serviceName,
45         const std::string& characteristicKey, const std::string& characteristicAttribute,
46         int32_t userId = DEFAULT_USER_ID);
47     // subscribeTrustDeviceProfile
48     void SetSubscribeKey(const std::string& subscribeKey, int32_t userId = DEFAULT_USER_ID);
49     sptr<IRemoteObject> GetListener() const;
50     void SetListener(sptr<IProfileChangeListener> listener);
51     std::unordered_set<ProfileChangeType> GetProfileChangeTypes() const;
52     void AddProfileChangeType(ProfileChangeType profileChangeType);
53     bool Marshalling(MessageParcel& parcel) const override;
54     bool UnMarshalling(MessageParcel& parcel) override;
55     std::string dump() const override;
56 
57 private:
58     int32_t saId_ = -1;
59     std::string subscribeKey_ = "";
60     std::unordered_set<ProfileChangeType> subscribeChangeTypes_;
61     sptr<IRemoteObject> listener_ = nullptr;
62 };
63 
64 class SubscribeCompare {
65 public:
66     SubscribeCompare() = default;
67     ~SubscribeCompare() = default;
68 
operator()69     int operator()(const SubscribeInfo& one, const SubscribeInfo& other) const
70     {
71         return (one.GetSaId() == other.GetSaId()) && (one.GetSubscribeKey() == other.GetSubscribeKey());
72     }
73 };
74 
75 class SubscribeHash {
76 public:
77     SubscribeHash() = default;
78     ~SubscribeHash() = default;
operator()79     int operator()(const SubscribeInfo& subscriberInfo) const
80     {
81         return subscriberInfo.GetSaId();
82     }
83 };
84 } // namespace DistributedDeviceProfile
85 } // namespace OHOS
86 #endif // OHOS_DP_SUBSCRIBER_INFO_H
87