1 /*
2 * Copyright (c) 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 #include "distributed_extension_context_js.h"
17
18 #include "dtbschedmgr_log.h"
19 #include "js_extension_context.h"
20 #include "js_runtime.h"
21
22 namespace OHOS {
23 namespace DistributedSchedule {
24 const std::string TAG = "DistributedExtensionContextJS";
25
CreateDistributedExtensionContextJS(napi_env env,std::shared_ptr<DistributedExtensionContext> context)26 napi_value CreateDistributedExtensionContextJS(napi_env env, std::shared_ptr<DistributedExtensionContext> context)
27 {
28 if (context == nullptr) {
29 HILOGE("Failed to CreateDistributedExtensionContextJS, context is nullptr.");
30 return nullptr;
31 }
32 std::shared_ptr<OHOS::AppExecFwk::AbilityInfo> abilityInfo = context->GetAbilityInfo();
33 napi_value object = CreateJsExtensionContext(env, context, abilityInfo);
34 if (object == nullptr) {
35 HILOGE("Failed to CreateJsServiceExtensionContext, context is nullptr.");
36 return nullptr;
37 }
38 std::unique_ptr<DistributedExtensionContextJS> jsContext =
39 std::make_unique<DistributedExtensionContextJS>(context);
40 napi_wrap(env, object, jsContext.release(), DistributedExtensionContextJS::Finalizer, nullptr, nullptr);
41 return object;
42 }
43
Finalizer(napi_env env,void * data,void * hint)44 void DistributedExtensionContextJS::Finalizer(napi_env env, void* data, void* hint)
45 {
46 HILOGI("Finalizer Called.");
47 std::unique_ptr<DistributedExtensionContextJS>(static_cast<DistributedExtensionContextJS*>(data));
48 }
49 }
50 }
51