1 /*
2 * Copyright (c) 2022 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 #include "zidl/ressched_report.h"
16 #include <dlfcn.h>
17
18 namespace OHOS::Rosen {
19 namespace {
20 #ifdef __aarch64__
21 const std::string RES_SCHED_CLIENT_SO = "/system/lib64/libressched_client.z.so";
22 #else
23 const std::string RES_SCHED_CLIENT_SO = "/system/lib/libressched_client.z.so";
24 #endif
25 }
26
LoadReportDataFunc()27 ReportDataFunc LoadReportDataFunc()
28 {
29 auto handle = dlopen(RES_SCHED_CLIENT_SO.c_str(), RTLD_NOW);
30 if (handle == nullptr) {
31 return nullptr;
32 }
33 auto func = reinterpret_cast<ReportDataFunc>(dlsym(handle, "ReportData"));
34 if (func == nullptr) {
35 dlclose(handle);
36 return nullptr;
37 }
38 return func;
39 }
40
GetInstance()41 ResSchedReport& ResSchedReport::GetInstance()
42 {
43 static ResSchedReport instance;
44 return instance;
45 }
46
ResSchedDataReport(uint32_t resType,int32_t value,const std::unordered_map<std::string,std::string> & payload)47 void ResSchedReport::ResSchedDataReport(uint32_t resType, int32_t value,
48 const std::unordered_map<std::string, std::string>& payload)
49 {
50 if (reportDataFunc_ == nullptr) {
51 reportDataFunc_ = LoadReportDataFunc();
52 }
53 if (reportDataFunc_ != nullptr) {
54 reportDataFunc_(resType, value, payload);
55 }
56 }
57 } // namespace OHOS::Rosen