• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "static_subscriber_extension.h"
17 
18 #include "event_log_wrapper.h"
19 #include "js_static_subscriber_extension.h"
20 #include "runtime.h"
21 #include "static_subscriber_extension_context.h"
22 
23 namespace OHOS {
24 namespace EventFwk {
25 using namespace OHOS::AppExecFwk;
Create(const std::unique_ptr<AbilityRuntime::Runtime> & runtime)26 StaticSubscriberExtension* StaticSubscriberExtension::Create(const std::unique_ptr<AbilityRuntime::Runtime>& runtime)
27 {
28     if (!runtime) {
29         return new StaticSubscriberExtension();
30     }
31 
32     EVENT_LOGI("Create runtime");
33     switch (runtime->GetLanguage()) {
34         case AbilityRuntime::Runtime::Language::JS:
35             return JsStaticSubscriberExtension::Create(runtime);
36         default:
37             return new StaticSubscriberExtension();
38     }
39 }
40 
Init(const std::shared_ptr<AbilityLocalRecord> & record,const std::shared_ptr<OHOSApplication> & application,std::shared_ptr<AbilityHandler> & handler,const sptr<IRemoteObject> & token)41 void StaticSubscriberExtension::Init(const std::shared_ptr<AbilityLocalRecord>& record,
42     const std::shared_ptr<OHOSApplication>& application,
43     std::shared_ptr<AbilityHandler>& handler,
44     const sptr<IRemoteObject>& token)
45 {
46     EVENT_LOGI("Init");
47     ExtensionBase<StaticSubscriberExtensionContext>::Init(record, application, handler, token);
48 }
49 
CreateAndInitContext(const std::shared_ptr<AbilityLocalRecord> & record,const std::shared_ptr<OHOSApplication> & application,std::shared_ptr<AbilityHandler> & handler,const sptr<IRemoteObject> & token)50 std::shared_ptr<StaticSubscriberExtensionContext> StaticSubscriberExtension::CreateAndInitContext(
51     const std::shared_ptr<AbilityLocalRecord>& record,
52     const std::shared_ptr<OHOSApplication>& application,
53     std::shared_ptr<AbilityHandler>& handler,
54     const sptr<IRemoteObject>& token)
55 {
56     std::shared_ptr<StaticSubscriberExtensionContext> context =
57         ExtensionBase<StaticSubscriberExtensionContext>::CreateAndInitContext(record, application, handler, token);
58     if (record == nullptr) {
59         EVENT_LOGE("record is nullptr");
60         return context;
61     }
62     return context;
63 }
64 
OnReceiveEvent(std::shared_ptr<CommonEventData> data)65 void StaticSubscriberExtension::OnReceiveEvent(std::shared_ptr<CommonEventData> data)
66 {
67     EVENT_LOGD("OnReceiveEvent called.");
68 }
69 } // namespace EventFwk
70 } // namespace OHOS
71