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