1 /* 2 * Copyright (c) 2023 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 OHOS_COMMON_EVENT_SERVICE_JS_STATIC_SUBSCRIBER_EXTENSION_H 17 #define OHOS_COMMON_EVENT_SERVICE_JS_STATIC_SUBSCRIBER_EXTENSION_H 18 19 #include "common_event_data.h" 20 #include "js_runtime.h" 21 #include "native_engine/native_reference.h" 22 #include "native_engine/native_value.h" 23 #include "runtime.h" 24 #include "static_subscriber_extension.h" 25 26 namespace OHOS { 27 namespace EventFwk { 28 class JsStaticSubscriberExtension : public StaticSubscriberExtension { 29 public: 30 explicit JsStaticSubscriberExtension(AbilityRuntime::JsRuntime& jsRuntime); 31 virtual ~JsStaticSubscriberExtension() override; 32 33 /** 34 * @brief Create JsStaticSubscriberExtension. 35 * 36 * @param runtime The runtime. 37 * @return The JsStaticSubscriberExtension instance. 38 */ 39 static JsStaticSubscriberExtension* Create(const std::unique_ptr<AbilityRuntime::Runtime>& runtime); 40 41 void Init(const std::shared_ptr<AppExecFwk::AbilityLocalRecord>& record, 42 const std::shared_ptr<AppExecFwk::OHOSApplication>& application, 43 std::shared_ptr<AppExecFwk::AbilityHandler>& handler, 44 const sptr<IRemoteObject>& token) override; 45 46 void OnStart(const AAFwk::Want& want) override; 47 48 sptr<IRemoteObject> OnConnect(const AAFwk::Want& want) override; 49 50 void OnDisconnect(const AAFwk::Want& want) override; 51 52 void OnStop() override; 53 54 void OnReceiveEvent(std::shared_ptr<CommonEventData> data) override; 55 56 private: 57 AbilityRuntime::JsRuntime& jsRuntime_; 58 std::unique_ptr<NativeReference> jsObj_; 59 }; 60 } // namespace EventFwk 61 } // namespace OHOS 62 #endif // OHOS_COMMON_EVENT_SERVICE_JS_STATIC_SUBSCRIBER_EXTENSION_H 63