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 #ifndef OHOS_GLOBAL_I18N_I18N_SERVICE_ABILITY_LOAD_MANAGER_H 17 #define OHOS_GLOBAL_I18N_I18N_SERVICE_ABILITY_LOAD_MANAGER_H 18 19 #include <mutex> 20 #include <singleton.h> 21 #include "iremote_object.h" 22 #include "iservice_registry.h" 23 24 namespace OHOS { 25 namespace Global { 26 namespace I18n { 27 /** 28 * @brief Provides i18n service loading and unloading functions. 29 */ 30 class I18nServiceAbilityLoadManager : public DelayedSingleton<I18nServiceAbilityLoadManager> { 31 public: 32 I18nServiceAbilityLoadManager(); 33 ~I18nServiceAbilityLoadManager(); 34 35 /** 36 * @brief Get i18n service proxy. 37 * 38 * @param systemAbilityId i18n system ability id. 39 * @return sptr<IRemoteObject> i18n service proxy. 40 */ 41 sptr<IRemoteObject> GetI18nServiceAbility(int32_t systemAbilityId); 42 bool UnloadI18nService(int32_t systemAbilityId); 43 44 /** 45 * @brief Provided for I18nServiceAbilityLoadCallback to Update i18n service loading status to success. 46 */ 47 void LoadSystemAbilitySuccess(); 48 49 /** 50 * @brief Provided for I18nServiceAbilityLoadCallback to Update i18n service loading status to failed. 51 */ 52 void LoadSystemAbilityFail(); 53 54 private: 55 sptr<ISystemAbilityManager> LoadI18nServiceAbility(int32_t systemAbilityId); 56 void InitLoadState(); 57 58 /** 59 * @brief Wait i18n system ability load. 60 * 61 * @param systemAbilityId i18n system ability id. 62 * @return true Returning true indicates that the loading process has ended. 63 * @return false Returning false indicates that the loading process has been overtime. 64 */ 65 bool WaitLoadStateChange(int32_t systemAbilityId); 66 std::condition_variable loadStateCondition; 67 std::mutex loadStateMutex; 68 bool loadState = false; 69 }; 70 } // namespace I18n 71 } // namespace Global 72 } // namespace OHOS 73 #endif // OHOS_GLOBAL_I18N_I18N_SERVICE_ABILITY_LOAD_MANAGER_H