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_PUBLISH_INFO_H 17 #define FOUNDATION_EVENT_CESFWK_KITS_NATIVE_INCLUDE_PUBLISH_INFO_H 18 19 #include "parcel.h" 20 21 namespace OHOS { 22 namespace EventFwk { 23 24 enum SubscriberType { 25 ALL_SUBSCRIBER_TYPE, 26 SYSTEM_SUBSCRIBER_TYPE 27 }; 28 29 class CommonEventPublishInfo : public Parcelable { 30 public: 31 CommonEventPublishInfo(); 32 33 /** 34 * A constructor used to create a CommonEventPublishInfo instance by copying 35 * parameters from an existing one. 36 * 37 * @param commonEventPublishInfo Indicates the publish info. 38 */ 39 explicit CommonEventPublishInfo(const CommonEventPublishInfo &commonEventPublishInfo); 40 41 ~CommonEventPublishInfo(); 42 43 /** 44 * Sets whether the type of a common event is sticky or not. 45 * 46 * @param sticky Indicates the type of a common event is sticky or not 47 */ 48 void SetSticky(bool sticky); 49 50 /** 51 * Obtains whether it is a sticky common event, which can be set 52 * by SetSticky(bool). 53 * 54 * @return Returns the common event is sticky or not. 55 */ 56 bool IsSticky() const; 57 58 /** 59 * Sets permissions for subscribers. 60 * 61 * @param subscriberPermissions Indicates the permissions for subscribers. 62 */ 63 void SetSubscriberPermissions(const std::vector<std::string> &subscriberPermissions); 64 65 /** 66 * Obtains subscriber permissions to a common event, which can be set by 67 * setSubscriberPermissions(const std::vector<std::string>&). 68 * 69 * @return Returns the permissions for subscribers. 70 */ 71 const std::vector<std::string> &GetSubscriberPermissions() const; 72 73 /** 74 * Sets whether the type of a common event is ordered or not. 75 * 76 * @param ordered Indicates the type of a common event is ordered or not. 77 */ 78 void SetOrdered(bool ordered); 79 80 /** 81 * 82 * Obtains whether it is an ordered common event, which can be set by setOrdered(boolean). 83 * set by SetOrdered(bool). 84 * 85 * @return Returns the type of a common event is ordered or not. 86 */ 87 bool IsOrdered() const; 88 89 /** 90 * Sets the bundleName. 91 * 92 * @param bundleName Indicates the bundleName of a common event. 93 */ 94 void SetBundleName(const std::string &bundleName); 95 96 /** 97 * Sets uid of subscriber. A maximum of three receiver UIDs are supported. 98 * If there are more subscribers, the publisher needs to control the permission. 99 * 100 * @param subscriberUids Indicates the uids of subscribers. 101 */ 102 void SetSubscriberUid(const std::vector<int32_t> &subscriberUids); 103 104 /** 105 * Obtains the uids of subscribers of this CommonEventPublishInfo object. 106 * 107 * @return Returns the uids of subscribers. 108 */ 109 std::vector<int32_t> GetSubscriberUid() const; 110 111 /** 112 * Sets type of subscriber. 113 * 114 * @param subscriberType Indicates the type of subscriber, which can be ALL_SUBSCRIBER_TYPE = 0 115 * or SYSTEM_SUBSCRIBER_TYPE = 1. default is ALL_SUBSCRIBER_TYPE when param is out of range. 116 */ 117 void SetSubscriberType(const int32_t &subscriberType); 118 119 /** 120 * Obtains the type of subscriber of this CommonEventPublishInfo object. 121 * 122 * @return Returns the type of subscriber. 123 */ 124 int32_t GetSubscriberType() const; 125 126 /** 127 * Obtains the bundleName of a common event 128 * 129 * @return Returns the bundleName of a common event. 130 */ 131 std::string GetBundleName() const; 132 133 /** 134 * Marshals a CommonEventData 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 CommonEventData. 143 * 144 * @return Returns the common event data. 145 */ 146 static CommonEventPublishInfo *Unmarshalling(Parcel &parcel); 147 148 private: 149 /** 150 * Reads a CommonEventData object from a Parcel. 151 * 152 * @param parcel Indicates specified Parcel object. 153 */ 154 bool ReadFromParcel(Parcel &parcel); 155 156 bool isSubscriberType(int32_t subsciberType); 157 158 private: 159 bool sticky_; 160 bool ordered_; 161 std::string bundleName_; 162 std::vector<std::string> subscriberPermissions_; 163 std::vector<int32_t> subscriberUids_; 164 int32_t subscriberType_; 165 }; 166 } // namespace EventFwk 167 } // namespace OHOS 168 169 #endif // FOUNDATION_EVENT_CESFWK_KITS_NATIVE_INCLUDE_PUBLISH_INFO_H