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 "res_sched_exe_service_stub.h"
20 
21 namespace OHOS {
22 namespace ResourceSchedule {
23 class ResSchedExeService : public ResSchedExeServiceStub {
24 public:
25     /**
26      * @brief Construct a new ResSchedExeService object.
27      */
28     ResSchedExeService() = default;
29 
30     /**
31      * @brief Destroy the ResSchedExeService object.
32      */
33     ~ResSchedExeService() override = default;
34 
35     /**
36      * @brief Send request sync to the ressched_executor through inter-process communication.
37      *
38      * @param resType Indicates the resource type, all of the type have listed in res_exe_type.h.
39      * @param value Indicates the value of the resource type, defined by the developers.
40      * @param context Indicates the context info of the resource type event.
41      * @param reply Indicates the context info of the ipc reply.
42      * @return function result
43      */
44     int32_t SendRequestSync(uint32_t resType, int64_t value,
45         const nlohmann::json& context, nlohmann::json& reply) 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      */
54     void SendRequestAsync(uint32_t resType, int64_t value, const nlohmann::json& context) override;
55 
56     /**
57      * @brief Send kill process request async to the ressched_executor.
58      *
59      * @param pid the pid whiche will be killed.
60      */
61     int32_t KillProcess(pid_t pid) override;
62 
63     /**
64      * @brief Support dump option.
65      *
66      * @param fd Save dump result to the file.
67      * @param args Dump option arguments.
68      */
69     int32_t Dump(int32_t fd, const std::vector<std::u16string>& args) override;
70 
71 private:
72     bool AllowDump();
73     void DumpAllInfo(std::string &result);
74     void DumpUsage(std::string &result);
75     DISALLOW_COPY_AND_MOVE(ResSchedExeService);
76 };
77 } // namespace ResourceSchedule
78 } // namespace OHOS
79 
80 #endif // RESSCHED_EXECUTOR_SERVICES_RESSCHEDEXESERVICE_INCLUDE_RES_SCHED_EXE_SERVICE_H
81