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 #ifndef OHOS_ARKCOMPILER_AOTCOMPILER_CLIENT_H 17 #define OHOS_ARKCOMPILER_AOTCOMPILER_CLIENT_H 18 19 #include <condition_variable> 20 #include <functional> 21 #include <mutex> 22 #include <string> 23 #include <unordered_map> 24 25 #include "iaot_compiler_interface.h" 26 #include "singleton.h" 27 28 namespace OHOS::ArkCompiler { 29 class AotCompilerClient { 30 public: 31 AotCompilerClient(); 32 virtual ~AotCompilerClient() = default; 33 static AotCompilerClient &GetInstance(); 34 int32_t AotCompiler(const std::unordered_map<std::string, std::string> &argsMap, 35 std::vector<int16_t> &sigData); 36 int32_t StopAotCompiler(); 37 int32_t NeedReCompile(const std::string& oldVersion, bool& sigData); 38 int32_t GetAOTVersion(std::string& sigData); 39 void OnLoadSystemAbilitySuccess(const sptr<IRemoteObject> &remoteObject); 40 void OnLoadSystemAbilityFail(); 41 void AotCompilerOnRemoteDied(const wptr<IRemoteObject> &remoteObject); 42 43 private: 44 sptr<IAotCompilerInterface> GetAotCompilerProxy(); 45 bool LoadAotCompilerService(); 46 void SetAotCompiler(const sptr<IRemoteObject> &remoteObject); 47 sptr<IAotCompilerInterface> GetAotCompiler(); 48 class AotCompilerDiedRecipient : public IRemoteObject::DeathRecipient { 49 public: 50 void OnRemoteDied(const wptr<IRemoteObject> &remote) override; 51 }; 52 53 private: 54 std::condition_variable loadSaCondition_; 55 std::mutex loadSaMutex_; 56 bool loadSaFinished_ {false}; 57 std::mutex mutex_; 58 sptr<IAotCompilerInterface> aotCompilerProxy_ = nullptr; 59 sptr<AotCompilerDiedRecipient> aotCompilerDiedRecipient_ = nullptr; 60 DISALLOW_COPY_AND_MOVE(AotCompilerClient); 61 }; 62 } // namespace OHOS::ArkCompiler 63 #endif // OHOS_ARKCOMPILER_AOTCOMPILER_CLIENT_H