1 /* 2 * Copyright (c) 2025 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 ACCESSIBILITY_API_REPORTER_HELPER_H 17 #define ACCESSIBILITY_API_REPORTER_HELPER_H 18 19 #include "api_event_reporter.h" 20 21 namespace OHOS { 22 namespace Accessibility { 23 class ApiReportHelper { 24 public: ApiReportHelper(const std::string & name)25 ApiReportHelper(const std::string &name) 26 { 27 beginTime_ = std::chrono::duration_cast<std::chrono::milliseconds>( 28 std::chrono::system_clock::now().time_since_epoch()).count(); 29 apiName_ = name; 30 } 31 ApiReportHelper(const std::string & name,int32_t thresholdValue)32 ApiReportHelper(const std::string &name, int32_t thresholdValue) 33 { 34 beginTime_ = std::chrono::duration_cast<std::chrono::milliseconds>( 35 std::chrono::system_clock::now().time_since_epoch()).count(); 36 apiName_ = name; 37 thresholdValue_ = thresholdValue; 38 } 39 ~ApiReportHelper()40 ~ApiReportHelper() 41 { 42 Accessibility::ApiEventReporter::GetInstance().ThresholdWriteEndEvent(result_, apiName_, 43 beginTime_, thresholdValue_); 44 } 45 setResult(int result)46 void setResult(int result) 47 { 48 result_ = result; 49 } 50 setApiName(const std::string & name)51 void setApiName(const std::string &name) 52 { 53 apiName_ = name; 54 } 55 private: 56 int64_t beginTime_ = 0; 57 int32_t thresholdValue_ = 1000; 58 int result_ = 0; 59 std::string apiName_; 60 }; 61 } // namespace Accessibility 62 } // namespace OHOS 63 #endif // ACCESSIBILITY_API_REPORTER_HELPER_H