1 /* 2 * Copyright (c) 2022-2025 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_SERVICES_INCLUDE_STATIC_SUBSCRIBER_CONNECTION_H 17 #define FOUNDATION_EVENT_CESFWK_SERVICES_INCLUDE_STATIC_SUBSCRIBER_CONNECTION_H 18 19 #include <ffrt.h> 20 21 #include "ability_connect_callback_stub.h" 22 #include "common_event_data.h" 23 #include "static_subscriber_proxy.h" 24 25 namespace OHOS { 26 namespace EventFwk { 27 class StaticSubscriberConnection : public AAFwk::AbilityConnectionStub { 28 public: 29 /** 30 * Constructor. 31 * 32 * @param event, Indicates the common event data. 33 */ StaticSubscriberConnection(const CommonEventData & event,const std::string & connectionKey)34 explicit StaticSubscriberConnection(const CommonEventData &event, const std::string &connectionKey) 35 { 36 staticNotifyQueue_ = std::make_shared<ffrt::queue>("StaticSubscriberConnection"); 37 events_.push_back(event); 38 connectionKey_ = connectionKey; 39 } 40 41 /** 42 * OnAbilityConnectDone, Ability Manager Service notify caller ability the result of connect. 43 * 44 * @param element, Indicates elementName of service ability. 45 * @param remoteObject, Indicates the session proxy of service ability. 46 * @param resultCode, Returns ERR_OK on success, others on failure. 47 */ 48 void OnAbilityConnectDone( 49 const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int resultCode) override; 50 51 /** 52 * OnAbilityDisconnectDone, Ability Manager Service notify caller ability the result of disconnect. 53 * 54 * @param element, Indicates elementName of service ability. 55 * @param resultCode, Returns ERR_OK on success, others on failure. 56 */ 57 void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) override; 58 59 void NotifyEvent(const CommonEventData &event); 60 void RemoveEvent(const std::string &action); IsEmptyAction()61 bool IsEmptyAction() 62 { 63 return action_.empty(); 64 } 65 66 private: 67 sptr<StaticSubscriberProxy> GetProxy(const sptr<IRemoteObject> &remoteObject); 68 sptr<StaticSubscriberProxy> proxy_ = nullptr; 69 ffrt::recursive_mutex mutex_; 70 std::vector<CommonEventData> events_; 71 std::vector<std::string> action_; 72 std::shared_ptr<ffrt::queue> staticNotifyQueue_ = nullptr; 73 std::string connectionKey_ = ""; 74 }; 75 } // namespace EventFwk 76 } // namespace OHOS 77 #endif // FOUNDATION_EVENT_CESFWK_SERVICES_INCLUDE_STATIC_SUBSCRIBER_CONNECTION_H 78