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 RESSCHED_EXECUTOR_SERVICES_RESSCHEDEXESERVICE_INCLUDE_RES_SCHED_EXE_SERVICE_H 17 #define RESSCHED_EXECUTOR_SERVICES_RESSCHEDEXESERVICE_INCLUDE_RES_SCHED_EXE_SERVICE_H 18 19 #include "singleton.h" 20 #include "system_ability.h" 21 22 #include "res_json_type.h" 23 #include "res_sched_exe_service_stub.h" 24 25 namespace OHOS { 26 namespace ResourceSchedule { 27 class ResSchedExeService : public ResSchedExeServiceStub, public SystemAbility, 28 public std::enable_shared_from_this<ResSchedExeService> { 29 DECLARE_SYSTEM_ABILITY(ResSchedExeService); 30 DECLARE_DELAYED_SINGLETON(ResSchedExeService); 31 DISALLOW_COPY_AND_MOVE(ResSchedExeService); 32 33 public: 34 /** 35 * @brief Send request sync to the ressched_executor through inter-process communication. 36 * 37 * @param resType Indicates the resource type, all of the type have listed in res_exe_type.h. 38 * @param value Indicates the value of the resource type, defined by the developers. 39 * @param context Indicates the context info of the resource type event. 40 * @param response Indicates the context info of the ipc reply. 41 * @param funcResult function result 42 * @return ErrCode 43 */ 44 ErrCode SendRequestSync(uint32_t resType, int64_t value, 45 const ResJsonType& context, ResJsonType& response, int32_t& funcResult) override; 46 47 /** 48 * @brief Send request async to the ressched_executor through inter-process communication. 49 * 50 * @param resType Indicates the resource type, all of the type have listed in res_exe_type.h. 51 * @param value Indicates the value of the resource type, defined by the developers. 52 * @param context Indicates the context info of the resource type event. 53 * @return ErrCode 54 */ 55 ErrCode SendRequestAsync(uint32_t resType, int64_t value, const ResJsonType& context) override; 56 57 /** 58 * @brief Send kill process request async to the ressched_executor. 59 * 60 * @param pid the pid whiche will be killed. 61 * @param funcResult function result 62 * @return ErrCode 63 */ 64 ErrCode KillProcess(uint32_t pid, int32_t& funcResult) override; 65 66 /** 67 * @brief Support dump option. 68 * 69 * @param fd Save dump result to the file. 70 * @param args Dump option arguments. 71 */ 72 int32_t Dump(int32_t fd, const std::vector<std::u16string>& args) override; 73 74 public: 75 ResSchedExeService(int32_t systemAbilityId, bool runOnCreate); 76 77 protected: 78 void OnStart() override; 79 void OnStop() override; 80 81 private: 82 void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; 83 bool AllowDump(); 84 void DumpAllInfo(std::string &result); 85 void DumpUsage(std::string &result); 86 }; 87 } // namespace ResourceSchedule 88 } // namespace OHOS 89 90 #endif // RESSCHED_EXECUTOR_SERVICES_RESSCHEDEXESERVICE_INCLUDE_RES_SCHED_EXE_SERVICE_H 91