1 /* 2 * Copyright (c) 2022 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 "interfaces/inner_api/ace/hot_reloader.h" 17 18 #include "utils.h" 19 20 namespace OHOS::Ace { 21 22 #if defined(WINDOWS_PLATFORM) 23 constexpr char ACE_LIB_NAME[] = "libace.dll"; 24 #elif defined(MAC_PLATFORM) 25 constexpr char ACE_LIB_NAME[] = "libace.dylib"; 26 #elif defined(LINUX_PLATFORM) 27 constexpr char ACE_LIB_NAME[] = "libace.so"; 28 #else 29 constexpr char ACE_LIB_NAME[] = "libace.z.so"; 30 #endif 31 32 using ReloadFunc = void (*)(); 33 constexpr char HOT_RELOAD_FUNC[] = "OHOS_ACE_HotReloadPage"; 34 InitAceModule()35void InitAceModule() 36 { 37 LIBHANDLE handle = LOADLIB(ACE_LIB_NAME); 38 if (handle == nullptr) { 39 return; 40 } 41 42 auto entry = reinterpret_cast<ReloadFunc>(LOADSYM(handle, HOT_RELOAD_FUNC)); 43 if (entry == nullptr) { 44 FREELIB(handle); 45 return; 46 } 47 48 entry(); 49 } 50 HotReload()51void HotReloader::HotReload() 52 { 53 InitAceModule(); 54 } 55 56 } // namespace OHOS::Ace 57