1 /* 2 * Copyright (c) 2022-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 RESSCHED_SERVICES_RESSCHEDMGR_RESSCHEDFWK_INCLUDE_RES_SCHED_MGR_H 17 #define RESSCHED_SERVICES_RESSCHEDMGR_RESSCHEDFWK_INCLUDE_RES_SCHED_MGR_H 18 19 #include <sys/types.h> 20 #include <string> 21 #include "event_handler.h" 22 #include "kill_process.h" 23 #include "single_instance.h" 24 #include "nlohmann/json.hpp" 25 26 namespace OHOS { 27 namespace ResourceSchedule { 28 class ResSchedMgr { 29 DECLARE_SINGLE_INSTANCE(ResSchedMgr); 30 31 public: 32 /** 33 * Init resource schedule manager. 34 */ 35 void Init(); 36 37 /** 38 * Stop resource schedule manager. 39 */ 40 void Stop(); 41 42 /** 43 * Report data from other modules, will report resource data async. 44 * 45 * @param resType Resource type 46 * @param value bit64 content. 47 * @param payload Extra content. 48 */ 49 void ReportData(uint32_t resType, int64_t value = 0, const nlohmann::json& payload = nullptr); 50 51 /** 52 * Report data inner, will report resource data async. 53 * 54 * @param resType Resource type. 55 * @param value bit64 content. 56 * @param payload Extra content. 57 */ 58 void ReportDataInner(uint32_t resType, int64_t value = 0, const nlohmann::json& payload = nullptr); 59 60 /** 61 * Kill process by pid. 62 * 63 * @param payload process message 64 * @param killClientInitiator who want to kill other 65 */ 66 int32_t KillProcessByClient(const nlohmann::json& payload = nullptr, std::string killClientInitiator = ""); 67 private: 68 void DispatchResourceInner(uint32_t resType, int64_t value, const nlohmann::json& payload); 69 std::shared_ptr<KillProcess> killProcess_ = nullptr; 70 }; 71 } // namespace ResourceSchedule 72 } // namespace OHOS 73 74 #endif // RESSCHED_SERVICES_RESSCHEDMGR_RESSCHEDFWK_INCLUDE_RES_SCHED_MGR_H 75