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 <string> 19 #include <utility> 20 21 #include "base/log/log.h" 22 #include "ffi_remote_data.h" 23 #include "cj_environment.h" 24 25 using namespace OHOS::Ace::Framework; 26 27 namespace { 28 constexpr int64_t VERIFY_VERSION = 10000; 29 } 30 31 CJRuntimeDelegate* CJRuntimeDelegate::instance_ = nullptr; 32 LoadCJLibrary(const char * dlName)33void* CJRuntimeDelegate::LoadCJLibrary(const char* dlName) 34 { 35 return CJEnvironment::GetInstance()->LoadCJLibrary(dlName); 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 LoadAtCPackage()51bool CJRuntimeDelegate::LoadAtCPackage() 52 { 53 if (!atCPackageLoaded_) { 54 return false; 55 } 56 bool result = false; 57 AtCOHOSAceFrameworkCJInstanceInitializeParams params(0, VERIFY_VERSION, &atCPackage_, &result); 58 atCPackage_.atCOHOSAceFrameworkCJInstanceInitialize(¶ms); 59 return result; 60 } 61 LoadAppEntry(const std::string & name)62bool CJRuntimeDelegate::LoadAppEntry(const std::string& name) 63 { 64 if (!atCPackageLoaded_ && !LoadAtCPackage()) { 65 return false; 66 } 67 bool result = false; 68 AtCOHOSAceFrameworkCJInstanceLoadEntryParams params(name.c_str(), &result); 69 atCPackage_.atCOHOSAceFrameworkCJInstanceLoadEntry(¶ms); 70 return result; 71 } 72