• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "concurrent_task_controller_interface.h"
17 
18 #include <cinttypes>
19 #include <fcntl.h>
20 #include <hitrace_meter.h>
21 #include <mutex>
22 #include <sched.h>
23 #include <securec.h>
24 #include <unistd.h>
25 
26 #include <linux/sched.h>
27 #include <sys/ioctl.h>
28 #include <sys/resource.h>
29 
30 #include "accesstoken_kit.h"
31 #include "concurrent_task_log.h"
32 #include "concurrent_task_type.h"
33 #include "ipc_skeleton.h"
34 #include "parameter.h"
35 #include "rtg_interface.h"
36 
37 namespace OHOS {
38 namespace ConcurrentTask {
TaskControllerInterface()39 TaskControllerInterface::TaskControllerInterface() : funcLoader_("libtask_controller.z.so") {}
40 
GetInstance()41 TaskControllerInterface& TaskControllerInterface::GetInstance()
42 {
43     static TaskControllerInterface instance;
44     return instance;
45 }
46 
RequestAuth(const std::unordered_map<std::string,std::string> & payload)47 void TaskControllerInterface::RequestAuth(const std::unordered_map<std::string, std::string>& payload)
48 {
49     if (!inited_) {
50         CONCUR_LOGE("[TaskControllerInterface] RequestAuth failed, funcLoader_ load func failed");
51         return;
52     }
53     requestAuthFunc_(payload);
54 }
55 
ReportData(uint32_t resType,int64_t value,const std::unordered_map<std::string,std::string> & payload)56 void TaskControllerInterface::ReportData(
57     uint32_t resType, int64_t value, const std::unordered_map<std::string, std::string> &payload)
58 {
59     if (!inited_) {
60         CONCUR_LOGE("[TaskControllerInterface] ReportData failed, funcLoader_ load func failed");
61         return;
62     }
63     reportDataFunc_(resType, value, payload);
64 }
65 
ReportSceneInfo(uint32_t type,const std::unordered_map<std::string,std::string> & payload)66 void TaskControllerInterface::ReportSceneInfo(
67     uint32_t type, const std::unordered_map<std::string, std::string>& payload)
68 {
69     if (!inited_) {
70         CONCUR_LOGE("[TaskControllerInterface] ReportSceneInfo failed, funcLoader_ load func failed");
71         return;
72     }
73     reportSceneInfoFunc_(type, payload);
74 }
75 
QueryInterval(int queryItem,IntervalReply & queryRs)76 void TaskControllerInterface::QueryInterval(int queryItem, IntervalReply& queryRs)
77 {
78     if (!inited_) {
79         CONCUR_LOGE("[TaskControllerInterface] QueryInterval failed, funcLoader_ load func failed");
80         return;
81     }
82     queryIntervalFunc_(queryItem, queryRs);
83 }
84 
QueryDeadline(int queryItem,DeadlineReply & ddlReply,const std::unordered_map<std::string,std::string> & payload)85 void TaskControllerInterface::QueryDeadline(
86     int queryItem, DeadlineReply& ddlReply, const std::unordered_map<std::string, std::string>& payload)
87 {
88     if (!inited_) {
89         CONCUR_LOGE("[TaskControllerInterface] QueryDeadline failed, funcLoader_ load func failed");
90         return;
91     }
92     queryDeadlineFunc_(queryItem, ddlReply, payload);
93 }
94 
SetAudioDeadline(int queryItem,int tid,int grpId,IntervalReply & queryRs)95 void TaskControllerInterface::SetAudioDeadline(int queryItem, int tid, int grpId, IntervalReply& queryRs)
96 {
97     if (!inited_) {
98         CONCUR_LOGE("[TaskControllerInterface] SetAudioDeadline failed, funcLoader_ load func failed");
99         return;
100     }
101     setAudioDeadlineFunc_(queryItem, tid, grpId, queryRs);
102 }
103 
Init()104 void TaskControllerInterface::Init()
105 {
106     std::lock_guard<std::mutex> autoLock(funcLoaderLock_);
107     if (inited_) {
108         return;
109     }
110     if (!LoadFunc()) {
111         qosPolicy_.Init();
112         CONCUR_LOGE("TaskControllerInterface load function failed.");
113         return;
114     }
115     CONCUR_LOGI("TaskControllerInterface load function success.");
116     inited_ = true;
117     initFunc_();
118     qosPolicy_.Init();
119 }
120 
Release()121 void TaskControllerInterface::Release()
122 {
123     if (!inited_) {
124         CONCUR_LOGE("[TaskControllerInterface] Release failed, funcLoader_ load func failed");
125         return;
126     }
127     releaseFunc_();
128 }
129 
LoadFunc()130 bool TaskControllerInterface::LoadFunc()
131 {
132     reportDataFunc_ = ReportDataFunc(funcLoader_.LoadSymbol("ReportData"));
133     reportSceneInfoFunc_ = ReportSceneInfoFunc(funcLoader_.LoadSymbol("ReportSceneInfo"));
134     queryIntervalFunc_ = QueryIntervalFunc(funcLoader_.LoadSymbol("QueryInterval"));
135     queryDeadlineFunc_ = QueryDeadlineFunc(funcLoader_.LoadSymbol("QueryDeadline"));
136     setAudioDeadlineFunc_ = SetAudioDeadlineFunc(funcLoader_.LoadSymbol("SetAudioDeadline"));
137     requestAuthFunc_ = RequestAuthFunc(funcLoader_.LoadSymbol("RequestAuth"));
138     initFunc_ = InitFunc(funcLoader_.LoadSymbol("Init"));
139     releaseFunc_ = ReleaseFunc(funcLoader_.LoadSymbol("Release"));
140 
141     return funcLoader_.GetLoadSuccess();
142 }
143 } // namespace ConcurrentTask
144 } // namespace OHOS