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_INNERKITS_INCLUDE_COMMON_EVENT_PROXY_H 17 #define FOUNDATION_EVENT_CESFWK_INNERKITS_INCLUDE_COMMON_EVENT_PROXY_H 18 19 #include "icommon_event.h" 20 #include "iremote_proxy.h" 21 22 namespace OHOS { 23 namespace EventFwk { 24 class CommonEventProxy : public IRemoteProxy<ICommonEvent> { 25 public: 26 /** 27 * Constructor. 28 * 29 * @param object Indicates the remote object 30 */ 31 explicit CommonEventProxy(const sptr<IRemoteObject> &object); 32 33 virtual ~CommonEventProxy(); 34 35 /** 36 * Publishes a common event. 37 * 38 * @param event Indicates the common event data. 39 * @param publishInfo Indicates the publish info. 40 * @param commonEventListener Indicates the last subscriber to receive the event. 41 * @param userId Indicates the user ID. 42 * @return Returns true if success; false otherwise. 43 */ 44 int32_t PublishCommonEvent(const CommonEventData &event, const CommonEventPublishInfo &publishInfo, 45 const sptr<IRemoteObject> &commonEventListener, const int32_t &userId) override; 46 47 /** 48 * Publishes a common event. 49 * 50 * @param event Indicates the common event data 51 * @param publishInfo Indicates the publish info 52 * @param commonEventListener Indicates the last subscriber to receive the event 53 * @param uid Indicates the uid 54 * @param callerToken Indicates the caller token 55 * @param userId Indicates the user ID 56 * @return Returns true if success; false otherwise. 57 */ 58 bool PublishCommonEvent(const CommonEventData &event, const CommonEventPublishInfo &publishinfo, 59 const sptr<IRemoteObject> &commonEventListener, const uid_t &uid, const int32_t &callerToken, 60 const int32_t &userId) override; 61 62 /** 63 * Subscribes to common events. 64 * 65 * @param subscribeInfo Indicates the subscribe information 66 * @param commonEventListener Indicates the subscriber object 67 * @return Returns true if successful; false otherwise. 68 */ 69 int32_t SubscribeCommonEvent( 70 const CommonEventSubscribeInfo &subscribeInfo, const sptr<IRemoteObject> &commonEventListener) override; 71 72 /** 73 * Unsubscribes from common events. 74 * 75 * @param commonEventListener Indicates the subscriber object 76 * @return Returns true if successful; false otherwise. 77 */ 78 int32_t UnsubscribeCommonEvent(const sptr<IRemoteObject> &commonEventListener) override; 79 80 /** 81 * Gets the current sticky common event 82 * 83 * @param event Indicates the common event. 84 * @param eventData Indicates the common event data. 85 * @return Returns true if successful; false otherwise. 86 */ 87 bool GetStickyCommonEvent(const std::string &event, CommonEventData &eventData) override; 88 89 /** 90 * Dumps the state for common event service. 91 * 92 * @param dumpType Indicates the dump type. 93 * @param event Indicates the specified event. 94 * @param userId Indicates the user id. 95 * @param state Indicates the output result. 96 * @return Returns true if successful; false otherwise. 97 */ 98 bool DumpState(const uint8_t &dumpType, const std::string &event, const int32_t &userId, 99 std::vector<std::string> &state) override; 100 101 /** 102 * Finishes the receiver for the ordered common event. 103 * 104 * @param proxy Indicates the current subscriber object. 105 * @param code Indicates the result code. 106 * @param receiverData Indicates the result data. 107 * @param abortEvent Indicates whether the current ordered common event should be aborted. 108 * @return Returns true if successful; false otherwise. 109 */ 110 bool FinishReceiver(const sptr<IRemoteObject> &proxy, const int32_t &code, const std::string &receiverData, 111 const bool &abortEvent) override; 112 113 /** 114 * Freezes the specified process. 115 * 116 * @param uid Indicates the uid of frozen process. 117 * @return Returns true if successful; false otherwise. 118 */ 119 bool Freeze(const uid_t &uid) override; 120 121 /** 122 * Unfreezes the specified process. 123 * 124 * @param uid Indicates the uid of unfrozen process. 125 * @return Returns true if successful; false otherwise. 126 */ 127 bool Unfreeze(const uid_t &uid) override; 128 129 /** 130 * Unfreezes all frozen applications. 131 * 132 * @return Returns true if successful; false otherwise. 133 */ 134 bool UnfreezeAll() override; 135 136 private: 137 bool SendRequest(ICommonEvent::Message code, MessageParcel &data, MessageParcel &reply); 138 139 private: 140 static inline BrokerDelegator<CommonEventProxy> delegator_; 141 }; 142 } // namespace EventFwk 143 } // namespace OHOS 144 145 #endif // FOUNDATION_EVENT_CESFWK_INNERKITS_INCLUDE_COMMON_EVENT_PROXY_H 146