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