1 /* 2 * Copyright (c) 2024 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 "bridge/cj_frontend/runtime/cj_runtime_delegate.h" 17 18 #include "cj_environment.h" 19 20 using namespace OHOS::Ace::Framework; 21 22 namespace { 23 constexpr int64_t VERIFY_VERSION = 10000; 24 } 25 26 CJRuntimeDelegate* CJRuntimeDelegate::instance_ = nullptr; 27 LoadCJLibrary(const char * dlName)28void* CJRuntimeDelegate::LoadCJLibrary(const char* dlName) 29 { 30 return CJEnvironment::GetInstance()->LoadCJLibrary(dlName); 31 } 32 CheckLoadCJLibrary()33bool CJRuntimeDelegate::CheckLoadCJLibrary() 34 { 35 return CJEnvironment::GetInstance()->CheckLoadCJLibrary(); 36 } 37 GetUIScheduler()38void* CJRuntimeDelegate::GetUIScheduler() 39 { 40 return CJEnvironment::GetInstance()->GetUIScheduler(); 41 } 42 RegisterCJFuncs(AtCPackage funcs)43void CJRuntimeDelegate::RegisterCJFuncs(AtCPackage funcs) 44 { 45 if (!atCPackageLoaded_) { 46 atCPackage_ = funcs; 47 atCPackageLoaded_ = true; 48 } 49 } 50 RegisterCJFuncsV2(void (* callback)(AtCPackageV2 * cjFuncs))51void CJRuntimeDelegate::RegisterCJFuncsV2(void (*callback)(AtCPackageV2* cjFuncs)) 52 { 53 if (!atCPackageLoadedV2_) { 54 callback(&atCPackageV2_); 55 atCPackageLoadedV2_ = true; 56 } 57 } 58 RegisterCJXCompCtrFuncs(AtCXComponentCallback funcs)59void CJRuntimeDelegate::RegisterCJXCompCtrFuncs(AtCXComponentCallback funcs) 60 { 61 if (!atCXcompCtrLoaded_) { 62 atCXcompCtr_ = funcs; 63 atCXcompCtrLoaded_ = true; 64 } 65 } 66 LoadAtCPackage()67bool CJRuntimeDelegate::LoadAtCPackage() 68 { 69 if (!atCPackageLoaded_) { 70 return false; 71 } 72 bool result = false; 73 AtCOHOSAceFrameworkCJInstanceInitializeParams params(0, VERIFY_VERSION, &atCPackage_, &result); 74 atCPackage_.atCOHOSAceFrameworkCJInstanceInitialize(¶ms); 75 return result; 76 } 77 LoadAppEntry(const std::string & name)78bool CJRuntimeDelegate::LoadAppEntry(const std::string& name) 79 { 80 if (!atCPackageLoaded_ && !LoadAtCPackage()) { 81 return false; 82 } 83 bool result = false; 84 AtCOHOSAceFrameworkCJInstanceLoadEntryParams params(name.c_str(), &result); 85 atCPackage_.atCOHOSAceFrameworkCJInstanceLoadEntry(¶ms); 86 return result; 87 } 88