• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 FOUNDATION_EVENT_CESFWK_KITS_NATIVE_INCLUDE_COMMON_EVENT_SUBSCRIBE_INFO_H
17 #define FOUNDATION_EVENT_CESFWK_KITS_NATIVE_INCLUDE_COMMON_EVENT_SUBSCRIBE_INFO_H
18 
19 #include "matching_skills.h"
20 
21 namespace OHOS {
22 namespace EventFwk {
23 class CommonEventSubscribeInfo : public Parcelable {
24 public:
25     enum ThreadMode {
26         HANDLER,     // the main thread of this ability.
27         POST,        // the event dispatch thread.
28         ASYNC,       // an asynchronous thread.
29         BACKGROUND,  // the background thread.
30     };
31 
32     /**
33      * A constructor used to create a CommonEventSubscribeInfo instance
34      * with the matchingSkills parameters passed.
35      *
36      * @param matchingSkills Indicates the matching skills.
37      */
38     explicit CommonEventSubscribeInfo(const MatchingSkills &matchingSkills);
39 
40     CommonEventSubscribeInfo();
41 
42     /**
43      * A constructor used to create a CommonEventSubscribeInfo instance by
44      * copying parameters from an existing one.
45      *
46      *  @param commonEventSubscribeInfo Indicates the commonEventSubscribeInfo.
47      */
48     explicit CommonEventSubscribeInfo(const CommonEventSubscribeInfo &commonEventSubscribeInfo);
49 
50     ~CommonEventSubscribeInfo();
51 
52     /**
53      * Sets the subscriber priority for this CommonEventSubscribeInfo object.
54      *
55      * @param priority Indicates the subscriber priority.
56      */
57     void SetPriority(const int32_t &priority);
58 
59     /**
60      * Obtains the subscriber priority of this CommonEventSubscribeInfo object.
61      *
62      * @return Returns the subscriber priority.
63      */
64     int32_t GetPriority() const;
65 
66     /**
67      * Sets the subscriber userId for this CommonEventSubscribeInfo object.
68      *
69      * @param userId Indicates the user ID of the subscriber.
70      */
71     void SetUserId(const int32_t &userId);
72 
73     /**
74      * Obtains the subscriber userId of this CommonEventSubscribeInfo object.
75      *
76      * @return Returns the user ID of the subscriber.
77      */
78     int32_t GetUserId() const;
79 
80     /**
81      * Sets the permission that the publisher must have in order to send
82      * a common event to this subscriber.
83      *
84      * @param permission Indicates the subscriber permission.
85      */
86     void SetPermission(const std::string &permission);
87 
88     /**
89      * Obtains the publisher permission of this CommonEventSubscribeInfo object.
90      *
91      * @return Returns the subscriber permission.
92      */
93     std::string GetPermission() const;
94 
95     /**
96      * Obtains the thread mode of this CommonEventSubscribeInfo object.
97      *
98      * @return Returns the thread mode.
99      */
100     CommonEventSubscribeInfo::ThreadMode GetThreadMode() const;
101 
102     /**
103      * Sets the thread mode of this CommonEventSubscribeInfo object.
104      *
105      * @param threadMode Indicates the thread mode to be set, which is specified in ThreadMode. Currently, only the
106      * HANDLER mode is supported.
107      */
108     void SetThreadMode(CommonEventSubscribeInfo::ThreadMode threadMode);
109 
110     /**
111      * Sets the device ID for this CommonEventSubscribeInfo object.
112      * Your application will only receive common events sent from the specified device.
113      *
114      * @param deviceId Indicates the device ID. The value must be an existing device ID on the same ohos network.
115      * Otherwise, it is invalid.
116      */
117     void SetDeviceId(const std::string &deviceId);
118 
119     /**
120      * Obtains the device ID in this CommonEventSubscribeInfo object.
121      *
122      * @return Returns the device ID.
123      */
124     std::string GetDeviceId() const;
125 
126     /**
127      * Obtains the MatchingSkills object carried in this CommonEventSubscribeInfo object.
128      *
129      * @return Returns the matchingSkills object.
130      */
131     const MatchingSkills &GetMatchingSkills() const;
132 
133     /**
134      * Marshals a subscriber info object into a Parcel.
135      *
136      * @param parcel Indicates specified Parcel object.
137      * @return Returns true if success; false otherwise.
138      */
139     virtual bool Marshalling(Parcel &parcel) const override;
140 
141     /**
142      * Unmarshals a Parcel object into a subscriber info.
143      *
144      * @return Returns the subscriber info.
145      */
146     static CommonEventSubscribeInfo *Unmarshalling(Parcel &parcel);
147 
148 private:
149     /**
150      * Read a subscriber object from a Parcel.
151      *
152      * @param parcel Indicates specified Parcel object.
153      * @return Returns true if success; false otherwise.
154      */
155     bool ReadFromParcel(Parcel &parcel);
156 
157 private:
158     MatchingSkills matchingSkills_;
159     int32_t priority_;
160     int32_t userId_;
161     std::string permission_;
162     std::string deviceId_;
163     CommonEventSubscribeInfo::ThreadMode threadMode_;
164 };
165 }  // namespace EventFwk
166 }  // namespace OHOS
167 
168 #endif  // FOUNDATION_EVENT_CESFWK_KITS_NATIVE_INCLUDE_COMMON_EVENT_SUBSCRIBE_INFO_H
169