• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 SOC_PERF_SERVICES_SERVER_INCLUDE_SOCPERF_SERVER_H
17 #define SOC_PERF_SERVICES_SERVER_INCLUDE_SOCPERF_SERVER_H
18 
19 #include "singleton.h"
20 #include "soc_perf_stub.h"
21 #include "socperf.h"
22 #include "system_ability.h"
23 
24 namespace OHOS {
25 namespace SOCPERF {
26 class SocPerfServer : public SystemAbility, public SocPerfStub,
27     public std::enable_shared_from_this<SocPerfServer> {
28 DISALLOW_COPY_AND_MOVE(SocPerfServer);
29 DECLARE_SYSTEM_ABILITY(SocPerfServer);
30 DECLARE_DELAYED_SINGLETON(SocPerfServer);
31 
32 public:
33     /**
34      * @brief Sending a performance request.
35      *
36      * @param cmdId Scene id defined in config file.
37      * @param msg Additional string info, which is used for other extensions.
38      */
39     virtual ErrCode PerfRequest(int32_t cmdId, const std::string& msg) override;
40 
41     /**
42      * @brief Sending a performance request.
43      *
44      * @param cmdId Scene id defined in config file.
45      * @param onOffTag Indicates the start of end of a long-term frequency increase event.
46      * @param msg Additional string info, which is used for other extensions.
47      */
48     virtual ErrCode PerfRequestEx(int32_t cmdId, bool onOffTag, const std::string& msg) override;
49 
50     /**
51      * @brief Sending a power limit boost request.
52      *
53      * @param onOffTag Indicates the start of end of a power limit boost event.
54      * @param msg Additional string info, which is used for other extensions.
55      */
56     virtual ErrCode PowerLimitBoost(bool onOffTag, const std::string& msg) override;
57 
58     /**
59      * @brief Sending a thermal limit boost request.
60      *
61      * @param onOffTag Indicates the start of end of a thermal limit boost event.
62      * @param msg Additional string info, which is used for other extensions.
63      */
64     virtual ErrCode ThermalLimitBoost(bool onOffTag, const std::string& msg) override;
65 
66     /**
67      * @brief Sending a limit request.
68      *
69      * @param clientId Used to indentify the caller of frequency limiting, such as
70      * the thermal module or power consumption module.
71      * @param configs Indicates the specific value to be limited.
72      * @param msg Additional string info, which is used for other extensions.
73      */
74     virtual ErrCode LimitRequest(int32_t clientId,
75         const std::vector<int32_t>& tags, const std::vector<int64_t>& configs, const std::string& msg) override;
76 
77     /**
78      * @brief set socperf server status, enable or disable
79      *
80      * @param status true means enable socperfserver, false means disable socperfserver
81      * @param msg the reason why we need change socperfserver status
82      */
83     virtual ErrCode SetRequestStatus(bool status, const std::string& msg) override;
84 
85     /**
86      * @brief set thermal level intermal for perfquest
87      *
88      * @param level thermal level
89      */
90     virtual ErrCode SetThermalLevel(int32_t level) override;
91 
92     /**
93      * @brief send the device mode, enable or disable
94      *
95      * @param mode the mode which will to be changed
96      * @param status true means socperfserver enter the device mode, false quit the device mode
97      */
98     virtual ErrCode RequestDeviceMode(const std::string& mode, bool status) override;
99 
100     /**
101      * @brief get cmd Id count, cmdID is trigger, its count++
102      * @param msg the reason
103      * @param funcResult return cmdId count, as 10000:xx,10001:xx
104      */
105     virtual ErrCode RequestCmdIdCount(const std::string& msg, std::string& funcResult) override;
106     int32_t Dump(int32_t fd, const std::vector<std::u16string>& args) override;
107 
108 public:
109     SocPerfServer(int32_t systemAbilityId, bool runOnCreate);
110 
111 protected:
112     void OnStart() override;
113     void OnStop() override;
114 
115 private:
116     SocPerf socPerf;
117     bool AllowDump();
118     bool HasPerfPermission();
119 };
120 } // namespace SOCPERF
121 } // namespace OHOS
122 
123 #endif // SOC_PERF_SERVICES_SERVER_INCLUDE_SOCPERF_SERVER_H
124