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 "driver_extension.h"
17
18 #include "configuration_utils.h"
19 #include "connection_manager.h"
20 #include "hilog_wrapper.h"
21 #include "js_driver_extension.h"
22 #include "runtime.h"
23 #include "driver_extension_context.h"
24
25 namespace OHOS {
26 namespace AbilityRuntime {
27 using namespace OHOS::AppExecFwk;
28
29 CreatorDriverFunc DriverExtension::creator_ = nullptr;
SetCreator(const CreatorDriverFunc & creator)30 void DriverExtension::SetCreator(const CreatorDriverFunc& creator)
31 {
32 creator_ = creator;
33 }
34
Create(const std::unique_ptr<Runtime> & runtime)35 DriverExtension* DriverExtension::Create(const std::unique_ptr<Runtime>& runtime)
36 {
37 if (!runtime) {
38 return new DriverExtension();
39 }
40
41 if (creator_) {
42 return creator_(runtime);
43 }
44
45 HILOG_INFO("DriverExtension::Create runtime");
46 switch (runtime->GetLanguage()) {
47 case Runtime::Language::JS:
48 return JsDriverExtension::Create(runtime);
49
50 default:
51 return new DriverExtension();
52 }
53 }
54
Init(const std::shared_ptr<AbilityLocalRecord> & record,const std::shared_ptr<OHOSApplication> & application,std::shared_ptr<AbilityHandler> & handler,const sptr<IRemoteObject> & token)55 void DriverExtension::Init(const std::shared_ptr<AbilityLocalRecord> &record,
56 const std::shared_ptr<OHOSApplication> &application,
57 std::shared_ptr<AbilityHandler> &handler,
58 const sptr<IRemoteObject> &token)
59 {
60 ExtensionBase<DriverExtensionContext>::Init(record, application, handler, token);
61 HILOG_INFO("DriverExtension begin init context");
62 }
63
CreateAndInitContext(const std::shared_ptr<AbilityLocalRecord> & record,const std::shared_ptr<OHOSApplication> & application,std::shared_ptr<AbilityHandler> & handler,const sptr<IRemoteObject> & token)64 std::shared_ptr<DriverExtensionContext> DriverExtension::CreateAndInitContext(
65 const std::shared_ptr<AbilityLocalRecord> &record,
66 const std::shared_ptr<OHOSApplication> &application,
67 std::shared_ptr<AbilityHandler> &handler,
68 const sptr<IRemoteObject> &token)
69 {
70 std::shared_ptr<DriverExtensionContext> context =
71 ExtensionBase<DriverExtensionContext>::CreateAndInitContext(record, application, handler, token);
72 if (context == nullptr) {
73 HILOG_ERROR("DriverExtension::CreateAndInitContext context is nullptr");
74 return context;
75 }
76 return context;
77 }
78 } // namespace AbilityRuntime
79 } // namespace OHOS
80