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