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_SERVICE_H 17 #define OHOS_ARKCOMPILER_AOTCOMPILER_SERVICE_H 18 19 #include <mutex> 20 #include <string> 21 #include <unordered_map> 22 23 #include "aot_compiler_interface_stub.h" 24 #include "event_handler.h" 25 #include "event_runner.h" 26 #include "refbase.h" 27 #include "singleton.h" 28 #include "system_ability.h" 29 30 #include "power_disconnected_listener.h" 31 #include "screen_status_listener.h" 32 #include "thermal_mgr_listener.h" 33 34 namespace OHOS::ArkCompiler { 35 enum class ServiceRunningState { 36 STATE_NOT_START, 37 STATE_RUNNING 38 }; 39 class AotCompilerService : public SystemAbility, public AotCompilerInterfaceStub { 40 DECLARE_SYSTEM_ABILITY(AotCompilerService) 41 DECLARE_DELAYED_SINGLETON(AotCompilerService) 42 public: 43 AotCompilerService(int32_t systemAbilityId, bool runOnCreate); 44 int32_t AotCompiler(const std::unordered_map<std::string, std::string> &argsMap, 45 std::vector<int16_t> &sigData) override; 46 int32_t StopAotCompiler() override; 47 int32_t GetAOTVersion(std::string& sigData) override; 48 int32_t NeedReCompile(const std::string& args, bool& sigData) override; 49 protected: 50 void OnStart() override; 51 void OnStop() override; 52 private: 53 bool Init(); 54 void RemoveUnloadTask(const std::string &taskId); 55 void DelayUnloadTask(const std::string &taskId, const int32_t delayTime); 56 void RegisterPowerDisconnectedListener(); 57 void RegisterScreenStatusSubscriber(); 58 void RegisterThermalMgrListener(); 59 void UnRegisterPowerDisconnectedListener(); 60 void UnRegisterScreenStatusSubscriber(); 61 void UnRegisterThermalMgrListener(); 62 63 mutable std::mutex aotCompilerMutex_; 64 std::shared_ptr<AppExecFwk::EventHandler> unLoadHandler_ { nullptr }; 65 ServiceRunningState state_; 66 std::shared_ptr<PowerDisconnectedListener> powerDisconnectedListener_ { nullptr }; 67 std::shared_ptr<ScreenStatusSubscriber> screenStatusSubscriber_ { nullptr }; 68 std::shared_ptr<ThermalMgrListener> thermalMgrListener_ { nullptr }; 69 bool isPowerEventSubscribered_ { false }; 70 bool isScreenStatusSubscribered_ { false }; 71 bool isThermalLevelEventSubscribered_ { false }; 72 }; 73 } // namespace OHOS::ArkCompiler 74 #endif // OHOS_ARKCOMPILER_AOTCOMPILER_SERVICE_H