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